-
-
Notifications
You must be signed in to change notification settings - Fork 7.4k
[Protobuf] Fix Discriminator Issue and add capability Enum Extraction #22740
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
Ocsidot
wants to merge
12
commits into
OpenAPITools:master
Choose a base branch
from
Ocsidot:fix/protobuf-discriminator-issues
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.
+1,828
−47
Open
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
d2366f6
fix(protobuf-codegen): Fix protobuf import path with discriminator
33fa3be
fix: Add missing element in OpenAPI discriminator test case
f4e162f
Merge branch 'master' into fix/protobuf-discriminator-issues
Ocsidot 8c2fd2b
Merge branch 'OpenAPITools:master' into fix/protobuf-discriminator-is…
Ocsidot aae8ca1
Merge branch 'OpenAPITools:master' into fix/protobuf-discriminator-is…
Ocsidot bac320d
feat(protobuf-generator): Improve protobuf generation
dbf98ab
fix: Improve logic when extracting enums to avoid collision in enum v…
a9d13a6
fix: Manage case with Enum in lists
118900e
Merge branch 'OpenAPITools:master' into fix/protobuf-discriminator-is…
Ocsidot 2498607
Merge branch 'fix/protobuf-discriminator-issues' of https://github.co…
79b9578
fix: Fix issue on enum extraction
0902089
Merge branch 'OpenAPITools:master' into fix/protobuf-discriminator-is…
Ocsidot 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
911 changes: 872 additions & 39 deletions
911
...api-generator/src/main/java/org/openapitools/codegen/languages/ProtobufSchemaCodegen.java
Large diffs are not rendered by default.
Oops, something went wrong.
31 changes: 25 additions & 6 deletions
31
modules/openapi-generator/src/main/resources/protobuf-schema/enum.mustache
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 |
|---|---|---|
| @@ -1,7 +1,26 @@ | ||
| enum {{classname}} { | ||
| {{#allowableValues}} | ||
| {{#enumVars}} | ||
| {{{name}}} = {{{protobuf-enum-index}}}; | ||
| {{/enumVars}} | ||
| {{/allowableValues}} | ||
| {{! | ||
| Generates an extracted enum wrapped in a message container. | ||
|
|
||
| This wrapper pattern is used to prevent enum value name collisions | ||
| in the Protocol Buffers global enum namespace. Multiple enums can | ||
| have values with the same name when wrapped in separate messages. | ||
|
|
||
| Generated format: | ||
| message EnumName { | ||
| enum Enum { | ||
| VALUE1 = 0; | ||
| VALUE2 = 1; | ||
| } | ||
| } | ||
|
|
||
| Usage in models: EnumName.Enum field_name = 1; | ||
| }} | ||
| message {{classname}} { | ||
| enum Enum { | ||
| {{#allowableValues}} | ||
| {{#enumVars}} | ||
| {{{name}}} = {{{protobuf-enum-index}}}; | ||
| {{/enumVars}} | ||
| {{/allowableValues}} | ||
| } | ||
| } |
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
655 changes: 655 additions & 0 deletions
655
...-generator/src/test/java/org/openapitools/codegen/protobuf/ProtobufSchemaCodegenTest.java
Large diffs are not rendered by default.
Oops, something went wrong.
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
58 changes: 58 additions & 0 deletions
58
...enerator/src/test/resources/3_0/allOf_composition_discriminator_multiple_inheritance.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,58 @@ | ||
| openapi: 3.0.3 | ||
| info: | ||
| title: OAI Specification example for Polymorphism | ||
| version: 1.0.0 | ||
| paths: | ||
| /status: | ||
| get: | ||
| responses: | ||
| '201': | ||
| description: desc | ||
|
|
||
| components: | ||
| schemas: | ||
| Animal: | ||
| type: object | ||
| required: | ||
| - petType | ||
| properties: | ||
| petType: | ||
| type: string | ||
| discriminator: | ||
| propertyName: petType | ||
| mapping: | ||
| dog: '#/components/schemas/Dog' | ||
| cat: '#/components/schemas/Cat' | ||
| Feline: | ||
| allOf: | ||
| - $ref: '#/components/schemas/Animal' | ||
| - type: object | ||
| properties: | ||
| name: | ||
| type: string | ||
| furColor: | ||
| type: string | ||
| Cat: | ||
| allOf: | ||
| - $ref: '#/components/schemas/Feline' | ||
| - type: object | ||
| properties: | ||
| isIndoor: | ||
| type: boolean | ||
| careDetails: | ||
| $ref: '#/components/schemas/CareDetails' | ||
| Dog: | ||
| allOf: | ||
| - $ref: '#/components/schemas/Animal' | ||
| - type: object | ||
| properties: | ||
| bark: | ||
| type: string | ||
| CareDetails: | ||
| type: object | ||
| properties: | ||
| veterinarian: | ||
| type: string | ||
| lastVetVisit: | ||
| type: string | ||
| format: date |
31 changes: 31 additions & 0 deletions
31
modules/openapi-generator/src/test/resources/3_0/protobuf-schema/animal.proto
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,31 @@ | ||
| /* | ||
| OAI Specification example for Polymorphism | ||
|
|
||
| No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator) | ||
|
|
||
| The version of the OpenAPI document: 1.0.0 | ||
|
|
||
| Generated by OpenAPI Generator: https://openapi-generator.tech | ||
| */ | ||
|
|
||
| syntax = "proto3"; | ||
|
|
||
| package openapitools; | ||
|
|
||
| import public "models/care_details.proto"; | ||
|
|
||
| message Animal { | ||
|
|
||
| string pet_type = 482112090; | ||
|
|
||
| string name = 3373707; | ||
|
|
||
| string fur_color = 478695002; | ||
|
|
||
| bool is_indoor = 183319801; | ||
|
|
||
| CareDetails care_details = 176721135; | ||
|
|
||
| string bark = 3016376; | ||
|
|
||
| } |
77 changes: 77 additions & 0 deletions
77
modules/openapi-generator/src/test/resources/3_0/protobuf-schema/extracted_enum.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,77 @@ | ||
| openapi: 3.0.0 | ||
| info: | ||
| title: Enum extraction test | ||
| version: '2.0' | ||
| paths: {} | ||
| components: | ||
| schemas: | ||
| SeparatedEnum: | ||
| type: string | ||
| enum: | ||
| - VALUE1 | ||
| - VALUE2 | ||
| ModelWithEnums: | ||
| type: object | ||
| properties: | ||
| referenceEnumProperty: | ||
| $ref: "#/components/schemas/SeparatedEnum" | ||
| inlineEnumProperty: | ||
| type: string | ||
| enum: | ||
| - VALUE2 | ||
| - VALUE3 | ||
| - VALUE4 | ||
| listOfEnums: | ||
| type: array | ||
| items: | ||
| type: string | ||
| enum: | ||
| - VALUE10 | ||
| - VALUE11 | ||
| AllOfModelWithEnums: | ||
| allOf: | ||
| - $ref: "#/components/schemas/ModelWithEnums" | ||
| - type: object | ||
| properties: | ||
| anotherInlineEnumProperty: | ||
| type: string | ||
| enum: | ||
| - VALUE5 | ||
| - VALUE6 | ||
| listOfReferencedEnums: | ||
| type: array | ||
| items: | ||
| $ref: '#/components/schemas/SeparatedEnum' | ||
| DiscriminatedModel: | ||
| type: object | ||
| properties: | ||
| commonProperty: | ||
| type: string | ||
| modelType: | ||
| type: string | ||
| discriminator: | ||
| propertyName: modelType | ||
| mapping: | ||
| typeA: "#/components/schemas/ModelTypeAWithInlineEnum" | ||
| typeB: "#/components/schemas/ModelTypeBWithInlineEnum" | ||
| ModelTypeAWithInlineEnum: | ||
| allOf: | ||
| - $ref: "#/components/schemas/DiscriminatedModel" | ||
| - type: object | ||
| properties: | ||
| specificPropertyA: | ||
| type: string | ||
| inlineEnumProperty: | ||
| type: string | ||
| enum: | ||
| - VALUE7 | ||
| - VALUE8 | ||
| ModelTypeBWithInlineEnum: | ||
| allOf: | ||
| - $ref: "#/components/schemas/DiscriminatedModel" | ||
| - type: object | ||
| properties: | ||
| specificPropertyB: | ||
| type: string | ||
| referenceEnumPropertyB: | ||
| $ref: "#/components/schemas/SeparatedEnum" |
89 changes: 89 additions & 0 deletions
89
modules/openapi-generator/src/test/resources/3_0/protobuf-schema/model_imported_once.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,89 @@ | ||
| openapi: 3.0.0 | ||
| info: | ||
| title: Model Import Test | ||
| version: 1.0.0 | ||
| paths: {} | ||
| components: | ||
| schemas: | ||
| A: | ||
| type: object | ||
| description: Base model A that will be referenced multiple times | ||
| properties: | ||
| id: | ||
| type: string | ||
| value: | ||
| type: string | ||
| required: | ||
| - id | ||
|
|
||
| SubModel: | ||
| type: object | ||
| description: SubModel that uses model A | ||
| allOf: | ||
| - $ref: '#/components/schemas/ExtensibleModel' | ||
| - type: object | ||
| properties: | ||
| subField: | ||
| type: string | ||
| aReference: | ||
| $ref: '#/components/schemas/A' | ||
| required: | ||
| - subField | ||
|
|
||
| Model: | ||
| type: object | ||
| description: Main model that uses A directly and via SubModel | ||
| properties: | ||
| name: | ||
| type: string | ||
| directA: | ||
| $ref: '#/components/schemas/A' | ||
| nestedSubModel: | ||
| $ref: '#/components/schemas/SubModel' | ||
| required: | ||
| - name | ||
|
|
||
| ExtensibleModel: | ||
| type: object | ||
| description: Extensible model with discriminator that uses model A | ||
| discriminator: | ||
| propertyName: type | ||
| mapping: | ||
| child1: '#/components/schemas/ChildModel_1' | ||
| child2: '#/components/schemas/ChildModel_2' | ||
| properties: | ||
| type: | ||
| type: string | ||
| extensibleA: | ||
| $ref: '#/components/schemas/A' | ||
| required: | ||
| - type | ||
|
|
||
| ChildModel_1: | ||
| allOf: | ||
| - $ref: '#/components/schemas/ExtensibleModel' | ||
| - type: object | ||
| properties: | ||
| childSpecificField: | ||
| type: string | ||
| childA: | ||
| $ref: '#/components/schemas/A' | ||
| ChildModel_2: | ||
| allOf: | ||
| - $ref: '#/components/schemas/SubExtensibleModel' | ||
| - type: object | ||
| properties: | ||
| anotherChildSpecificField: | ||
| type: integer | ||
| directA: | ||
| $ref: '#/components/schemas/A' | ||
|
|
||
| SubExtensibleModel: | ||
| allOf: | ||
| - $ref: '#/components/schemas/ExtensibleModel' | ||
| - type: object | ||
| properties: | ||
| aSubExtensibleField: | ||
| type: boolean | ||
| subDirectA: | ||
| $ref: '#/components/schemas/A' |
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
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.
Uh oh!
There was an error while loading. Please reload this page.
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.
P1: Imported proto file
models/characteristics.protois missing, leavingCharacteristicsunresolved and making the schema uncompilable.Prompt for AI agents