-
Notifications
You must be signed in to change notification settings - Fork 122
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
Skip duplicate enum values #674
Skip duplicate enum values #674
Conversation
I don't believe this applies to enums outside of the schema definitions, should it? E.g. omit and raise a warning for duplicates for server enum definitions. I don't remember explicitly testing duplicates when I made the recent changes |
@theoriginalbit correct, this is only for schema enums, as that's what the JSON Schema spec is concerned with. The server enum values also (inexplicably) aren't required to be unique, so would you mind opening a PR fixing that? https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.4.md#fixed-fields-5 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch. Wondering if we can simplify the logic a bit though.
Sources/_OpenAPIGeneratorCore/Translator/CommonTranslations/translateRawEnum.swift
Outdated
Show resolved
Hide resolved
Sources/_OpenAPIGeneratorCore/Translator/CommonTranslations/translateRawEnum.swift
Show resolved
Hide resolved
…swift-openapi-generator into hd-skip-duplicate-enum-values
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for taking the time to polish this!
Motivation
Some OpenAPI docs, usually through imperfect conversion from another representation, end up with duplicate raw values in
enum
schemas.The OpenAPI specification (by referencing the JSON Schema specification) says:
So elements should be unique, but don't have to be. Today the generator fails to generate documents with such duplicate values.
Modifications
Gracefully handle duplicate values by emitting a warning diagnostic and skipping it.
Result
This unblocks generating OpenAPI documents with duplicate enum values, such as the Bluesky OpenAPI doc.
Test Plan
Added a unit test for duplicates.