Skip to content

Commit

Permalink
Also add support for a period
Browse files Browse the repository at this point in the history
  • Loading branch information
czechboy0 committed Jul 23, 2024
1 parent 8531e2c commit 413ac87
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ extension OperationDescription {
/// The regular expression for parsing subcomponents of path components.
///
/// Either a parameter `{foo}` or a constant value `foo`.
private static let pathParameterRegex = try! NSRegularExpression(pattern: #"(\{[a-zA-Z0-9_-]+\})|([^{}]+)"#)
private static let pathParameterRegex = try! NSRegularExpression(pattern: #"(\{[a-zA-Z0-9_\-\.]+\})|([^{}]+)"#)

/// Returns a string that contains the template to be generated for
/// the client that fills in path parameters, and an array expression
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2697,13 +2697,13 @@ final class SnippetBasedReferenceTests: XCTestCase {
)
}

func testRequestWithPathParamWithHyphen() throws {
func testRequestWithPathParamWithHyphenAndPeriod() throws {
try self.assertRequestInTypesClientServerTranslation(
"""
/foo/{a-b}:
/foo/{p.a-b}:
get:
parameters:
- name: a-b
- name: p.a-b
in: path
required: true
schema:
Expand All @@ -2716,9 +2716,9 @@ final class SnippetBasedReferenceTests: XCTestCase {
types: """
public struct Input: Sendable, Hashable {
public struct Path: Sendable, Hashable {
public var a_hyphen_b: Swift.String
public init(a_hyphen_b: Swift.String) {
self.a_hyphen_b = a_hyphen_b
public var p_period_a_hyphen_b: Swift.String
public init(p_period_a_hyphen_b: Swift.String) {
self.p_period_a_hyphen_b = p_period_a_hyphen_b
}
}
public var path: Operations.getFoo.Input.Path
Expand All @@ -2732,7 +2732,7 @@ final class SnippetBasedReferenceTests: XCTestCase {
let path = try converter.renderedPath(
template: "/foo/{}",
parameters: [
input.path.a_hyphen_b
input.path.p_period_a_hyphen_b
]
)
var request: HTTPTypes.HTTPRequest = .init(
Expand All @@ -2745,9 +2745,9 @@ final class SnippetBasedReferenceTests: XCTestCase {
""",
server: """
{ request, requestBody, metadata in
let path: Operations.getFoo.Input.Path = .init(a_hyphen_b: try converter.getPathParameterAsURI(
let path: Operations.getFoo.Input.Path = .init(p_period_a_hyphen_b: try converter.getPathParameterAsURI(
in: metadata.pathParameters,
name: "a-b",
name: "p.a-b",
as: Swift.String.self
))
return Operations.getFoo.Input(path: path)
Expand Down

0 comments on commit 413ac87

Please sign in to comment.