@@ -23,7 +23,7 @@ extension OpenAPI {
2323 ///
2424 /// You can access an array of equatable `HttpMethod`/`Operation` paris with the
2525 /// `endpoints` property.
26- public struct PathItem : Equatable , CodableVendorExtendable , Sendable {
26+ public struct PathItem : HasConditionalWarnings , CodableVendorExtendable , Sendable {
2727 public var summary : String ?
2828 public var description : String ?
2929 public var servers : [ OpenAPI . Server ] ?
@@ -64,6 +64,12 @@ extension OpenAPI {
6464 /// where the values are anything codable.
6565 public var vendorExtensions : [ String : AnyCodable ]
6666
67+ /// Warnings that apply conditionally depending on the OpenAPI Document
68+ /// the PathItem belongs to.
69+ ///
70+ /// Check these with the `applicableConditionalWarnings(for:)` method.
71+ public let conditionalWarnings : [ ( any Condition , OpenAPI . Warning ) ]
72+
6773 public init (
6874 summary: String ? = nil ,
6975 description: String ? = nil ,
@@ -95,6 +101,11 @@ extension OpenAPI {
95101 self . trace = trace
96102 self . query = query
97103 self . vendorExtensions = vendorExtensions
104+
105+ self . conditionalWarnings = [
106+ // If query is non-nil, the document must be OAS version 3.2.0 or greater
107+ nonNilVersionWarning ( fieldName: " query " , value: query, minimumVersion: . v3_2_0)
108+ ] . compactMap { $0 }
98109 }
99110
100111 /// Set the `GET` endpoint operation.
@@ -144,6 +155,34 @@ extension OpenAPI {
144155 }
145156}
146157
158+ extension OpenAPI . PathItem : Equatable {
159+ public static func == ( lhs: Self , rhs: Self ) -> Bool {
160+ lhs. summary == rhs. summary
161+ && lhs. description == rhs. description
162+ && lhs. servers == rhs. servers
163+ && lhs. parameters == rhs. parameters
164+ && lhs. get == rhs. get
165+ && lhs. put == rhs. put
166+ && lhs. post == rhs. post
167+ && lhs. delete == rhs. delete
168+ && lhs. options == rhs. options
169+ && lhs. head == rhs. head
170+ && lhs. patch == rhs. patch
171+ && lhs. trace == rhs. trace
172+ && lhs. query == rhs. query
173+ && lhs. vendorExtensions == rhs. vendorExtensions
174+ }
175+ }
176+
177+ fileprivate func nonNilVersionWarning< Subject> ( fieldName: String , value: Subject ? , minimumVersion: OpenAPI . Document . Version ) -> ( any Condition , OpenAPI . Warning ) ? {
178+ value. map { _ in
179+ OpenAPI . Document. ConditionalWarnings. version (
180+ lessThan: minimumVersion,
181+ doesNotSupport: " The PathItem \( fieldName) field "
182+ )
183+ }
184+ }
185+
147186extension OpenAPI . PathItem {
148187 public typealias Map = OrderedDictionary < OpenAPI . Path , Either < OpenAPI . Reference < OpenAPI . PathItem > , OpenAPI . PathItem > >
149188}
@@ -300,6 +339,11 @@ extension OpenAPI.PathItem: Decodable {
300339 query = try container. decodeIfPresent ( OpenAPI . Operation. self, forKey: . query)
301340
302341 vendorExtensions = try Self . extensions ( from: decoder)
342+
343+ self . conditionalWarnings = [
344+ // If query is non-nil, the document must be OAS version 3.2.0 or greater
345+ nonNilVersionWarning ( fieldName: " query " , value: query, minimumVersion: . v3_2_0)
346+ ] . compactMap { $0 }
303347 } catch let error as DecodingError {
304348
305349 throw OpenAPI . Error. Decoding. Path ( error)
0 commit comments