@@ -12,7 +12,7 @@ extension OpenAPI.Parameter {
1212 ///
1313 /// See [OpenAPI Parameter Object](https://spec.openapis.org/oas/v3.1.1.html#parameter-object)
1414 /// and [OpenAPI Style Values](https://spec.openapis.org/oas/v3.1.1.html#style-values).
15- public struct SchemaContext : Equatable , Sendable {
15+ public struct SchemaContext : HasConditionalWarnings , Sendable {
1616 public var style : Style
1717 public var explode : Bool
1818 public var allowReserved : Bool //defaults to false
@@ -21,6 +21,8 @@ extension OpenAPI.Parameter {
2121 public var example : AnyCodable ?
2222 public var examples : OpenAPI . Example . Map ?
2323
24+ public let conditionalWarnings : [ ( any Condition , OpenAPI . Warning ) ]
25+
2426 public init ( _ schema: JSONSchema ,
2527 style: Style ,
2628 explode: Bool ,
@@ -32,6 +34,8 @@ extension OpenAPI.Parameter {
3234 self . schema = . init( schema)
3335 self . example = example
3436 self . examples = nil
37+
38+ self . conditionalWarnings = style. conditionalWarnings
3539 }
3640
3741 public init ( _ schema: JSONSchema ,
@@ -45,6 +49,8 @@ extension OpenAPI.Parameter {
4549 self . examples = nil
4650
4751 self . explode = style. defaultExplode
52+
53+ self . conditionalWarnings = style. conditionalWarnings
4854 }
4955
5056 public init ( schemaReference: OpenAPI . Reference < JSONSchema > ,
@@ -58,6 +64,8 @@ extension OpenAPI.Parameter {
5864 self . schema = . init( schemaReference)
5965 self . example = example
6066 self . examples = nil
67+
68+ self . conditionalWarnings = style. conditionalWarnings
6169 }
6270
6371 public init ( schemaReference: OpenAPI . Reference < JSONSchema > ,
@@ -71,6 +79,8 @@ extension OpenAPI.Parameter {
7179 self . examples = nil
7280
7381 self . explode = style. defaultExplode
82+
83+ self . conditionalWarnings = style. conditionalWarnings
7484 }
7585
7686 public init ( _ schema: JSONSchema ,
@@ -84,6 +94,8 @@ extension OpenAPI.Parameter {
8494 self . schema = . init( schema)
8595 self . examples = examples
8696 self . example = examples. flatMap ( OpenAPI . Content. firstExample ( from: ) )
97+
98+ self . conditionalWarnings = style. conditionalWarnings
8799 }
88100
89101 public init ( _ schema: JSONSchema ,
@@ -97,6 +109,8 @@ extension OpenAPI.Parameter {
97109 self . example = examples. flatMap ( OpenAPI . Content. firstExample ( from: ) )
98110
99111 self . explode = style. defaultExplode
112+
113+ self . conditionalWarnings = style. conditionalWarnings
100114 }
101115
102116 public init ( schemaReference: OpenAPI . Reference < JSONSchema > ,
@@ -110,6 +124,8 @@ extension OpenAPI.Parameter {
110124 self . schema = . init( schemaReference)
111125 self . examples = examples
112126 self . example = examples. flatMap ( OpenAPI . Content. firstExample ( from: ) )
127+
128+ self . conditionalWarnings = style. conditionalWarnings
113129 }
114130
115131 public init ( schemaReference: OpenAPI . Reference < JSONSchema > ,
@@ -123,10 +139,39 @@ extension OpenAPI.Parameter {
123139 self . example = examples. flatMap ( OpenAPI . Content. firstExample ( from: ) )
124140
125141 self . explode = style. defaultExplode
142+
143+ self . conditionalWarnings = style. conditionalWarnings
126144 }
127145 }
128146}
129147
148+ extension OpenAPI . Parameter . SchemaContext . Style {
149+ fileprivate var conditionalWarnings : [ ( any Condition , OpenAPI . Warning ) ] {
150+ let cookieStyleWarning : ( any Condition , OpenAPI . Warning ) ?
151+ if self != . cookie {
152+ cookieStyleWarning = nil
153+ } else {
154+ cookieStyleWarning = OpenAPI . Document. ConditionalWarnings. version ( lessThan: . v3_2_0, doesNotSupport: " The cookie style " )
155+ }
156+
157+
158+ return [
159+ cookieStyleWarning
160+ ] . compactMap { $0 }
161+ }
162+ }
163+
164+ extension OpenAPI . Parameter . SchemaContext : Equatable {
165+ public static func == ( _ lhs: Self , _ rhs: Self ) -> Bool {
166+ lhs. style == rhs. style
167+ && lhs. allowReserved == rhs. allowReserved
168+ && lhs. explode == rhs. explode
169+ && lhs. schema == rhs. schema
170+ && lhs. examples == rhs. examples
171+ && lhs. example == rhs. example
172+ }
173+ }
174+
130175extension OpenAPI . Parameter . SchemaContext {
131176 public static func schema( _ schema: JSONSchema ,
132177 style: Style ,
@@ -278,6 +323,8 @@ extension OpenAPI.Parameter.SchemaContext {
278323 examples = examplesMap
279324 example = examplesMap. flatMap ( OpenAPI . Content. firstExample ( from: ) )
280325 }
326+
327+ self . conditionalWarnings = style. conditionalWarnings
281328 }
282329}
283330
0 commit comments