@@ -21,8 +21,12 @@ function validateSchema(api) {
2121 schema = openapi . v2 ;
2222 ajv = initializeAjv ( ) ;
2323 } else {
24- if ( api . openapi . startsWith ( "3.1" ) ) {
25- schema = openapi . v31 ;
24+ if ( api . openapi . startsWith ( "3.1" ) || api . openapi . startsWith ( "3.2" ) ) {
25+ schema = structuredClone ( openapi . v31 ) ;
26+
27+ if ( api . openapi . startsWith ( "3.2" ) ) {
28+ applyOpenApi32Compat ( schema ) ;
29+ }
2630
2731 // There's a bug with Ajv in how it handles `$dynamicRef` in the way that it's used within the 3.1 schema so we
2832 // need to do some adhoc workarounds.
@@ -34,6 +38,9 @@ function validateSchema(api) {
3438 schema . $defs . components . properties . schemas . additionalProperties = schemaDynamicRef ;
3539 schema . $defs . header . dependentSchemas . schema . properties . schema = schemaDynamicRef ;
3640 schema . $defs [ "media-type" ] . properties . schema = schemaDynamicRef ;
41+ if ( schema . $defs [ "media-type" ] . properties . itemSchema ) {
42+ schema . $defs [ "media-type" ] . properties . itemSchema = schemaDynamicRef ;
43+ }
3744 schema . $defs . parameter . properties . schema = schemaDynamicRef ;
3845
3946 ajv = initializeAjv ( false ) ;
@@ -54,6 +61,94 @@ function validateSchema(api) {
5461 }
5562}
5663
64+ /**
65+ * Applies a targeted compatibility layer so the bundled OpenAPI 3.1 schema can validate
66+ * the most important OpenAPI 3.2 additions until @apidevtools/openapi-schemas ships v3.2.
67+ *
68+ * @param {object } schema
69+ */
70+ function applyOpenApi32Compat ( schema ) {
71+ schema . properties . openapi . pattern = "^3\\.2\\.\\d+(-.+)?$" ;
72+
73+ schema . $defs . components . properties . mediaTypes = {
74+ type : "object" ,
75+ additionalProperties : {
76+ $ref : "#/$defs/media-type" ,
77+ } ,
78+ } ;
79+
80+ schema . $defs [ "path-item" ] . patternProperties [ "^query$" ] = {
81+ $ref : "#/$defs/operation" ,
82+ } ;
83+ schema . $defs [ "path-item" ] . properties . additionalOperations = {
84+ type : "object" ,
85+ additionalProperties : {
86+ $ref : "#/$defs/operation" ,
87+ } ,
88+ } ;
89+
90+ schema . $defs . response . properties . summary = {
91+ type : "string" ,
92+ } ;
93+
94+ schema . $defs [ "media-type" ] . properties . itemSchema = {
95+ $dynamicRef : "#meta" ,
96+ } ;
97+ schema . $defs [ "media-type" ] . properties . prefixEncoding = {
98+ type : "array" ,
99+ items : {
100+ $ref : "#/$defs/encoding" ,
101+ } ,
102+ } ;
103+ schema . $defs [ "media-type" ] . properties . itemEncoding = {
104+ $ref : "#/$defs/encoding" ,
105+ } ;
106+
107+ schema . $defs . tag . properties . summary = {
108+ type : "string" ,
109+ } ;
110+ schema . $defs . tag . properties . parent = {
111+ type : "string" ,
112+ } ;
113+ schema . $defs . tag . properties . kind = {
114+ type : "string" ,
115+ } ;
116+
117+ schema . $defs . parameter . properties . in . enum . push ( "querystring" ) ;
118+
119+ schema . $defs [ "security-scheme" ] . properties . oauth2MetadataUrl = {
120+ $ref : "#/$defs/uri" ,
121+ } ;
122+ schema . $defs [ "security-scheme" ] . properties . deprecated = {
123+ default : false ,
124+ type : "boolean" ,
125+ } ;
126+
127+ schema . $defs [ "oauth-flows" ] . properties . deviceAuthorization = {
128+ $ref : "#/$defs/oauth-flows/$defs/device-authorization" ,
129+ } ;
130+ schema . $defs [ "oauth-flows" ] . $defs [ "device-authorization" ] = {
131+ type : "object" ,
132+ properties : {
133+ deviceAuthorizationUrl : {
134+ type : "string" ,
135+ } ,
136+ tokenUrl : {
137+ type : "string" ,
138+ } ,
139+ refreshUrl : {
140+ type : "string" ,
141+ } ,
142+ scopes : {
143+ $ref : "#/$defs/map-of-strings" ,
144+ } ,
145+ } ,
146+ required : [ "deviceAuthorizationUrl" , "tokenUrl" , "scopes" ] ,
147+ $ref : "#/$defs/specification-extensions" ,
148+ unevaluatedProperties : false ,
149+ } ;
150+ }
151+
57152/**
58153 * Determines which version of Ajv to load and prepares it for use.
59154 *
0 commit comments