Skip to content
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

Merged
merged 4 commits into from
Nov 19, 2024

Conversation

czechboy0
Copy link
Contributor

@czechboy0 czechboy0 commented Nov 16, 2024

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:

The value of this keyword MUST be an array.  This array SHOULD have at least one element.  Elements in the array SHOULD be unique.

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.

@theoriginalbit
Copy link
Contributor

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

@czechboy0
Copy link
Contributor Author

czechboy0 commented Nov 17, 2024

@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

Copy link
Contributor

@simonjbeaumont simonjbeaumont left a 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.

Copy link
Contributor

@simonjbeaumont simonjbeaumont left a 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!

@simonjbeaumont simonjbeaumont merged commit ecce1b7 into apple:main Nov 19, 2024
34 checks passed
@czechboy0 czechboy0 deleted the hd-skip-duplicate-enum-values branch November 19, 2024 21:23
@czechboy0 czechboy0 added the semver/patch No public API change. label Nov 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
semver/patch No public API change.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants