-
-
Notifications
You must be signed in to change notification settings - Fork 7.6k
Add swift5 option for generating frozen enums #11013
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
Merged
wing328
merged 11 commits into
OpenAPITools:master
from
jarrodparkes:feat-1529/swift-frozen-enum-option
Dec 4, 2021
Merged
Changes from 3 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
0a6d4da
add swift5 option for generating frozen enums
jarrodparkes bd8cba2
use case unknownDefault to avoid conflicts
jarrodparkes 96a8b4b
update comments to reflect unknownDefault case
jarrodparkes 1d6efb3
set default values for unknown case to avoid conflict
jarrodparkes 9280e55
dont need vendor extensions to detect enum raw data type
jarrodparkes 2950d0d
move CaseIterableDefaultsLast into models mustache template
jarrodparkes 219e3d5
comment catch all case and add support for other types
jarrodparkes 8113ed9
add frozen enums to ci pipeline
jarrodparkes 869499e
remove extraneous edit to extensions template
jarrodparkes 0e873a9
remove left over protocols files
jarrodparkes 6eab5c3
small comment and case adjustments
jarrodparkes 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| generatorName: swift5 | ||
| outputDir: samples/client/petstore/swift5/frozenEnums | ||
| inputSpec: modules/openapi-generator/src/test/resources/2_0/swift/petstore-with-fake-endpoints-models-for-testing.yaml | ||
| templateDir: modules/openapi-generator/src/main/resources/swift5 | ||
| generateAliasAsModel: true | ||
| additionalProperties: | ||
| podAuthors: "" | ||
| podSummary: PetstoreClient | ||
| sortParamsByRequiredFlag: false | ||
| generateFrozenEnums: false | ||
| projectName: PetstoreClient | ||
| podHomepage: https://github.com/openapitools/openapi-generator |
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
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
9 changes: 9 additions & 0 deletions
9
modules/openapi-generator/src/main/resources/swift5/Protocols.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 |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| // Protocols.swift | ||
| // | ||
| // Generated by openapi-generator | ||
| // https://openapi-generator.tech | ||
| // | ||
|
|
||
| /// An enum where the last case value is "unknownDefault" and can be used as a default catch-all. | ||
| public protocol CaseIterableDefaultsLast: Decodable & CaseIterable & RawRepresentable | ||
| where RawValue: Decodable, AllCases: BidirectionalCollection {} |
7 changes: 6 additions & 1 deletion
7
modules/openapi-generator/src/main/resources/swift5/modelEnum.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,12 @@ | ||
| {{#nonPublicApi}}internal{{/nonPublicApi}}{{^nonPublicApi}}public{{/nonPublicApi}} enum {{classname}}: {{dataType}}, {{#useVapor}}Content, Hashable{{/useVapor}}{{^useVapor}}Codable{{/useVapor}}, CaseIterable { | ||
| {{#nonPublicApi}}internal{{/nonPublicApi}}{{^nonPublicApi}}public{{/nonPublicApi}} enum {{classname}}: {{dataType}}, {{#useVapor}}Content, Hashable{{/useVapor}}{{^useVapor}}Codable{{/useVapor}}, CaseIterable{{^generateFrozenEnums}}{{#vendorExtensions.x-non-frozen-enum-capable}}, CaseIterableDefaultsLast{{/vendorExtensions.x-non-frozen-enum-capable}}{{/generateFrozenEnums}} { | ||
| {{#allowableValues}} | ||
| {{#enumVars}} | ||
| case {{{name}}} = {{{value}}} | ||
| {{/enumVars}} | ||
| {{/allowableValues}} | ||
| {{^generateFrozenEnums}} | ||
| {{#vendorExtensions.x-non-frozen-enum-capable}} | ||
| case unknownDefault | ||
| {{/vendorExtensions.x-non-frozen-enum-capable}} | ||
| {{/generateFrozenEnums}} | ||
| } |
7 changes: 6 additions & 1 deletion
7
modules/openapi-generator/src/main/resources/swift5/modelInlineEnumDeclaration.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,12 @@ | ||
| {{#nonPublicApi}}internal{{/nonPublicApi}}{{^nonPublicApi}}public{{/nonPublicApi}} enum {{enumName}}: {{^isContainer}}{{dataType}}{{/isContainer}}{{#isContainer}}String{{/isContainer}}, {{#useVapor}}Content, Hashable{{/useVapor}}{{^useVapor}}Codable{{/useVapor}}, CaseIterable { | ||
| {{#nonPublicApi}}internal{{/nonPublicApi}}{{^nonPublicApi}}public{{/nonPublicApi}} enum {{enumName}}: {{^isContainer}}{{dataType}}{{/isContainer}}{{#isContainer}}String{{/isContainer}}, {{#useVapor}}Content, Hashable{{/useVapor}}{{^useVapor}}Codable{{/useVapor}}, CaseIterable{{^generateFrozenEnums}}{{#vendorExtensions.x-non-frozen-enum-capable}}, CaseIterableDefaultsLast{{/vendorExtensions.x-non-frozen-enum-capable}}{{/generateFrozenEnums}} { | ||
| {{#allowableValues}} | ||
| {{#enumVars}} | ||
| case {{{name}}} = {{{value}}} | ||
| {{/enumVars}} | ||
| {{/allowableValues}} | ||
| {{^generateFrozenEnums}} | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @jarrodparkes please apply all the feedback from |
||
| {{#vendorExtensions.x-non-frozen-enum-capable}} | ||
| case unknownDefault | ||
| {{/vendorExtensions.x-non-frozen-enum-capable}} | ||
| {{/generateFrozenEnums}} | ||
| } | ||
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
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
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
9 changes: 9 additions & 0 deletions
9
...s/client/petstore/swift5/alamofireLibrary/PetstoreClient/Classes/OpenAPIs/Protocols.swift
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,9 @@ | ||
| // Protocols.swift | ||
| // | ||
| // Generated by openapi-generator | ||
| // https://openapi-generator.tech | ||
| // | ||
|
|
||
| /// An enum where the last case value is "unknownDefault" and can be used as a default catch-all. | ||
| public protocol CaseIterableDefaultsLast: Decodable & CaseIterable & RawRepresentable | ||
| where RawValue: Decodable, AllCases: BidirectionalCollection {} |
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
9 changes: 9 additions & 0 deletions
9
.../client/petstore/swift5/asyncAwaitLibrary/PetstoreClient/Classes/OpenAPIs/Protocols.swift
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,9 @@ | ||
| // Protocols.swift | ||
| // | ||
| // Generated by openapi-generator | ||
| // https://openapi-generator.tech | ||
| // | ||
|
|
||
| /// An enum where the last case value is "unknownDefault" and can be used as a default catch-all. | ||
| public protocol CaseIterableDefaultsLast: Decodable & CaseIterable & RawRepresentable | ||
| where RawValue: Decodable, AllCases: BidirectionalCollection {} |
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
9 changes: 9 additions & 0 deletions
9
...les/client/petstore/swift5/combineLibrary/PetstoreClient/Classes/OpenAPIs/Protocols.swift
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,9 @@ | ||
| // Protocols.swift | ||
| // | ||
| // Generated by openapi-generator | ||
| // https://openapi-generator.tech | ||
| // | ||
|
|
||
| /// An enum where the last case value is "unknownDefault" and can be used as a default catch-all. | ||
| public protocol CaseIterableDefaultsLast: Decodable & CaseIterable & RawRepresentable | ||
| where RawValue: Decodable, AllCases: BidirectionalCollection {} |
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
9 changes: 9 additions & 0 deletions
9
samples/client/petstore/swift5/default/PetstoreClient/Classes/OpenAPIs/Protocols.swift
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,9 @@ | ||
| // Protocols.swift | ||
| // | ||
| // Generated by openapi-generator | ||
| // https://openapi-generator.tech | ||
| // | ||
|
|
||
| /// An enum where the last case value is "unknownDefault" and can be used as a default catch-all. | ||
| public protocol CaseIterableDefaultsLast: Decodable & CaseIterable & RawRepresentable | ||
| where RawValue: Decodable, AllCases: BidirectionalCollection {} |
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
Oops, something went wrong.
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.
Since now we are going to assign values to the enums, can we remove this?
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.
Maybe. Let me push the next update. I think we'll want to know the enum's type in order to assign a default value that is correct.
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.
Is there any enum type that we don't support?
I think there is an easier way to do this, by removing this block of code and do this type check in the mustache files.
I think there are checks like isString, isInt, isDouble, isNumber, but I need to check tomorrow, because I'm not 100% sure.
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.
@4brunu You are correct. I had tried this earlier, but was using the mustache clauses incorrectly. I made the change to remove the custom vendor extensions and use the built-in type checks. I think we should be good now