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

Support usage of fields like "oneOf", "anyOf", or "examples" within a parameter #3078

Closed
1 task done
alex-statsig opened this issue Sep 17, 2024 · 3 comments
Closed
1 task done
Labels

Comments

@alex-statsig
Copy link
Contributor

Is there an existing issue that is already proposing this?

  • I have searched the existing issues

Is your feature request related to a problem? Please describe it

When defining a parameter with a "type" property, the "type" is correctly nested within the "schema" field. However, there are several fields that you can reference (in particular, I'm using zod-nestjs to automatically generate the types) which will not be properly moved into the "schema" field. Some examples include "oneOf", "anyOf", or "examples".

Describe the solution you'd like

I believe the fix should be a simple change to include more fields (like "oneOf") in this list of schema keys, but I don't have the full context of if the change makes sense here (locally patching this fixed all of my issues):

'properties',
'patternProperties',
'additionalProperties',
'minimum',
'maximum',
'maxProperties',
'minItems',
'minProperties',
'maxItems',
'minLength',
'maxLength',
'exclusiveMaximum',
'exclusiveMinimum',
'uniqueItems',
'title',
'format',
'pattern',
'nullable',
'default'

Teachability, documentation, adoption, migration strategy

No response

What is the motivation / use case for changing the behavior?

The current spec generated will not be valid if a parameter uses a feature like "oneOf" or "examples" (I believe "examples" is specific to 3.1.0, but "oneOf" is valid in 3.0.0)

@kamilmysliwiec
Copy link
Member

Would you like to create a PR for this issue?

alex-statsig added a commit to alex-statsig/swagger that referenced this issue Oct 28, 2024
Add support for "oneOf" and "anyOf" as schema keys, ensuring
they work properly when used in parameter types.

Closes nestjs#3078
@alex-statsig
Copy link
Contributor Author

Yes, I've put up #3129 which adds support for oneOf and anyOf.

I saw "example" got added already recently. I think "examples" should also be added, but it seems slightly more complicated due to the OAS 3.0 support for "examples" outside of the "schema" field (in 3.1 its only allowed inside the schema, and follows the json-schema format of examples). This makes it hard to tell which type of "examples" is in use. I might try and follow up with this still, but am less confident on it

@kamilmysliwiec
Copy link
Member

Let's track this here #3129

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

No branches or pull requests

2 participants