Skip to content

[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

Closed
ehmicky opened this issue May 7, 2018 · 5 comments
Closed

[Feature] Add support for allowEmptyValue #8

ehmicky opened this issue May 7, 2018 · 5 comments

Comments

@ehmicky
Copy link
Contributor

ehmicky commented May 7, 2018

Should allowEmptyValue be converted to minLength: 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 mean empty string. It's also not clear whether empty is after trimming or not. Since the minLength keyword would have no effect when type is not string, it might not be necessary to check for type to perform the conversion.

If minLength is already specified, the maximum should probably be taken.

Alternatives to minLength could be using not: { const } (JSON schema version 6 only) and using pattern (might be less performant, and would require potentially merging several patterns).

I've send an issue on the OpenAPI specification for possible clarification.

@mikunn
Copy link
Owner

mikunn commented May 9, 2018

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?

@ehmicky
Copy link
Contributor Author

ehmicky commented May 9, 2018

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.

@mikunn
Copy link
Owner

mikunn commented May 9, 2018

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).

@ehmicky
Copy link
Contributor Author

ehmicky commented May 9, 2018

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 😄

@ehmicky ehmicky closed this as completed May 9, 2018
@mikunn
Copy link
Owner

mikunn commented May 9, 2018

OK, cool 😃 I created an issue about the option to leave out $schema.

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

No branches or pull requests

2 participants