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

fix(openapi): support nullish consts #751

Merged
merged 1 commit into from
Sep 25, 2023
Merged

Conversation

WoH
Copy link
Contributor

@WoH WoH commented Aug 23, 2023

Checklist

Copy link
Contributor

@Uzlopak Uzlopak left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

seems right, but I would like to have a second opinion by @ivan-tymoshenko

Copy link
Member

@ivan-tymoshenko ivan-tymoshenko left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not really deep into this library. The only thing I would check (add a test) is how it would work with nullable keyword and type null. For example:

{
  "type": "string",
  "nullable": false,
  "const": null
}

and

{
  "type": "string",
  "const": null
}

Both these schemas are invalid (there is no value that would match them). You want to be sure that you handle cases like that correctly.

Copy link
Member

@mcollina mcollina left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@WoH
Copy link
Contributor Author

WoH commented Aug 25, 2023

I'm not really deep into this library. The only thing I would check (add a test) is how it would work with nullable keyword and type null. For example:

{
  "type": "string",
  "nullable": false,
  "const": null
}

and

{
  "type": "string",
  "const": null
}

Both these schemas are invalid (there is no value that would match them). You want to be sure that you handle cases like that correctly.

In both of these cases I'd argue it's not the job of this library to figure out what may have been implied, but just convert it to an equally useless (albeit OAS compatible) schema.

I would like to mention that one could make an argument for converting:

{
  "const": null
}

to:

{
  "enum": [null],
  "nullable": true // with this added
}

but that is is not required from my understanding of the spec (which seems to be in line with the swagger-validator).

@mcollina mcollina merged commit ff02608 into fastify:master Sep 25, 2023
15 checks passed
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 this pull request may close these issues.

None yet

4 participants