Closed ehmicky closed 6 years ago
This package supports only the Schema Object. I believe allowEmptyValue
can only be specified in the root level of Parameter Object. Or am I mistaken?
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: name
, description
, required
, allowEmptyValue
, allowReserved
.
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 schema
portion and then augments the result based on the parameter options as necessary (adding minLength
and stuff). Then it would construct the final JSON schema from each of these "sub-schemas".
This package should probably have a flag to not include the schema declaration ($schema
).
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 :smile:
OK, cool :smiley: 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.