Skip to content

serDes does not work in additionalProperties objects #821

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
leonardo-speranzon opened this issue Mar 3, 2023 · 0 comments · Fixed by #822
Closed

serDes does not work in additionalProperties objects #821

leonardo-speranzon opened this issue Mar 3, 2023 · 0 comments · Fixed by #822

Comments

@leonardo-speranzon
Copy link
Contributor

leonardo-speranzon commented Mar 3, 2023

Describe the bug
The serialization of date-time not work if the field is in a additionalProperties object

To Reproduce

The openapi definition

  /test:
    get: 
      responses:
        '200':
          description: foo
          content:
            application/json:
              schema:
                type: object
                properties:
                  good_date:
                    type: string
                    format: date-time
                  other_info:
                    type: object
                    additionalProperties:
                      type: object
                      properties:
                        bad_date:
                          type: string
                          format: date-time

Express server implementation

app.use(
    OpenApiValidator.middleware({
        apiSpec: './openapi.yaml',
        validateRequests: true, // (default)
        validateResponses: true, // false by default
        serDes: [
            OpenApiValidator.serdes.date,
            OpenApiValidator.serdes.dateTime,
        ]  // the default ones
    }),
)

app.get('/test', (req:Request,res:Response,next:NextFunction)=>{
    return res.json({
        good_date: new Date(),
        other_info: {
            something:{
                bad_date: new Date()
            }
        }
    })
})

Actual behavior
The serializer does not convert the bad_date from date to string and so the validator produce an error

  "message": "/response/other_info/something/bad_date must be string",
    "errors": [
        {
            "path": "/response/other_info/something/bad_date",
            "message": "must be string",
            "errorCode": "type.openapi.validation"
        }
    ]

Expected behavior
The response should be validated succesfully

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant