Skip to content
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

[Swift5] add enum name mapping option #17297

Merged
merged 1 commit into from
Dec 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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"
}
Loading