I have an API that a client is trying to use and they need Swagger documentation for it. They take it and upload it into a very strict interpreter that gives unhelpful error messages and I’m not sure what the problem with my docs are. Here’s an abbreviated part that is the problem area:
{
"info": { ... },
"paths": { ... },
"components" : {
"schemas" : {
"ItemImport" : {
"type" : "object",
"properties" : {
"items" : {
"type" : "array",
"items" : {
"$ref" : "#/components/schemas/ItemImportResource"
},
"example" : [ {
"date_field" : "2020-01-01"
} ]
}
}
},
"ItemImportResource" : {
"type" : "object",
"required" : ["date_field"],
"properties" : {
"date_field" : {
"type" : "string",
"format" : "date",
"pattern": "^[0-9]{4}-(0[1-9]|1[0-2])-(0[1-9]|[1-2][0-9]|3[0-1])$",
"description" : "description",
"example" : "2020-01-01",
"minLength": 0,
"maxLength": 10
}
}
}
}
}
}
This is the error that comes back
Swagger document is invalid - Data and type mismatch found. #/components/schemas/ItemImport/properties/items/example/0/date_field
It obviously doesn’t like the date_field
but according to the Swagger docs https://swagger.io/docs/specification/data-models/data-types/https://swagger.io/docs/specification/data-models/data-types/ I don’t know what other fields to add.
Furthermore if I change "pattern"
from
"pattern": "^[0-9]{4}-(0[1-9]|1[0-2])-(0[1-9]|[1-2][0-9]|3[0-1])$",
to
"pattern": /^[0-9]{4}-(0[1-9]|1[0-2])-(0[1-9]|[1-2][0-9]|3[0-1])$/,
I then get this error
Swagger document is invalid - The field 'info' in 'document' object is REQUIRED. #/info The field 'paths' in 'document' object is REQUIRED. #/paths
which also makes no sense because I have both the info
and paths
keys in the docs (I just omitted the innards of them).
Anyone have any idea what I’m missing here?
4