-
-
Notifications
You must be signed in to change notification settings - Fork 7.3k
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
Changes from all commits
0a6d4da
bd8cba2
96a8b4b
1d6efb3
9280e55
2950d0d
219e3d5
8113ed9
869499e
0e873a9
6eab5c3
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| 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 |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1,32 @@ | ||
| {{#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}}{{#isInteger}}, CaseIterableDefaultsLast{{/isInteger}}{{#isFloat}}, CaseIterableDefaultsLast{{/isFloat}}{{#isDouble}}, CaseIterableDefaultsLast{{/isDouble}}{{#isString}}, CaseIterableDefaultsLast{{/isString}}{{/generateFrozenEnums}} { | ||
| {{#allowableValues}} | ||
| {{#enumVars}} | ||
| case {{{name}}} = {{{value}}} | ||
| {{/enumVars}} | ||
| {{/allowableValues}} | ||
| {{^generateFrozenEnums}} | ||
| // This case is a catch-all generated by OpenAPI such that the enum is "non-frozen". | ||
| // If new enum cases are added that are unknown to the spec/client, they are safely | ||
| // decoded to this case. The raw value of this case is a dummy value that attempts | ||
| // to avoids collisions with previously specified cases. | ||
| {{#isString}} | ||
| case unknownDefaultOpenAPI = "unknown_default_open_api" | ||
| {{/isString}} | ||
| {{#isNumeric}} | ||
| // | ||
| // 192, used to calculate the raw value, was the Swift Evolution proposal for | ||
| // frozen/non-frozen enums. | ||
| // [SE-0192](https://github.com/apple/swift-evolution/blob/master/proposals/0192-non-exhaustive-enums.md) | ||
| // | ||
| {{/isNumeric}} | ||
| {{#isInteger}} | ||
| case unknownDefaultOpenAPI = -11184809 // Int.min / 192 | ||
| {{/isInteger}} | ||
| {{#isDouble}} | ||
| case unknownDefaultOpenAPI = -11184809 // Int.min / 192 | ||
| {{/isDouble}} | ||
| {{#isFloat}} | ||
| case unknownDefaultOpenAPI = -11184809 // Int.min / 192 | ||
| {{/isFloat}} | ||
| {{/generateFrozenEnums}} | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1,35 @@ | ||
| {{#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}}{{#isInteger}}, CaseIterableDefaultsLast{{/isInteger}}{{#isFloat}}, CaseIterableDefaultsLast{{/isFloat}}{{#isDouble}}, CaseIterableDefaultsLast{{/isDouble}}{{#isString}}, CaseIterableDefaultsLast{{/isString}}{{#isContainer}}, CaseIterableDefaultsLast{{/isContainer}}{{/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 |
||
| // This case is a catch-all generated by OpenAPI such that the enum is "non-frozen". | ||
| // If new enum cases are added that are unknown to the spec/client, they are safely | ||
| // decoded to this case. The raw value of this case is a dummy value that attempts | ||
| // to avoids collisions with previously specified cases. | ||
| {{#isString}} | ||
| case unknownDefaultOpenAPI = "unknown_default_open_api" | ||
| {{/isString}} | ||
| {{#isContainer}} | ||
|
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 should this logic of the
Contributor
Author
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. I don't believe so — the only thing that gave me the hunch to use
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. You are right 👍 |
||
| case unknownDefaultOpenAPI = "unknown_default_open_api" | ||
| {{/isContainer}} | ||
| {{#isNumeric}} | ||
| // | ||
| // 192, used to calculate the raw value, was the Swift Evolution proposal for | ||
| // frozen/non-frozen enums. | ||
| // [SE-0192](https://github.com/apple/swift-evolution/blob/master/proposals/0192-non-exhaustive-enums.md) | ||
| // | ||
| {{/isNumeric}} | ||
| {{#isInteger}} | ||
| case unknownDefaultOpenAPI = -11184809 // Int.min / 192 | ||
| {{/isInteger}} | ||
| {{#isDouble}} | ||
| case unknownDefaultOpenAPI = -11184809 // Int.min / 192 | ||
| {{/isDouble}} | ||
| {{#isFloat}} | ||
| case unknownDefaultOpenAPI = -11184809 // Int.min / 192 | ||
| {{/isFloat}} | ||
| {{/generateFrozenEnums}} | ||
| } | ||
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.
@jarrodparkes should we support more types? Maybe Double, Float, and more?
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.
now that we are specifying the raw values, yes 😄 — will add shortly