1- /* eslint-disable no-unused-vars */
21/* eslint-disable no-use-before-define */
3- import { ErrorObject , Options as AjvOptions } from 'ajv' ;
2+ import { Options as AjvOptions } from 'ajv' ;
43
4+ /********
5+ Typescript string literals are broken and require this garbage to work: https://stackoverflow.com/questions/37978528/typescript-type-string-is-not-assignable-to-type so we'll break the allowed validation using typescript interfaces, we don't really care to use this for validation of the schema, so any place we use string literals we'll allow any "STRING" until it is fixed.
6+ => When fixed search here for places with `'literal' | string` and remove the string part.
7+ */
58export type BodySchema =
69 | OpenAPIV3 . ReferenceObject
710 | OpenAPIV3 . SchemaObject
@@ -80,6 +83,7 @@ export interface OpenApiValidatorOpts {
8083 formats ?: Format [ ] ;
8184}
8285
86+ // eslint-disable-next-line @typescript-eslint/no-namespace
8387export namespace OpenAPIV3 {
8488 export interface Document {
8589 openapi : string ;
@@ -169,7 +173,7 @@ export namespace OpenAPIV3 {
169173 in : string ;
170174 }
171175
172- export interface HeaderObject extends ParameterBaseObject { }
176+ export type HeaderObject = ParameterBaseObject
173177
174178 interface ParameterBaseObject {
175179 description ?: string ;
@@ -184,23 +188,34 @@ export namespace OpenAPIV3 {
184188 examples ?: { [ media : string ] : ReferenceObject | ExampleObject } ;
185189 content ?: { [ media : string ] : MediaTypeObject } ;
186190 }
187- export type NonArraySchemaObjectType =
188- | 'null'
189- | 'boolean'
190- | 'object'
191- | 'number'
192- | 'string'
193- | 'integer' ;
194- export type ArraySchemaObjectType = 'array' ;
195- export type SchemaObject = ArraySchemaObject | NonArraySchemaObject ;
196191
192+ export type SchemaObject = ArraySchemaObject | NonArraySchemaObject | AllOfSchemaObject | OneOfSchemaObject | anyOfSchemaObject | notSchemaObject ;
193+
194+ export interface AllOfSchemaObject extends BaseSchemaObject {
195+ allOf : Array < ReferenceObject | SchemaObject > ;
196+ }
197+
198+ export interface OneOfSchemaObject extends BaseSchemaObject {
199+ oneOf : Array < ReferenceObject | SchemaObject > ;
200+ }
201+
202+ export interface anyOfSchemaObject extends BaseSchemaObject {
203+ anyOf : Array < ReferenceObject | SchemaObject > ;
204+ }
205+
206+ export interface notSchemaObject extends BaseSchemaObject {
207+ not : Array < ReferenceObject | SchemaObject > ;
208+ }
209+
210+ export type ArraySchemaObjectType = 'array' ;
197211 export interface ArraySchemaObject extends BaseSchemaObject {
198- type : ArraySchemaObjectType ;
212+ type : ArraySchemaObjectType | string ;
199213 items : ReferenceObject | SchemaObject ;
200214 }
201215
216+ export type NonArraySchemaObjectType = 'null' | 'boolean' | 'object' | 'number' | 'string' | 'integer' ;
202217 export interface NonArraySchemaObject extends BaseSchemaObject {
203- type : NonArraySchemaObjectType ;
218+ type : NonArraySchemaObjectType | string ;
204219 }
205220
206221 interface BaseSchemaObject {
@@ -228,10 +243,6 @@ export namespace OpenAPIV3 {
228243 properties ?: {
229244 [ name : string ] : ReferenceObject | SchemaObject ;
230245 } ;
231- allOf ?: Array < ReferenceObject | SchemaObject > ;
232- oneOf ?: Array < ReferenceObject | SchemaObject > ;
233- anyOf ?: Array < ReferenceObject | SchemaObject > ;
234- not ?: ReferenceObject | SchemaObject ;
235246
236247 // OpenAPI-specific properties
237248 nullable ?: boolean ;
@@ -339,21 +350,22 @@ export namespace OpenAPIV3 {
339350 | OpenIdSecurityScheme ;
340351
341352 export interface HttpSecurityScheme {
342- type : 'http' ;
353+ type : 'http' | string ;
343354 description ?: string ;
344355 scheme : string ;
345356 bearerFormat ?: string ;
346357 }
347358
348359 export interface ApiKeySecurityScheme {
349- type : 'apiKey' ;
360+ type : 'apiKey' | string ;
350361 description ?: string ;
351362 name : string ;
352363 in : string ;
353364 }
354365
355366 export interface OAuth2SecurityScheme {
356- type : 'oauth2' ;
367+ type : 'oauth2' | string ;
368+ description ?: string ;
357369 flows : {
358370 implicit ?: {
359371 authorizationUrl : string ;
@@ -380,7 +392,7 @@ export namespace OpenAPIV3 {
380392 }
381393
382394 export interface OpenIdSecurityScheme {
383- type : 'openIdConnect' ;
395+ type : 'openIdConnect' | string ;
384396 description ?: string ;
385397 openIdConnectUrl : string ;
386398 }
@@ -481,9 +493,9 @@ interface ErrorHeaders {
481493}
482494
483495export class BadRequest extends Error implements ValidationError {
484- status : number = 400 ;
496+ status = 400 ;
485497 path ?: string ;
486- name : string = 'Bad Request' ;
498+ name = 'Bad Request' ;
487499 message ! : string ;
488500 headers ?: ErrorHeaders ;
489501 errors ! : ValidationErrorItem [ ] ;
0 commit comments