Repository navigation
[core] Keep explicit inlineSchemaNameMappings when several inline schemas map to one name #25181
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
Open
mohitduhan19
wants to merge
6
commits into
OpenAPITools:master
Choose a base branch
from
mohitduhan19:fix-inline-mapping-many-to-one
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+65
−5
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
4e6166e
Keep explicit inlineSchemaNameMappings when several inline schemas ma…
mohitduhan19 8dc1f51
Add spec for many-to-one inlineSchemaNameMappings test
mohitduhan19 459dda6
Add test for many-to-one inlineSchemaNameMappings
mohitduhan19 9867efd
Warn when an inlineSchemaNameMapping replaces a schema defined in the…
mohitduhan19 ba26463
Drop the Money1 assertion that can never fail
mohitduhan19 a3bcbe1
Only warn for mapped names that were defined in the spec
mohitduhan19 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 35 additions & 0 deletions
35
modules/openapi-generator/src/test/resources/3_0/inline_schema_name_mapping_many_to_one.yaml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| openapi: 3.0.3 | ||
| info: | ||
| title: inlineSchemaNameMappings many-to-one | ||
| version: "1" | ||
| paths: | ||
| /preview: | ||
| get: | ||
| responses: | ||
| "200": | ||
| description: ok | ||
| content: | ||
| application/json: | ||
| schema: | ||
| $ref: "#/components/schemas/Preview" | ||
| components: | ||
| schemas: | ||
| Preview: | ||
| type: object | ||
| properties: | ||
| balance: | ||
| type: object | ||
| description: The balance at the end of the range. | ||
| properties: | ||
| amount: | ||
| type: string | ||
| currency: | ||
| type: string | ||
| interest: | ||
| type: object | ||
| description: The interest accrued over the range. | ||
| properties: | ||
| amount: | ||
| type: string | ||
| currency: | ||
| type: string |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
P2: Mapped names now bypass the
components.schemas.containsKey(name)check entirely, so a mapped value that collides with an existing spec-defined schema silently overwrites it.addSchemasunconditionally callsopenAPI.getComponents().addSchemas(name, schema)(a map put) afterward, so e.g.inlineSchemaNameMapping: {Preview_balance: Money}with a pre-existingcomponents.schemas.Moneyreplaces the originalMoneydefinition and rebinds every existing$ref: '#/components/schemas/Money'to the inline schema. Guard the overwrite: only allow the explicit name to win when the existing entry was itself created by an earlier mapping, otherwise fall back touniqueName(name)(or at least emit a warning before overwriting).Prompt for AI agents
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.
Using the mapped name as is matches 7.25.0, where a mapping onto an existing schema name also replaced it, so I kept that behaviour rather than falling back to
uniqueName. In 9867efd the resolver now logs a warning when a mapped name already exists in the spec and wasn't added by an earlier mapping. Several mappings onto the same name (the case from #25179) don't trigger it.