JSON Schema validation error when submitting a form with a date field
See original GitHub issueHi! I have a swagger file that looks like this:
paths:
/purchases:
post:
summary: Submit a purchase
description: |
Purchase form
consumes:
- application/json
parameters:
- name: body
in: body
required: true
schema:
$ref: '#/definitions/Booking'
responses:
200:
description: Purchase successful
schema:
$ref: '#/definitions/Success'
definitions:
Booking:
type: object
properties:
tour_id:
type: integer
format: int32
date:
type: string
format: date
Note the date field that has a format date
.
When I submit a POST request to /purchases
with a body that looks like this:
{
"tour_id": 1,
"date": "2017-08-11"
}
I get this error:
JSON Schema validation error.
Data path: "date"
Schema path: "/items/properties/date/type"
Invalid type: object (expected string)
Invalid type: object (expected string)
at ono (/client/node_modules/ono/lib/index.js:62:17)
at parseParameter (/client/node_modules/swagger-express-middleware/lib/param-parser.js:148:11)
at /client/node_modules/swagger-express-middleware/lib/param-parser.js:93:18
Error: JSON Schema validation error.
Data path: "date"
Schema path: "/items/properties/date/type"
Invalid type: object (expected string)
at ono (/client/node_modules/ono/lib/index.js:62:17)
at jsonValidate (/client/node_modules/swagger-express-middleware/lib/helpers/json-schema.js:208:11)
at parseArray (/client/node_modules/swagger-express-middleware/lib/helpers/json-schema.js:435:5)
at JsonSchema.parse (/client/node_modules/swagger-express-middleware/lib/helpers/json-schema.js:89:14)
at /client/node_modules/swagger-express-middleware/lib/helpers/json-schema.js:513:42
I assume that this library converts the date field to a date object, and passes it to the JSON schema validator, which expects it to be string.
Issue Analytics
- State:
- Created 6 years ago
- Reactions:2
- Comments:7 (2 by maintainers)
Top Results From Across the Web
Validation - react-jsonschema-form documentation
React Json Schema Form provides a default @rjsf/validator-ajv6 ... errors (such as when a field is required ) may be displayed before the...
Read more >Json schema validation error - Stack Overflow
This errors happen when validating the JSON with the schema draft-04 or higher, the problem is that "id" is expected to be in...
Read more >Validation - JSON Forms
The easiest way to declare an error for a property is by specifying the instancePath , which represents the path of the property...
Read more >Date format in JSON schema - Forums - IBM Support
Dates in YYYY-MM-DD format can be validated with format "date" as you thought. In particular, DataPower v6.0.0 will validate the string with this...
Read more >A Vocabulary for Structural Validation of JSON - JSON Schema
This Internet-Draft is submitted in full conformance with the provisions of BCP 78 and BCP 79.¶ ... Date and time format names are...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Ok, thanks for the clarification. I’ve updated my test code, and now I’m able to reproduce the bug. The problem boils down to this:
Same issue, same not nice solution…