-
Notifications
You must be signed in to change notification settings - Fork 9.1k
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
dictionary key descriptions/schema (additionalProperties) #2294
Comments
Note - the name/label part has been implemented as a an extension in ReDoc |
This will be possible in OAS 3.1 using type: object
patternProperties:
'^[a-z]{2}$': # <--- key regex
type: string # <--- value schema
additionalProperties: false or type: object
propertyNames:
pattern: '^[a-z]{2}$':
description: lowercase 2 letter ISO 639-1 Code
additionalProperties:
type: string |
@hkosova I couldn't find it in the 3.1.0 spec. |
@xehpuk the OAS document only lists JSON Schema keywords that it changes, and in 3.1.0, most of them are left unchanged. You can find both of those keywords in the JSON Schema spec (note that there will be another draft for the final 3.1.0 OAS, based on feedback from 3.1.0-rc0 and other parts of the JSON Schema community, but neither of these keywords are expected to change. |
@handrews I'm not sure I can follow. What does it mean to "change" a keyword? To treat it differently than the JSON Schema defines? (Not a native speaker, probably missing a subtlety.) If I understand correctly, |
In 3.0 and earlier, some keywords in the Schema Object are taken from the JSON Schema specification (a much older draft), and some are specific to OAS. Of the keywords taken from the JSON Schema specification, some mean exactly what they mean in JSON Schema ("unchanged"), while others have restrictions or additional behavior in OAS that is not present in JSON Schema ("changed"). OAS 3.0 explicitly lists which JSON Schema keywords it uses, and whether they are changed. 'patternProperties' is not in the list so it is not supported. 'propertyNames' did not exist in that draft of JSON Schema, so it's not supported either. In OAS 3.1 all JSON Schema keywords are included unchanged. Therefore they are not explicitly listed in the OpenAPI Specification. So you won't find 'propertyNames' or 'patternProperties' in the spec (it just happens that neither are used in any examples either). But you do see:
Which links to where those keywords are defined (the JSON Schema Core link is the same document I linked you to above, except I linked to a specific section). You can use any of the JSON Schema keywords in the Core and Validation specs (although I strongly recommend ignoring |
@handrews Thank you for the elaborate explanation, makes sense to me now. 🙂 |
Question was resolved, no idea why I didn't close it at the time... closing now. |
I didnt see any way to add documentation/info about the keys that can be used when using dictionaries (ie "additionalProperties")
In the swagger docs example here, it appears the valid keys are all 2 letter ISO language codes. It would be great to be able to specify for these keys:
{ type: "string", pattern: '^[a-z]{2}$' }
Also as a sidenote, the name "additionalProperties" isn't super intuitive, but probably somewhat settled to change it now...
The text was updated successfully, but these errors were encountered: