@scalar/openapi-parser 0.0.0 → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md ADDED
@@ -0,0 +1,7 @@
1
+ # @scalar/openapi-parser
2
+
3
+ ## 0.1.0
4
+
5
+ ### Minor Changes
6
+
7
+ - fb3b15f: init :)
package/README.md CHANGED
@@ -8,15 +8,6 @@
8
8
 
9
9
  Modern OpenAPI parser written in TypeScript, with support for Swagger 2.0, OpenAPI 3.0 and OpenAPI 3.1
10
10
 
11
- ## Goals
12
-
13
- - [x] TypeScript FTW
14
- - [x] No Node.js polyfills required
15
- - [x] Well tested
16
- - [x] Small bundlesize
17
- - [x] Better errors
18
- - [ ] Support for OpenAPI 4.0 👀
19
-
20
11
  ## Installation
21
12
 
22
13
  ```
@@ -64,3 +55,22 @@ if (!result.valid) {
64
55
  console.log(result.errors)
65
56
  }
66
57
  ```
58
+
59
+ ### Version
60
+
61
+ ```ts
62
+ import { parse } from '@scalar/openapi-parser'
63
+
64
+ const file = `{
65
+ "openapi": "3.1.0",
66
+ "info": {
67
+ "title": "Hello World",
68
+ "version": "1.0.0"
69
+ },
70
+ "paths": {}
71
+ }`
72
+
73
+ const result = await parse(file)
74
+
75
+ console.log(result.version)
76
+ ```
@@ -0,0 +1,807 @@
1
+ export declare type AjvOptions = {
2
+ strict?: boolean | 'log';
3
+ };
4
+
5
+ export declare type EmptyObject = Record<string, never>;
6
+
7
+ export declare type ErrorObject = {
8
+ start: {
9
+ line: number;
10
+ column: number;
11
+ offset: number;
12
+ };
13
+ error: string;
14
+ path: string;
15
+ };
16
+
17
+ export declare interface IJsonSchema {
18
+ id?: string;
19
+ $schema?: string;
20
+ title?: string;
21
+ description?: string;
22
+ multipleOf?: number;
23
+ maximum?: number;
24
+ exclusiveMaximum?: boolean;
25
+ minimum?: number;
26
+ exclusiveMinimum?: boolean;
27
+ maxLength?: number;
28
+ minLength?: number;
29
+ pattern?: string;
30
+ additionalItems?: boolean | IJsonSchema;
31
+ items?: IJsonSchema | IJsonSchema[];
32
+ maxItems?: number;
33
+ minItems?: number;
34
+ uniqueItems?: boolean;
35
+ maxProperties?: number;
36
+ minProperties?: number;
37
+ required?: string[];
38
+ additionalProperties?: boolean | IJsonSchema;
39
+ definitions?: {
40
+ [name: string]: IJsonSchema;
41
+ };
42
+ properties?: {
43
+ [name: string]: IJsonSchema;
44
+ };
45
+ patternProperties?: {
46
+ [name: string]: IJsonSchema;
47
+ };
48
+ dependencies?: {
49
+ [name: string]: IJsonSchema | string[];
50
+ };
51
+ enum?: any[];
52
+ type?: string | string[];
53
+ allOf?: IJsonSchema[];
54
+ anyOf?: IJsonSchema[];
55
+ oneOf?: IJsonSchema[];
56
+ not?: IJsonSchema;
57
+ $ref?: string;
58
+ }
59
+
60
+ /**
61
+ * These types are copied from 'openapi-types', but the `ReferenceObject` type is removed.
62
+ * After an OpenAPI schema is parsed, all references are resolved and replaced with the actual object.
63
+ */
64
+ export declare namespace OpenAPI {
65
+ export type Document<T extends {} = EmptyObject> = OpenAPIV2.Document<T> | OpenAPIV3.Document<T> | OpenAPIV3_1.Document<T>;
66
+ export type Operation<T extends {} = EmptyObject> = OpenAPIV2.OperationObject<T> | OpenAPIV3.OperationObject<T> | OpenAPIV3_1.OperationObject<T>;
67
+ export type Parameter = OpenAPIV3_1.ParameterObject | OpenAPIV3.ParameterObject | OpenAPIV2.Parameter;
68
+ export type Parameters = OpenAPIV3_1.ParameterObject[] | OpenAPIV3.ParameterObject[] | OpenAPIV2.Parameter[];
69
+ export interface Request {
70
+ body?: any;
71
+ headers?: object;
72
+ params?: object;
73
+ query?: object;
74
+ }
75
+ }
76
+
77
+ export declare namespace OpenAPIV2 {
78
+ export interface Document<T extends {} = EmptyObject> {
79
+ 'basePath'?: string;
80
+ 'consumes'?: MimeTypes;
81
+ 'definitions'?: DefinitionsObject;
82
+ 'externalDocs'?: ExternalDocumentationObject;
83
+ 'host'?: string;
84
+ 'info': InfoObject;
85
+ 'parameters'?: ParametersDefinitionsObject;
86
+ 'paths': PathsObject<T>;
87
+ 'produces'?: MimeTypes;
88
+ 'responses'?: ResponsesDefinitionsObject;
89
+ 'schemes'?: string[];
90
+ 'security'?: SecurityRequirementObject[];
91
+ 'securityDefinitions'?: SecurityDefinitionsObject;
92
+ 'swagger': string;
93
+ 'tags'?: TagObject[];
94
+ 'x-express-openapi-additional-middleware'?: (((request: any, response: any, next: any) => Promise<void>) | ((request: any, response: any, next: any) => void))[];
95
+ 'x-express-openapi-validation-strict'?: boolean;
96
+ }
97
+ export interface TagObject {
98
+ name: string;
99
+ description?: string;
100
+ externalDocs?: ExternalDocumentationObject;
101
+ }
102
+ export interface SecuritySchemeObjectBase {
103
+ type: 'basic' | 'apiKey' | 'oauth2';
104
+ description?: string;
105
+ }
106
+ export interface SecuritySchemeBasic extends SecuritySchemeObjectBase {
107
+ type: 'basic';
108
+ }
109
+ export interface SecuritySchemeApiKey extends SecuritySchemeObjectBase {
110
+ type: 'apiKey';
111
+ name: string;
112
+ in: string;
113
+ }
114
+ export type SecuritySchemeOauth2 = SecuritySchemeOauth2Implicit | SecuritySchemeOauth2AccessCode | SecuritySchemeOauth2Password | SecuritySchemeOauth2Application;
115
+ export interface ScopesObject {
116
+ [index: string]: any;
117
+ }
118
+ export interface SecuritySchemeOauth2Base extends SecuritySchemeObjectBase {
119
+ type: 'oauth2';
120
+ flow: 'implicit' | 'password' | 'application' | 'accessCode';
121
+ scopes: ScopesObject;
122
+ }
123
+ export interface SecuritySchemeOauth2Implicit extends SecuritySchemeOauth2Base {
124
+ flow: 'implicit';
125
+ authorizationUrl: string;
126
+ }
127
+ export interface SecuritySchemeOauth2AccessCode extends SecuritySchemeOauth2Base {
128
+ flow: 'accessCode';
129
+ authorizationUrl: string;
130
+ tokenUrl: string;
131
+ }
132
+ export interface SecuritySchemeOauth2Password extends SecuritySchemeOauth2Base {
133
+ flow: 'password';
134
+ tokenUrl: string;
135
+ }
136
+ export interface SecuritySchemeOauth2Application extends SecuritySchemeOauth2Base {
137
+ flow: 'application';
138
+ tokenUrl: string;
139
+ }
140
+ export type SecuritySchemeObject = SecuritySchemeBasic | SecuritySchemeApiKey | SecuritySchemeOauth2;
141
+ export interface SecurityDefinitionsObject {
142
+ [index: string]: SecuritySchemeObject;
143
+ }
144
+ export interface SecurityRequirementObject {
145
+ [index: string]: string[];
146
+ }
147
+ export interface ReferenceObject {
148
+ $ref: string;
149
+ }
150
+ export type Response = ResponseObject;
151
+ export interface ResponsesDefinitionsObject {
152
+ [index: string]: ResponseObject;
153
+ }
154
+ export type Schema = SchemaObject;
155
+ export interface ResponseObject {
156
+ description: string;
157
+ schema?: Schema;
158
+ headers?: HeadersObject;
159
+ examples?: ExampleObject;
160
+ }
161
+ export interface HeadersObject {
162
+ [index: string]: HeaderObject;
163
+ }
164
+ export interface HeaderObject extends ItemsObject {
165
+ description?: string;
166
+ }
167
+ export interface ExampleObject {
168
+ [index: string]: any;
169
+ }
170
+ export interface ResponseObject {
171
+ description: string;
172
+ schema?: Schema;
173
+ headers?: HeadersObject;
174
+ examples?: ExampleObject;
175
+ }
176
+ export type OperationObject<T extends {} = EmptyObject> = {
177
+ tags?: string[];
178
+ summary?: string;
179
+ description?: string;
180
+ externalDocs?: ExternalDocumentationObject;
181
+ operationId?: string;
182
+ consumes?: MimeTypes;
183
+ produces?: MimeTypes;
184
+ parameters?: Parameters;
185
+ responses: ResponsesObject;
186
+ schemes?: string[];
187
+ deprecated?: boolean;
188
+ security?: SecurityRequirementObject[];
189
+ } & T;
190
+ export interface ResponsesObject {
191
+ [index: string]: Response | undefined;
192
+ default?: Response;
193
+ }
194
+ export type Parameters = (ReferenceObject | Parameter)[];
195
+ export type Parameter = InBodyParameterObject | GeneralParameterObject;
196
+ export interface InBodyParameterObject extends ParameterObject {
197
+ schema: Schema;
198
+ }
199
+ export interface GeneralParameterObject extends ParameterObject, ItemsObject {
200
+ allowEmptyValue?: boolean;
201
+ }
202
+ export enum HttpMethods {
203
+ GET = "get",
204
+ PUT = "put",
205
+ POST = "post",
206
+ DELETE = "delete",
207
+ OPTIONS = "options",
208
+ HEAD = "head",
209
+ PATCH = "patch"
210
+ }
211
+ export type PathItemObject<T extends {} = EmptyObject> = {
212
+ $ref?: string;
213
+ parameters?: Parameters;
214
+ } & {
215
+ [method in HttpMethods]?: OperationObject<T>;
216
+ };
217
+ export interface PathsObject<T extends {} = EmptyObject> {
218
+ [index: string]: PathItemObject<T>;
219
+ }
220
+ export interface ParametersDefinitionsObject {
221
+ [index: string]: ParameterObject;
222
+ }
223
+ export interface ParameterObject {
224
+ name: string;
225
+ in: string;
226
+ description?: string;
227
+ required?: boolean;
228
+ [index: string]: any;
229
+ }
230
+ export type MimeTypes = string[];
231
+ export interface DefinitionsObject {
232
+ [index: string]: SchemaObject;
233
+ }
234
+ export interface SchemaObject extends IJsonSchema {
235
+ [index: string]: any;
236
+ discriminator?: string;
237
+ readOnly?: boolean;
238
+ xml?: XMLObject;
239
+ externalDocs?: ExternalDocumentationObject;
240
+ example?: any;
241
+ default?: any;
242
+ items?: ItemsObject;
243
+ properties?: {
244
+ [name: string]: SchemaObject;
245
+ };
246
+ }
247
+ export interface ExternalDocumentationObject {
248
+ [index: string]: any;
249
+ description?: string;
250
+ url: string;
251
+ }
252
+ export interface ItemsObject {
253
+ type: string;
254
+ format?: string;
255
+ items?: ItemsObject;
256
+ collectionFormat?: string;
257
+ default?: any;
258
+ maximum?: number;
259
+ exclusiveMaximum?: boolean;
260
+ minimum?: number;
261
+ exclusiveMinimum?: boolean;
262
+ maxLength?: number;
263
+ minLength?: number;
264
+ pattern?: string;
265
+ maxItems?: number;
266
+ minItems?: number;
267
+ uniqueItems?: boolean;
268
+ enum?: any[];
269
+ multipleOf?: number;
270
+ $ref?: string;
271
+ }
272
+ export interface XMLObject {
273
+ [index: string]: any;
274
+ name?: string;
275
+ namespace?: string;
276
+ prefix?: string;
277
+ attribute?: boolean;
278
+ wrapped?: boolean;
279
+ }
280
+ export interface InfoObject {
281
+ title: string;
282
+ description?: string;
283
+ termsOfService?: string;
284
+ contact?: ContactObject;
285
+ license?: LicenseObject;
286
+ version: string;
287
+ }
288
+ export interface ContactObject {
289
+ name?: string;
290
+ url?: string;
291
+ email?: string;
292
+ }
293
+ export interface LicenseObject {
294
+ name: string;
295
+ url?: string;
296
+ }
297
+ }
298
+
299
+ export declare namespace OpenAPIV3 {
300
+ export interface Document<T extends {} = EmptyObject> {
301
+ 'openapi': string;
302
+ 'info': InfoObject;
303
+ 'servers'?: ServerObject[];
304
+ 'paths': PathsObject<T>;
305
+ 'components'?: ComponentsObject;
306
+ 'security'?: SecurityRequirementObject[];
307
+ 'tags'?: TagObject[];
308
+ 'externalDocs'?: ExternalDocumentationObject;
309
+ 'x-express-openapi-additional-middleware'?: (((request: any, response: any, next: any) => Promise<void>) | ((request: any, response: any, next: any) => void))[];
310
+ 'x-express-openapi-validation-strict'?: boolean;
311
+ }
312
+ export interface InfoObject {
313
+ title: string;
314
+ description?: string;
315
+ termsOfService?: string;
316
+ contact?: ContactObject;
317
+ license?: LicenseObject;
318
+ version: string;
319
+ }
320
+ export interface ContactObject {
321
+ name?: string;
322
+ url?: string;
323
+ email?: string;
324
+ }
325
+ export interface LicenseObject {
326
+ name: string;
327
+ url?: string;
328
+ }
329
+ export interface ServerObject {
330
+ url: string;
331
+ description?: string;
332
+ variables?: {
333
+ [variable: string]: ServerVariableObject;
334
+ };
335
+ }
336
+ export interface ServerVariableObject {
337
+ enum?: string[];
338
+ default: string;
339
+ description?: string;
340
+ }
341
+ export interface PathsObject<T extends {} = EmptyObject, P extends {} = EmptyObject> {
342
+ [pattern: string]: (PathItemObject<T> & P) | undefined;
343
+ }
344
+ export enum HttpMethods {
345
+ GET = "get",
346
+ PUT = "put",
347
+ POST = "post",
348
+ DELETE = "delete",
349
+ OPTIONS = "options",
350
+ HEAD = "head",
351
+ PATCH = "patch",
352
+ TRACE = "trace"
353
+ }
354
+ export type PathItemObject<T extends {} = EmptyObject> = {
355
+ $ref?: string;
356
+ summary?: string;
357
+ description?: string;
358
+ servers?: ServerObject[];
359
+ parameters?: ParameterObject[];
360
+ } & {
361
+ [method in HttpMethods]?: OperationObject<T>;
362
+ };
363
+ export type OperationObject<T extends {} = EmptyObject> = {
364
+ tags?: string[];
365
+ summary?: string;
366
+ description?: string;
367
+ externalDocs?: ExternalDocumentationObject;
368
+ operationId?: string;
369
+ parameters?: ParameterObject[];
370
+ requestBody?: RequestBodyObject;
371
+ responses: ResponsesObject;
372
+ callbacks?: {
373
+ [callback: string]: CallbackObject;
374
+ };
375
+ deprecated?: boolean;
376
+ security?: SecurityRequirementObject[];
377
+ servers?: ServerObject[];
378
+ } & T;
379
+ export interface ExternalDocumentationObject {
380
+ description?: string;
381
+ url: string;
382
+ }
383
+ export interface ParameterObject extends ParameterBaseObject {
384
+ name: string;
385
+ in: string;
386
+ }
387
+ export interface HeaderObject extends ParameterBaseObject {
388
+ }
389
+ export interface ParameterBaseObject {
390
+ description?: string;
391
+ required?: boolean;
392
+ deprecated?: boolean;
393
+ allowEmptyValue?: boolean;
394
+ style?: string;
395
+ explode?: boolean;
396
+ allowReserved?: boolean;
397
+ schema?: SchemaObject;
398
+ example?: any;
399
+ examples?: {
400
+ [media: string]: ExampleObject;
401
+ };
402
+ content?: {
403
+ [media: string]: MediaTypeObject;
404
+ };
405
+ }
406
+ export type NonArraySchemaObjectType = 'boolean' | 'object' | 'number' | 'string' | 'integer';
407
+ export type ArraySchemaObjectType = 'array';
408
+ export type SchemaObject = ArraySchemaObject | NonArraySchemaObject;
409
+ export interface ArraySchemaObject extends BaseSchemaObject {
410
+ type: ArraySchemaObjectType;
411
+ items: SchemaObject;
412
+ }
413
+ export interface NonArraySchemaObject extends BaseSchemaObject {
414
+ type?: NonArraySchemaObjectType;
415
+ }
416
+ export interface BaseSchemaObject {
417
+ title?: string;
418
+ description?: string;
419
+ format?: string;
420
+ default?: any;
421
+ multipleOf?: number;
422
+ maximum?: number;
423
+ exclusiveMaximum?: boolean;
424
+ minimum?: number;
425
+ exclusiveMinimum?: boolean;
426
+ maxLength?: number;
427
+ minLength?: number;
428
+ pattern?: string;
429
+ additionalProperties?: boolean | SchemaObject;
430
+ maxItems?: number;
431
+ minItems?: number;
432
+ uniqueItems?: boolean;
433
+ maxProperties?: number;
434
+ minProperties?: number;
435
+ required?: string[];
436
+ enum?: any[];
437
+ properties?: {
438
+ [name: string]: SchemaObject;
439
+ };
440
+ allOf?: SchemaObject[];
441
+ oneOf?: SchemaObject[];
442
+ anyOf?: SchemaObject[];
443
+ not?: SchemaObject;
444
+ nullable?: boolean;
445
+ discriminator?: DiscriminatorObject;
446
+ readOnly?: boolean;
447
+ writeOnly?: boolean;
448
+ xml?: XMLObject;
449
+ externalDocs?: ExternalDocumentationObject;
450
+ example?: any;
451
+ deprecated?: boolean;
452
+ }
453
+ export interface DiscriminatorObject {
454
+ propertyName: string;
455
+ mapping?: {
456
+ [value: string]: string;
457
+ };
458
+ }
459
+ export interface XMLObject {
460
+ name?: string;
461
+ namespace?: string;
462
+ prefix?: string;
463
+ attribute?: boolean;
464
+ wrapped?: boolean;
465
+ }
466
+ export interface ExampleObject {
467
+ summary?: string;
468
+ description?: string;
469
+ value?: any;
470
+ externalValue?: string;
471
+ }
472
+ export interface MediaTypeObject {
473
+ schema?: SchemaObject;
474
+ example?: any;
475
+ examples?: {
476
+ [media: string]: ExampleObject;
477
+ };
478
+ encoding?: {
479
+ [media: string]: EncodingObject;
480
+ };
481
+ }
482
+ export interface EncodingObject {
483
+ contentType?: string;
484
+ headers?: {
485
+ [header: string]: HeaderObject;
486
+ };
487
+ style?: string;
488
+ explode?: boolean;
489
+ allowReserved?: boolean;
490
+ }
491
+ export interface RequestBodyObject {
492
+ description?: string;
493
+ content: {
494
+ [media: string]: MediaTypeObject;
495
+ };
496
+ required?: boolean;
497
+ }
498
+ export interface ResponsesObject {
499
+ [code: string]: ResponseObject;
500
+ }
501
+ export interface ResponseObject {
502
+ description: string;
503
+ headers?: {
504
+ [header: string]: HeaderObject;
505
+ };
506
+ content?: {
507
+ [media: string]: MediaTypeObject;
508
+ };
509
+ links?: {
510
+ [link: string]: LinkObject;
511
+ };
512
+ }
513
+ export interface LinkObject {
514
+ operationRef?: string;
515
+ operationId?: string;
516
+ parameters?: {
517
+ [parameter: string]: any;
518
+ };
519
+ requestBody?: any;
520
+ description?: string;
521
+ server?: ServerObject;
522
+ }
523
+ export interface CallbackObject {
524
+ [url: string]: PathItemObject;
525
+ }
526
+ export interface SecurityRequirementObject {
527
+ [name: string]: string[];
528
+ }
529
+ export interface ComponentsObject {
530
+ schemas?: {
531
+ [key: string]: SchemaObject;
532
+ };
533
+ responses?: {
534
+ [key: string]: ResponseObject;
535
+ };
536
+ parameters?: {
537
+ [key: string]: ParameterObject;
538
+ };
539
+ examples?: {
540
+ [key: string]: ExampleObject;
541
+ };
542
+ requestBodies?: {
543
+ [key: string]: RequestBodyObject;
544
+ };
545
+ headers?: {
546
+ [key: string]: HeaderObject;
547
+ };
548
+ securitySchemes?: {
549
+ [key: string]: SecuritySchemeObject;
550
+ };
551
+ links?: {
552
+ [key: string]: LinkObject;
553
+ };
554
+ callbacks?: {
555
+ [key: string]: CallbackObject;
556
+ };
557
+ }
558
+ export type SecuritySchemeObject = HttpSecurityScheme | ApiKeySecurityScheme | OAuth2SecurityScheme | OpenIdSecurityScheme;
559
+ export interface HttpSecurityScheme {
560
+ type: 'http';
561
+ description?: string;
562
+ scheme: string;
563
+ bearerFormat?: string;
564
+ }
565
+ export interface ApiKeySecurityScheme {
566
+ type: 'apiKey';
567
+ description?: string;
568
+ name: string;
569
+ in: string;
570
+ }
571
+ export interface OAuth2SecurityScheme {
572
+ type: 'oauth2';
573
+ description?: string;
574
+ flows: {
575
+ implicit?: {
576
+ authorizationUrl: string;
577
+ refreshUrl?: string;
578
+ scopes: {
579
+ [scope: string]: string;
580
+ };
581
+ };
582
+ password?: {
583
+ tokenUrl: string;
584
+ refreshUrl?: string;
585
+ scopes: {
586
+ [scope: string]: string;
587
+ };
588
+ };
589
+ clientCredentials?: {
590
+ tokenUrl: string;
591
+ refreshUrl?: string;
592
+ scopes: {
593
+ [scope: string]: string;
594
+ };
595
+ };
596
+ authorizationCode?: {
597
+ authorizationUrl: string;
598
+ tokenUrl: string;
599
+ refreshUrl?: string;
600
+ scopes: {
601
+ [scope: string]: string;
602
+ };
603
+ };
604
+ };
605
+ }
606
+ export interface OpenIdSecurityScheme {
607
+ type: 'openIdConnect';
608
+ description?: string;
609
+ openIdConnectUrl: string;
610
+ }
611
+ export interface TagObject {
612
+ name: string;
613
+ description?: string;
614
+ externalDocs?: ExternalDocumentationObject;
615
+ }
616
+ }
617
+
618
+ export declare namespace OpenAPIV3_1 {
619
+ export type Modify<T, R> = Omit<T, keyof R> & R;
620
+ export type PathsWebhooksComponents<T extends {} = EmptyObject> = {
621
+ paths: PathsObject<T>;
622
+ webhooks: Record<string, PathItemObject>;
623
+ components: ComponentsObject;
624
+ };
625
+ export type Document<T extends {} = EmptyObject> = Modify<Omit<OpenAPIV3.Document<T>, 'paths' | 'components'>, {
626
+ info: InfoObject;
627
+ jsonSchemaDialect?: string;
628
+ servers?: ServerObject[];
629
+ } & ((Pick<PathsWebhooksComponents<T>, 'paths'> & Omit<Partial<PathsWebhooksComponents<T>>, 'paths'>) | (Pick<PathsWebhooksComponents<T>, 'webhooks'> & Omit<Partial<PathsWebhooksComponents<T>>, 'webhooks'>) | (Pick<PathsWebhooksComponents<T>, 'components'> & Omit<Partial<PathsWebhooksComponents<T>>, 'components'>))>;
630
+ export type InfoObject = Modify<OpenAPIV3.InfoObject, {
631
+ summary?: string;
632
+ license?: LicenseObject;
633
+ }>;
634
+ export type ContactObject = OpenAPIV3.ContactObject;
635
+ export type LicenseObject = Modify<OpenAPIV3.LicenseObject, {
636
+ identifier?: string;
637
+ }>;
638
+ export type ServerObject = Modify<OpenAPIV3.ServerObject, {
639
+ url: string;
640
+ description?: string;
641
+ variables?: Record<string, ServerVariableObject>;
642
+ }>;
643
+ export type ServerVariableObject = Modify<OpenAPIV3.ServerVariableObject, {
644
+ enum?: [string, ...string[]];
645
+ }>;
646
+ export type PathsObject<T extends {} = EmptyObject, P extends {} = EmptyObject> = Record<string, (PathItemObject<T> & P) | undefined>;
647
+ export type HttpMethods = OpenAPIV3.HttpMethods;
648
+ export type PathItemObject<T extends {} = EmptyObject> = Modify<OpenAPIV3.PathItemObject<T>, {
649
+ servers?: ServerObject[];
650
+ parameters?: ParameterObject[];
651
+ }> & {
652
+ [method in HttpMethods]?: OperationObject<T>;
653
+ };
654
+ export type OperationObject<T extends {} = EmptyObject> = Modify<OpenAPIV3.OperationObject<T>, {
655
+ parameters?: ParameterObject[];
656
+ requestBody?: RequestBodyObject;
657
+ responses?: ResponsesObject;
658
+ callbacks?: Record<string, CallbackObject>;
659
+ servers?: ServerObject[];
660
+ }> & T;
661
+ export type ExternalDocumentationObject = OpenAPIV3.ExternalDocumentationObject;
662
+ export type ParameterObject = OpenAPIV3.ParameterObject;
663
+ export type HeaderObject = OpenAPIV3.HeaderObject;
664
+ export type ParameterBaseObject = OpenAPIV3.ParameterBaseObject;
665
+ export type NonArraySchemaObjectType = OpenAPIV3.NonArraySchemaObjectType | 'null';
666
+ export type ArraySchemaObjectType = OpenAPIV3.ArraySchemaObjectType;
667
+ /**
668
+ * There is no way to tell typescript to require items when type is either 'array' or array containing 'array' type
669
+ * 'items' will be always visible as optional
670
+ * Casting schema object to ArraySchemaObject or NonArraySchemaObject will work fine
671
+ */
672
+ export type SchemaObject = ArraySchemaObject | NonArraySchemaObject | MixedSchemaObject;
673
+ export interface ArraySchemaObject extends BaseSchemaObject {
674
+ type: ArraySchemaObjectType;
675
+ items: SchemaObject;
676
+ }
677
+ export interface NonArraySchemaObject extends BaseSchemaObject {
678
+ type?: NonArraySchemaObjectType;
679
+ }
680
+ export interface MixedSchemaObject extends BaseSchemaObject {
681
+ type?: (ArraySchemaObjectType | NonArraySchemaObjectType)[];
682
+ items?: SchemaObject;
683
+ }
684
+ export type BaseSchemaObject = Modify<Omit<OpenAPIV3.BaseSchemaObject, 'nullable'>, {
685
+ examples?: OpenAPIV3.BaseSchemaObject['example'][];
686
+ exclusiveMinimum?: boolean | number;
687
+ exclusiveMaximum?: boolean | number;
688
+ contentMediaType?: string;
689
+ $schema?: string;
690
+ additionalProperties?: boolean | SchemaObject;
691
+ properties?: {
692
+ [name: string]: SchemaObject;
693
+ };
694
+ allOf?: SchemaObject[];
695
+ oneOf?: SchemaObject[];
696
+ anyOf?: SchemaObject[];
697
+ not?: SchemaObject;
698
+ discriminator?: DiscriminatorObject;
699
+ externalDocs?: ExternalDocumentationObject;
700
+ xml?: XMLObject;
701
+ const?: any;
702
+ }>;
703
+ export type DiscriminatorObject = OpenAPIV3.DiscriminatorObject;
704
+ export type XMLObject = OpenAPIV3.XMLObject;
705
+ export type ExampleObject = OpenAPIV3.ExampleObject;
706
+ export type MediaTypeObject = Modify<OpenAPIV3.MediaTypeObject, {
707
+ schema?: SchemaObject;
708
+ examples?: Record<string, ExampleObject>;
709
+ }>;
710
+ export type EncodingObject = OpenAPIV3.EncodingObject;
711
+ export type RequestBodyObject = Modify<OpenAPIV3.RequestBodyObject, {
712
+ content: {
713
+ [media: string]: MediaTypeObject;
714
+ };
715
+ }>;
716
+ export type ResponsesObject = Record<string, ResponseObject>;
717
+ export type ResponseObject = Modify<OpenAPIV3.ResponseObject, {
718
+ headers?: {
719
+ [header: string]: HeaderObject;
720
+ };
721
+ content?: {
722
+ [media: string]: MediaTypeObject;
723
+ };
724
+ links?: {
725
+ [link: string]: LinkObject;
726
+ };
727
+ }>;
728
+ export type LinkObject = Modify<OpenAPIV3.LinkObject, {
729
+ server?: ServerObject;
730
+ }>;
731
+ export type CallbackObject = Record<string, PathItemObject>;
732
+ export type SecurityRequirementObject = OpenAPIV3.SecurityRequirementObject;
733
+ export type ComponentsObject = Modify<OpenAPIV3.ComponentsObject, {
734
+ schemas?: Record<string, SchemaObject>;
735
+ responses?: Record<string, ResponseObject>;
736
+ parameters?: Record<string, ParameterObject>;
737
+ examples?: Record<string, ExampleObject>;
738
+ requestBodies?: Record<string, RequestBodyObject>;
739
+ headers?: Record<string, HeaderObject>;
740
+ securitySchemes?: Record<string, SecuritySchemeObject>;
741
+ links?: Record<string, LinkObject>;
742
+ callbacks?: Record<string, CallbackObject>;
743
+ pathItems?: Record<string, PathItemObject>;
744
+ }>;
745
+ export type SecuritySchemeObject = OpenAPIV3.SecuritySchemeObject;
746
+ export type HttpSecurityScheme = OpenAPIV3.HttpSecurityScheme;
747
+ export type ApiKeySecurityScheme = OpenAPIV3.ApiKeySecurityScheme;
748
+ export type OAuth2SecurityScheme = OpenAPIV3.OAuth2SecurityScheme;
749
+ export type OpenIdSecurityScheme = OpenAPIV3.OpenIdSecurityScheme;
750
+ export type TagObject = OpenAPIV3.TagObject;
751
+ }
752
+
753
+ /**
754
+ * Validates an OpenAPI schema and resolves all references.
755
+ */
756
+ export declare function parse(value: string): Promise<ParseResult>;
757
+
758
+ export declare type ParseResult = {
759
+ valid: boolean;
760
+ version: string | undefined;
761
+ document?: OpenAPI.Document;
762
+ errors?: ErrorObject[];
763
+ };
764
+
765
+ export declare type Specification = {
766
+ $id?: string;
767
+ };
768
+
769
+ /**
770
+ * Validates an OpenAPI schema.
771
+ */
772
+ export declare function validate(value: string, options?: ValidateOptions): Promise<ValidateResult>;
773
+
774
+ export declare type ValidateOptions = {
775
+ format?: 'js' | 'cli';
776
+ indent?: number;
777
+ };
778
+
779
+ export declare type ValidateResult = {
780
+ valid: boolean;
781
+ errors?: ErrorObject[];
782
+ };
783
+
784
+ export declare class Validator {
785
+ protected ajvOptions: AjvOptions;
786
+ protected ajvValidators: Record<string, ((specification: Specification) => boolean) & {
787
+ errors: string;
788
+ }>;
789
+ protected externalRefs: Record<string, Specification>;
790
+ protected specification: Specification;
791
+ version: string;
792
+ protected errors: string;
793
+ protected specificationVersion: string;
794
+ protected specificationType: string;
795
+ constructor(ajvOptions?: AjvOptions);
796
+ static supportedVersions: Set<string>;
797
+ resolveRefs(opts?: {
798
+ specification?: Specification;
799
+ }): Specification;
800
+ addSpecRef(data: string | object, uri: string): Promise<void>;
801
+ validate(data: string | object, options?: ValidateOptions): Promise<ValidateResult>;
802
+ getAjvValidator(version: string): Promise<((specification: Specification) => boolean) & {
803
+ errors: string;
804
+ }>;
805
+ }
806
+
807
+ export { }
package/dist/index.js CHANGED
@@ -8230,12 +8230,17 @@ class Ta {
8230
8230
  Ue(Ta, "supportedVersions", qo);
8231
8231
  async function M0(e) {
8232
8232
  const t = new Ta(), r = await t.validate(e);
8233
- return r.valid ? {
8233
+ if (!r.valid)
8234
+ return {
8235
+ valid: !1,
8236
+ version: void 0,
8237
+ errors: r.errors
8238
+ };
8239
+ const n = t.resolveRefs();
8240
+ return {
8234
8241
  valid: !0,
8235
- document: t.resolveRefs()
8236
- } : {
8237
- valid: !1,
8238
- errors: r.errors
8242
+ version: t.version,
8243
+ document: n
8239
8244
  };
8240
8245
  }
8241
8246
  async function F0(e, t) {
package/package.json CHANGED
@@ -12,7 +12,7 @@
12
12
  "author": "Scalar (https://github.com/scalar)",
13
13
  "homepage": "https://github.com/scalar/scalar",
14
14
  "bugs": "https://github.com/scalar/scalar/issues/new/choose",
15
- "version": "0.0.0",
15
+ "version": "0.1.0",
16
16
  "engines": {
17
17
  "node": ">=18"
18
18
  },
@@ -22,7 +22,7 @@
22
22
  "CHANGELOG.md"
23
23
  ],
24
24
  "main": "./dist/index.js",
25
- "types": "dist/index.d.ts",
25
+ "types": "./dist/index.d.ts",
26
26
  "module": "./dist/index.js",
27
27
  "repository": {
28
28
  "type": "git",
@@ -30,20 +30,15 @@
30
30
  "directory": "packages/openapi-parser"
31
31
  },
32
32
  "devDependencies": {
33
- "@biomejs/biome": "1.5.3",
34
33
  "@types/js-yaml": "^4.0.9",
35
- "typescript": "^5.3.3",
36
- "vite-plugin-node-polyfills": "^0.19.0"
34
+ "vite-plugin-dts": "^3.7.2"
37
35
  },
38
36
  "dependencies": {
39
- "@babel/code-frame": "^7.23.5",
40
- "@babel/runtime": "^7.23.9",
41
37
  "@humanwhocodes/momoa": "^3.0.0",
42
38
  "@types/node": "^20.11.10",
43
39
  "ajv": "^8.12.0",
44
40
  "ajv-draft-04": "^1.0.0",
45
41
  "ajv-formats": "^2.1.1",
46
- "chalk": "^5.3.0",
47
42
  "glob": "^10.3.10",
48
43
  "js-yaml": "^4.1.0",
49
44
  "json-to-ast": "^2.1.0",