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

Support empty string OpenAPI identifiers #59

Merged
merged 2 commits into from
Jun 11, 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: 1 addition & 1 deletion Sources/_OpenAPIGeneratorCore/Extensions/String.swift
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ fileprivate extension String {
/// ensures that the identifier starts with a letter and not a number.
var sanitizedForSwiftCode: String {
guard !isEmpty else {
return self
return "_empty"
}

// Only allow [a-zA-Z][a-zA-Z0-9_]*
Expand Down
3 changes: 3 additions & 0 deletions Tests/OpenAPIGeneratorCoreTests/Extensions/Test_String.swift
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ final class Test_String: Test_Core {

// Reserved name
("Type", "_Type"),

// Empty string
("", "_empty"),
]
for (input, sanitized) in cases {
XCTAssertEqual(input.asSwiftSafeName, sanitized)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ paths:
- water
- land
- air
- ""
type: string
- name: feeds
in: query
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -691,13 +691,15 @@ public enum Operations {
case water
case land
case air
case _empty
/// Parsed a raw value that was not defined in the OpenAPI document.
case undocumented(String)
public init?(rawValue: String) {
switch rawValue {
case "water": self = .water
case "land": self = .land
case "air": self = .air
case "": self = ._empty
default: self = .undocumented(rawValue)
}
}
Expand All @@ -707,9 +709,10 @@ public enum Operations {
case .water: return "water"
case .land: return "land"
case .air: return "air"
case ._empty: return ""
}
}
public static var allCases: [habitatPayload] { [.water, .land, .air] }
public static var allCases: [habitatPayload] { [.water, .land, .air, ._empty] }
}
public var habitat: Operations.listPets.Input.Query.habitatPayload?
/// - Remark: Generated from `#/paths/pets/GET/query/feedsPayload`.
Expand Down