-
Notifications
You must be signed in to change notification settings - Fork 2.2k
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
Add x-enumNames support #1054
Add x-enumNames support #1054
Conversation
@RSuter Thanks for the PR and description! One question: where is x-enumNames defined in the JSON schema spec? |
x-enumNames is not in the spec but so is enumNames which is already supported - enumNames even violates json schema as custom extensions must start with x-. I maintain a json schema library which generate with x-... |
That's a good point. It looks like enumNames was added in the past because it was in the v5 draft, and retrospectively it probably shouldn't have been added, given that it would have been better to wait until draft-06 was finalized. It's worth noting, though, that adding custom attributes technically doesn't violate JSON Schema according to draft-07:
@RSuter , where do you see in the spec that custom extensions should start with x-? The only place I can find that rule is with Swagger. |
I don't even think |
I really dislike the way json schema handles enums: There is a native/clean way to describe enums but as soon as you need to add more metadata (names) you need to switch to a completely different construct which is less concise and much more verbose... I probably will not switch to oneOf enums as i’m pretty sure that most json schema/swagger/openapi tools (code gens) will not support that... |
Closing due to inactivity. |
First: Thanks for this awesome project, works like a charm...
Reasons for making this change
Add support for the x-enumNames property which has the same semantics as enumNames but uses the x- prefix to declare it as a custom/extension property. I'm maintaining the NJsonSchema C# library which generates these properties from .NET enums. See https://github.com/RSuter/NJsonSchema/wiki/Enums
I think it makes sense to support this scenario because this prefix is required/defined in the JSON Schema spec. It seems that the proposal for the property enumNames has been rejected in favor of const (see below).
Alternatives
There are also const enums: json-schema-org/json-schema-spec#67 (comment)
Spec for const: json-schema-org/json-schema-spec#58
Checklist
npm run cs-format
on my branch to conform my code to prettier coding style