@kubb/oas 3.0.0-alpha.21 → 3.0.0-alpha.25

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.
@@ -29,6 +29,9 @@ declare class Oas<const TOAS = unknown> extends BaseOas {
29
29
  oas: TOAS | OASDocument | string;
30
30
  user?: User;
31
31
  }, options?: Options);
32
+ get($ref: string): any;
33
+ set($ref: string, value: unknown): false | undefined;
34
+ resolveDiscriminators(): void;
32
35
  dereferenceWithRef(schema?: unknown): any;
33
36
  getResponseSchema(operation: Operation, statusCode: string | number): SchemaObject$1;
34
37
  getRequestSchema(operation: Operation): SchemaObject$1 | undefined;
@@ -29,6 +29,9 @@ declare class Oas<const TOAS = unknown> extends BaseOas {
29
29
  oas: TOAS | OASDocument | string;
30
30
  user?: User;
31
31
  }, options?: Options);
32
+ get($ref: string): any;
33
+ set($ref: string, value: unknown): false | undefined;
34
+ resolveDiscriminators(): void;
32
35
  dereferenceWithRef(schema?: unknown): any;
33
36
  getResponseSchema(operation: Operation, statusCode: string | number): SchemaObject$1;
34
37
  getRequestSchema(operation: Operation): SchemaObject$1 | undefined;
@@ -1,17 +1,17 @@
1
1
  'use strict';
2
2
 
3
3
  var types = require('oas/types');
4
- var openapiFormat = require('openapi-format');
5
4
  var remeda = require('remeda');
6
5
  var BaseOas = require('oas');
7
6
  var OASNormalize = require('oas-normalize');
8
7
  var utils = require('oas/utils');
8
+ var jsonpointer = require('jsonpointer');
9
9
 
10
10
  function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
11
11
 
12
- var openapiFormat__default = /*#__PURE__*/_interopDefault(openapiFormat);
13
12
  var BaseOas__default = /*#__PURE__*/_interopDefault(BaseOas);
14
13
  var OASNormalize__default = /*#__PURE__*/_interopDefault(OASNormalize);
14
+ var jsonpointer__default = /*#__PURE__*/_interopDefault(jsonpointer);
15
15
 
16
16
  // src/utils.ts
17
17
  function isOpenApiV2Document(doc) {
@@ -35,47 +35,6 @@ function isRequired(schema) {
35
35
  function isOptional(schema) {
36
36
  return !isRequired(schema);
37
37
  }
38
- async function filterAndSort(data, options = {}) {
39
- const mergedOptions = {
40
- sort: options.sort ?? true,
41
- ["no-sort"]: options["no-sort"] ?? false,
42
- sortSet: {
43
- root: ["openapi", "info", "servers", "paths", "components", "tags", "x-tagGroups", "externalDocs"],
44
- get: ["operationId", "summary", "description", "parameters", "requestBody", "responses"],
45
- post: ["operationId", "summary", "description", "parameters", "requestBody", "responses"],
46
- put: ["operationId", "summary", "description", "parameters", "requestBody", "responses"],
47
- patch: ["operationId", "summary", "description", "parameters", "requestBody", "responses"],
48
- delete: ["operationId", "summary", "description", "parameters", "requestBody", "responses"],
49
- parameters: ["name", "in", "description", "required", "schema"],
50
- requestBody: ["description", "required", "content"],
51
- responses: ["description", "headers", "content", "links"],
52
- content: [],
53
- components: ["parameters", "schemas"],
54
- schema: ["description", "type", "items", "properties", "format", "example", "default"],
55
- schemas: ["description", "type", "items", "properties", "format", "example", "default"],
56
- properties: ["description", "type", "items", "format", "example", "default", "enum"],
57
- ...options.sortSet
58
- },
59
- sortComponentsSet: {
60
- ...options.sortComponentsSet
61
- },
62
- filterSet: {
63
- inverseMethods: ["get", "put", "post", "delete", "patch", "head", "options", "trace", "parameters"],
64
- unusedComponents: options.filterSet ? ["requestBodies", "schemas", "parameters", "responses"] : [],
65
- ...options.filterSet
66
- },
67
- casingSet: {
68
- ...options.casingSet
69
- }
70
- };
71
- const restFilter = await openapiFormat__default.default.openapiFilter(data, mergedOptions);
72
- data = restFilter.data;
73
- const resFormat = await openapiFormat__default.default.openapiSort(data, mergedOptions);
74
- data = resFormat.data;
75
- const resChangeCase = await openapiFormat__default.default.openapiChangeCase(data, mergedOptions);
76
- data = resChangeCase.data;
77
- return data;
78
- }
79
38
  var Oas = class extends BaseOas__default.default {
80
39
  #options = {};
81
40
  document = void 0;
@@ -87,10 +46,62 @@ var Oas = class extends BaseOas__default.default {
87
46
  this.document = oas;
88
47
  this.#options = options;
89
48
  }
49
+ get($ref) {
50
+ const origRef = $ref;
51
+ $ref = $ref.trim();
52
+ if ($ref === "") {
53
+ return false;
54
+ }
55
+ if ($ref.startsWith("#")) {
56
+ $ref = globalThis.decodeURIComponent($ref.substring(1));
57
+ } else {
58
+ throw new Error(`Could not find a definition for ${origRef}.`);
59
+ }
60
+ const current = jsonpointer__default.default.get(this.api, $ref);
61
+ if (!current) {
62
+ throw new Error(`Could not find a definition for ${origRef}.`);
63
+ }
64
+ return current;
65
+ }
66
+ set($ref, value) {
67
+ const origRef = $ref;
68
+ $ref = $ref.trim();
69
+ if ($ref === "") {
70
+ return false;
71
+ }
72
+ if ($ref.startsWith("#")) {
73
+ $ref = globalThis.decodeURIComponent($ref.substring(1));
74
+ } else {
75
+ throw new Error(`Could not find a definition for ${origRef}.`);
76
+ }
77
+ jsonpointer__default.default.set(this.api, $ref, value);
78
+ }
79
+ resolveDiscriminators() {
80
+ const schemas = this.api.components?.schemas || {};
81
+ Object.entries(schemas).forEach(([key, schemaObject]) => {
82
+ if ("discriminator" in schemaObject) {
83
+ const { mapping = {}, propertyName } = schemaObject.discriminator || {};
84
+ Object.entries(mapping).forEach(([mappingKey, mappingValue]) => {
85
+ if (mappingValue) {
86
+ const childSchema = this.get(mappingValue);
87
+ const property = childSchema.properties?.[propertyName];
88
+ if (property) {
89
+ childSchema.properties[propertyName] = {
90
+ ...childSchema.properties[propertyName],
91
+ enum: [...property?.enum?.filter((value) => value !== mappingKey) ?? [], mappingKey]
92
+ };
93
+ childSchema.required = [...childSchema.required ?? [], propertyName];
94
+ this.set(mappingValue, childSchema);
95
+ }
96
+ }
97
+ });
98
+ }
99
+ });
100
+ }
90
101
  dereferenceWithRef(schema) {
91
102
  if (isReference(schema)) {
92
103
  return {
93
- ...utils.findSchemaDefinition(schema.$ref, this.api),
104
+ ...this.get(schema.$ref),
94
105
  $ref: schema.$ref
95
106
  };
96
107
  }
@@ -145,7 +156,7 @@ var Oas = class extends BaseOas__default.default {
145
156
  const schema2 = operation.schema.responses[key];
146
157
  const $ref = isReference(schema2) ? schema2.$ref : void 0;
147
158
  if (schema2 && $ref) {
148
- operation.schema.responses[key] = utils.findSchemaDefinition($ref, this.api);
159
+ operation.schema.responses[key] = this.get($ref);
149
160
  }
150
161
  });
151
162
  }
@@ -223,12 +234,11 @@ var Oas = class extends BaseOas__default.default {
223
234
  };
224
235
 
225
236
  exports.Oas = Oas;
226
- exports.filterAndSort = filterAndSort;
227
237
  exports.isOpenApiV2Document = isOpenApiV2Document;
228
238
  exports.isOpenApiV3_1Document = isOpenApiV3_1Document;
229
239
  exports.isOptional = isOptional;
230
240
  exports.isParameterObject = isParameterObject;
231
241
  exports.isReference = isReference;
232
242
  exports.isRequired = isRequired;
233
- //# sourceMappingURL=chunk-2ZT6EJGT.cjs.map
234
- //# sourceMappingURL=chunk-2ZT6EJGT.cjs.map
243
+ //# sourceMappingURL=chunk-JAZKMYLT.cjs.map
244
+ //# sourceMappingURL=chunk-JAZKMYLT.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/utils.ts","../src/Oas.ts"],"names":["isPlainObject","isRef","BaseOas","jsonpointer","matchesMimeType","schema","OASNormalize"],"mappings":";;;;;;;;;;;;;;;;AAMO,SAAS,oBAAoB,GAAqC,EAAA;AACvE,EAAA,OAAO,GAAO,IAAAA,oBAAA,CAAc,GAAG,CAAA,IAAK,EAAE,SAAa,IAAA,GAAA,CAAA,CAAA;AACrD,CAAA;AAKO,SAAS,sBAAsB,GAAuC,EAAA;AAC3E,EAAO,OAAA,GAAA,IAAOA,qBAAoC,GAAG,CAAA,IAAK,aAAa,GAAO,IAAA,GAAA,CAAI,OAAQ,CAAA,UAAA,CAAW,KAAK,CAAA,CAAA;AAC5G,CAAA;AAMO,SAAS,kBAAkB,GAA6D,EAAA;AAC7F,EAAA,OAAO,OAAO,IAAQ,IAAA,GAAA,CAAA;AACxB,CAAA;AAEO,SAAS,YAAY,GAA+E,EAAA;AACzG,EAAA,OAAO,C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A,QACN,QAAU,EAAA;AAAA,UACR,cAAgB,EAAA,IAAA;AAAA,SAClB;AAAA,OACF;AAAA,KACD,CAAA,CAAA;AAAA,GACH;AACF","file":"chunk-JAZKMYLT.cjs","sourcesContent":["import { isRef, isSchema } from 'oas/types'\nimport { isPlainObject } from 'remeda'\n\nimport type { ParameterObject, SchemaObject } from 'oas/types'\nimport type { OpenAPIV2, OpenAPIV3, OpenAPIV3_1 } from 'openapi-types'\n\nexport function isOpenApiV2Document(doc: any): doc is OpenAPIV2.Document {\n return doc && isPlainObject(doc) && !('openapi' in doc)\n}\nexport function isOpenApiV3Document(doc: any): doc is OpenAPIV3.Document {\n return doc && isPlainObject(doc) && 'openapi' in doc\n}\n\nexport function isOpenApiV3_1Document(doc: any): doc is OpenAPIV3_1.Document {\n return doc && isPlainObject<OpenAPIV3_1.Document>(doc) && 'openapi' in doc && doc.openapi.startsWith('3.1')\n}\n\nexport function isJSONSchema(obj?: unknown): obj is SchemaObject {\n return !!obj && isSchema(obj)\n}\n\nexport function isParameterObject(obj: ParameterObject | SchemaObject): obj is ParameterObject {\n return obj && 'in' in obj\n}\n\nexport function isReference(obj?: unknown): obj is OpenAPIV3.ReferenceObject | OpenAPIV3_1.ReferenceObject {\n return !!obj && isRef(obj)\n}\n\nexport function isRequired(schema?: SchemaObject): boolean {\n if (!schema) {\n return false\n }\n\n return Array.isArray(schema.required) ? !!schema.required?.length : !!schema.required\n}\n\nexport function isOptional(schema?: SchemaObject): boolean {\n return !isRequired(schema)\n}\n","import BaseOas from 'oas'\nimport OASNormalize from 'oas-normalize'\nimport { matchesMimeType } from 'oas/utils'\n\nimport jsonpointer from 'jsonpointer'\n\nimport { isReference } from './utils.ts'\n\nimport type { Operation } from 'oas/operation'\nimport type { MediaTypeObject, OASDocument, ResponseObject, SchemaObject, User } from 'oas/types'\nimport type { OasTypes, OpenAPIV3 } from './index.ts'\nimport type { contentType } from './types.ts'\n\ntype Options = {\n contentType?: contentType\n}\n\nexport class Oas<const TOAS = unknown> extends BaseOas {\n #options: Options = {}\n document: TOAS = undefined as unknown as TOAS\n\n constructor({ oas, user }: { oas: TOAS | OASDocument | string; user?: User }, options: Options = {}) {\n if (typeof oas === 'string') {\n oas = JSON.parse(oas)\n }\n\n super(oas as OASDocument, user)\n\n this.document = oas as TOAS\n this.#options = options\n }\n\n get($ref: string) {\n const origRef = $ref\n $ref = $ref.trim()\n if ($ref === '') {\n return false\n }\n if ($ref.startsWith('#')) {\n $ref = globalThis.decodeURIComponent($ref.substring(1))\n } else {\n throw new Error(`Could not find a definition for ${origRef}.`)\n }\n const current = jsonpointer.get(this.api, $ref)\n\n if (!current) {\n throw new Error(`Could not find a definition for ${origRef}.`)\n }\n return current\n }\n\n set($ref: string, value: unknown) {\n const origRef = $ref\n $ref = $ref.trim()\n if ($ref === '') {\n return false\n }\n if ($ref.startsWith('#')) {\n $ref = globalThis.decodeURIComponent($ref.substring(1))\n } else {\n throw new Error(`Could not find a definition for ${origRef}.`)\n }\n\n jsonpointer.set(this.api, $ref, value)\n }\n\n resolveDiscriminators(): void {\n const schemas = (this.api.components?.schemas || {}) as Record<string, OasTypes.SchemaObject>\n\n Object.entries(schemas).forEach(([key, schemaObject]) => {\n if ('discriminator' in schemaObject) {\n const { mapping = {}, propertyName } = (schemaObject.discriminator || {}) as OpenAPIV3.DiscriminatorObject\n\n Object.entries(mapping).forEach(([mappingKey, mappingValue]) => {\n if (mappingValue) {\n const childSchema = this.get(mappingValue)\n const property = childSchema.properties?.[propertyName] as SchemaObject\n\n if (property) {\n childSchema.properties[propertyName] = {\n ...childSchema.properties[propertyName],\n enum: [...(property?.enum?.filter((value) => value !== mappingKey) ?? []), mappingKey],\n }\n\n childSchema.required = [...(childSchema.required ?? []), propertyName]\n\n this.set(mappingValue, childSchema)\n }\n }\n })\n }\n })\n }\n\n dereferenceWithRef(schema?: unknown) {\n if (isReference(schema)) {\n return {\n ...this.get(schema.$ref),\n $ref: schema.$ref,\n }\n }\n\n return schema\n }\n\n /**\n * Oas does not have a getResponseBody(contentType)\n */\n #getResponseBodyFactory(responseBody: boolean | ResponseObject): (contentType?: string) => MediaTypeObject | false | [string, MediaTypeObject, ...string[]] {\n function hasResponseBody(res = responseBody): res is ResponseObject {\n return !!res\n }\n\n return (contentType) => {\n if (!hasResponseBody(responseBody)) {\n return false\n }\n\n if (isReference(responseBody)) {\n // If the request body is still a `$ref` pointer we should return false because this library\n // assumes that you've run dereferencing beforehand.\n return false\n }\n\n if (!responseBody.content) {\n return false\n }\n\n if (contentType) {\n if (!(contentType in responseBody.content)) {\n return false\n }\n\n return responseBody.content[contentType]!\n }\n\n // Since no media type was supplied we need to find either the first JSON-like media type that\n // we've got, or the first available of anything else if no JSON-like media types are present.\n let availablecontentType: string | undefined = undefined\n const contentTypes = Object.keys(responseBody.content)\n contentTypes.forEach((mt: string) => {\n if (!availablecontentType && matchesMimeType.json(mt)) {\n availablecontentType = mt\n }\n })\n\n if (!availablecontentType) {\n contentTypes.forEach((mt: string) => {\n if (!availablecontentType) {\n availablecontentType = mt\n }\n })\n }\n\n if (availablecontentType) {\n return [availablecontentType, responseBody.content[availablecontentType]!, ...(responseBody.description ? [responseBody.description] : [])]\n }\n\n return false\n }\n }\n\n getResponseSchema(operation: Operation, statusCode: string | number): SchemaObject {\n if (operation.schema.responses) {\n Object.keys(operation.schema.responses).forEach((key) => {\n const schema = operation.schema.responses![key]\n const $ref = isReference(schema) ? schema.$ref : undefined\n\n if (schema && $ref) {\n operation.schema.responses![key] = this.get($ref)\n }\n })\n }\n\n const getResponseBody = this.#getResponseBodyFactory(operation.getResponseByStatusCode(statusCode))\n\n const { contentType } = this.#options\n const responseBody = getResponseBody(contentType)\n\n if (responseBody === false) {\n // return empty object because response will always be defined(request does not need a body)\n return {}\n }\n\n const schema = Array.isArray(responseBody) ? responseBody[1].schema : responseBody.schema\n\n if (!schema) {\n // return empty object because response will always be defined(request does not need a body)\n\n return {}\n }\n\n return this.dereferenceWithRef(schema)\n }\n\n getRequestSchema(operation: Operation): SchemaObject | undefined {\n const { contentType } = this.#options\n\n if (operation.schema.requestBody) {\n operation.schema.requestBody = this.dereferenceWithRef(operation.schema.requestBody)\n }\n\n const requestBody = operation.getRequestBody(contentType)\n\n if (requestBody === false) {\n return undefined\n }\n\n const schema = Array.isArray(requestBody) ? requestBody[1].schema : requestBody.schema\n\n if (!schema) {\n return undefined\n }\n\n return this.dereferenceWithRef(schema)\n }\n\n getParametersSchema(operation: Operation, inKey: 'path' | 'query' | 'header'): SchemaObject | null {\n const { contentType = operation.getContentType() } = this.#options\n const params = operation\n .getParameters()\n .map((schema) => {\n return this.dereferenceWithRef(schema)\n })\n .filter((v) => v.in === inKey)\n\n if (!params.length) {\n return null\n }\n\n return params.reduce(\n (schema, pathParameters) => {\n const property = pathParameters.content?.[contentType]?.schema ?? (pathParameters.schema as SchemaObject)\n const required = [...(schema.required || ([] as any)), pathParameters.required ? pathParameters.name : undefined].filter(Boolean)\n\n return {\n ...schema,\n description: schema.description,\n deprecated: schema.deprecated,\n example: schema.example,\n required,\n properties: {\n ...schema.properties,\n [pathParameters.name]: {\n description: pathParameters.description,\n ...property,\n },\n },\n }\n },\n { type: 'object', required: [], properties: {} } as SchemaObject,\n )\n }\n\n async valdiate() {\n const oasNormalize = new OASNormalize(this.api, {\n enablePaths: true,\n colorizeErrors: true,\n })\n\n await oasNormalize.validate({\n convertToLatest: true,\n parser: {\n validate: {\n colorizeErrors: true,\n },\n },\n })\n }\n}\n"]}
@@ -1,9 +1,9 @@
1
1
  import { isRef } from 'oas/types';
2
- import openapiFormat from 'openapi-format';
3
2
  import { isPlainObject } from 'remeda';
4
3
  import BaseOas from 'oas';
5
4
  import OASNormalize from 'oas-normalize';
6
- import { findSchemaDefinition, matchesMimeType } from 'oas/utils';
5
+ import { matchesMimeType } from 'oas/utils';
6
+ import jsonpointer from 'jsonpointer';
7
7
 
8
8
  // src/utils.ts
9
9
  function isOpenApiV2Document(doc) {
@@ -27,47 +27,6 @@ function isRequired(schema) {
27
27
  function isOptional(schema) {
28
28
  return !isRequired(schema);
29
29
  }
30
- async function filterAndSort(data, options = {}) {
31
- const mergedOptions = {
32
- sort: options.sort ?? true,
33
- ["no-sort"]: options["no-sort"] ?? false,
34
- sortSet: {
35
- root: ["openapi", "info", "servers", "paths", "components", "tags", "x-tagGroups", "externalDocs"],
36
- get: ["operationId", "summary", "description", "parameters", "requestBody", "responses"],
37
- post: ["operationId", "summary", "description", "parameters", "requestBody", "responses"],
38
- put: ["operationId", "summary", "description", "parameters", "requestBody", "responses"],
39
- patch: ["operationId", "summary", "description", "parameters", "requestBody", "responses"],
40
- delete: ["operationId", "summary", "description", "parameters", "requestBody", "responses"],
41
- parameters: ["name", "in", "description", "required", "schema"],
42
- requestBody: ["description", "required", "content"],
43
- responses: ["description", "headers", "content", "links"],
44
- content: [],
45
- components: ["parameters", "schemas"],
46
- schema: ["description", "type", "items", "properties", "format", "example", "default"],
47
- schemas: ["description", "type", "items", "properties", "format", "example", "default"],
48
- properties: ["description", "type", "items", "format", "example", "default", "enum"],
49
- ...options.sortSet
50
- },
51
- sortComponentsSet: {
52
- ...options.sortComponentsSet
53
- },
54
- filterSet: {
55
- inverseMethods: ["get", "put", "post", "delete", "patch", "head", "options", "trace", "parameters"],
56
- unusedComponents: options.filterSet ? ["requestBodies", "schemas", "parameters", "responses"] : [],
57
- ...options.filterSet
58
- },
59
- casingSet: {
60
- ...options.casingSet
61
- }
62
- };
63
- const restFilter = await openapiFormat.openapiFilter(data, mergedOptions);
64
- data = restFilter.data;
65
- const resFormat = await openapiFormat.openapiSort(data, mergedOptions);
66
- data = resFormat.data;
67
- const resChangeCase = await openapiFormat.openapiChangeCase(data, mergedOptions);
68
- data = resChangeCase.data;
69
- return data;
70
- }
71
30
  var Oas = class extends BaseOas {
72
31
  #options = {};
73
32
  document = void 0;
@@ -79,10 +38,62 @@ var Oas = class extends BaseOas {
79
38
  this.document = oas;
80
39
  this.#options = options;
81
40
  }
41
+ get($ref) {
42
+ const origRef = $ref;
43
+ $ref = $ref.trim();
44
+ if ($ref === "") {
45
+ return false;
46
+ }
47
+ if ($ref.startsWith("#")) {
48
+ $ref = globalThis.decodeURIComponent($ref.substring(1));
49
+ } else {
50
+ throw new Error(`Could not find a definition for ${origRef}.`);
51
+ }
52
+ const current = jsonpointer.get(this.api, $ref);
53
+ if (!current) {
54
+ throw new Error(`Could not find a definition for ${origRef}.`);
55
+ }
56
+ return current;
57
+ }
58
+ set($ref, value) {
59
+ const origRef = $ref;
60
+ $ref = $ref.trim();
61
+ if ($ref === "") {
62
+ return false;
63
+ }
64
+ if ($ref.startsWith("#")) {
65
+ $ref = globalThis.decodeURIComponent($ref.substring(1));
66
+ } else {
67
+ throw new Error(`Could not find a definition for ${origRef}.`);
68
+ }
69
+ jsonpointer.set(this.api, $ref, value);
70
+ }
71
+ resolveDiscriminators() {
72
+ const schemas = this.api.components?.schemas || {};
73
+ Object.entries(schemas).forEach(([key, schemaObject]) => {
74
+ if ("discriminator" in schemaObject) {
75
+ const { mapping = {}, propertyName } = schemaObject.discriminator || {};
76
+ Object.entries(mapping).forEach(([mappingKey, mappingValue]) => {
77
+ if (mappingValue) {
78
+ const childSchema = this.get(mappingValue);
79
+ const property = childSchema.properties?.[propertyName];
80
+ if (property) {
81
+ childSchema.properties[propertyName] = {
82
+ ...childSchema.properties[propertyName],
83
+ enum: [...property?.enum?.filter((value) => value !== mappingKey) ?? [], mappingKey]
84
+ };
85
+ childSchema.required = [...childSchema.required ?? [], propertyName];
86
+ this.set(mappingValue, childSchema);
87
+ }
88
+ }
89
+ });
90
+ }
91
+ });
92
+ }
82
93
  dereferenceWithRef(schema) {
83
94
  if (isReference(schema)) {
84
95
  return {
85
- ...findSchemaDefinition(schema.$ref, this.api),
96
+ ...this.get(schema.$ref),
86
97
  $ref: schema.$ref
87
98
  };
88
99
  }
@@ -137,7 +148,7 @@ var Oas = class extends BaseOas {
137
148
  const schema2 = operation.schema.responses[key];
138
149
  const $ref = isReference(schema2) ? schema2.$ref : void 0;
139
150
  if (schema2 && $ref) {
140
- operation.schema.responses[key] = findSchemaDefinition($ref, this.api);
151
+ operation.schema.responses[key] = this.get($ref);
141
152
  }
142
153
  });
143
154
  }
@@ -214,6 +225,6 @@ var Oas = class extends BaseOas {
214
225
  }
215
226
  };
216
227
 
217
- export { Oas, filterAndSort, isOpenApiV2Document, isOpenApiV3_1Document, isOptional, isParameterObject, isReference, isRequired };
218
- //# sourceMappingURL=chunk-TVOJ46T6.js.map
219
- //# sourceMappingURL=chunk-TVOJ46T6.js.map
228
+ export { Oas, isOpenApiV2Document, isOpenApiV3_1Document, isOptional, isParameterObject, isReference, isRequired };
229
+ //# sourceMappingURL=chunk-PHE7X6W6.js.map
230
+ //# sourceMappingURL=chunk-PHE7X6W6.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/utils.ts","../src/Oas.ts"],"names":["schema"],"mappings":";;;;;;;;AAMO,SAAS,oBAAoB,GAAqC,EAAA;AACvE,EAAA,OAAO,GAAO,IAAA,aAAA,CAAc,GAAG,CAAA,IAAK,EAAE,SAAa,IAAA,GAAA,CAAA,CAAA;AACrD,CAAA;AAKO,SAAS,sBAAsB,GAAuC,EAAA;AAC3E,EAAO,OAAA,GAAA,IAAO,cAAoC,GAAG,CAAA,IAAK,aAAa,GAAO,IAAA,GAAA,CAAI,OAAQ,CAAA,UAAA,CAAW,KAAK,CAAA,CAAA;AAC5G,CAAA;AAMO,SAAS,kBAAkB,GAA6D,EAAA;AAC7F,EAAA,OAAO,OAAO,IAAQ,IAAA,GAAA,CAAA;AACxB,CAAA;AAEO,SAAS,YAAY,GAA+E,EAAA;AACzG,EAAA,OAAO,CAAC,CAAC,GAAO,IAAA,KAAA,CAAM,GAAG,CAAA,CAAA;AAC3B,CAAA;AAEO,SAAS,WAAW,MAAgC,EAAA;AACzD,EAAA,IAAI,CAAC,MAAQ,EAAA;AACX,IAAO,OAAA,KAAA,CAAA;AAAA,GACT;AAEA,EAAA,OAAO,KAAM,CAAA,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W,cAAe,CAAA,OAAA,GAAU,WAAW,CAAA,EAAG,UAAW,cAAe,CAAA,MAAA,CAAA;AAClF,QAAA,MAAM,QAAW,GAAA,CAAC,GAAI,MAAA,CAAO,YAAa,EAAC,EAAY,cAAe,CAAA,QAAA,GAAW,cAAe,CAAA,IAAA,GAAO,KAAS,CAAA,CAAA,CAAE,OAAO,OAAO,CAAA,CAAA;AAEhI,QAAO,OAAA;AAAA,UACL,GAAG,MAAA;AAAA,UACH,aAAa,MAAO,CAAA,WAAA;AAAA,UACpB,YAAY,MAAO,CAAA,UAAA;AAAA,UACnB,SAAS,MAAO,CAAA,OAAA;AAAA,UAChB,QAAA;AAAA,UACA,UAAY,EAAA;AAAA,YACV,GAAG,MAAO,CAAA,UAAA;AAAA,YACV,CAAC,cAAe,CAAA,IAAI,GAAG;AAAA,cACrB,aAAa,cAAe,CAAA,WAAA;AAAA,cAC5B,GAAG,QAAA;AAAA,aACL;AAAA,WACF;AAAA,SACF,CAAA;AAAA,OACF;AAAA,MACA,EAAE,MAAM,QAAU,EAAA,QAAA,EAAU,EAAI,EAAA,UAAA,EAAY,EAAG,EAAA;AAAA,KACjD,CAAA;AAAA,GACF;AAAA,EAEA,MAAM,QAAW,GAAA;AACf,IAAA,MAAM,YAAe,GAAA,IAAI,YAAa,CAAA,IAAA,CAAK,GAAK,EAAA;AAAA,MAC9C,WAAa,EAAA,IAAA;AAAA,MACb,cAAgB,EAAA,IAAA;AAAA,KACjB,CAAA,CAAA;AAED,IAAA,MAAM,aAAa,QAAS,CAAA;AAAA,MAC1B,eAAiB,EAAA,IAAA;AAAA,MACjB,MAAQ,EAAA;AAAA,QACN,QAAU,EAAA;AAAA,UACR,cAAgB,EAAA,IAAA;AAAA,SAClB;AAAA,OACF;AAAA,KACD,CAAA,CAAA;AAAA,GACH;AACF","file":"chunk-PHE7X6W6.js","sourcesContent":["import { isRef, isSchema } from 'oas/types'\nimport { isPlainObject } from 'remeda'\n\nimport type { ParameterObject, SchemaObject } from 'oas/types'\nimport type { OpenAPIV2, OpenAPIV3, OpenAPIV3_1 } from 'openapi-types'\n\nexport function isOpenApiV2Document(doc: any): doc is OpenAPIV2.Document {\n return doc && isPlainObject(doc) && !('openapi' in doc)\n}\nexport function isOpenApiV3Document(doc: any): doc is OpenAPIV3.Document {\n return doc && isPlainObject(doc) && 'openapi' in doc\n}\n\nexport function isOpenApiV3_1Document(doc: any): doc is OpenAPIV3_1.Document {\n return doc && isPlainObject<OpenAPIV3_1.Document>(doc) && 'openapi' in doc && doc.openapi.startsWith('3.1')\n}\n\nexport function isJSONSchema(obj?: unknown): obj is SchemaObject {\n return !!obj && isSchema(obj)\n}\n\nexport function isParameterObject(obj: ParameterObject | SchemaObject): obj is ParameterObject {\n return obj && 'in' in obj\n}\n\nexport function isReference(obj?: unknown): obj is OpenAPIV3.ReferenceObject | OpenAPIV3_1.ReferenceObject {\n return !!obj && isRef(obj)\n}\n\nexport function isRequired(schema?: SchemaObject): boolean {\n if (!schema) {\n return false\n }\n\n return Array.isArray(schema.required) ? !!schema.required?.length : !!schema.required\n}\n\nexport function isOptional(schema?: SchemaObject): boolean {\n return !isRequired(schema)\n}\n","import BaseOas from 'oas'\nimport OASNormalize from 'oas-normalize'\nimport { matchesMimeType } from 'oas/utils'\n\nimport jsonpointer from 'jsonpointer'\n\nimport { isReference } from './utils.ts'\n\nimport type { Operation } from 'oas/operation'\nimport type { MediaTypeObject, OASDocument, ResponseObject, SchemaObject, User } from 'oas/types'\nimport type { OasTypes, OpenAPIV3 } from './index.ts'\nimport type { contentType } from './types.ts'\n\ntype Options = {\n contentType?: contentType\n}\n\nexport class Oas<const TOAS = unknown> extends BaseOas {\n #options: Options = {}\n document: TOAS = undefined as unknown as TOAS\n\n constructor({ oas, user }: { oas: TOAS | OASDocument | string; user?: User }, options: Options = {}) {\n if (typeof oas === 'string') {\n oas = JSON.parse(oas)\n }\n\n super(oas as OASDocument, user)\n\n this.document = oas as TOAS\n this.#options = options\n }\n\n get($ref: string) {\n const origRef = $ref\n $ref = $ref.trim()\n if ($ref === '') {\n return false\n }\n if ($ref.startsWith('#')) {\n $ref = globalThis.decodeURIComponent($ref.substring(1))\n } else {\n throw new Error(`Could not find a definition for ${origRef}.`)\n }\n const current = jsonpointer.get(this.api, $ref)\n\n if (!current) {\n throw new Error(`Could not find a definition for ${origRef}.`)\n }\n return current\n }\n\n set($ref: string, value: unknown) {\n const origRef = $ref\n $ref = $ref.trim()\n if ($ref === '') {\n return false\n }\n if ($ref.startsWith('#')) {\n $ref = globalThis.decodeURIComponent($ref.substring(1))\n } else {\n throw new Error(`Could not find a definition for ${origRef}.`)\n }\n\n jsonpointer.set(this.api, $ref, value)\n }\n\n resolveDiscriminators(): void {\n const schemas = (this.api.components?.schemas || {}) as Record<string, OasTypes.SchemaObject>\n\n Object.entries(schemas).forEach(([key, schemaObject]) => {\n if ('discriminator' in schemaObject) {\n const { mapping = {}, propertyName } = (schemaObject.discriminator || {}) as OpenAPIV3.DiscriminatorObject\n\n Object.entries(mapping).forEach(([mappingKey, mappingValue]) => {\n if (mappingValue) {\n const childSchema = this.get(mappingValue)\n const property = childSchema.properties?.[propertyName] as SchemaObject\n\n if (property) {\n childSchema.properties[propertyName] = {\n ...childSchema.properties[propertyName],\n enum: [...(property?.enum?.filter((value) => value !== mappingKey) ?? []), mappingKey],\n }\n\n childSchema.required = [...(childSchema.required ?? []), propertyName]\n\n this.set(mappingValue, childSchema)\n }\n }\n })\n }\n })\n }\n\n dereferenceWithRef(schema?: unknown) {\n if (isReference(schema)) {\n return {\n ...this.get(schema.$ref),\n $ref: schema.$ref,\n }\n }\n\n return schema\n }\n\n /**\n * Oas does not have a getResponseBody(contentType)\n */\n #getResponseBodyFactory(responseBody: boolean | ResponseObject): (contentType?: string) => MediaTypeObject | false | [string, MediaTypeObject, ...string[]] {\n function hasResponseBody(res = responseBody): res is ResponseObject {\n return !!res\n }\n\n return (contentType) => {\n if (!hasResponseBody(responseBody)) {\n return false\n }\n\n if (isReference(responseBody)) {\n // If the request body is still a `$ref` pointer we should return false because this library\n // assumes that you've run dereferencing beforehand.\n return false\n }\n\n if (!responseBody.content) {\n return false\n }\n\n if (contentType) {\n if (!(contentType in responseBody.content)) {\n return false\n }\n\n return responseBody.content[contentType]!\n }\n\n // Since no media type was supplied we need to find either the first JSON-like media type that\n // we've got, or the first available of anything else if no JSON-like media types are present.\n let availablecontentType: string | undefined = undefined\n const contentTypes = Object.keys(responseBody.content)\n contentTypes.forEach((mt: string) => {\n if (!availablecontentType && matchesMimeType.json(mt)) {\n availablecontentType = mt\n }\n })\n\n if (!availablecontentType) {\n contentTypes.forEach((mt: string) => {\n if (!availablecontentType) {\n availablecontentType = mt\n }\n })\n }\n\n if (availablecontentType) {\n return [availablecontentType, responseBody.content[availablecontentType]!, ...(responseBody.description ? [responseBody.description] : [])]\n }\n\n return false\n }\n }\n\n getResponseSchema(operation: Operation, statusCode: string | number): SchemaObject {\n if (operation.schema.responses) {\n Object.keys(operation.schema.responses).forEach((key) => {\n const schema = operation.schema.responses![key]\n const $ref = isReference(schema) ? schema.$ref : undefined\n\n if (schema && $ref) {\n operation.schema.responses![key] = this.get($ref)\n }\n })\n }\n\n const getResponseBody = this.#getResponseBodyFactory(operation.getResponseByStatusCode(statusCode))\n\n const { contentType } = this.#options\n const responseBody = getResponseBody(contentType)\n\n if (responseBody === false) {\n // return empty object because response will always be defined(request does not need a body)\n return {}\n }\n\n const schema = Array.isArray(responseBody) ? responseBody[1].schema : responseBody.schema\n\n if (!schema) {\n // return empty object because response will always be defined(request does not need a body)\n\n return {}\n }\n\n return this.dereferenceWithRef(schema)\n }\n\n getRequestSchema(operation: Operation): SchemaObject | undefined {\n const { contentType } = this.#options\n\n if (operation.schema.requestBody) {\n operation.schema.requestBody = this.dereferenceWithRef(operation.schema.requestBody)\n }\n\n const requestBody = operation.getRequestBody(contentType)\n\n if (requestBody === false) {\n return undefined\n }\n\n const schema = Array.isArray(requestBody) ? requestBody[1].schema : requestBody.schema\n\n if (!schema) {\n return undefined\n }\n\n return this.dereferenceWithRef(schema)\n }\n\n getParametersSchema(operation: Operation, inKey: 'path' | 'query' | 'header'): SchemaObject | null {\n const { contentType = operation.getContentType() } = this.#options\n const params = operation\n .getParameters()\n .map((schema) => {\n return this.dereferenceWithRef(schema)\n })\n .filter((v) => v.in === inKey)\n\n if (!params.length) {\n return null\n }\n\n return params.reduce(\n (schema, pathParameters) => {\n const property = pathParameters.content?.[contentType]?.schema ?? (pathParameters.schema as SchemaObject)\n const required = [...(schema.required || ([] as any)), pathParameters.required ? pathParameters.name : undefined].filter(Boolean)\n\n return {\n ...schema,\n description: schema.description,\n deprecated: schema.deprecated,\n example: schema.example,\n required,\n properties: {\n ...schema.properties,\n [pathParameters.name]: {\n description: pathParameters.description,\n ...property,\n },\n },\n }\n },\n { type: 'object', required: [], properties: {} } as SchemaObject,\n )\n }\n\n async valdiate() {\n const oasNormalize = new OASNormalize(this.api, {\n enablePaths: true,\n colorizeErrors: true,\n })\n\n await oasNormalize.validate({\n convertToLatest: true,\n parser: {\n validate: {\n colorizeErrors: true,\n },\n },\n })\n }\n}\n"]}
package/dist/index.cjs CHANGED
@@ -1,6 +1,6 @@
1
1
  'use strict';
2
2
 
3
- var chunk2ZT6EJGT_cjs = require('./chunk-2ZT6EJGT.cjs');
3
+ var chunkJAZKMYLT_cjs = require('./chunk-JAZKMYLT.cjs');
4
4
  var utils = require('oas/utils');
5
5
 
6
6
  // src/types.ts
@@ -17,27 +17,27 @@ var HttpMethods = {
17
17
 
18
18
  Object.defineProperty(exports, "Oas", {
19
19
  enumerable: true,
20
- get: function () { return chunk2ZT6EJGT_cjs.Oas; }
20
+ get: function () { return chunkJAZKMYLT_cjs.Oas; }
21
21
  });
22
22
  Object.defineProperty(exports, "isOpenApiV3_1Document", {
23
23
  enumerable: true,
24
- get: function () { return chunk2ZT6EJGT_cjs.isOpenApiV3_1Document; }
24
+ get: function () { return chunkJAZKMYLT_cjs.isOpenApiV3_1Document; }
25
25
  });
26
26
  Object.defineProperty(exports, "isOptional", {
27
27
  enumerable: true,
28
- get: function () { return chunk2ZT6EJGT_cjs.isOptional; }
28
+ get: function () { return chunkJAZKMYLT_cjs.isOptional; }
29
29
  });
30
30
  Object.defineProperty(exports, "isParameterObject", {
31
31
  enumerable: true,
32
- get: function () { return chunk2ZT6EJGT_cjs.isParameterObject; }
32
+ get: function () { return chunkJAZKMYLT_cjs.isParameterObject; }
33
33
  });
34
34
  Object.defineProperty(exports, "isReference", {
35
35
  enumerable: true,
36
- get: function () { return chunk2ZT6EJGT_cjs.isReference; }
36
+ get: function () { return chunkJAZKMYLT_cjs.isReference; }
37
37
  });
38
38
  Object.defineProperty(exports, "isRequired", {
39
39
  enumerable: true,
40
- get: function () { return chunk2ZT6EJGT_cjs.isRequired; }
40
+ get: function () { return chunkJAZKMYLT_cjs.isRequired; }
41
41
  });
42
42
  Object.defineProperty(exports, "findSchemaDefinition", {
43
43
  enumerable: true,
package/dist/index.d.cts CHANGED
@@ -1,4 +1,4 @@
1
- export { H as HttpMethods, O as Oas, S as SchemaObject, c as contentType } from './Oas-BEe7KZDj.cjs';
1
+ export { H as HttpMethods, O as Oas, S as SchemaObject, c as contentType } from './Oas-Br0yKhGF.cjs';
2
2
  export { findSchemaDefinition, matchesMimeType } from 'oas/utils';
3
3
  import { ParameterObject, SchemaObject } from 'oas/types';
4
4
  import * as OasTypes from 'oas/types';
@@ -13,58 +13,6 @@ import 'hotscript';
13
13
  import 'ts-toolbelt';
14
14
  import 'json-schema-to-ts';
15
15
 
16
- declare module 'openapi-format' {
17
- interface Options {
18
- verbose?: boolean
19
- 'no-sort'?: boolean
20
- sort?: boolean
21
- output?: string
22
- sortSet?: {
23
- root?: Array<'openapi' | 'info' | 'servers' | 'paths' | 'components' | 'tags' | 'x-tagGroups' | 'externalDocs'>
24
- get?: Array<'operationId' | 'summary' | 'description' | 'parameters' | 'requestBody' | 'responses'>
25
- post?: Array<'operationId' | 'summary' | 'description' | 'parameters' | 'requestBody' | 'responses'>
26
- put?: Array<'operationId' | 'summary' | 'description' | 'parameters' | 'requestBody' | 'responses'>
27
- patch?: Array<'operationId' | 'summary' | 'description' | 'parameters' | 'requestBody' | 'responses'>
28
- delete?: Array<'operationId' | 'summary' | 'description' | 'parameters' | 'requestBody' | 'responses'>
29
- parameters?: Array<'name' | 'in' | 'description' | 'required' | 'schema'>
30
- requestBody?: Array<'description' | 'required' | 'content'>
31
- responses?: Array<'description' | 'headers' | 'content' | 'links'>
32
- content?: Array<string>
33
- components?: Array<'parameters' | 'schemas'>
34
- schema?: Array<'description' | 'type' | 'items' | 'properties' | 'format' | 'example' | 'default'>
35
- schemas?: Array<'description' | 'type' | 'items' | 'properties' | 'format' | 'example' | 'default'>
36
- properties?: Array<'description' | 'type' | 'items' | 'format' | 'example' | 'default' | 'enum'>
37
- }
38
- filterSet?: {
39
- methods?: Array<'get' | 'post' | 'put' | 'patch' | 'delete' | 'options' | 'trace' | 'head' | 'parameters'>
40
- inverseMethods?: Array<'get' | 'post' | 'put' | 'patch' | 'delete' | 'options' | 'trace' | 'head' | 'parameters'>
41
- tags?: Array<string>
42
- inverseTags?: Array<string>
43
- operationIds?: Array<string>
44
- inverseOperationIds?: Array<string>
45
- operations?: Array<string>
46
- flags?: Array<string>
47
- inverseFlags?: Array<string>
48
- flagValues?: Array<string>
49
- inverseFlagValues?: Array<string>
50
- stripFlags?: Array<string>
51
- responseContent?: Array<string>
52
- inverseResponseContent?: Array<string>
53
- unusedComponents?: Array<'requestBodies' | 'schemas' | 'parameters' | 'responses'>
54
- }
55
- sortComponentsSet?: {}
56
- casingSet?: {}
57
- }
58
- function parseFile(path: string): Promise<unknown>
59
-
60
- function openapiFilter<TOas>(document: TOas, options: Options): { data: Toas; resultData: { unusedComp: any } }
61
-
62
- function openapiSort<TOas>(document: TOas, options: Options): { data: Toas; resultData: { unusedComp: any } }
63
- function openapiChangeCase<TOas>(document: TOas, options: Options): { data: Toas; resultData: { unusedComp: any } }
64
-
65
- function stringify<TOas>(document: TOas, options: Options): string
66
- }
67
-
68
16
  declare function isOpenApiV3_1Document(doc: any): doc is OpenAPIV3_1.Document;
69
17
  declare function isParameterObject(obj: ParameterObject | SchemaObject): obj is ParameterObject;
70
18
  declare function isReference(obj?: unknown): obj is OpenAPIV3.ReferenceObject | OpenAPIV3_1.ReferenceObject;
package/dist/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- export { H as HttpMethods, O as Oas, S as SchemaObject, c as contentType } from './Oas-BEe7KZDj.js';
1
+ export { H as HttpMethods, O as Oas, S as SchemaObject, c as contentType } from './Oas-Br0yKhGF.js';
2
2
  export { findSchemaDefinition, matchesMimeType } from 'oas/utils';
3
3
  import { ParameterObject, SchemaObject } from 'oas/types';
4
4
  import * as OasTypes from 'oas/types';
@@ -13,58 +13,6 @@ import 'hotscript';
13
13
  import 'ts-toolbelt';
14
14
  import 'json-schema-to-ts';
15
15
 
16
- declare module 'openapi-format' {
17
- interface Options {
18
- verbose?: boolean
19
- 'no-sort'?: boolean
20
- sort?: boolean
21
- output?: string
22
- sortSet?: {
23
- root?: Array<'openapi' | 'info' | 'servers' | 'paths' | 'components' | 'tags' | 'x-tagGroups' | 'externalDocs'>
24
- get?: Array<'operationId' | 'summary' | 'description' | 'parameters' | 'requestBody' | 'responses'>
25
- post?: Array<'operationId' | 'summary' | 'description' | 'parameters' | 'requestBody' | 'responses'>
26
- put?: Array<'operationId' | 'summary' | 'description' | 'parameters' | 'requestBody' | 'responses'>
27
- patch?: Array<'operationId' | 'summary' | 'description' | 'parameters' | 'requestBody' | 'responses'>
28
- delete?: Array<'operationId' | 'summary' | 'description' | 'parameters' | 'requestBody' | 'responses'>
29
- parameters?: Array<'name' | 'in' | 'description' | 'required' | 'schema'>
30
- requestBody?: Array<'description' | 'required' | 'content'>
31
- responses?: Array<'description' | 'headers' | 'content' | 'links'>
32
- content?: Array<string>
33
- components?: Array<'parameters' | 'schemas'>
34
- schema?: Array<'description' | 'type' | 'items' | 'properties' | 'format' | 'example' | 'default'>
35
- schemas?: Array<'description' | 'type' | 'items' | 'properties' | 'format' | 'example' | 'default'>
36
- properties?: Array<'description' | 'type' | 'items' | 'format' | 'example' | 'default' | 'enum'>
37
- }
38
- filterSet?: {
39
- methods?: Array<'get' | 'post' | 'put' | 'patch' | 'delete' | 'options' | 'trace' | 'head' | 'parameters'>
40
- inverseMethods?: Array<'get' | 'post' | 'put' | 'patch' | 'delete' | 'options' | 'trace' | 'head' | 'parameters'>
41
- tags?: Array<string>
42
- inverseTags?: Array<string>
43
- operationIds?: Array<string>
44
- inverseOperationIds?: Array<string>
45
- operations?: Array<string>
46
- flags?: Array<string>
47
- inverseFlags?: Array<string>
48
- flagValues?: Array<string>
49
- inverseFlagValues?: Array<string>
50
- stripFlags?: Array<string>
51
- responseContent?: Array<string>
52
- inverseResponseContent?: Array<string>
53
- unusedComponents?: Array<'requestBodies' | 'schemas' | 'parameters' | 'responses'>
54
- }
55
- sortComponentsSet?: {}
56
- casingSet?: {}
57
- }
58
- function parseFile(path: string): Promise<unknown>
59
-
60
- function openapiFilter<TOas>(document: TOas, options: Options): { data: Toas; resultData: { unusedComp: any } }
61
-
62
- function openapiSort<TOas>(document: TOas, options: Options): { data: Toas; resultData: { unusedComp: any } }
63
- function openapiChangeCase<TOas>(document: TOas, options: Options): { data: Toas; resultData: { unusedComp: any } }
64
-
65
- function stringify<TOas>(document: TOas, options: Options): string
66
- }
67
-
68
16
  declare function isOpenApiV3_1Document(doc: any): doc is OpenAPIV3_1.Document;
69
17
  declare function isParameterObject(obj: ParameterObject | SchemaObject): obj is ParameterObject;
70
18
  declare function isReference(obj?: unknown): obj is OpenAPIV3.ReferenceObject | OpenAPIV3_1.ReferenceObject;
package/dist/index.js CHANGED
@@ -1,4 +1,4 @@
1
- export { Oas, isOpenApiV3_1Document, isOptional, isParameterObject, isReference, isRequired } from './chunk-TVOJ46T6.js';
1
+ export { Oas, isOpenApiV3_1Document, isOptional, isParameterObject, isReference, isRequired } from './chunk-PHE7X6W6.js';
2
2
  export { findSchemaDefinition, matchesMimeType } from 'oas/utils';
3
3
 
4
4
  // src/types.ts
package/dist/parser.cjs CHANGED
@@ -1,6 +1,6 @@
1
1
  'use strict';
2
2
 
3
- var chunk2ZT6EJGT_cjs = require('./chunk-2ZT6EJGT.cjs');
3
+ var chunkJAZKMYLT_cjs = require('./chunk-JAZKMYLT.cjs');
4
4
  var openapiCore = require('@redocly/openapi-core');
5
5
  var OASNormalize = require('oas-normalize');
6
6
  var swagger2openapi = require('swagger2openapi');
@@ -10,26 +10,24 @@ function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
10
10
  var OASNormalize__default = /*#__PURE__*/_interopDefault(OASNormalize);
11
11
  var swagger2openapi__default = /*#__PURE__*/_interopDefault(swagger2openapi);
12
12
 
13
- async function parse(pathOrApi, options = {}, oasClass = chunk2ZT6EJGT_cjs.Oas) {
13
+ async function parse(pathOrApi, oasClass = chunkJAZKMYLT_cjs.Oas) {
14
14
  if (typeof pathOrApi === "string") {
15
15
  const config = await openapiCore.loadConfig();
16
16
  const bundleResults = await openapiCore.bundle({ ref: pathOrApi, config, base: pathOrApi });
17
- return parse(bundleResults.bundle.parsed, options);
17
+ return parse(bundleResults.bundle.parsed);
18
18
  }
19
19
  const oasNormalize = new OASNormalize__default.default(pathOrApi, {
20
20
  enablePaths: true,
21
21
  colorizeErrors: true
22
22
  });
23
23
  const document = await oasNormalize.load();
24
- if (chunk2ZT6EJGT_cjs.isOpenApiV2Document(document)) {
24
+ if (chunkJAZKMYLT_cjs.isOpenApiV2Document(document)) {
25
25
  const { openapi } = await swagger2openapi__default.default.convertObj(document, {
26
26
  anchors: true
27
27
  });
28
- const oas2 = await chunk2ZT6EJGT_cjs.filterAndSort(openapi, options);
29
- return new oasClass({ oas: oas2 });
28
+ return new oasClass({ oas: openapi });
30
29
  }
31
- const oas = await chunk2ZT6EJGT_cjs.filterAndSort(document, options);
32
- return new oasClass({ oas });
30
+ return new oasClass({ oas: document });
33
31
  }
34
32
 
35
33
  exports.parse = parse;
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/parser/index.ts"],"names":["Oas","loadConfig","bundle","OASNormalize","isOpenApiV2Document","swagger2openapi","oas","filterAndSort"],"mappings":";;;;;;;;;;;;AAoDA,eAAsB,MAAM,SAAiC,EAAA,OAAA,GAAyB,EAAC,EAAG,WAAuBA,qBAAmB,EAAA;AAClI,EAAI,IAAA,OAAO,cAAc,QAAU,EAAA;AAEjC,IAAM,MAAA,MAAA,GAAS,MAAMC,sBAAW,EAAA,CAAA;AAChC,IAAM,MAAA,aAAA,GAAgB,MAAMC,kBAAO,CAAA,EAAE,KAAK,SAAW,EAAA,MAAA,EAAQ,IAAM,EAAA,SAAA,EAAW,CAAA,CAAA;AAE9E,IAAA,OAAO,KAAM,CAAA,aAAA,CAAc,MAAO,CAAA,MAAA,EAAQ,OAAO,CAAA,CAAA;AAAA,GACnD;AAEA,EAAM,MAAA,YAAA,GAAe,IAAIC,6BAAA,CAAa,SAAW,EAAA;AAAA,IAC/C,WAAa,EAAA,IAAA;AAAA,IACb,cAAgB,EAAA,IAAA;AAAA,GACjB,CAAA,CAAA;AACD,EAAM,MAAA,QAAA,GAAY,MAAM,YAAA,CAAa,IAAK,EAAA,CAAA;AAE1C,EAAI,IAAAC,qCAAA,CAAoB,QAAQ,CAAG,EAAA;AACjC,IAAA,MAAM,EAAE,OAAQ,EAAA,GAAI,MAAMC,gCAAA,CAAgB,WAAW,QAAU,EAAA;AAAA,MAC7D,OAAS,EAAA,IAAA;AAAA,KACV,CAAA,CAAA;AAED,IAAA,MAAMC,IAAM,GAAA,MAAMC,+BAAc,CAAA,OAAA,EAAwB,OAAO,CAAA,CAAA;AAE/D,IAAA,OAAO,IAAI,QAAA,CAAS,EAAE,GAAA,EAAKD,MAAoB,CAAA,CAAA;AAAA,GACjD;AAEA,EAAA,MAAM,GAAM,GAAA,MAAMC,+BAAc,CAAA,QAAA,EAAyB,OAAO,CAAA,CAAA;AAEhE,EAAA,OAAO,IAAI,QAAA,CAAS,EAAE,GAAA,EAAK,CAAA,CAAA;AAC7B","file":"parser.cjs","sourcesContent":["import { bundle, loadConfig } from '@redocly/openapi-core'\nimport OASNormalize from 'oas-normalize'\nimport swagger2openapi from 'swagger2openapi'\n\nimport { Oas } from '../Oas.ts'\nimport { filterAndSort, isOpenApiV2Document } from '../utils.ts'\n\nimport type { OASDocument } from 'oas/types'\nimport type { OpenAPI } from 'openapi-types'\n\nexport type FormatOptions = {\n verbose?: boolean\n 'no-sort'?: boolean\n sort?: boolean\n output?: string\n sortSet?: {\n root?: Array<'openapi' | 'info' | 'servers' | 'paths' | 'components' | 'tags' | 'x-tagGroups' | 'externalDocs'>\n get?: Array<'operationId' | 'summary' | 'description' | 'parameters' | 'requestBody' | 'responses'>\n post?: Array<'operationId' | 'summary' | 'description' | 'parameters' | 'requestBody' | 'responses'>\n put?: Array<'operationId' | 'summary' | 'description' | 'parameters' | 'requestBody' | 'responses'>\n patch?: Array<'operationId' | 'summary' | 'description' | 'parameters' | 'requestBody' | 'responses'>\n delete?: Array<'operationId' | 'summary' | 'description' | 'parameters' | 'requestBody' | 'responses'>\n parameters?: Array<'name' | 'in' | 'description' | 'required' | 'schema'>\n requestBody?: Array<'description' | 'required' | 'content'>\n responses?: Array<'description' | 'headers' | 'content' | 'links'>\n content?: Array<string>\n components?: Array<'parameters' | 'schemas'>\n schema?: Array<'description' | 'type' | 'items' | 'properties' | 'format' | 'example' | 'default'>\n schemas?: Array<'description' | 'type' | 'items' | 'properties' | 'format' | 'example' | 'default'>\n properties?: Array<'description' | 'type' | 'items' | 'format' | 'example' | 'default' | 'enum'>\n }\n filterSet?: {\n methods?: Array<'get' | 'post' | 'put' | 'patch' | 'delete' | 'options' | 'trace' | 'head' | 'parameters'>\n inverseMethods?: Array<'get' | 'post' | 'put' | 'patch' | 'delete' | 'options' | 'trace' | 'head' | 'parameters'>\n tags?: Array<string>\n inverseTags?: Array<string>\n operationIds?: Array<string>\n inverseOperationIds?: Array<string>\n operations?: Array<string>\n flags?: Array<string>\n inverseFlags?: Array<string>\n flagValues?: Array<string>\n inverseFlagValues?: Array<string>\n stripFlags?: Array<string>\n responseContent?: Array<string>\n inverseResponseContent?: Array<string>\n unusedComponents?: Array<'requestBodies' | 'schemas' | 'parameters' | 'responses'>\n }\n sortComponentsSet?: {}\n casingSet?: {}\n}\n\nexport async function parse(pathOrApi: string | OASDocument, options: FormatOptions = {}, oasClass: typeof Oas = Oas): Promise<Oas> {\n if (typeof pathOrApi === 'string') {\n // resolve external refs\n const config = await loadConfig()\n const bundleResults = await bundle({ ref: pathOrApi, config, base: pathOrApi })\n\n return parse(bundleResults.bundle.parsed, options)\n }\n\n const oasNormalize = new OASNormalize(pathOrApi, {\n enablePaths: true,\n colorizeErrors: true,\n })\n const document = (await oasNormalize.load()) as OpenAPI.Document\n\n if (isOpenApiV2Document(document)) {\n const { openapi } = await swagger2openapi.convertObj(document, {\n anchors: true,\n })\n\n const oas = await filterAndSort(openapi as OASDocument, options)\n\n return new oasClass({ oas: oas as OASDocument })\n }\n\n const oas = await filterAndSort(document as OASDocument, options)\n\n return new oasClass({ oas })\n}\n"]}
1
+ {"version":3,"sources":["../src/parser/index.ts"],"names":["Oas","loadConfig","bundle","OASNormalize","isOpenApiV2Document","swagger2openapi"],"mappings":";;;;;;;;;;;;AAUA,eAAsB,KAAA,CAAM,SAAiC,EAAA,QAAA,GAAuBA,qBAAmB,EAAA;AACrG,EAAI,IAAA,OAAO,cAAc,QAAU,EAAA;AAEjC,IAAM,MAAA,MAAA,GAAS,MAAMC,sBAAW,EAAA,CAAA;AAChC,IAAM,MAAA,aAAA,GAAgB,MAAMC,kBAAO,CAAA,EAAE,KAAK,SAAW,EAAA,MAAA,EAAQ,IAAM,EAAA,SAAA,EAAW,CAAA,CAAA;AAE9E,IAAO,OAAA,KAAA,CAAM,aAAc,CAAA,MAAA,CAAO,MAAM,CAAA,CAAA;AAAA,GAC1C;AAEA,EAAM,MAAA,YAAA,GAAe,IAAIC,6BAAA,CAAa,SAAW,EAAA;AAAA,IAC/C,WAAa,EAAA,IAAA;AAAA,IACb,cAAgB,EAAA,IAAA;AAAA,GACjB,CAAA,CAAA;AACD,EAAM,MAAA,QAAA,GAAY,MAAM,YAAA,CAAa,IAAK,EAAA,CAAA;AAE1C,EAAI,IAAAC,qCAAA,CAAoB,QAAQ,CAAG,EAAA;AACjC,IAAA,MAAM,EAAE,OAAQ,EAAA,GAAI,MAAMC,gCAAA,CAAgB,WAAW,QAAU,EAAA;AAAA,MAC7D,OAAS,EAAA,IAAA;AAAA,KACV,CAAA,CAAA;AAED,IAAA,OAAO,IAAI,QAAA,CAAS,EAAE,GAAA,EAAK,SAAwB,CAAA,CAAA;AAAA,GACrD;AAEA,EAAA,OAAO,IAAI,QAAA,CAAS,EAAE,GAAA,EAAK,UAAU,CAAA,CAAA;AACvC","file":"parser.cjs","sourcesContent":["import { bundle, loadConfig } from '@redocly/openapi-core'\nimport OASNormalize from 'oas-normalize'\nimport swagger2openapi from 'swagger2openapi'\n\nimport { Oas } from '../Oas.ts'\nimport { isOpenApiV2Document } from '../utils.ts'\n\nimport type { OASDocument } from 'oas/types'\nimport type { OpenAPI } from 'openapi-types'\n\nexport async function parse(pathOrApi: string | OASDocument, oasClass: typeof Oas = Oas): Promise<Oas> {\n if (typeof pathOrApi === 'string') {\n // resolve external refs\n const config = await loadConfig()\n const bundleResults = await bundle({ ref: pathOrApi, config, base: pathOrApi })\n\n return parse(bundleResults.bundle.parsed)\n }\n\n const oasNormalize = new OASNormalize(pathOrApi, {\n enablePaths: true,\n colorizeErrors: true,\n })\n const document = (await oasNormalize.load()) as OpenAPI.Document\n\n if (isOpenApiV2Document(document)) {\n const { openapi } = await swagger2openapi.convertObj(document, {\n anchors: true,\n })\n\n return new oasClass({ oas: openapi as OASDocument })\n }\n\n return new oasClass({ oas: document })\n}\n"]}
package/dist/parser.d.cts CHANGED
@@ -1,49 +1,8 @@
1
- import { O as Oas } from './Oas-BEe7KZDj.cjs';
1
+ import { O as Oas } from './Oas-Br0yKhGF.cjs';
2
2
  import { OASDocument } from 'oas/types';
3
3
  import 'oas';
4
4
  import 'oas/operation';
5
5
 
6
- type FormatOptions = {
7
- verbose?: boolean;
8
- 'no-sort'?: boolean;
9
- sort?: boolean;
10
- output?: string;
11
- sortSet?: {
12
- root?: Array<'openapi' | 'info' | 'servers' | 'paths' | 'components' | 'tags' | 'x-tagGroups' | 'externalDocs'>;
13
- get?: Array<'operationId' | 'summary' | 'description' | 'parameters' | 'requestBody' | 'responses'>;
14
- post?: Array<'operationId' | 'summary' | 'description' | 'parameters' | 'requestBody' | 'responses'>;
15
- put?: Array<'operationId' | 'summary' | 'description' | 'parameters' | 'requestBody' | 'responses'>;
16
- patch?: Array<'operationId' | 'summary' | 'description' | 'parameters' | 'requestBody' | 'responses'>;
17
- delete?: Array<'operationId' | 'summary' | 'description' | 'parameters' | 'requestBody' | 'responses'>;
18
- parameters?: Array<'name' | 'in' | 'description' | 'required' | 'schema'>;
19
- requestBody?: Array<'description' | 'required' | 'content'>;
20
- responses?: Array<'description' | 'headers' | 'content' | 'links'>;
21
- content?: Array<string>;
22
- components?: Array<'parameters' | 'schemas'>;
23
- schema?: Array<'description' | 'type' | 'items' | 'properties' | 'format' | 'example' | 'default'>;
24
- schemas?: Array<'description' | 'type' | 'items' | 'properties' | 'format' | 'example' | 'default'>;
25
- properties?: Array<'description' | 'type' | 'items' | 'format' | 'example' | 'default' | 'enum'>;
26
- };
27
- filterSet?: {
28
- methods?: Array<'get' | 'post' | 'put' | 'patch' | 'delete' | 'options' | 'trace' | 'head' | 'parameters'>;
29
- inverseMethods?: Array<'get' | 'post' | 'put' | 'patch' | 'delete' | 'options' | 'trace' | 'head' | 'parameters'>;
30
- tags?: Array<string>;
31
- inverseTags?: Array<string>;
32
- operationIds?: Array<string>;
33
- inverseOperationIds?: Array<string>;
34
- operations?: Array<string>;
35
- flags?: Array<string>;
36
- inverseFlags?: Array<string>;
37
- flagValues?: Array<string>;
38
- inverseFlagValues?: Array<string>;
39
- stripFlags?: Array<string>;
40
- responseContent?: Array<string>;
41
- inverseResponseContent?: Array<string>;
42
- unusedComponents?: Array<'requestBodies' | 'schemas' | 'parameters' | 'responses'>;
43
- };
44
- sortComponentsSet?: {};
45
- casingSet?: {};
46
- };
47
- declare function parse(pathOrApi: string | OASDocument, options?: FormatOptions, oasClass?: typeof Oas): Promise<Oas>;
6
+ declare function parse(pathOrApi: string | OASDocument, oasClass?: typeof Oas): Promise<Oas>;
48
7
 
49
- export { type FormatOptions, parse };
8
+ export { parse };
package/dist/parser.d.ts CHANGED
@@ -1,49 +1,8 @@
1
- import { O as Oas } from './Oas-BEe7KZDj.js';
1
+ import { O as Oas } from './Oas-Br0yKhGF.js';
2
2
  import { OASDocument } from 'oas/types';
3
3
  import 'oas';
4
4
  import 'oas/operation';
5
5
 
6
- type FormatOptions = {
7
- verbose?: boolean;
8
- 'no-sort'?: boolean;
9
- sort?: boolean;
10
- output?: string;
11
- sortSet?: {
12
- root?: Array<'openapi' | 'info' | 'servers' | 'paths' | 'components' | 'tags' | 'x-tagGroups' | 'externalDocs'>;
13
- get?: Array<'operationId' | 'summary' | 'description' | 'parameters' | 'requestBody' | 'responses'>;
14
- post?: Array<'operationId' | 'summary' | 'description' | 'parameters' | 'requestBody' | 'responses'>;
15
- put?: Array<'operationId' | 'summary' | 'description' | 'parameters' | 'requestBody' | 'responses'>;
16
- patch?: Array<'operationId' | 'summary' | 'description' | 'parameters' | 'requestBody' | 'responses'>;
17
- delete?: Array<'operationId' | 'summary' | 'description' | 'parameters' | 'requestBody' | 'responses'>;
18
- parameters?: Array<'name' | 'in' | 'description' | 'required' | 'schema'>;
19
- requestBody?: Array<'description' | 'required' | 'content'>;
20
- responses?: Array<'description' | 'headers' | 'content' | 'links'>;
21
- content?: Array<string>;
22
- components?: Array<'parameters' | 'schemas'>;
23
- schema?: Array<'description' | 'type' | 'items' | 'properties' | 'format' | 'example' | 'default'>;
24
- schemas?: Array<'description' | 'type' | 'items' | 'properties' | 'format' | 'example' | 'default'>;
25
- properties?: Array<'description' | 'type' | 'items' | 'format' | 'example' | 'default' | 'enum'>;
26
- };
27
- filterSet?: {
28
- methods?: Array<'get' | 'post' | 'put' | 'patch' | 'delete' | 'options' | 'trace' | 'head' | 'parameters'>;
29
- inverseMethods?: Array<'get' | 'post' | 'put' | 'patch' | 'delete' | 'options' | 'trace' | 'head' | 'parameters'>;
30
- tags?: Array<string>;
31
- inverseTags?: Array<string>;
32
- operationIds?: Array<string>;
33
- inverseOperationIds?: Array<string>;
34
- operations?: Array<string>;
35
- flags?: Array<string>;
36
- inverseFlags?: Array<string>;
37
- flagValues?: Array<string>;
38
- inverseFlagValues?: Array<string>;
39
- stripFlags?: Array<string>;
40
- responseContent?: Array<string>;
41
- inverseResponseContent?: Array<string>;
42
- unusedComponents?: Array<'requestBodies' | 'schemas' | 'parameters' | 'responses'>;
43
- };
44
- sortComponentsSet?: {};
45
- casingSet?: {};
46
- };
47
- declare function parse(pathOrApi: string | OASDocument, options?: FormatOptions, oasClass?: typeof Oas): Promise<Oas>;
6
+ declare function parse(pathOrApi: string | OASDocument, oasClass?: typeof Oas): Promise<Oas>;
48
7
 
49
- export { type FormatOptions, parse };
8
+ export { parse };
package/dist/parser.js CHANGED
@@ -1,13 +1,13 @@
1
- import { isOpenApiV2Document, filterAndSort, Oas } from './chunk-TVOJ46T6.js';
1
+ import { isOpenApiV2Document, Oas } from './chunk-PHE7X6W6.js';
2
2
  import { loadConfig, bundle } from '@redocly/openapi-core';
3
3
  import OASNormalize from 'oas-normalize';
4
4
  import swagger2openapi from 'swagger2openapi';
5
5
 
6
- async function parse(pathOrApi, options = {}, oasClass = Oas) {
6
+ async function parse(pathOrApi, oasClass = Oas) {
7
7
  if (typeof pathOrApi === "string") {
8
8
  const config = await loadConfig();
9
9
  const bundleResults = await bundle({ ref: pathOrApi, config, base: pathOrApi });
10
- return parse(bundleResults.bundle.parsed, options);
10
+ return parse(bundleResults.bundle.parsed);
11
11
  }
12
12
  const oasNormalize = new OASNormalize(pathOrApi, {
13
13
  enablePaths: true,
@@ -18,11 +18,9 @@ async function parse(pathOrApi, options = {}, oasClass = Oas) {
18
18
  const { openapi } = await swagger2openapi.convertObj(document, {
19
19
  anchors: true
20
20
  });
21
- const oas2 = await filterAndSort(openapi, options);
22
- return new oasClass({ oas: oas2 });
21
+ return new oasClass({ oas: openapi });
23
22
  }
24
- const oas = await filterAndSort(document, options);
25
- return new oasClass({ oas });
23
+ return new oasClass({ oas: document });
26
24
  }
27
25
 
28
26
  export { parse };
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/parser/index.ts"],"names":["oas"],"mappings":";;;;;AAoDA,eAAsB,MAAM,SAAiC,EAAA,OAAA,GAAyB,EAAC,EAAG,WAAuB,GAAmB,EAAA;AAClI,EAAI,IAAA,OAAO,cAAc,QAAU,EAAA;AAEjC,IAAM,MAAA,MAAA,GAAS,MAAM,UAAW,EAAA,CAAA;AAChC,IAAM,MAAA,aAAA,GAAgB,MAAM,MAAO,CAAA,EAAE,KAAK,SAAW,EAAA,MAAA,EAAQ,IAAM,EAAA,SAAA,EAAW,CAAA,CAAA;AAE9E,IAAA,OAAO,KAAM,CAAA,aAAA,CAAc,MAAO,CAAA,MAAA,EAAQ,OAAO,CAAA,CAAA;AAAA,GACnD;AAEA,EAAM,MAAA,YAAA,GAAe,IAAI,YAAA,CAAa,SAAW,EAAA;AAAA,IAC/C,WAAa,EAAA,IAAA;AAAA,IACb,cAAgB,EAAA,IAAA;AAAA,GACjB,CAAA,CAAA;AACD,EAAM,MAAA,QAAA,GAAY,MAAM,YAAA,CAAa,IAAK,EAAA,CAAA;AAE1C,EAAI,IAAA,mBAAA,CAAoB,QAAQ,CAAG,EAAA;AACjC,IAAA,MAAM,EAAE,OAAQ,EAAA,GAAI,MAAM,eAAA,CAAgB,WAAW,QAAU,EAAA;AAAA,MAC7D,OAAS,EAAA,IAAA;AAAA,KACV,CAAA,CAAA;AAED,IAAA,MAAMA,IAAM,GAAA,MAAM,aAAc,CAAA,OAAA,EAAwB,OAAO,CAAA,CAAA;AAE/D,IAAA,OAAO,IAAI,QAAA,CAAS,EAAE,GAAA,EAAKA,MAAoB,CAAA,CAAA;AAAA,GACjD;AAEA,EAAA,MAAM,GAAM,GAAA,MAAM,aAAc,CAAA,QAAA,EAAyB,OAAO,CAAA,CAAA;AAEhE,EAAA,OAAO,IAAI,QAAA,CAAS,EAAE,GAAA,EAAK,CAAA,CAAA;AAC7B","file":"parser.js","sourcesContent":["import { bundle, loadConfig } from '@redocly/openapi-core'\nimport OASNormalize from 'oas-normalize'\nimport swagger2openapi from 'swagger2openapi'\n\nimport { Oas } from '../Oas.ts'\nimport { filterAndSort, isOpenApiV2Document } from '../utils.ts'\n\nimport type { OASDocument } from 'oas/types'\nimport type { OpenAPI } from 'openapi-types'\n\nexport type FormatOptions = {\n verbose?: boolean\n 'no-sort'?: boolean\n sort?: boolean\n output?: string\n sortSet?: {\n root?: Array<'openapi' | 'info' | 'servers' | 'paths' | 'components' | 'tags' | 'x-tagGroups' | 'externalDocs'>\n get?: Array<'operationId' | 'summary' | 'description' | 'parameters' | 'requestBody' | 'responses'>\n post?: Array<'operationId' | 'summary' | 'description' | 'parameters' | 'requestBody' | 'responses'>\n put?: Array<'operationId' | 'summary' | 'description' | 'parameters' | 'requestBody' | 'responses'>\n patch?: Array<'operationId' | 'summary' | 'description' | 'parameters' | 'requestBody' | 'responses'>\n delete?: Array<'operationId' | 'summary' | 'description' | 'parameters' | 'requestBody' | 'responses'>\n parameters?: Array<'name' | 'in' | 'description' | 'required' | 'schema'>\n requestBody?: Array<'description' | 'required' | 'content'>\n responses?: Array<'description' | 'headers' | 'content' | 'links'>\n content?: Array<string>\n components?: Array<'parameters' | 'schemas'>\n schema?: Array<'description' | 'type' | 'items' | 'properties' | 'format' | 'example' | 'default'>\n schemas?: Array<'description' | 'type' | 'items' | 'properties' | 'format' | 'example' | 'default'>\n properties?: Array<'description' | 'type' | 'items' | 'format' | 'example' | 'default' | 'enum'>\n }\n filterSet?: {\n methods?: Array<'get' | 'post' | 'put' | 'patch' | 'delete' | 'options' | 'trace' | 'head' | 'parameters'>\n inverseMethods?: Array<'get' | 'post' | 'put' | 'patch' | 'delete' | 'options' | 'trace' | 'head' | 'parameters'>\n tags?: Array<string>\n inverseTags?: Array<string>\n operationIds?: Array<string>\n inverseOperationIds?: Array<string>\n operations?: Array<string>\n flags?: Array<string>\n inverseFlags?: Array<string>\n flagValues?: Array<string>\n inverseFlagValues?: Array<string>\n stripFlags?: Array<string>\n responseContent?: Array<string>\n inverseResponseContent?: Array<string>\n unusedComponents?: Array<'requestBodies' | 'schemas' | 'parameters' | 'responses'>\n }\n sortComponentsSet?: {}\n casingSet?: {}\n}\n\nexport async function parse(pathOrApi: string | OASDocument, options: FormatOptions = {}, oasClass: typeof Oas = Oas): Promise<Oas> {\n if (typeof pathOrApi === 'string') {\n // resolve external refs\n const config = await loadConfig()\n const bundleResults = await bundle({ ref: pathOrApi, config, base: pathOrApi })\n\n return parse(bundleResults.bundle.parsed, options)\n }\n\n const oasNormalize = new OASNormalize(pathOrApi, {\n enablePaths: true,\n colorizeErrors: true,\n })\n const document = (await oasNormalize.load()) as OpenAPI.Document\n\n if (isOpenApiV2Document(document)) {\n const { openapi } = await swagger2openapi.convertObj(document, {\n anchors: true,\n })\n\n const oas = await filterAndSort(openapi as OASDocument, options)\n\n return new oasClass({ oas: oas as OASDocument })\n }\n\n const oas = await filterAndSort(document as OASDocument, options)\n\n return new oasClass({ oas })\n}\n"]}
1
+ {"version":3,"sources":["../src/parser/index.ts"],"names":[],"mappings":";;;;;AAUA,eAAsB,KAAA,CAAM,SAAiC,EAAA,QAAA,GAAuB,GAAmB,EAAA;AACrG,EAAI,IAAA,OAAO,cAAc,QAAU,EAAA;AAEjC,IAAM,MAAA,MAAA,GAAS,MAAM,UAAW,EAAA,CAAA;AAChC,IAAM,MAAA,aAAA,GAAgB,MAAM,MAAO,CAAA,EAAE,KAAK,SAAW,EAAA,MAAA,EAAQ,IAAM,EAAA,SAAA,EAAW,CAAA,CAAA;AAE9E,IAAO,OAAA,KAAA,CAAM,aAAc,CAAA,MAAA,CAAO,MAAM,CAAA,CAAA;AAAA,GAC1C;AAEA,EAAM,MAAA,YAAA,GAAe,IAAI,YAAA,CAAa,SAAW,EAAA;AAAA,IAC/C,WAAa,EAAA,IAAA;AAAA,IACb,cAAgB,EAAA,IAAA;AAAA,GACjB,CAAA,CAAA;AACD,EAAM,MAAA,QAAA,GAAY,MAAM,YAAA,CAAa,IAAK,EAAA,CAAA;AAE1C,EAAI,IAAA,mBAAA,CAAoB,QAAQ,CAAG,EAAA;AACjC,IAAA,MAAM,EAAE,OAAQ,EAAA,GAAI,MAAM,eAAA,CAAgB,WAAW,QAAU,EAAA;AAAA,MAC7D,OAAS,EAAA,IAAA;AAAA,KACV,CAAA,CAAA;AAED,IAAA,OAAO,IAAI,QAAA,CAAS,EAAE,GAAA,EAAK,SAAwB,CAAA,CAAA;AAAA,GACrD;AAEA,EAAA,OAAO,IAAI,QAAA,CAAS,EAAE,GAAA,EAAK,UAAU,CAAA,CAAA;AACvC","file":"parser.js","sourcesContent":["import { bundle, loadConfig } from '@redocly/openapi-core'\nimport OASNormalize from 'oas-normalize'\nimport swagger2openapi from 'swagger2openapi'\n\nimport { Oas } from '../Oas.ts'\nimport { isOpenApiV2Document } from '../utils.ts'\n\nimport type { OASDocument } from 'oas/types'\nimport type { OpenAPI } from 'openapi-types'\n\nexport async function parse(pathOrApi: string | OASDocument, oasClass: typeof Oas = Oas): Promise<Oas> {\n if (typeof pathOrApi === 'string') {\n // resolve external refs\n const config = await loadConfig()\n const bundleResults = await bundle({ ref: pathOrApi, config, base: pathOrApi })\n\n return parse(bundleResults.bundle.parsed)\n }\n\n const oasNormalize = new OASNormalize(pathOrApi, {\n enablePaths: true,\n colorizeErrors: true,\n })\n const document = (await oasNormalize.load()) as OpenAPI.Document\n\n if (isOpenApiV2Document(document)) {\n const { openapi } = await swagger2openapi.convertObj(document, {\n anchors: true,\n })\n\n return new oasClass({ oas: openapi as OASDocument })\n }\n\n return new oasClass({ oas: document })\n}\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kubb/oas",
3
- "version": "3.0.0-alpha.21",
3
+ "version": "3.0.0-alpha.25",
4
4
  "description": "Oas helpers",
5
5
  "keywords": [
6
6
  "typescript",
@@ -59,9 +59,9 @@
59
59
  "@redocly/openapi-core": "^1.25.3",
60
60
  "hotscript": "^1.0.13",
61
61
  "json-schema-to-ts": "^3.1.1",
62
- "oas": "^24.9.0",
62
+ "jsonpointer": "^5.0.1",
63
+ "oas": "^25.0.1",
63
64
  "oas-normalize": "^11.1.2",
64
- "openapi-format": "^1.23.2",
65
65
  "openapi-types": "^12.1.3",
66
66
  "remeda": "^2.14.0",
67
67
  "swagger2openapi": "^7.0.8",
@@ -73,8 +73,8 @@
73
73
  "expect-type": "^0.19.0",
74
74
  "tsup": "^8.3.0",
75
75
  "typescript": "^5.6.2",
76
- "@kubb/config-ts": "3.0.0-alpha.21",
77
- "@kubb/config-tsup": "3.0.0-alpha.21"
76
+ "@kubb/config-ts": "3.0.0-alpha.25",
77
+ "@kubb/config-tsup": "3.0.0-alpha.25"
78
78
  },
79
79
  "engines": {
80
80
  "node": ">=20"
package/src/Oas.ts CHANGED
@@ -1,11 +1,14 @@
1
1
  import BaseOas from 'oas'
2
2
  import OASNormalize from 'oas-normalize'
3
- import { findSchemaDefinition, matchesMimeType } from 'oas/utils'
3
+ import { matchesMimeType } from 'oas/utils'
4
+
5
+ import jsonpointer from 'jsonpointer'
4
6
 
5
7
  import { isReference } from './utils.ts'
6
8
 
7
9
  import type { Operation } from 'oas/operation'
8
10
  import type { MediaTypeObject, OASDocument, ResponseObject, SchemaObject, User } from 'oas/types'
11
+ import type { OasTypes, OpenAPIV3 } from './index.ts'
9
12
  import type { contentType } from './types.ts'
10
13
 
11
14
  type Options = {
@@ -27,10 +30,72 @@ export class Oas<const TOAS = unknown> extends BaseOas {
27
30
  this.#options = options
28
31
  }
29
32
 
33
+ get($ref: string) {
34
+ const origRef = $ref
35
+ $ref = $ref.trim()
36
+ if ($ref === '') {
37
+ return false
38
+ }
39
+ if ($ref.startsWith('#')) {
40
+ $ref = globalThis.decodeURIComponent($ref.substring(1))
41
+ } else {
42
+ throw new Error(`Could not find a definition for ${origRef}.`)
43
+ }
44
+ const current = jsonpointer.get(this.api, $ref)
45
+
46
+ if (!current) {
47
+ throw new Error(`Could not find a definition for ${origRef}.`)
48
+ }
49
+ return current
50
+ }
51
+
52
+ set($ref: string, value: unknown) {
53
+ const origRef = $ref
54
+ $ref = $ref.trim()
55
+ if ($ref === '') {
56
+ return false
57
+ }
58
+ if ($ref.startsWith('#')) {
59
+ $ref = globalThis.decodeURIComponent($ref.substring(1))
60
+ } else {
61
+ throw new Error(`Could not find a definition for ${origRef}.`)
62
+ }
63
+
64
+ jsonpointer.set(this.api, $ref, value)
65
+ }
66
+
67
+ resolveDiscriminators(): void {
68
+ const schemas = (this.api.components?.schemas || {}) as Record<string, OasTypes.SchemaObject>
69
+
70
+ Object.entries(schemas).forEach(([key, schemaObject]) => {
71
+ if ('discriminator' in schemaObject) {
72
+ const { mapping = {}, propertyName } = (schemaObject.discriminator || {}) as OpenAPIV3.DiscriminatorObject
73
+
74
+ Object.entries(mapping).forEach(([mappingKey, mappingValue]) => {
75
+ if (mappingValue) {
76
+ const childSchema = this.get(mappingValue)
77
+ const property = childSchema.properties?.[propertyName] as SchemaObject
78
+
79
+ if (property) {
80
+ childSchema.properties[propertyName] = {
81
+ ...childSchema.properties[propertyName],
82
+ enum: [...(property?.enum?.filter((value) => value !== mappingKey) ?? []), mappingKey],
83
+ }
84
+
85
+ childSchema.required = [...(childSchema.required ?? []), propertyName]
86
+
87
+ this.set(mappingValue, childSchema)
88
+ }
89
+ }
90
+ })
91
+ }
92
+ })
93
+ }
94
+
30
95
  dereferenceWithRef(schema?: unknown) {
31
96
  if (isReference(schema)) {
32
97
  return {
33
- ...findSchemaDefinition(schema.$ref, this.api),
98
+ ...this.get(schema.$ref),
34
99
  $ref: schema.$ref,
35
100
  }
36
101
  }
@@ -102,7 +167,7 @@ export class Oas<const TOAS = unknown> extends BaseOas {
102
167
  const $ref = isReference(schema) ? schema.$ref : undefined
103
168
 
104
169
  if (schema && $ref) {
105
- operation.schema.responses![key] = findSchemaDefinition($ref, this.api)
170
+ operation.schema.responses![key] = this.get($ref)
106
171
  }
107
172
  })
108
173
  }
package/src/index.ts CHANGED
@@ -1,5 +1,3 @@
1
- import './typings.d.ts'
2
-
3
1
  export * from './types.ts'
4
2
  export { findSchemaDefinition, matchesMimeType } from 'oas/utils'
5
3
  export { isRequired, isOptional, isReference, isParameterObject, isOpenApiV3_1Document } from './utils.ts'
@@ -3,60 +3,18 @@ import OASNormalize from 'oas-normalize'
3
3
  import swagger2openapi from 'swagger2openapi'
4
4
 
5
5
  import { Oas } from '../Oas.ts'
6
- import { filterAndSort, isOpenApiV2Document } from '../utils.ts'
6
+ import { isOpenApiV2Document } from '../utils.ts'
7
7
 
8
8
  import type { OASDocument } from 'oas/types'
9
9
  import type { OpenAPI } from 'openapi-types'
10
10
 
11
- export type FormatOptions = {
12
- verbose?: boolean
13
- 'no-sort'?: boolean
14
- sort?: boolean
15
- output?: string
16
- sortSet?: {
17
- root?: Array<'openapi' | 'info' | 'servers' | 'paths' | 'components' | 'tags' | 'x-tagGroups' | 'externalDocs'>
18
- get?: Array<'operationId' | 'summary' | 'description' | 'parameters' | 'requestBody' | 'responses'>
19
- post?: Array<'operationId' | 'summary' | 'description' | 'parameters' | 'requestBody' | 'responses'>
20
- put?: Array<'operationId' | 'summary' | 'description' | 'parameters' | 'requestBody' | 'responses'>
21
- patch?: Array<'operationId' | 'summary' | 'description' | 'parameters' | 'requestBody' | 'responses'>
22
- delete?: Array<'operationId' | 'summary' | 'description' | 'parameters' | 'requestBody' | 'responses'>
23
- parameters?: Array<'name' | 'in' | 'description' | 'required' | 'schema'>
24
- requestBody?: Array<'description' | 'required' | 'content'>
25
- responses?: Array<'description' | 'headers' | 'content' | 'links'>
26
- content?: Array<string>
27
- components?: Array<'parameters' | 'schemas'>
28
- schema?: Array<'description' | 'type' | 'items' | 'properties' | 'format' | 'example' | 'default'>
29
- schemas?: Array<'description' | 'type' | 'items' | 'properties' | 'format' | 'example' | 'default'>
30
- properties?: Array<'description' | 'type' | 'items' | 'format' | 'example' | 'default' | 'enum'>
31
- }
32
- filterSet?: {
33
- methods?: Array<'get' | 'post' | 'put' | 'patch' | 'delete' | 'options' | 'trace' | 'head' | 'parameters'>
34
- inverseMethods?: Array<'get' | 'post' | 'put' | 'patch' | 'delete' | 'options' | 'trace' | 'head' | 'parameters'>
35
- tags?: Array<string>
36
- inverseTags?: Array<string>
37
- operationIds?: Array<string>
38
- inverseOperationIds?: Array<string>
39
- operations?: Array<string>
40
- flags?: Array<string>
41
- inverseFlags?: Array<string>
42
- flagValues?: Array<string>
43
- inverseFlagValues?: Array<string>
44
- stripFlags?: Array<string>
45
- responseContent?: Array<string>
46
- inverseResponseContent?: Array<string>
47
- unusedComponents?: Array<'requestBodies' | 'schemas' | 'parameters' | 'responses'>
48
- }
49
- sortComponentsSet?: {}
50
- casingSet?: {}
51
- }
52
-
53
- export async function parse(pathOrApi: string | OASDocument, options: FormatOptions = {}, oasClass: typeof Oas = Oas): Promise<Oas> {
11
+ export async function parse(pathOrApi: string | OASDocument, oasClass: typeof Oas = Oas): Promise<Oas> {
54
12
  if (typeof pathOrApi === 'string') {
55
13
  // resolve external refs
56
14
  const config = await loadConfig()
57
15
  const bundleResults = await bundle({ ref: pathOrApi, config, base: pathOrApi })
58
16
 
59
- return parse(bundleResults.bundle.parsed, options)
17
+ return parse(bundleResults.bundle.parsed)
60
18
  }
61
19
 
62
20
  const oasNormalize = new OASNormalize(pathOrApi, {
@@ -70,12 +28,8 @@ export async function parse(pathOrApi: string | OASDocument, options: FormatOpti
70
28
  anchors: true,
71
29
  })
72
30
 
73
- const oas = await filterAndSort(openapi as OASDocument, options)
74
-
75
- return new oasClass({ oas: oas as OASDocument })
31
+ return new oasClass({ oas: openapi as OASDocument })
76
32
  }
77
33
 
78
- const oas = await filterAndSort(document as OASDocument, options)
79
-
80
- return new oasClass({ oas })
34
+ return new oasClass({ oas: document })
81
35
  }
package/src/utils.ts CHANGED
@@ -1,10 +1,8 @@
1
1
  import { isRef, isSchema } from 'oas/types'
2
- import openapiFormat from 'openapi-format'
3
2
  import { isPlainObject } from 'remeda'
4
3
 
5
- import type { OASDocument, ParameterObject, SchemaObject } from 'oas/types'
4
+ import type { ParameterObject, SchemaObject } from 'oas/types'
6
5
  import type { OpenAPIV2, OpenAPIV3, OpenAPIV3_1 } from 'openapi-types'
7
- import type { FormatOptions } from './parser/index.ts'
8
6
 
9
7
  export function isOpenApiV2Document(doc: any): doc is OpenAPIV2.Document {
10
8
  return doc && isPlainObject(doc) && !('openapi' in doc)
@@ -40,49 +38,3 @@ export function isRequired(schema?: SchemaObject): boolean {
40
38
  export function isOptional(schema?: SchemaObject): boolean {
41
39
  return !isRequired(schema)
42
40
  }
43
-
44
- export async function filterAndSort(data: OASDocument, options: FormatOptions = {}): Promise<OASDocument> {
45
- const mergedOptions: FormatOptions = {
46
- sort: options.sort ?? true,
47
- ['no-sort']: options['no-sort'] ?? false,
48
- sortSet: {
49
- root: ['openapi', 'info', 'servers', 'paths', 'components', 'tags', 'x-tagGroups', 'externalDocs'],
50
- get: ['operationId', 'summary', 'description', 'parameters', 'requestBody', 'responses'],
51
- post: ['operationId', 'summary', 'description', 'parameters', 'requestBody', 'responses'],
52
- put: ['operationId', 'summary', 'description', 'parameters', 'requestBody', 'responses'],
53
- patch: ['operationId', 'summary', 'description', 'parameters', 'requestBody', 'responses'],
54
- delete: ['operationId', 'summary', 'description', 'parameters', 'requestBody', 'responses'],
55
- parameters: ['name', 'in', 'description', 'required', 'schema'],
56
- requestBody: ['description', 'required', 'content'],
57
- responses: ['description', 'headers', 'content', 'links'],
58
- content: [],
59
- components: ['parameters', 'schemas'],
60
- schema: ['description', 'type', 'items', 'properties', 'format', 'example', 'default'],
61
- schemas: ['description', 'type', 'items', 'properties', 'format', 'example', 'default'],
62
- properties: ['description', 'type', 'items', 'format', 'example', 'default', 'enum'],
63
- ...options.sortSet,
64
- },
65
- sortComponentsSet: {
66
- ...options.sortComponentsSet,
67
- },
68
- filterSet: {
69
- inverseMethods: ['get', 'put', 'post', 'delete', 'patch', 'head', 'options', 'trace', 'parameters'],
70
- unusedComponents: options.filterSet ? ['requestBodies', 'schemas', 'parameters', 'responses'] : [],
71
- ...options.filterSet,
72
- },
73
- casingSet: {
74
- ...options.casingSet,
75
- },
76
- }
77
-
78
- const restFilter = await openapiFormat.openapiFilter(data, mergedOptions)
79
- data = restFilter.data
80
-
81
- const resFormat = await openapiFormat.openapiSort(data, mergedOptions)
82
- data = resFormat.data
83
-
84
- const resChangeCase = await openapiFormat.openapiChangeCase(data, mergedOptions)
85
- data = resChangeCase.data
86
-
87
- return data
88
- }
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/utils.ts","../src/Oas.ts"],"names":["isPlainObject","isRef","openapiFormat","BaseOas","findSchemaDefinition","matchesMimeType","schema","OASNormalize"],"mappings":";;;;;;;;;;;;;;;;AAQO,SAAS,oBAAoB,GAAqC,EAAA;AACvE,EAAA,OAAO,GAAO,IAAAA,oBAAA,CAAc,GAAG,CAAA,IAAK,EAAE,SAAa,IAAA,GAAA,CAAA,CAAA;AACrD,CAAA;AAKO,SAAS,sBAAsB,GAAuC,EAAA;AAC3E,EAAO,OAAA,GAAA,IAAOA,qBAAoC,GAAG,CAAA,IAAK,aAAa,GAAO,IAAA,GAAA,CAAI,OAAQ,CAAA,UAAA,CAAW,KAAK,CAAA,CAAA;AAC5G,CAAA;AAMO,SAAS,kBAAkB,GAA6D,EAAA;AAC7F,EAAA,OAAO,OAAO,IAAQ,IAAA,GAAA,CAAA;AACxB,CAAA;AAEO,SAAS,YAAY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;AAAA,GACH;AACF","file":"chunk-2ZT6EJGT.cjs","sourcesContent":["import { isRef, isSchema } from 'oas/types'\nimport openapiFormat from 'openapi-format'\nimport { isPlainObject } from 'remeda'\n\nimport type { OASDocument, ParameterObject, SchemaObject } from 'oas/types'\nimport type { OpenAPIV2, OpenAPIV3, OpenAPIV3_1 } from 'openapi-types'\nimport type { FormatOptions } from './parser/index.ts'\n\nexport function isOpenApiV2Document(doc: any): doc is OpenAPIV2.Document {\n return doc && isPlainObject(doc) && !('openapi' in doc)\n}\nexport function isOpenApiV3Document(doc: any): doc is OpenAPIV3.Document {\n return doc && isPlainObject(doc) && 'openapi' in doc\n}\n\nexport function isOpenApiV3_1Document(doc: any): doc is OpenAPIV3_1.Document {\n return doc && isPlainObject<OpenAPIV3_1.Document>(doc) && 'openapi' in doc && doc.openapi.startsWith('3.1')\n}\n\nexport function isJSONSchema(obj?: unknown): obj is SchemaObject {\n return !!obj && isSchema(obj)\n}\n\nexport function isParameterObject(obj: ParameterObject | SchemaObject): obj is ParameterObject {\n return obj && 'in' in obj\n}\n\nexport function isReference(obj?: unknown): obj is OpenAPIV3.ReferenceObject | OpenAPIV3_1.ReferenceObject {\n return !!obj && isRef(obj)\n}\n\nexport function isRequired(schema?: SchemaObject): boolean {\n if (!schema) {\n return false\n }\n\n return Array.isArray(schema.required) ? !!schema.required?.length : !!schema.required\n}\n\nexport function isOptional(schema?: SchemaObject): boolean {\n return !isRequired(schema)\n}\n\nexport async function filterAndSort(data: OASDocument, options: FormatOptions = {}): Promise<OASDocument> {\n const mergedOptions: FormatOptions = {\n sort: options.sort ?? true,\n ['no-sort']: options['no-sort'] ?? false,\n sortSet: {\n root: ['openapi', 'info', 'servers', 'paths', 'components', 'tags', 'x-tagGroups', 'externalDocs'],\n get: ['operationId', 'summary', 'description', 'parameters', 'requestBody', 'responses'],\n post: ['operationId', 'summary', 'description', 'parameters', 'requestBody', 'responses'],\n put: ['operationId', 'summary', 'description', 'parameters', 'requestBody', 'responses'],\n patch: ['operationId', 'summary', 'description', 'parameters', 'requestBody', 'responses'],\n delete: ['operationId', 'summary', 'description', 'parameters', 'requestBody', 'responses'],\n parameters: ['name', 'in', 'description', 'required', 'schema'],\n requestBody: ['description', 'required', 'content'],\n responses: ['description', 'headers', 'content', 'links'],\n content: [],\n components: ['parameters', 'schemas'],\n schema: ['description', 'type', 'items', 'properties', 'format', 'example', 'default'],\n schemas: ['description', 'type', 'items', 'properties', 'format', 'example', 'default'],\n properties: ['description', 'type', 'items', 'format', 'example', 'default', 'enum'],\n ...options.sortSet,\n },\n sortComponentsSet: {\n ...options.sortComponentsSet,\n },\n filterSet: {\n inverseMethods: ['get', 'put', 'post', 'delete', 'patch', 'head', 'options', 'trace', 'parameters'],\n unusedComponents: options.filterSet ? ['requestBodies', 'schemas', 'parameters', 'responses'] : [],\n ...options.filterSet,\n },\n casingSet: {\n ...options.casingSet,\n },\n }\n\n const restFilter = await openapiFormat.openapiFilter(data, mergedOptions)\n data = restFilter.data\n\n const resFormat = await openapiFormat.openapiSort(data, mergedOptions)\n data = resFormat.data\n\n const resChangeCase = await openapiFormat.openapiChangeCase(data, mergedOptions)\n data = resChangeCase.data\n\n return data\n}\n","import BaseOas from 'oas'\nimport OASNormalize from 'oas-normalize'\nimport { findSchemaDefinition, matchesMimeType } from 'oas/utils'\n\nimport { isReference } from './utils.ts'\n\nimport type { Operation } from 'oas/operation'\nimport type { MediaTypeObject, OASDocument, ResponseObject, SchemaObject, User } from 'oas/types'\nimport type { contentType } from './types.ts'\n\ntype Options = {\n contentType?: contentType\n}\n\nexport class Oas<const TOAS = unknown> extends BaseOas {\n #options: Options = {}\n document: TOAS = undefined as unknown as TOAS\n\n constructor({ oas, user }: { oas: TOAS | OASDocument | string; user?: User }, options: Options = {}) {\n if (typeof oas === 'string') {\n oas = JSON.parse(oas)\n }\n\n super(oas as OASDocument, user)\n\n this.document = oas as TOAS\n this.#options = options\n }\n\n dereferenceWithRef(schema?: unknown) {\n if (isReference(schema)) {\n return {\n ...findSchemaDefinition(schema.$ref, this.api),\n $ref: schema.$ref,\n }\n }\n\n return schema\n }\n\n /**\n * Oas does not have a getResponseBody(contentType)\n */\n #getResponseBodyFactory(responseBody: boolean | ResponseObject): (contentType?: string) => MediaTypeObject | false | [string, MediaTypeObject, ...string[]] {\n function hasResponseBody(res = responseBody): res is ResponseObject {\n return !!res\n }\n\n return (contentType) => {\n if (!hasResponseBody(responseBody)) {\n return false\n }\n\n if (isReference(responseBody)) {\n // If the request body is still a `$ref` pointer we should return false because this library\n // assumes that you've run dereferencing beforehand.\n return false\n }\n\n if (!responseBody.content) {\n return false\n }\n\n if (contentType) {\n if (!(contentType in responseBody.content)) {\n return false\n }\n\n return responseBody.content[contentType]!\n }\n\n // Since no media type was supplied we need to find either the first JSON-like media type that\n // we've got, or the first available of anything else if no JSON-like media types are present.\n let availablecontentType: string | undefined = undefined\n const contentTypes = Object.keys(responseBody.content)\n contentTypes.forEach((mt: string) => {\n if (!availablecontentType && matchesMimeType.json(mt)) {\n availablecontentType = mt\n }\n })\n\n if (!availablecontentType) {\n contentTypes.forEach((mt: string) => {\n if (!availablecontentType) {\n availablecontentType = mt\n }\n })\n }\n\n if (availablecontentType) {\n return [availablecontentType, responseBody.content[availablecontentType]!, ...(responseBody.description ? [responseBody.description] : [])]\n }\n\n return false\n }\n }\n\n getResponseSchema(operation: Operation, statusCode: string | number): SchemaObject {\n if (operation.schema.responses) {\n Object.keys(operation.schema.responses).forEach((key) => {\n const schema = operation.schema.responses![key]\n const $ref = isReference(schema) ? schema.$ref : undefined\n\n if (schema && $ref) {\n operation.schema.responses![key] = findSchemaDefinition($ref, this.api)\n }\n })\n }\n\n const getResponseBody = this.#getResponseBodyFactory(operation.getResponseByStatusCode(statusCode))\n\n const { contentType } = this.#options\n const responseBody = getResponseBody(contentType)\n\n if (responseBody === false) {\n // return empty object because response will always be defined(request does not need a body)\n return {}\n }\n\n const schema = Array.isArray(responseBody) ? responseBody[1].schema : responseBody.schema\n\n if (!schema) {\n // return empty object because response will always be defined(request does not need a body)\n\n return {}\n }\n\n return this.dereferenceWithRef(schema)\n }\n\n getRequestSchema(operation: Operation): SchemaObject | undefined {\n const { contentType } = this.#options\n\n if (operation.schema.requestBody) {\n operation.schema.requestBody = this.dereferenceWithRef(operation.schema.requestBody)\n }\n\n const requestBody = operation.getRequestBody(contentType)\n\n if (requestBody === false) {\n return undefined\n }\n\n const schema = Array.isArray(requestBody) ? requestBody[1].schema : requestBody.schema\n\n if (!schema) {\n return undefined\n }\n\n return this.dereferenceWithRef(schema)\n }\n\n getParametersSchema(operation: Operation, inKey: 'path' | 'query' | 'header'): SchemaObject | null {\n const { contentType = operation.getContentType() } = this.#options\n const params = operation\n .getParameters()\n .map((schema) => {\n return this.dereferenceWithRef(schema)\n })\n .filter((v) => v.in === inKey)\n\n if (!params.length) {\n return null\n }\n\n return params.reduce(\n (schema, pathParameters) => {\n const property = pathParameters.content?.[contentType]?.schema ?? (pathParameters.schema as SchemaObject)\n const required = [...(schema.required || ([] as any)), pathParameters.required ? pathParameters.name : undefined].filter(Boolean)\n\n return {\n ...schema,\n description: schema.description,\n deprecated: schema.deprecated,\n example: schema.example,\n required,\n properties: {\n ...schema.properties,\n [pathParameters.name]: {\n description: pathParameters.description,\n ...property,\n },\n },\n }\n },\n { type: 'object', required: [], properties: {} } as SchemaObject,\n )\n }\n\n async valdiate() {\n const oasNormalize = new OASNormalize(this.api, {\n enablePaths: true,\n colorizeErrors: true,\n })\n\n await oasNormalize.validate({\n convertToLatest: true,\n parser: {\n validate: {\n colorizeErrors: true,\n },\n },\n })\n }\n}\n"]}
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/utils.ts","../src/Oas.ts"],"names":["schema"],"mappings":";;;;;;;;AAQO,SAAS,oBAAoB,GAAqC,EAAA;AACvE,EAAA,OAAO,GAAO,IAAA,aAAA,CAAc,GAAG,CAAA,IAAK,EAAE,SAAa,IAAA,GAAA,CAAA,CAAA;AACrD,CAAA;AAKO,SAAS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AAa,EAAA,IAAA;AAAA,MACb,cAAgB,EAAA,IAAA;AAAA,KACjB,CAAA,CAAA;AAED,IAAA,MAAM,aAAa,QAAS,CAAA;AAAA,MAC1B,eAAiB,EAAA,IAAA;AAAA,MACjB,MAAQ,EAAA;AAAA,QACN,QAAU,EAAA;AAAA,UACR,cAAgB,EAAA,IAAA;AAAA,SAClB;AAAA,OACF;AAAA,KACD,CAAA,CAAA;AAAA,GACH;AACF","file":"chunk-TVOJ46T6.js","sourcesContent":["import { isRef, isSchema } from 'oas/types'\nimport openapiFormat from 'openapi-format'\nimport { isPlainObject } from 'remeda'\n\nimport type { OASDocument, ParameterObject, SchemaObject } from 'oas/types'\nimport type { OpenAPIV2, OpenAPIV3, OpenAPIV3_1 } from 'openapi-types'\nimport type { FormatOptions } from './parser/index.ts'\n\nexport function isOpenApiV2Document(doc: any): doc is OpenAPIV2.Document {\n return doc && isPlainObject(doc) && !('openapi' in doc)\n}\nexport function isOpenApiV3Document(doc: any): doc is OpenAPIV3.Document {\n return doc && isPlainObject(doc) && 'openapi' in doc\n}\n\nexport function isOpenApiV3_1Document(doc: any): doc is OpenAPIV3_1.Document {\n return doc && isPlainObject<OpenAPIV3_1.Document>(doc) && 'openapi' in doc && doc.openapi.startsWith('3.1')\n}\n\nexport function isJSONSchema(obj?: unknown): obj is SchemaObject {\n return !!obj && isSchema(obj)\n}\n\nexport function isParameterObject(obj: ParameterObject | SchemaObject): obj is ParameterObject {\n return obj && 'in' in obj\n}\n\nexport function isReference(obj?: unknown): obj is OpenAPIV3.ReferenceObject | OpenAPIV3_1.ReferenceObject {\n return !!obj && isRef(obj)\n}\n\nexport function isRequired(schema?: SchemaObject): boolean {\n if (!schema) {\n return false\n }\n\n return Array.isArray(schema.required) ? !!schema.required?.length : !!schema.required\n}\n\nexport function isOptional(schema?: SchemaObject): boolean {\n return !isRequired(schema)\n}\n\nexport async function filterAndSort(data: OASDocument, options: FormatOptions = {}): Promise<OASDocument> {\n const mergedOptions: FormatOptions = {\n sort: options.sort ?? true,\n ['no-sort']: options['no-sort'] ?? false,\n sortSet: {\n root: ['openapi', 'info', 'servers', 'paths', 'components', 'tags', 'x-tagGroups', 'externalDocs'],\n get: ['operationId', 'summary', 'description', 'parameters', 'requestBody', 'responses'],\n post: ['operationId', 'summary', 'description', 'parameters', 'requestBody', 'responses'],\n put: ['operationId', 'summary', 'description', 'parameters', 'requestBody', 'responses'],\n patch: ['operationId', 'summary', 'description', 'parameters', 'requestBody', 'responses'],\n delete: ['operationId', 'summary', 'description', 'parameters', 'requestBody', 'responses'],\n parameters: ['name', 'in', 'description', 'required', 'schema'],\n requestBody: ['description', 'required', 'content'],\n responses: ['description', 'headers', 'content', 'links'],\n content: [],\n components: ['parameters', 'schemas'],\n schema: ['description', 'type', 'items', 'properties', 'format', 'example', 'default'],\n schemas: ['description', 'type', 'items', 'properties', 'format', 'example', 'default'],\n properties: ['description', 'type', 'items', 'format', 'example', 'default', 'enum'],\n ...options.sortSet,\n },\n sortComponentsSet: {\n ...options.sortComponentsSet,\n },\n filterSet: {\n inverseMethods: ['get', 'put', 'post', 'delete', 'patch', 'head', 'options', 'trace', 'parameters'],\n unusedComponents: options.filterSet ? ['requestBodies', 'schemas', 'parameters', 'responses'] : [],\n ...options.filterSet,\n },\n casingSet: {\n ...options.casingSet,\n },\n }\n\n const restFilter = await openapiFormat.openapiFilter(data, mergedOptions)\n data = restFilter.data\n\n const resFormat = await openapiFormat.openapiSort(data, mergedOptions)\n data = resFormat.data\n\n const resChangeCase = await openapiFormat.openapiChangeCase(data, mergedOptions)\n data = resChangeCase.data\n\n return data\n}\n","import BaseOas from 'oas'\nimport OASNormalize from 'oas-normalize'\nimport { findSchemaDefinition, matchesMimeType } from 'oas/utils'\n\nimport { isReference } from './utils.ts'\n\nimport type { Operation } from 'oas/operation'\nimport type { MediaTypeObject, OASDocument, ResponseObject, SchemaObject, User } from 'oas/types'\nimport type { contentType } from './types.ts'\n\ntype Options = {\n contentType?: contentType\n}\n\nexport class Oas<const TOAS = unknown> extends BaseOas {\n #options: Options = {}\n document: TOAS = undefined as unknown as TOAS\n\n constructor({ oas, user }: { oas: TOAS | OASDocument | string; user?: User }, options: Options = {}) {\n if (typeof oas === 'string') {\n oas = JSON.parse(oas)\n }\n\n super(oas as OASDocument, user)\n\n this.document = oas as TOAS\n this.#options = options\n }\n\n dereferenceWithRef(schema?: unknown) {\n if (isReference(schema)) {\n return {\n ...findSchemaDefinition(schema.$ref, this.api),\n $ref: schema.$ref,\n }\n }\n\n return schema\n }\n\n /**\n * Oas does not have a getResponseBody(contentType)\n */\n #getResponseBodyFactory(responseBody: boolean | ResponseObject): (contentType?: string) => MediaTypeObject | false | [string, MediaTypeObject, ...string[]] {\n function hasResponseBody(res = responseBody): res is ResponseObject {\n return !!res\n }\n\n return (contentType) => {\n if (!hasResponseBody(responseBody)) {\n return false\n }\n\n if (isReference(responseBody)) {\n // If the request body is still a `$ref` pointer we should return false because this library\n // assumes that you've run dereferencing beforehand.\n return false\n }\n\n if (!responseBody.content) {\n return false\n }\n\n if (contentType) {\n if (!(contentType in responseBody.content)) {\n return false\n }\n\n return responseBody.content[contentType]!\n }\n\n // Since no media type was supplied we need to find either the first JSON-like media type that\n // we've got, or the first available of anything else if no JSON-like media types are present.\n let availablecontentType: string | undefined = undefined\n const contentTypes = Object.keys(responseBody.content)\n contentTypes.forEach((mt: string) => {\n if (!availablecontentType && matchesMimeType.json(mt)) {\n availablecontentType = mt\n }\n })\n\n if (!availablecontentType) {\n contentTypes.forEach((mt: string) => {\n if (!availablecontentType) {\n availablecontentType = mt\n }\n })\n }\n\n if (availablecontentType) {\n return [availablecontentType, responseBody.content[availablecontentType]!, ...(responseBody.description ? [responseBody.description] : [])]\n }\n\n return false\n }\n }\n\n getResponseSchema(operation: Operation, statusCode: string | number): SchemaObject {\n if (operation.schema.responses) {\n Object.keys(operation.schema.responses).forEach((key) => {\n const schema = operation.schema.responses![key]\n const $ref = isReference(schema) ? schema.$ref : undefined\n\n if (schema && $ref) {\n operation.schema.responses![key] = findSchemaDefinition($ref, this.api)\n }\n })\n }\n\n const getResponseBody = this.#getResponseBodyFactory(operation.getResponseByStatusCode(statusCode))\n\n const { contentType } = this.#options\n const responseBody = getResponseBody(contentType)\n\n if (responseBody === false) {\n // return empty object because response will always be defined(request does not need a body)\n return {}\n }\n\n const schema = Array.isArray(responseBody) ? responseBody[1].schema : responseBody.schema\n\n if (!schema) {\n // return empty object because response will always be defined(request does not need a body)\n\n return {}\n }\n\n return this.dereferenceWithRef(schema)\n }\n\n getRequestSchema(operation: Operation): SchemaObject | undefined {\n const { contentType } = this.#options\n\n if (operation.schema.requestBody) {\n operation.schema.requestBody = this.dereferenceWithRef(operation.schema.requestBody)\n }\n\n const requestBody = operation.getRequestBody(contentType)\n\n if (requestBody === false) {\n return undefined\n }\n\n const schema = Array.isArray(requestBody) ? requestBody[1].schema : requestBody.schema\n\n if (!schema) {\n return undefined\n }\n\n return this.dereferenceWithRef(schema)\n }\n\n getParametersSchema(operation: Operation, inKey: 'path' | 'query' | 'header'): SchemaObject | null {\n const { contentType = operation.getContentType() } = this.#options\n const params = operation\n .getParameters()\n .map((schema) => {\n return this.dereferenceWithRef(schema)\n })\n .filter((v) => v.in === inKey)\n\n if (!params.length) {\n return null\n }\n\n return params.reduce(\n (schema, pathParameters) => {\n const property = pathParameters.content?.[contentType]?.schema ?? (pathParameters.schema as SchemaObject)\n const required = [...(schema.required || ([] as any)), pathParameters.required ? pathParameters.name : undefined].filter(Boolean)\n\n return {\n ...schema,\n description: schema.description,\n deprecated: schema.deprecated,\n example: schema.example,\n required,\n properties: {\n ...schema.properties,\n [pathParameters.name]: {\n description: pathParameters.description,\n ...property,\n },\n },\n }\n },\n { type: 'object', required: [], properties: {} } as SchemaObject,\n )\n }\n\n async valdiate() {\n const oasNormalize = new OASNormalize(this.api, {\n enablePaths: true,\n colorizeErrors: true,\n })\n\n await oasNormalize.validate({\n convertToLatest: true,\n parser: {\n validate: {\n colorizeErrors: true,\n },\n },\n })\n }\n}\n"]}
package/src/typings.d.ts DELETED
@@ -1,51 +0,0 @@
1
- declare module 'openapi-format' {
2
- interface Options {
3
- verbose?: boolean
4
- 'no-sort'?: boolean
5
- sort?: boolean
6
- output?: string
7
- sortSet?: {
8
- root?: Array<'openapi' | 'info' | 'servers' | 'paths' | 'components' | 'tags' | 'x-tagGroups' | 'externalDocs'>
9
- get?: Array<'operationId' | 'summary' | 'description' | 'parameters' | 'requestBody' | 'responses'>
10
- post?: Array<'operationId' | 'summary' | 'description' | 'parameters' | 'requestBody' | 'responses'>
11
- put?: Array<'operationId' | 'summary' | 'description' | 'parameters' | 'requestBody' | 'responses'>
12
- patch?: Array<'operationId' | 'summary' | 'description' | 'parameters' | 'requestBody' | 'responses'>
13
- delete?: Array<'operationId' | 'summary' | 'description' | 'parameters' | 'requestBody' | 'responses'>
14
- parameters?: Array<'name' | 'in' | 'description' | 'required' | 'schema'>
15
- requestBody?: Array<'description' | 'required' | 'content'>
16
- responses?: Array<'description' | 'headers' | 'content' | 'links'>
17
- content?: Array<string>
18
- components?: Array<'parameters' | 'schemas'>
19
- schema?: Array<'description' | 'type' | 'items' | 'properties' | 'format' | 'example' | 'default'>
20
- schemas?: Array<'description' | 'type' | 'items' | 'properties' | 'format' | 'example' | 'default'>
21
- properties?: Array<'description' | 'type' | 'items' | 'format' | 'example' | 'default' | 'enum'>
22
- }
23
- filterSet?: {
24
- methods?: Array<'get' | 'post' | 'put' | 'patch' | 'delete' | 'options' | 'trace' | 'head' | 'parameters'>
25
- inverseMethods?: Array<'get' | 'post' | 'put' | 'patch' | 'delete' | 'options' | 'trace' | 'head' | 'parameters'>
26
- tags?: Array<string>
27
- inverseTags?: Array<string>
28
- operationIds?: Array<string>
29
- inverseOperationIds?: Array<string>
30
- operations?: Array<string>
31
- flags?: Array<string>
32
- inverseFlags?: Array<string>
33
- flagValues?: Array<string>
34
- inverseFlagValues?: Array<string>
35
- stripFlags?: Array<string>
36
- responseContent?: Array<string>
37
- inverseResponseContent?: Array<string>
38
- unusedComponents?: Array<'requestBodies' | 'schemas' | 'parameters' | 'responses'>
39
- }
40
- sortComponentsSet?: {}
41
- casingSet?: {}
42
- }
43
- function parseFile(path: string): Promise<unknown>
44
-
45
- function openapiFilter<TOas>(document: TOas, options: Options): { data: Toas; resultData: { unusedComp: any } }
46
-
47
- function openapiSort<TOas>(document: TOas, options: Options): { data: Toas; resultData: { unusedComp: any } }
48
- function openapiChangeCase<TOas>(document: TOas, options: Options): { data: Toas; resultData: { unusedComp: any } }
49
-
50
- function stringify<TOas>(document: TOas, options: Options): string
51
- }