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

[avro-schema] fix: enum logic (sanitize, remove collisions) #19549

Merged
merged 1 commit into from
Sep 12, 2024

Conversation

joscha
Copy link
Contributor

@joscha joscha commented Sep 8, 2024

Currently, enums in Avro schemas are generated directly from the model, whether they are valid or not.

Unfortunately, Avro schema values follow tighter rules.

This pull request sanitizes enum values from the Swagger spec to follow the Avro schema by:

  • replacing invalid characters with _
  • prefixing values starting with numbers with _
  • removing collisions that happen because of the above or otherwise by adding a numbered suffix.

PR checklist

  • Read the contribution guidelines.
  • Pull Request title clearly describes the work in the pull request and Pull Request description provides details about how to validate the work. Missing information here may result in delayed response from the community.
  • Run the following to build the project and update samples
  • File the PR against the correct branch: master (upcoming 7.6.0 minor release - breaking changes with fallbacks), 8.0.x (breaking changes without fallbacks)
  • If your PR is targeting a particular programming language, @mention the technical committee members, so they are more likely to review the pull request. - @sgadouar?

"symbols": [
"a",
"b",
"uh_oh",
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

- to _

"a",
"b",
"uh_oh",
"_0h_oh",
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

prefixed with _

"uh_oh",
"_0h_oh",
"coll_ision",
"coll_ision2"
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

count suffix

@wing328
Copy link
Member

wing328 commented Sep 9, 2024

thanks for the PR.

cc @sgadouar

@wing328 wing328 added Issue: Bug Schema: Avro Generation of Avro schemas labels Sep 9, 2024
@wing328 wing328 added this to the 7.9.0 milestone Sep 9, 2024
@@ -0,0 +1,26 @@
{
Copy link
Contributor Author

@joscha joscha Sep 9, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

happy to express this in unit tests instead if you prefer @sgadouar

@joscha joscha changed the title [avro-schema] fix enum logic (sanitize) [avro-schema] fix: enum logic (sanitize, remove collisions) Sep 9, 2024
@wing328 wing328 merged commit cd349dc into OpenAPITools:master Sep 12, 2024
15 checks passed
@joscha joscha deleted the joscha/avro-fix-enums-2 branch September 12, 2024 09:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Issue: Bug Schema: Avro Generation of Avro schemas
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants