Skip to content
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

Default values missing in query #287

Closed
xeoneux opened this issue May 5, 2020 · 7 comments
Closed

Default values missing in query #287

xeoneux opened this issue May 5, 2020 · 7 comments
Assignees
Labels
bug Something isn't working

Comments

@xeoneux
Copy link

xeoneux commented May 5, 2020

First of all, thanks a lot for this package @cdimascio

I couldn't find any other lib that handles OpenAPI v3 well, is well maintained and has a good amount of tests 😄

So here's my issue:
For example, I'm using this schema:

Sort:
      properties:
        field:
          default: id
          enum:
            - id
          type: string
        order:
          default: ASC
          enum:
            - ASC
            - DESC
          type: string
      type: object

Along with this query item:

parameters:
        - in: query
          name: sort
          required: false
          schema:
            $ref: '#/components/schemas/Sort'
          style: deepObject

Then, inside the route, the req.query.sort is an empty object instead of the default values, { sort: {field: 'id', order: 'ASC'} }

Is the not the desired behaviour or is it because of the deepObject style?

@cdimascio
Copy link
Owner

cdimascio commented May 6, 2020

Thanks for the issue @xeoneux. I created 2 new tests for deepObject that use default values. The tests are similar to your use case. They appear to work.

Here are some links

tests:

spec:

Please have a look at the tests. As I noted they work. I could use some help reproducing your case. If you can create a test that demonstrates the issue, I'll certainly take a look. Thanks.

Note, you can click the Gitpod link at the top right of this page (or the Gitpod link on the README) to get a full dev environment setup for this project. Once it completes, you can run the two tests to poke around (see CONTRIBUTING.MD for details on running tests).

@xeoneux
Copy link
Author

xeoneux commented May 6, 2020

Hi @cdimascio, I created a repo for the case here: https://github.com/xeoneux/express-openapi-validator-default-query-issue

I'm using $ref for schema to query object and I can see your test as well for that deep_object_2 but it's not working for this case.

cdimascio pushed a commit that referenced this issue May 7, 2020
@cdimascio cdimascio self-assigned this May 7, 2020
@cdimascio cdimascio added the bug Something isn't working label May 7, 2020
@cdimascio
Copy link
Owner

@xeoneux Thanks for the sample. I'm working on a fix. Should have something soon

cdimascio added a commit that referenced this issue May 7, 2020
deepObject default value support #287
@cdimascio
Copy link
Owner

@xeoneux please give version 3.12.8 a try. The issue should be resolved there

@xeoneux
Copy link
Author

xeoneux commented May 7, 2020

Sure, will you create a release on npm please?

@cdimascio
Copy link
Owner

Yes. Its already available. Let me know how it goes

@xeoneux
Copy link
Author

xeoneux commented May 7, 2020

Works perfectly fine! Thanks @cdimascio 😄

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants