You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Describe the bug
When you return a JSON response that contains a date object created by an ISO-8601 string, and in the API spec (.yaml) the date field is type Date, you get the wrong YYYY-MM-DD back! For example, if the date was created using "1996-01-03T22:00:00.000Z" then in the response you get 1996-01-03 instead of 1996-01-04 which is the correct YYYY-MM-DD representation of that UTC date. This only happens if you are using the open-api-validator, else what you get back is the actual ISO-8601 "1996-01-03T22:00:00.000Z". It seems like the open-api-validator cuts the string to only keep the first 10 characters.
Just use the following example with the YAML spec to test it out. You will see that the response returns 1996-01-03 as the date.
Now disable the open-api-validator middleware by commenting it out. What you will get as a response will be "1996-01-03T22:00:00.000Z" which of course is not the right format but it's definitely the correct DateTime!!!
openapi: 3.0.0servers:
# Added by API Auto Mocking Plugin
- description: SwaggerHub API Auto Mockingurl: https://virtserver.swaggerhub.com/babaliaris/test/1.0.0
- description: My Computerurl: http://localhost:1996info:
description: This is a simple APIversion: "1.0.0"title: Simple Inventory APIcontact:
email: [email protected]license:
name: Apache 2.0url: 'http://www.apache.org/licenses/LICENSE-2.0.html'paths:
/user:
get:
tags:
- Userssummary: get user.operationId: getUserresponses:
'200':
description: Get the json user data.content:
application/json:
schema:
$ref: '#/components/schemas/User'default:
description: Something went wrong.components:
schemas:
User:
type: objectrequired:
- id
- name
- dateproperties:
id:
type: integername:
type: stringdate:
type: stringformat: date
The text was updated successfully, but these errors were encountered:
Describe the bug
When you return a JSON response that contains a date object created by an ISO-8601 string, and in the API spec (.yaml) the date field is type Date, you get the wrong YYYY-MM-DD back! For example, if the date was created using "1996-01-03T22:00:00.000Z" then in the response you get 1996-01-03 instead of 1996-01-04 which is the correct YYYY-MM-DD representation of that UTC date. This only happens if you are using the open-api-validator, else what you get back is the actual ISO-8601 "1996-01-03T22:00:00.000Z". It seems like the open-api-validator cuts the string to only keep the first 10 characters.
Just use the following example with the YAML spec to test it out. You will see that the response returns 1996-01-03 as the date.
Now disable the open-api-validator middleware by commenting it out. What you will get as a response will be "1996-01-03T22:00:00.000Z" which of course is not the right format but it's definitely the correct DateTime!!!
Examples and context
index.js
api.yaml
The text was updated successfully, but these errors were encountered: