Skip to content

Commit

Permalink
add enum name mapping option to swift generators (#17297)
Browse files Browse the repository at this point in the history
  • Loading branch information
wing328 committed Dec 5, 2023
1 parent bbd0ce3 commit cdb020d
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 3 deletions.
2 changes: 2 additions & 0 deletions bin/configs/swift-combine-petstore-new.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,5 @@ templateDir: modules/openapi-generator/src/main/resources/swift-combine
additionalProperties:
hideGenerationTimestamp: "true"
projectName: "PetstoreOpenAPI"
enumNameMappings:
delivered: shipped
2 changes: 2 additions & 0 deletions bin/configs/swift5-default.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,5 @@ additionalProperties:
podSummary: PetstoreClient
projectName: PetstoreClient
podHomepage: https://github.com/openapitools/openapi-generator
enumNameMappings:
delivered: shipped
Original file line number Diff line number Diff line change
Expand Up @@ -1027,6 +1027,10 @@ public String toEnumDefaultValue(String value, String datatype) {

@Override
public String toEnumVarName(String name, String datatype) {
if (enumNameMapping.containsKey(name)) {
return enumNameMapping.get(name);
}

if (name.length() == 0) {
return "empty";
}
Expand Down Expand Up @@ -1127,6 +1131,10 @@ private String titleCase(final String input) {

@Override
public String toEnumName(CodegenProperty property) {
if (enumNameMapping.containsKey(property.name)) {
return enumNameMapping.get(property.name);
}

String enumName = toModelName(property.name);

// Ensure that the enum type doesn't match a reserved word or
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -575,6 +575,10 @@ public String toEnumDefaultValue(String value, String datatype) {

@Override
public String toEnumVarName(String name, String datatype) {
if (enumNameMapping.containsKey(name)) {
return enumNameMapping.get(name);
}

if (name.length() == 0) {
return "empty";
}
Expand Down Expand Up @@ -630,6 +634,10 @@ public String toEnumVarName(String name, String datatype) {

@Override
public String toEnumName(CodegenProperty property) {
if (enumNameMapping.containsKey(property.name)) {
return enumNameMapping.get(property.name);
}

String enumName = toModelName(property.name);

// Ensure that the enum type doesn't match a reserved word or
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public struct Order: Codable {
public enum Status: String, Codable, CaseIterable {
case placed = "placed"
case approved = "approved"
case delivered = "delivered"
case shipped = "delivered"
}
public var id: Int64?
public var petId: Int64?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public struct Order: Codable, JSONEncodable, Hashable {
public enum Status: String, Codable, CaseIterable {
case placed = "placed"
case approved = "approved"
case delivered = "delivered"
case shipped = "delivered"
}
public var id: Int64?
public var petId: Int64?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,5 @@ import AnyCodable
public enum OuterEnum: String, Codable, CaseIterable {
case placed = "placed"
case approved = "approved"
case delivered = "delivered"
case shipped = "delivered"
}

0 comments on commit cdb020d

Please sign in to comment.