Skip to content

Commit 87cd1e7

Browse files
committed
Fix ts issues with string literals
1 parent 73b60f1 commit 87cd1e7

1 file changed

Lines changed: 31 additions & 19 deletions

File tree

src/framework/types.ts

Lines changed: 31 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
/* eslint-disable no-use-before-define */
22
import { Options as AjvOptions } from 'ajv';
33

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+
*/
48
export type BodySchema =
59
| OpenAPIV3.ReferenceObject
610
| OpenAPIV3.SchemaObject
@@ -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
}

0 commit comments

Comments
 (0)