Skip to content

Commit 1334311

Browse files
committed
Add more Tests for requred & optionals params.
1 parent 7e8f9a2 commit 1334311

File tree

7 files changed

+117
-13
lines changed

7 files changed

+117
-13
lines changed

Package.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ let package = Package(
5454
// Tests-only: Runtime library linked by generated code, and also
5555
// helps keep the runtime library new enough to work with the generated
5656
// code.
57-
.package(url: "https://github.com/apple/swift-openapi-runtime", from: "1.5.0"),
57+
.package(url: "https://github.com/apple/swift-openapi-runtime", from: "1.8.0"),
5858
.package(url: "https://github.com/apple/swift-http-types", from: "1.0.2"),
5959
],
6060
targets: [

Tests/OpenAPIGeneratorReferenceTests/Resources/Docs/petstore.yaml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,11 +76,27 @@ paths:
7676
explode: true
7777
schema:
7878
type: object
79+
required:
80+
- id
7981
properties:
8082
id:
8183
type: string
8284
name:
8385
type: string
86+
- name: filter
87+
in: query
88+
required: true
89+
style: deepObject
90+
explode: true
91+
schema:
92+
type: object
93+
required:
94+
- name
95+
properties:
96+
name:
97+
type: string
98+
state:
99+
type: string
84100
- $ref: '#/components/parameters/query.born-since'
85101
responses:
86102
'200':

Tests/OpenAPIGeneratorReferenceTests/Resources/ReferenceSources/Petstore/Client.swift

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,13 @@ public struct Client: APIProtocol {
9494
name: "sort",
9595
value: input.query.sort
9696
)
97+
try converter.setQueryItemAsURI(
98+
in: &request,
99+
style: .deepObject,
100+
explode: true,
101+
name: "filter",
102+
value: input.query.filter
103+
)
97104
try converter.setQueryItemAsURI(
98105
in: &request,
99106
style: .form,

Tests/OpenAPIGeneratorReferenceTests/Resources/ReferenceSources/Petstore/Server.swift

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,14 @@ fileprivate extension UniversalServer where APIHandler: APIProtocol {
192192
style: .deepObject,
193193
explode: true,
194194
name: "sort",
195-
as: Operations.listPets.Input.Query.sortPayload.self
195+
as: Operations.ListPets.Input.Query.SortPayload.self
196+
),
197+
filter: try converter.getRequiredQueryItemAsURI(
198+
in: request.soar_query,
199+
style: .deepObject,
200+
explode: true,
201+
name: "filter",
202+
as: Operations.ListPets.Input.Query.FilterPayload.self
196203
),
197204
since: try converter.getOptionalQueryItemAsURI(
198205
in: request.soar_query,

Tests/OpenAPIGeneratorReferenceTests/Resources/ReferenceSources/Petstore/Types.swift

Lines changed: 35 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ extension APIProtocol {
6666
/// - Remark: HTTP `GET /pets`.
6767
/// - Remark: Generated from `#/paths//pets/get(listPets)`.
6868
public func listPets(
69-
query: Operations.ListPets.Input.Query = .init(),
69+
query: Operations.ListPets.Input.Query,
7070
headers: Operations.ListPets.Input.Headers = .init()
7171
) async throws -> Operations.ListPets.Output {
7272
try await listPets(Operations.ListPets.Input(
@@ -1898,16 +1898,16 @@ public enum Operations {
18981898
/// - Remark: Generated from `#/paths/pets/GET/query/sort`.
18991899
public struct SortPayload: Codable, Hashable, Sendable {
19001900
/// - Remark: Generated from `#/paths/pets/GET/query/sort/id`.
1901-
public var id: Swift.String?
1901+
public var id: Swift.String
19021902
/// - Remark: Generated from `#/paths/pets/GET/query/sort/name`.
19031903
public var name: Swift.String?
1904-
/// Creates a new `sortPayload`.
1904+
/// Creates a new `SortPayload`.
19051905
///
19061906
/// - Parameters:
19071907
/// - id:
19081908
/// - name:
19091909
public init(
1910-
id: Swift.String? = nil,
1910+
id: Swift.String,
19111911
name: Swift.String? = nil
19121912
) {
19131913
self.id = id
@@ -1919,7 +1919,32 @@ public enum Operations {
19191919
}
19201920
}
19211921
/// - Remark: Generated from `#/paths/pets/GET/query/sort`.
1922-
public var sort: Operations.listPets.Input.Query.SortPayload?
1922+
public var sort: Operations.ListPets.Input.Query.SortPayload?
1923+
/// - Remark: Generated from `#/paths/pets/GET/query/filter`.
1924+
public struct FilterPayload: Codable, Hashable, Sendable {
1925+
/// - Remark: Generated from `#/paths/pets/GET/query/filter/name`.
1926+
public var name: Swift.String
1927+
/// - Remark: Generated from `#/paths/pets/GET/query/filter/state`.
1928+
public var state: Swift.String?
1929+
/// Creates a new `FilterPayload`.
1930+
///
1931+
/// - Parameters:
1932+
/// - name:
1933+
/// - state:
1934+
public init(
1935+
name: Swift.String,
1936+
state: Swift.String? = nil
1937+
) {
1938+
self.name = name
1939+
self.state = state
1940+
}
1941+
public enum CodingKeys: String, CodingKey {
1942+
case name
1943+
case state
1944+
}
1945+
}
1946+
/// - Remark: Generated from `#/paths/pets/GET/query/filter`.
1947+
public var filter: Operations.ListPets.Input.Query.FilterPayload
19231948
/// Supply this parameter to filter pets born since the provided date.
19241949
///
19251950
/// - Remark: Generated from `#/paths/pets/GET/query/since`.
@@ -1931,18 +1956,21 @@ public enum Operations {
19311956
/// - habitat:
19321957
/// - feeds:
19331958
/// - sort:
1959+
/// - filter:
19341960
/// - since: Supply this parameter to filter pets born since the provided date.
19351961
public init(
19361962
limit: Swift.Int32? = nil,
19371963
habitat: Operations.ListPets.Input.Query.HabitatPayload? = nil,
19381964
feeds: Operations.ListPets.Input.Query.FeedsPayload? = nil,
1939-
sort: Operations.listPets.Input.Query.SortPayload? = nil,
1965+
sort: Operations.ListPets.Input.Query.SortPayload? = nil,
1966+
filter: Operations.ListPets.Input.Query.FilterPayload,
19401967
since: Components.Parameters.Query_bornSince? = nil
19411968
) {
19421969
self.limit = limit
19431970
self.habitat = habitat
19441971
self.feeds = feeds
19451972
self.sort = sort
1973+
self.filter = filter
19461974
self.since = since
19471975
}
19481976
}
@@ -1974,7 +2002,7 @@ public enum Operations {
19742002
/// - query:
19752003
/// - headers:
19762004
public init(
1977-
query: Operations.ListPets.Input.Query = .init(),
2005+
query: Operations.ListPets.Input.Query,
19782006
headers: Operations.ListPets.Input.Headers = .init()
19792007
) {
19802008
self.query = query

Tests/OpenAPIGeneratorReferenceTests/SnippetBasedReferenceTests.swift

Lines changed: 49 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2551,6 +2551,20 @@ final class SnippetBasedReferenceTests: XCTestCase {
25512551
type: string
25522552
option2:
25532553
type: string
2554+
- name: filter
2555+
in: query
2556+
required: true
2557+
style: deepObject
2558+
explode: true
2559+
schema:
2560+
type: object
2561+
required:
2562+
- option3
2563+
properties:
2564+
option3:
2565+
type: string
2566+
option4:
2567+
type: string
25542568
responses:
25552569
default:
25562570
description: Response
@@ -2576,17 +2590,35 @@ final class SnippetBasedReferenceTests: XCTestCase {
25762590
case option2
25772591
}
25782592
}
2579-
public var sort: Operations.get_sol_foo.Input.Query.sortPayload
2593+
public var sort: Operations.get_sol_foo.Input.Query.sortPayload?
2594+
public struct filterPayload: Codable, Hashable, Sendable {
2595+
public var option3: Swift.String
2596+
public var option4: Swift.String?
2597+
public init(
2598+
option3: Swift.String,
2599+
option4: Swift.String? = nil
2600+
) {
2601+
self.option3 = option3
2602+
self.option4 = option4
2603+
}
2604+
public enum CodingKeys: String, CodingKey {
2605+
case option3
2606+
case option4
2607+
}
2608+
}
2609+
public var filter: Operations.get_sol_foo.Input.Query.filterPayload
25802610
public init(
25812611
single: Swift.String? = nil,
25822612
manyExploded: [Swift.String]? = nil,
25832613
manyUnexploded: [Swift.String]? = nil,
2584-
sort: Operations.get_sol_foo.Input.Query.sortPayload
2614+
sort: Operations.get_sol_foo.Input.Query.sortPayload? = nil,
2615+
filter: Operations.get_sol_foo.Input.Query.filterPayload
25852616
) {
25862617
self.single = single
25872618
self.manyExploded = manyExploded
25882619
self.manyUnexploded = manyUnexploded
25892620
self.sort = sort
2621+
self.filter = filter
25902622
}
25912623
}
25922624
public var query: Operations.get_sol_foo.Input.Query
@@ -2634,6 +2666,13 @@ final class SnippetBasedReferenceTests: XCTestCase {
26342666
name: "sort",
26352667
value: input.query.sort
26362668
)
2669+
try converter.setQueryItemAsURI(
2670+
in: &request,
2671+
style: .deepObject,
2672+
explode: true,
2673+
name: "filter",
2674+
value: input.query.filter
2675+
)
26372676
return (request, nil)
26382677
}
26392678
""",
@@ -2661,12 +2700,19 @@ final class SnippetBasedReferenceTests: XCTestCase {
26612700
name: "manyUnexploded",
26622701
as: [Swift.String].self
26632702
),
2664-
sort: try converter.getRequiredQueryItemAsURI(
2703+
sort: try converter.getOptionalQueryItemAsURI(
26652704
in: request.soar_query,
26662705
style: .deepObject,
26672706
explode: true,
26682707
name: "sort",
26692708
as: Operations.get_sol_foo.Input.Query.sortPayload.self
2709+
),
2710+
filter: try converter.getRequiredQueryItemAsURI(
2711+
in: request.soar_query,
2712+
style: .deepObject,
2713+
explode: true,
2714+
name: "filter",
2715+
as: Operations.get_sol_foo.Input.Query.filterPayload.self
26702716
)
26712717
)
26722718
return Operations.get_sol_foo.Input(query: query)

Tests/PetstoreConsumerTests/Test_Server.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ final class Test_Server: XCTestCase {
4444
})
4545
let (response, responseBody) = try await server.listPets(
4646
.init(
47-
soar_path: "/api/pets?sort%5Bid%5D=ascending&sort%5Bname%5D=descending",
47+
soar_path: "/api/pets?limit=24&habitat=water&feeds=carnivore&feeds=herbivore&sort%5Bid%5D=ascending&sort%5Bname%5D=descending&since=\(Date.testString)",
4848
method: .get,
4949
headerFields: [.init("My-Request-UUID")!: "abcd-1234"]
5050
),

0 commit comments

Comments
 (0)