-
-
Notifications
You must be signed in to change notification settings - Fork 7.4k
[Go] Generate type aliases for deduplicated inline model schemas #22694
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
base: master
Are you sure you want to change the base?
[Go] Generate type aliases for deduplicated inline model schemas #22694
Conversation
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.
1 issue found across 7 files
Prompt for AI agents (all issues)
Check if these issues are valid — if so, understand the root cause of each and fix them.
<file name="modules/openapi-generator/src/main/java/org/openapitools/codegen/CodegenProperty.java">
<violation number="1" location="modules/openapi-generator/src/main/java/org/openapitools/codegen/CodegenProperty.java:195">
P2: `dataTypeAlias` was added but omitted from equals/hashCode/toString, so properties differing only by alias compare equal and hash the same</violation>
</file>
Since this is your first cubic review, here's how it works:
- cubic automatically reviews your code and comments on bugs and improvements
- Teach cubic by replying to its comments. cubic learns from your replies and gets better over time
- Ask questions if you need clarification on any suggestion
Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.
modules/openapi-generator/src/main/java/org/openapitools/codegen/CodegenProperty.java
Show resolved
Hide resolved
|
@cubic-dev-ai please re-run a review. |
@AriehSchneier I have started the AI code review. It will take a few minutes to complete. |
@AriehSchneier I have started the AI code review. It will take a few minutes to complete. |
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.
2 issues found across 7 files
Prompt for AI agents (all issues)
Check if these issues are valid — if so, understand the root cause of each and fix them.
<file name="modules/openapi-generator/src/main/java/org/openapitools/codegen/InlineModelResolver.java">
<violation number="1" location="modules/openapi-generator/src/main/java/org/openapitools/codegen/InlineModelResolver.java:1002">
P2: Alias vendor extension can be overwritten; deduplication alias is lost if source schema already defines x-alias-name.</violation>
<violation number="2" location="modules/openapi-generator/src/main/java/org/openapitools/codegen/InlineModelResolver.java:1002">
P2: Alias metadata is added only for dedup via makeSchemaInComponents; other schema reuse paths still drop x-alias-name, so deduplicated inline schemas may miss alias information.</violation>
</file>
Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.
modules/openapi-generator/src/main/java/org/openapitools/codegen/InlineModelResolver.java
Outdated
Show resolved
Hide resolved
modules/openapi-generator/src/main/java/org/openapitools/codegen/InlineModelResolver.java
Outdated
Show resolved
Hide resolved
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.
1 issue found across 7 files
Prompt for AI agents (all issues)
Check if these issues are valid — if so, understand the root cause of each and fix them.
<file name="modules/openapi-generator/src/main/java/org/openapitools/codegen/InlineModelResolver.java">
<violation number="1" location="modules/openapi-generator/src/main/java/org/openapitools/codegen/InlineModelResolver.java:1002">
P2: Deduplicated inline schema alias ignores inlineSchemaNameMapping by storing the unmapped name in x-alias-name</violation>
</file>
Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.
modules/openapi-generator/src/main/java/org/openapitools/codegen/InlineModelResolver.java
Outdated
Show resolved
Hide resolved
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.
1 issue found across 2 files (changes from recent commits).
Prompt for AI agents (all issues)
Check if these issues are valid — if so, understand the root cause of each and fix them.
<file name="modules/openapi-generator/src/main/java/org/openapitools/codegen/InlineModelResolver.java">
<violation number="1" location="modules/openapi-generator/src/main/java/org/openapitools/codegen/InlineModelResolver.java:670">
P2: x-alias-name for deduplicated inline schemas bypasses inlineSchemaNameMapping, producing unmapped alias names</violation>
</file>
Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.
Relates to #22632, I implemented the proposed enhancement so that I no longer need the bugfix. (Noting that it doesn't actually fix the bug in that issue)
Description
When the
InlineModelResolverdeduplicates inline schemas that share the same structure, the Go code generator now creates type aliases using the original inline model names, pointing to the shared deduplicated type.Example
Given an OpenAPI spec with two different models that happen to have identically-structured inline schemas:
Before this PR:
The second inline schema would reuse the first deduplicated type, losing context:
After this PR:
Each field uses its own alias, preserving the original naming context:
Implementation Details
x-deduped-namewhen deduplicating schemasCodegenProperty.dataTypeAlias(language-neutral)dataTypeanddataTypeAliasinpostProcessModels()so struct fields use the alias names[]RecipeIngredients)Benefits
[]RecipeIngredientsinstead of[]BlogPostAuthor)Testing
Added comprehensive test
typeAliasForDeduplicatedInlineSchemasTestcovering:Configuration Option
I have not added a configuration option to turn this on/off, but can if you think I should.
Summary by cubic
Generates Go type aliases for deduplicated inline model schemas so fields keep their original, contextual names. Related to #22632.
Written for commit 7089435. Summary will update on new commits.