-
Notifications
You must be signed in to change notification settings - Fork 6
[Feature] Add support for allowEmptyValue
#8
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
Comments
This package supports only the Schema Object. I believe |
Thanks for your response. Yes indeed, that is true. Could this be a good idea to allow passing a parameter or array of parameters as input? There are several properties that could be re-used as JSON schema properties: For example: openapiSchemaToJsonSchema.fromParameter([{
name: 'paramName',
in: 'query',
description: 'param description',
required: true,
allowEmptyValue: true,
allowReserved: false,
schema: {
type: 'string',
},
}]); would return: {
type: 'object'
properties: {
paramName: {
type: 'string'
minLength: 1,
pattern: '...' // For `allowReserved`
}
}
required: ['paramName']
} I understand though the motivation to keep this library small and only as a translation layer between OpenAPI schemas and JSON schemas. My use case would be when this library is used to get as much information as possible from OpenAPI into JSON schemas to (for example) validate the parameters. There are several libraries that do this by hand, for example Sway. |
Thanks for the example! I can definitely see the use case. However, I would like to keep this package strictly for converting from Schema Object. I think the best option could be to write a new package that uses this package to convert the This package should probably have a flag to not include the schema declaration ( |
I understand, that makes perfect sense. I might end up creating that package, depending on time constraints. If I do, I'll keep you posted 😄 |
OK, cool 😃 I created an issue about the option to leave out $schema. |
Should
allowEmptyValue
be converted tominLength: 1
? At the moment, it is just deleted.The specification is not really clear when it comes to the meaning of the word
empty
, but I take it they meanempty string
. It's also not clear whetherempty
is after trimming or not. Since theminLength
keyword would have no effect whentype
is notstring
, it might not be necessary to check fortype
to perform the conversion.If
minLength
is already specified, the maximum should probably be taken.Alternatives to
minLength
could be usingnot: { const }
(JSON schema version 6 only) and usingpattern
(might be less performant, and would require potentially merging several patterns).I've send an issue on the OpenAPI specification for possible clarification.
The text was updated successfully, but these errors were encountered: