oas 31.0.0-alpha.1 → 31.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +9 -6
- package/dist/analyzer/index.cjs +8 -8
- package/dist/analyzer/index.cjs.map +1 -1
- package/dist/analyzer/index.js +6 -6
- package/dist/analyzer/types.cjs.map +1 -1
- package/dist/{chunk-WXXFTJ6D.js → chunk-5EP6HY2E.js} +86 -13
- package/dist/chunk-5EP6HY2E.js.map +1 -0
- package/dist/chunk-AYA3UT4L.cjs.map +1 -1
- package/dist/{chunk-O3LGAZN6.cjs → chunk-B5WP4BJM.cjs} +123 -50
- package/dist/chunk-B5WP4BJM.cjs.map +1 -0
- package/dist/{chunk-ZZMTF6AO.cjs → chunk-BRYRBTD7.cjs} +97 -166
- package/dist/chunk-BRYRBTD7.cjs.map +1 -0
- package/dist/{chunk-GXVGNDBE.js → chunk-HGVFNEKW.js} +7 -76
- package/dist/chunk-HGVFNEKW.js.map +1 -0
- package/dist/{chunk-UH66IERJ.js → chunk-LSH3X5NA.js} +6 -6
- package/dist/chunk-LSH3X5NA.js.map +1 -0
- package/dist/chunk-O3GIPZLC.cjs.map +1 -1
- package/dist/{chunk-MCECW7PR.cjs → chunk-SYZDNSG6.cjs} +16 -16
- package/dist/chunk-SYZDNSG6.cjs.map +1 -0
- package/dist/chunk-VQBEI5WI.cjs.map +1 -1
- package/dist/chunk-W6GBV2JT.cjs.map +1 -1
- package/dist/{extensions-BT2-f2Nh.d.cts → extensions-9XckV6aO.d.cts} +1 -1
- package/dist/{extensions-i-B9rqxJ.d.ts → extensions-gq53-7Ux.d.ts} +1 -1
- package/dist/extensions.cjs.map +1 -1
- package/dist/extensions.d.cts +1 -1
- package/dist/extensions.d.ts +1 -1
- package/dist/index.cjs +4 -4
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +3 -3
- package/dist/operation/index.cjs +3 -3
- package/dist/operation/index.cjs.map +1 -1
- package/dist/operation/index.d.cts +1 -1
- package/dist/operation/index.d.ts +1 -1
- package/dist/operation/index.js +2 -2
- package/dist/operation/lib/get-parameters-as-json-schema.cjs +2 -2
- package/dist/operation/lib/get-parameters-as-json-schema.cjs.map +1 -1
- package/dist/operation/lib/get-parameters-as-json-schema.d.cts +1 -1
- package/dist/operation/lib/get-parameters-as-json-schema.d.ts +1 -1
- package/dist/operation/lib/get-parameters-as-json-schema.js +1 -1
- package/dist/reducer/index.cjs +314 -107
- package/dist/reducer/index.cjs.map +1 -1
- package/dist/reducer/index.d.cts +108 -22
- package/dist/reducer/index.d.ts +108 -22
- package/dist/reducer/index.js +312 -103
- package/dist/reducer/index.js.map +1 -1
- package/dist/types.cjs.map +1 -1
- package/dist/utils.cjs +2 -2
- package/dist/utils.cjs.map +1 -1
- package/dist/utils.d.cts +1 -1
- package/dist/utils.d.ts +1 -1
- package/dist/utils.js +1 -1
- package/package.json +7 -6
- package/dist/chunk-GXVGNDBE.js.map +0 -1
- package/dist/chunk-MCECW7PR.cjs.map +0 -1
- package/dist/chunk-O3LGAZN6.cjs.map +0 -1
- package/dist/chunk-UH66IERJ.js.map +0 -1
- package/dist/chunk-WXXFTJ6D.js.map +0 -1
- package/dist/chunk-ZZMTF6AO.cjs.map +0 -1
package/README.md
CHANGED
|
@@ -152,6 +152,7 @@ const operation = petstore.operation('/pet', 'post');
|
|
|
152
152
|
<!-- prettier-ignore-start -->
|
|
153
153
|
| Method | Description |
|
|
154
154
|
| :--- | :--- |
|
|
155
|
+
| `.dereference()` | Dereference the current operation. Note that this will ignore circular references. |
|
|
155
156
|
| `.getContentType()` | Retrieve the primary request body content type. If multiple are present, prefer whichever is JSON-compliant. |
|
|
156
157
|
| `.getDescription()` | Retrieve the `description` that's set on this operation. This supports common descriptions that may be set at the [path item level](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#path-item-object). |
|
|
157
158
|
| `.getOperationId()` | Retrieve the `operationId` that's present on the operation, and if one is not present one will be created based off the method + path and returned instead. |
|
|
@@ -302,27 +303,29 @@ console.log(await analyzer(petstore));
|
|
|
302
303
|
> [!WARNING]
|
|
303
304
|
> This API is still very experimental and should not be used in production environments!
|
|
304
305
|
|
|
305
|
-
The
|
|
306
|
+
The `OpenAPIReducer` utility, located in `oas/reducer`, can be used to reduce an OpenAPI definition down to only the information necessary to fulfill a specific set of tags, paths, or operations.
|
|
307
|
+
|
|
308
|
+
OpenAPI reduction can be helpful not only to isolate and troubleshoot issues with large API definitions, but also to compress a large API definition down to a manageable size containing a specific set of items. All OpenAPI definitions reduced will still be fully functional and valid OpenAPI definitions.
|
|
306
309
|
|
|
307
310
|
```ts
|
|
308
311
|
import petstore from '@readme/oas-examples/3.0/json/petstore.json' with { type: 'json' };
|
|
309
|
-
import
|
|
312
|
+
import { OpenAPIReducer } from 'oas/reducer';
|
|
310
313
|
|
|
311
314
|
// This will reduce the `petstore` API definition down to only operations, and
|
|
312
315
|
// any referenced schemas, that are a part of the `Store` tag.
|
|
313
|
-
console.log(
|
|
316
|
+
console.log(OpenAPIReducer.init(petstore).byTag('Store').reduce());
|
|
314
317
|
|
|
315
318
|
// Reduces the `petstore` down to only the `POST /pet` operation.
|
|
316
|
-
console.log(
|
|
319
|
+
console.log(OpenAPIReducer.init(petstore).byOperation('/pet', 'post').reduce());
|
|
317
320
|
|
|
318
321
|
// You can also select all of the methods of a given path by using the `*`
|
|
319
322
|
// wildcard. The resulting reduced API definition here will contain `POST /pet`
|
|
320
323
|
// and `PUT /put`.
|
|
321
|
-
console.log(
|
|
324
|
+
console.log(OpenAPIReducer.init(petstore).byPath('/pet').reduce());
|
|
322
325
|
```
|
|
323
326
|
|
|
324
327
|
> [!NOTE]
|
|
325
|
-
>
|
|
328
|
+
> Note that this does not yet support OpenAPI 3.1+ definitions that contain webhooks.
|
|
326
329
|
|
|
327
330
|
## FAQ
|
|
328
331
|
|
package/dist/analyzer/index.cjs
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
"use strict";Object.defineProperty(exports, "__esModule", {value: true});
|
|
2
2
|
|
|
3
|
-
var
|
|
4
|
-
require('../chunk-
|
|
5
|
-
require('../chunk-O3GIPZLC.cjs');
|
|
6
|
-
require('../chunk-O3LGAZN6.cjs');
|
|
7
|
-
require('../chunk-AYA3UT4L.cjs');
|
|
8
|
-
require('../chunk-VQBEI5WI.cjs');
|
|
3
|
+
var _chunkSYZDNSG6cjs = require('../chunk-SYZDNSG6.cjs');
|
|
4
|
+
require('../chunk-BRYRBTD7.cjs');
|
|
9
5
|
|
|
10
6
|
|
|
11
7
|
|
|
12
8
|
var _chunkW6GBV2JTcjs = require('../chunk-W6GBV2JT.cjs');
|
|
9
|
+
require('../chunk-O3GIPZLC.cjs');
|
|
10
|
+
require('../chunk-B5WP4BJM.cjs');
|
|
11
|
+
require('../chunk-AYA3UT4L.cjs');
|
|
12
|
+
require('../chunk-VQBEI5WI.cjs');
|
|
13
13
|
|
|
14
14
|
// src/analyzer/queries/openapi.ts
|
|
15
15
|
function additionalProperties(definition) {
|
|
@@ -21,7 +21,7 @@ function callbacks(definition) {
|
|
|
21
21
|
);
|
|
22
22
|
}
|
|
23
23
|
async function circularRefs(definition) {
|
|
24
|
-
const oas = new (0,
|
|
24
|
+
const oas = new (0, _chunkSYZDNSG6cjs.Oas)(JSON.parse(JSON.stringify(definition)));
|
|
25
25
|
await oas.dereference();
|
|
26
26
|
const results = oas.getCircularReferences();
|
|
27
27
|
results.sort();
|
|
@@ -34,7 +34,7 @@ function discriminators(definition) {
|
|
|
34
34
|
return _chunkW6GBV2JTcjs.query.call(void 0, ["$..discriminator"], definition).map((res) => _chunkW6GBV2JTcjs.refizePointer.call(void 0, res.pointer));
|
|
35
35
|
}
|
|
36
36
|
async function fileSize(definition) {
|
|
37
|
-
const oas = new (0,
|
|
37
|
+
const oas = new (0, _chunkSYZDNSG6cjs.Oas)(structuredClone(definition));
|
|
38
38
|
const originalSizeInBytes = Buffer.from(JSON.stringify(oas.api)).length;
|
|
39
39
|
const raw = Number((originalSizeInBytes / (1024 * 1024)).toFixed(2));
|
|
40
40
|
await oas.dereference();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["/Users/darrenyong/Desktop/oas-stuff/oas/packages/oas/dist/analyzer/index.cjs","../../src/analyzer/queries/openapi.ts","../../src/analyzer/index.ts"],"names":["additionalProperties","callbacks","circularRefs","commonParameters","discriminators","links","parameterSerialization","polymorphism","refNames","serverVariables","xmlSchemas","xmlRequests","xmlResponses","webhooks"],"mappings":"AAAA;AACE;AACF,yDAA8B;AAC9B,iCAA8B;AAC9B,iCAA8B;AAC9B,iCAA8B;AAC9B,iCAA8B;AAC9B,iCAA8B;AAC9B;AACE;AACA;AACF,yDAA8B;AAC9B;AACA;ACFO,SAAS,oBAAA,CAAqB,UAAA,EAAmC;AACtE,EAAA,OAAO,qCAAA,CAAO,yBAAyB,CAAA,EAAG,UAAU,CAAA,CAAE,GAAA,CAAI,CAAA,GAAA,EAAA,GAAO,6CAAA,GAAc,CAAI,OAAO,CAAC,CAAA;AAC7F;AAQO,SAAS,SAAA,CAAU,UAAA,EAAmC;AAC3D,EAAA,OAAO,qCAAA,CAAO,wBAAA,EAA0B,qCAAqC,CAAA,EAAG,UAAU,CAAA,CAAE,GAAA;AAAA,IAAI,CAAA,GAAA,EAAA,GAC9F,6CAAA,GAAc,CAAI,OAAO;AAAA,EAC3B,CAAA;AACF;AAQA,MAAA,SAAsB,YAAA,CAAa,UAAA,EAA4C;AAG7E,EAAA,MAAM,IAAA,EAAM,IAAI,0BAAA,CAAI,IAAA,CAAK,KAAA,CAAM,IAAA,CAAK,SAAA,CAAU,UAAU,CAAC,CAAC,CAAA;AAC1D,EAAA,MAAM,GAAA,CAAI,WAAA,CAAY,CAAA;AAEtB,EAAA,MAAM,QAAA,EAAU,GAAA,CAAI,qBAAA,CAAsB,CAAA;AAE1C,EAAA,OAAA,CAAQ,IAAA,CAAK,CAAA;AACb,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a,MAAA;AAAA,QACxB,SAAA,EAAWA;AAAA,MACb,CAAA;AAAA,MACA,UAAA,EAAY;AAAA,QACV,OAAA,EAAS,CAAC,CAACF,WAAAA,CAAW,MAAA;AAAA,QACtB,SAAA,EAAWA;AAAA,MACb,CAAA;AAAA,MACA,QAAA,EAAU;AAAA,QACR,OAAA,EAAS,CAAC,CAACG,SAAAA,CAAS,MAAA;AAAA,QACpB,SAAA,EAAWA;AAAA,MACb;AAAA,IACF;AAAA,EACF,CAAA;AAEA,EAAA,OAAO,QAAA;AACT;AF0EA;AACE;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACF,4zBAAC","file":"/Users/darrenyong/Desktop/oas-stuff/oas/packages/oas/dist/analyzer/index.cjs","sourcesContent":[null,"import type { OASDocument } from '../../types.js';\n\nimport Oas from '../../index.js';\nimport { query, refizePointer } from '../util.js';\n\n/**\n * Determine if a given API definition uses the `additionalProperties` schema property.\n *\n * @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#schema-object}\n * @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#schema-object}\n */\nexport function additionalProperties(definition: OASDocument): string[] {\n return query(['$..additionalProperties'], definition).map(res => refizePointer(res.pointer));\n}\n\n/**\n * Determine if a given API definition utilizes `callbacks`.\n *\n * @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#callback-object}\n * @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#callback-object}\n */\nexport function callbacks(definition: OASDocument): string[] {\n return query(['$.components.callbacks', '$.paths.*[?(@.callbacks)].callbacks'], definition).map(res =>\n refizePointer(res.pointer),\n );\n}\n\n/**\n * Determine if a given API definition has circular refs.\n *\n * @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#schema-object}\n * @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#schema-object}\n */\nexport async function circularRefs(definition: OASDocument): Promise<string[]> {\n // Dereferencing will update the passed in variable, which we don't want to do, so we\n // instantiated `Oas` with a clone.\n const oas = new Oas(JSON.parse(JSON.stringify(definition)));\n await oas.dereference();\n\n const results = oas.getCircularReferences();\n\n results.sort();\n return results;\n}\n\n/**\n * Determine if a given API definition utilizes common parameters.\n *\n * @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#path-item-object}\n * @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#path-item-object}\n */\nexport function commonParameters(definition: OASDocument): string[] {\n return query(['$..paths[*].parameters'], definition).map(res => refizePointer(res.pointer));\n}\n\n/**\n * Determine if a given API definition utilizes discriminators.\n *\n * @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#discriminator-object}\n * @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#discriminator-object}\n */\nexport function discriminators(definition: OASDocument): string[] {\n return query(['$..discriminator'], definition).map(res => refizePointer(res.pointer));\n}\n\n/**\n * Calculate the size of the raw and dereferenced OpenAPI file in MB.\n *\n * If a dereferenced API definition is too large to be stringified the file size will be returned\n * as NaN.\n *\n */\nexport async function fileSize(definition: OASDocument): Promise<{ raw: number; dereferenced: number | typeof NaN }> {\n const oas = new Oas(structuredClone(definition));\n\n const originalSizeInBytes = Buffer.from(JSON.stringify(oas.api)).length;\n const raw = Number((originalSizeInBytes / (1024 * 1024)).toFixed(2));\n\n await oas.dereference();\n\n let dereferenced: number;\n try {\n const dereferencedSizeInBytes = Buffer.from(JSON.stringify(oas.api)).length;\n dereferenced = Number((dereferencedSizeInBytes / (1024 * 1024)).toFixed(2));\n } catch (err) {\n // If the dereferenced API definition is too large to be stringified then we don't have a safer\n // way to estimate its size that wouldn't sacrifice accuracy so we'll just return NaN.\n if (err instanceof RangeError) {\n dereferenced = NaN;\n } else {\n throw err;\n }\n }\n\n return { raw, dereferenced };\n}\n\n/**\n * Determine if a given API definition utilizes `links`.\n *\n * @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#link-object}\n * @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#link-object}\n */\nexport function links(definition: OASDocument): string[] {\n return query(['$.components.links', '$.paths..responses.*.links'], definition).map(res => refizePointer(res.pointer));\n}\n\n/**\n * Determine all of the available media types used within an API definition.\n *\n * @todo This query currently picks up false positives if there is an object named `content`.\n * @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#request-body-object}\n * @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#request-body-object}\n */\nexport function mediaTypes(definition: OASDocument): string[] {\n const results = Array.from(\n new Set(\n query(['$..paths..content'], definition).flatMap(res => {\n // This'll transform `results`, which looks like `[['application/json'], ['text/xml']]`\n // into `['application/json', 'text/xml']`.\n return Object.keys(res.value);\n }),\n ),\n );\n\n results.sort();\n return results;\n}\n\n/**\n * Determine if a given API definition uses parameter serialization.\n *\n * @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#parameter-object}\n * @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#parameter-object}\n */\nexport function parameterSerialization(definition: OASDocument): string[] {\n return query(['$..parameters[*].style^'], definition).map(res => refizePointer(res.pointer));\n}\n\n/**\n * Determine if a given API definition utilizes schema polymorphism and/of interitance.\n *\n * @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#schema-object}\n * @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#schema-object}\n */\nexport function polymorphism(definition: OASDocument): string[] {\n const results = Array.from(\n new Set(query(['$..allOf^', '$..anyOf^', '$..oneOf^'], definition).map(res => refizePointer(res.pointer))),\n );\n\n results.sort();\n return results;\n}\n\n/**\n * Determine if a given API definition previously had references by checking if we added the\n * `x-readme-ref-name` extension after dereferencing. This extension is added only during the\n * dereferencing process.\n *\n */\nexport function refNames(definition: OASDocument): string[] {\n return query([\"$..['x-readme-ref-name']\"], definition).map(res => refizePointer(res.pointer));\n}\n\n/**\n * Determine every kind of security type that a given API definition has documented.\n *\n * @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#security-scheme-object}\n * @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#security-scheme-object}\n */\nexport function securityTypes(definition: OASDocument): string[] {\n return Array.from(new Set(query(['$.components.securitySchemes..type'], definition).map(res => res.value as string)));\n}\n\n/**\n * Determine if a given API definition utilizes server variables.\n *\n * @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#server-variable-object}\n * @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#server-variable-object}\n */\nexport function serverVariables(definition: OASDocument): string[] {\n return query(['$.servers..variables^'], definition).map(res => refizePointer(res.pointer));\n}\n\n/**\n * Determine how many operations are defined in a given API definition.\n *\n * @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#operation-object}\n * @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#operation-object}\n */\nexport function totalOperations(definition: OASDocument): number {\n return query(['$..paths[*]'], definition).flatMap(res => Object.keys(res.value)).length;\n}\n\n/**\n * Determine if a given API definition utilizes `webhooks` support in OpenAPI 3.1.\n *\n * @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#oasWebhooks}\n */\nexport function webhooks(definition: OASDocument): string[] {\n return query(['$.webhooks[*]'], definition).map(res => refizePointer(res.pointer));\n}\n\n/**\n * Determine if a given API definition uses XML in a request body payload.\n *\n * @todo detect `+xml` media types\n * @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#media-type-object}\n * @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#media-type-object}\n */\nexport function xmlRequests(definition: OASDocument): string[] {\n return query(\n [\n \"$..requestBody..['application/xml']\",\n \"$..requestBody..['application/xml-external-parsed-entity']\",\n \"$..requestBody..['application/xml-dtd']\",\n \"$..requestBody..['text/xml']\",\n \"$..requestBody..['text/xml-external-parsed-entity']\",\n '$..requestBody.content[?(@property.match(/\\\\+xml$/i))]',\n ],\n definition,\n ).map(res => refizePointer(res.pointer));\n}\n\n/**\n * Determine if a given API definition uses XML in a response body.\n *\n * @todo detect `+xml` media types\n * @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#media-type-object}\n * @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#media-type-object}\n */\nexport function xmlResponses(definition: OASDocument): string[] {\n return query(\n [\n \"$..responses..['application/xml']\",\n \"$..responses..['application/xml-external-parsed-entity']\",\n \"$..responses..['application/xml-dtd']\",\n \"$..responses..['text/xml']\",\n \"$..responses..['text/xml-external-parsed-entity']\",\n '$..responses[*].content[?(@property.match(/\\\\+xml$/i))]',\n ],\n definition,\n ).map(res => refizePointer(res.pointer));\n}\n\n/**\n * Determine if a given API definition utilises the XML object for defining XML schemas.\n *\n * @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#xml-object}\n * @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#xml-object}\n */\nexport function xmlSchemas(definition: OASDocument): string[] {\n return query(['$.components.schemas..xml^', '$..parameters..xml^', '$..requestBody..xml^'], definition).map(res =>\n refizePointer(res.pointer),\n );\n}\n","import type { OASDocument } from '../types.js';\nimport type { OASAnalysis } from './types.js';\n\nimport {\n additionalProperties as analyzeAdditionalProperties,\n callbacks as analyzeCallbacks,\n circularRefs as analyzeCircularRefs,\n commonParameters as analyzeCommonParameters,\n discriminators as analyzeDiscriminators,\n fileSize as analyzeFileSize,\n links as analyzeLinks,\n mediaTypes as analyzeMediaTypes,\n parameterSerialization as analyzeParameterSerialization,\n polymorphism as analyzePolymorphism,\n refNames as analyzeRefNames,\n securityTypes as analyzeSecurityTypes,\n serverVariables as analyzeServerVariables,\n totalOperations as analyzeTotalOperations,\n webhooks as analyzeWebhooks,\n xmlRequests as analyzeXMLRequests,\n xmlResponses as analyzeXMLResponses,\n xmlSchemas as analyzeXMLSchemas,\n} from './queries/openapi.js';\n\nexport {\n analyzeAdditionalProperties,\n analyzeCallbacks,\n analyzeCircularRefs,\n analyzeCommonParameters,\n analyzeDiscriminators,\n analyzeFileSize,\n analyzeLinks,\n analyzeMediaTypes,\n analyzeParameterSerialization,\n analyzePolymorphism,\n analyzeRefNames,\n analyzeSecurityTypes,\n analyzeServerVariables,\n analyzeTotalOperations,\n analyzeWebhooks,\n analyzeXMLRequests,\n analyzeXMLResponses,\n analyzeXMLSchemas,\n};\n\n/**\n * Analyze a given OpenAPI or Swagger definition for any OpenAPI or JSON Schema feature uses it\n * may contain or utilize.\n *\n */\nexport async function analyzer(definition: OASDocument): Promise<OASAnalysis> {\n const additionalProperties = analyzeAdditionalProperties(definition);\n const callbacks = analyzeCallbacks(definition);\n const circularRefs = await analyzeCircularRefs(definition);\n const commonParameters = analyzeCommonParameters(definition);\n const discriminators = analyzeDiscriminators(definition);\n const { raw: rawFileSize, dereferenced: dereferencedFileSize } = await analyzeFileSize(definition);\n const links = analyzeLinks(definition);\n const parameterSerialization = analyzeParameterSerialization(definition);\n const polymorphism = analyzePolymorphism(definition);\n const refNames = analyzeRefNames(definition);\n const serverVariables = analyzeServerVariables(definition);\n const xmlSchemas = analyzeXMLSchemas(definition);\n const xmlRequests = analyzeXMLRequests(definition);\n const xmlResponses = analyzeXMLResponses(definition);\n const webhooks = analyzeWebhooks(definition);\n\n const analysis: OASAnalysis = {\n general: {\n dereferencedFileSize: {\n name: 'Dereferenced File Size',\n found: dereferencedFileSize,\n },\n mediaTypes: {\n name: 'Media Type',\n found: analyzeMediaTypes(definition),\n },\n operationTotal: {\n name: 'Operation',\n found: analyzeTotalOperations(definition),\n },\n rawFileSize: {\n name: 'Raw File Size',\n found: rawFileSize,\n },\n securityTypes: {\n name: 'Security Type',\n found: analyzeSecurityTypes(definition),\n },\n },\n openapi: {\n additionalProperties: {\n present: !!additionalProperties.length,\n locations: additionalProperties,\n },\n callbacks: {\n present: !!callbacks.length,\n locations: callbacks,\n },\n circularRefs: {\n present: !!circularRefs.length,\n locations: circularRefs,\n },\n commonParameters: {\n present: !!commonParameters.length,\n locations: commonParameters,\n },\n discriminators: {\n present: !!discriminators.length,\n locations: discriminators,\n },\n links: {\n present: !!links.length,\n locations: links,\n },\n style: {\n present: !!parameterSerialization.length,\n locations: parameterSerialization,\n },\n polymorphism: {\n present: !!polymorphism.length,\n locations: polymorphism,\n },\n refNames: {\n present: !!refNames.length,\n locations: refNames,\n },\n serverVariables: {\n present: !!serverVariables.length,\n locations: serverVariables,\n },\n xmlRequests: {\n present: !!xmlRequests.length,\n locations: xmlRequests,\n },\n xmlResponses: {\n present: !!xmlResponses.length,\n locations: xmlResponses,\n },\n xmlSchemas: {\n present: !!xmlSchemas.length,\n locations: xmlSchemas,\n },\n webhooks: {\n present: !!webhooks.length,\n locations: webhooks,\n },\n },\n };\n\n return analysis;\n}\n"]}
|
|
1
|
+
{"version":3,"sources":["/Users/erunion/code/readme/oas/packages/oas/dist/analyzer/index.cjs","../../src/analyzer/queries/openapi.ts","../../src/analyzer/index.ts"],"names":["additionalProperties","callbacks","circularRefs","commonParameters","discriminators","links","parameterSerialization","polymorphism","refNames","serverVariables","xmlSchemas","xmlRequests","xmlResponses","webhooks"],"mappings":"AAAA;AACE;AACF,yDAA8B;AAC9B,iCAA8B;AAC9B;AACE;AACA;AACF,yDAA8B;AAC9B,iCAA8B;AAC9B,iCAA8B;AAC9B,iCAA8B;AAC9B,iCAA8B;AAC9B;AACA;ACFO,SAAS,oBAAA,CAAqB,UAAA,EAAmC;AACtE,EAAA,OAAO,qCAAA,CAAO,yBAAyB,CAAA,EAAG,UAAU,CAAA,CAAE,GAAA,CAAI,CAAA,GAAA,EAA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AA;AAAA,QAClC,SAAA,EAAWA;AAAA,MACb,CAAA;AAAA,MACA,YAAA,EAAc;AAAA,QACZ,OAAA,EAAS,CAAC,CAACC,aAAAA,CAAa,MAAA;AAAA,QACxB,SAAA,EAAWA;AAAA,MACb,CAAA;AAAA,MACA,QAAA,EAAU;AAAA,QACR,OAAA,EAAS,CAAC,CAACC,SAAAA,CAAS,MAAA;AAAA,QACpB,SAAA,EAAWA;AAAA,MACb,CAAA;AAAA,MACA,eAAA,EAAiB;AAAA,QACf,OAAA,EAAS,CAAC,CAACC,gBAAAA,CAAgB,MAAA;AAAA,QAC3B,SAAA,EAAWA;AAAA,MACb,CAAA;AAAA,MACA,WAAA,EAAa;AAAA,QACX,OAAA,EAAS,CAAC,CAACE,YAAAA,CAAY,MAAA;AAAA,QACvB,SAAA,EAAWA;AAAA,MACb,CAAA;AAAA,MACA,YAAA,EAAc;AAAA,QACZ,OAAA,EAAS,CAAC,CAACC,aAAAA,CAAa,MAAA;AAAA,QACxB,SAAA,EAAWA;AAAA,MACb,CAAA;AAAA,MACA,UAAA,EAAY;AAAA,QACV,OAAA,EAAS,CAAC,CAACF,WAAAA,CAAW,MAAA;AAAA,QACtB,SAAA,EAAWA;AAAA,MACb,CAAA;AAAA,MACA,QAAA,EAAU;AAAA,QACR,OAAA,EAAS,CAAC,CAACG,SAAAA,CAAS,MAAA;AAAA,QACpB,SAAA,EAAWA;AAAA,MACb;AAAA,IACF;AAAA,EACF,CAAA;AAEA,EAAA,OAAO,QAAA;AACT;AF0EA;AACE;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACF,4zBAAC","file":"/Users/erunion/code/readme/oas/packages/oas/dist/analyzer/index.cjs","sourcesContent":[null,"import type { OASDocument } from '../../types.js';\n\nimport Oas from '../../index.js';\nimport { query, refizePointer } from '../util.js';\n\n/**\n * Determine if a given API definition uses the `additionalProperties` schema property.\n *\n * @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#schema-object}\n * @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#schema-object}\n */\nexport function additionalProperties(definition: OASDocument): string[] {\n return query(['$..additionalProperties'], definition).map(res => refizePointer(res.pointer));\n}\n\n/**\n * Determine if a given API definition utilizes `callbacks`.\n *\n * @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#callback-object}\n * @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#callback-object}\n */\nexport function callbacks(definition: OASDocument): string[] {\n return query(['$.components.callbacks', '$.paths.*[?(@.callbacks)].callbacks'], definition).map(res =>\n refizePointer(res.pointer),\n );\n}\n\n/**\n * Determine if a given API definition has circular refs.\n *\n * @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#schema-object}\n * @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#schema-object}\n */\nexport async function circularRefs(definition: OASDocument): Promise<string[]> {\n // Dereferencing will update the passed in variable, which we don't want to do, so we\n // instantiated `Oas` with a clone.\n const oas = new Oas(JSON.parse(JSON.stringify(definition)));\n await oas.dereference();\n\n const results = oas.getCircularReferences();\n\n results.sort();\n return results;\n}\n\n/**\n * Determine if a given API definition utilizes common parameters.\n *\n * @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#path-item-object}\n * @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#path-item-object}\n */\nexport function commonParameters(definition: OASDocument): string[] {\n return query(['$..paths[*].parameters'], definition).map(res => refizePointer(res.pointer));\n}\n\n/**\n * Determine if a given API definition utilizes discriminators.\n *\n * @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#discriminator-object}\n * @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#discriminator-object}\n */\nexport function discriminators(definition: OASDocument): string[] {\n return query(['$..discriminator'], definition).map(res => refizePointer(res.pointer));\n}\n\n/**\n * Calculate the size of the raw and dereferenced OpenAPI file in MB.\n *\n * If a dereferenced API definition is too large to be stringified the file size will be returned\n * as NaN.\n *\n */\nexport async function fileSize(definition: OASDocument): Promise<{ raw: number; dereferenced: number | typeof NaN }> {\n const oas = new Oas(structuredClone(definition));\n\n const originalSizeInBytes = Buffer.from(JSON.stringify(oas.api)).length;\n const raw = Number((originalSizeInBytes / (1024 * 1024)).toFixed(2));\n\n await oas.dereference();\n\n let dereferenced: number;\n try {\n const dereferencedSizeInBytes = Buffer.from(JSON.stringify(oas.api)).length;\n dereferenced = Number((dereferencedSizeInBytes / (1024 * 1024)).toFixed(2));\n } catch (err) {\n // If the dereferenced API definition is too large to be stringified then we don't have a safer\n // way to estimate its size that wouldn't sacrifice accuracy so we'll just return NaN.\n if (err instanceof RangeError) {\n dereferenced = NaN;\n } else {\n throw err;\n }\n }\n\n return { raw, dereferenced };\n}\n\n/**\n * Determine if a given API definition utilizes `links`.\n *\n * @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#link-object}\n * @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#link-object}\n */\nexport function links(definition: OASDocument): string[] {\n return query(['$.components.links', '$.paths..responses.*.links'], definition).map(res => refizePointer(res.pointer));\n}\n\n/**\n * Determine all of the available media types used within an API definition.\n *\n * @todo This query currently picks up false positives if there is an object named `content`.\n * @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#request-body-object}\n * @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#request-body-object}\n */\nexport function mediaTypes(definition: OASDocument): string[] {\n const results = Array.from(\n new Set(\n query(['$..paths..content'], definition).flatMap(res => {\n // This'll transform `results`, which looks like `[['application/json'], ['text/xml']]`\n // into `['application/json', 'text/xml']`.\n return Object.keys(res.value);\n }),\n ),\n );\n\n results.sort();\n return results;\n}\n\n/**\n * Determine if a given API definition uses parameter serialization.\n *\n * @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#parameter-object}\n * @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#parameter-object}\n */\nexport function parameterSerialization(definition: OASDocument): string[] {\n return query(['$..parameters[*].style^'], definition).map(res => refizePointer(res.pointer));\n}\n\n/**\n * Determine if a given API definition utilizes schema polymorphism and/of interitance.\n *\n * @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#schema-object}\n * @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#schema-object}\n */\nexport function polymorphism(definition: OASDocument): string[] {\n const results = Array.from(\n new Set(query(['$..allOf^', '$..anyOf^', '$..oneOf^'], definition).map(res => refizePointer(res.pointer))),\n );\n\n results.sort();\n return results;\n}\n\n/**\n * Determine if a given API definition previously had references by checking if we added the\n * `x-readme-ref-name` extension after dereferencing. This extension is added only during the\n * dereferencing process.\n *\n */\nexport function refNames(definition: OASDocument): string[] {\n return query([\"$..['x-readme-ref-name']\"], definition).map(res => refizePointer(res.pointer));\n}\n\n/**\n * Determine every kind of security type that a given API definition has documented.\n *\n * @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#security-scheme-object}\n * @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#security-scheme-object}\n */\nexport function securityTypes(definition: OASDocument): string[] {\n return Array.from(new Set(query(['$.components.securitySchemes..type'], definition).map(res => res.value as string)));\n}\n\n/**\n * Determine if a given API definition utilizes server variables.\n *\n * @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#server-variable-object}\n * @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#server-variable-object}\n */\nexport function serverVariables(definition: OASDocument): string[] {\n return query(['$.servers..variables^'], definition).map(res => refizePointer(res.pointer));\n}\n\n/**\n * Determine how many operations are defined in a given API definition.\n *\n * @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#operation-object}\n * @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#operation-object}\n */\nexport function totalOperations(definition: OASDocument): number {\n return query(['$..paths[*]'], definition).flatMap(res => Object.keys(res.value)).length;\n}\n\n/**\n * Determine if a given API definition utilizes `webhooks` support in OpenAPI 3.1.\n *\n * @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#oasWebhooks}\n */\nexport function webhooks(definition: OASDocument): string[] {\n return query(['$.webhooks[*]'], definition).map(res => refizePointer(res.pointer));\n}\n\n/**\n * Determine if a given API definition uses XML in a request body payload.\n *\n * @todo detect `+xml` media types\n * @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#media-type-object}\n * @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#media-type-object}\n */\nexport function xmlRequests(definition: OASDocument): string[] {\n return query(\n [\n \"$..requestBody..['application/xml']\",\n \"$..requestBody..['application/xml-external-parsed-entity']\",\n \"$..requestBody..['application/xml-dtd']\",\n \"$..requestBody..['text/xml']\",\n \"$..requestBody..['text/xml-external-parsed-entity']\",\n '$..requestBody.content[?(@property.match(/\\\\+xml$/i))]',\n ],\n definition,\n ).map(res => refizePointer(res.pointer));\n}\n\n/**\n * Determine if a given API definition uses XML in a response body.\n *\n * @todo detect `+xml` media types\n * @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#media-type-object}\n * @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#media-type-object}\n */\nexport function xmlResponses(definition: OASDocument): string[] {\n return query(\n [\n \"$..responses..['application/xml']\",\n \"$..responses..['application/xml-external-parsed-entity']\",\n \"$..responses..['application/xml-dtd']\",\n \"$..responses..['text/xml']\",\n \"$..responses..['text/xml-external-parsed-entity']\",\n '$..responses[*].content[?(@property.match(/\\\\+xml$/i))]',\n ],\n definition,\n ).map(res => refizePointer(res.pointer));\n}\n\n/**\n * Determine if a given API definition utilises the XML object for defining XML schemas.\n *\n * @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#xml-object}\n * @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#xml-object}\n */\nexport function xmlSchemas(definition: OASDocument): string[] {\n return query(['$.components.schemas..xml^', '$..parameters..xml^', '$..requestBody..xml^'], definition).map(res =>\n refizePointer(res.pointer),\n );\n}\n","import type { OASDocument } from '../types.js';\nimport type { OASAnalysis } from './types.js';\n\nimport {\n additionalProperties as analyzeAdditionalProperties,\n callbacks as analyzeCallbacks,\n circularRefs as analyzeCircularRefs,\n commonParameters as analyzeCommonParameters,\n discriminators as analyzeDiscriminators,\n fileSize as analyzeFileSize,\n links as analyzeLinks,\n mediaTypes as analyzeMediaTypes,\n parameterSerialization as analyzeParameterSerialization,\n polymorphism as analyzePolymorphism,\n refNames as analyzeRefNames,\n securityTypes as analyzeSecurityTypes,\n serverVariables as analyzeServerVariables,\n totalOperations as analyzeTotalOperations,\n webhooks as analyzeWebhooks,\n xmlRequests as analyzeXMLRequests,\n xmlResponses as analyzeXMLResponses,\n xmlSchemas as analyzeXMLSchemas,\n} from './queries/openapi.js';\n\nexport {\n analyzeAdditionalProperties,\n analyzeCallbacks,\n analyzeCircularRefs,\n analyzeCommonParameters,\n analyzeDiscriminators,\n analyzeFileSize,\n analyzeLinks,\n analyzeMediaTypes,\n analyzeParameterSerialization,\n analyzePolymorphism,\n analyzeRefNames,\n analyzeSecurityTypes,\n analyzeServerVariables,\n analyzeTotalOperations,\n analyzeWebhooks,\n analyzeXMLRequests,\n analyzeXMLResponses,\n analyzeXMLSchemas,\n};\n\n/**\n * Analyze a given OpenAPI or Swagger definition for any OpenAPI or JSON Schema feature uses it\n * may contain or utilize.\n *\n */\nexport async function analyzer(definition: OASDocument): Promise<OASAnalysis> {\n const additionalProperties = analyzeAdditionalProperties(definition);\n const callbacks = analyzeCallbacks(definition);\n const circularRefs = await analyzeCircularRefs(definition);\n const commonParameters = analyzeCommonParameters(definition);\n const discriminators = analyzeDiscriminators(definition);\n const { raw: rawFileSize, dereferenced: dereferencedFileSize } = await analyzeFileSize(definition);\n const links = analyzeLinks(definition);\n const parameterSerialization = analyzeParameterSerialization(definition);\n const polymorphism = analyzePolymorphism(definition);\n const refNames = analyzeRefNames(definition);\n const serverVariables = analyzeServerVariables(definition);\n const xmlSchemas = analyzeXMLSchemas(definition);\n const xmlRequests = analyzeXMLRequests(definition);\n const xmlResponses = analyzeXMLResponses(definition);\n const webhooks = analyzeWebhooks(definition);\n\n const analysis: OASAnalysis = {\n general: {\n dereferencedFileSize: {\n name: 'Dereferenced File Size',\n found: dereferencedFileSize,\n },\n mediaTypes: {\n name: 'Media Type',\n found: analyzeMediaTypes(definition),\n },\n operationTotal: {\n name: 'Operation',\n found: analyzeTotalOperations(definition),\n },\n rawFileSize: {\n name: 'Raw File Size',\n found: rawFileSize,\n },\n securityTypes: {\n name: 'Security Type',\n found: analyzeSecurityTypes(definition),\n },\n },\n openapi: {\n additionalProperties: {\n present: !!additionalProperties.length,\n locations: additionalProperties,\n },\n callbacks: {\n present: !!callbacks.length,\n locations: callbacks,\n },\n circularRefs: {\n present: !!circularRefs.length,\n locations: circularRefs,\n },\n commonParameters: {\n present: !!commonParameters.length,\n locations: commonParameters,\n },\n discriminators: {\n present: !!discriminators.length,\n locations: discriminators,\n },\n links: {\n present: !!links.length,\n locations: links,\n },\n style: {\n present: !!parameterSerialization.length,\n locations: parameterSerialization,\n },\n polymorphism: {\n present: !!polymorphism.length,\n locations: polymorphism,\n },\n refNames: {\n present: !!refNames.length,\n locations: refNames,\n },\n serverVariables: {\n present: !!serverVariables.length,\n locations: serverVariables,\n },\n xmlRequests: {\n present: !!xmlRequests.length,\n locations: xmlRequests,\n },\n xmlResponses: {\n present: !!xmlResponses.length,\n locations: xmlResponses,\n },\n xmlSchemas: {\n present: !!xmlSchemas.length,\n locations: xmlSchemas,\n },\n webhooks: {\n present: !!webhooks.length,\n locations: webhooks,\n },\n },\n };\n\n return analysis;\n}\n"]}
|
package/dist/analyzer/index.js
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
import {
|
|
2
2
|
Oas
|
|
3
|
-
} from "../chunk-
|
|
4
|
-
import "../chunk-
|
|
5
|
-
import "../chunk-VA3NKXX7.js";
|
|
6
|
-
import "../chunk-WXXFTJ6D.js";
|
|
7
|
-
import "../chunk-S27IGTVG.js";
|
|
8
|
-
import "../chunk-7MARUOFZ.js";
|
|
3
|
+
} from "../chunk-LSH3X5NA.js";
|
|
4
|
+
import "../chunk-HGVFNEKW.js";
|
|
9
5
|
import {
|
|
10
6
|
query,
|
|
11
7
|
refizePointer
|
|
12
8
|
} from "../chunk-CKC36IL7.js";
|
|
9
|
+
import "../chunk-VA3NKXX7.js";
|
|
10
|
+
import "../chunk-5EP6HY2E.js";
|
|
11
|
+
import "../chunk-S27IGTVG.js";
|
|
12
|
+
import "../chunk-7MARUOFZ.js";
|
|
13
13
|
|
|
14
14
|
// src/analyzer/queries/openapi.ts
|
|
15
15
|
function additionalProperties(definition) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["/Users/
|
|
1
|
+
{"version":3,"sources":["/Users/erunion/code/readme/oas/packages/oas/dist/analyzer/types.cjs"],"names":[],"mappings":"AAAA","file":"/Users/erunion/code/readme/oas/packages/oas/dist/analyzer/types.cjs"}
|
|
@@ -87,17 +87,91 @@ function isPrimitive(val) {
|
|
|
87
87
|
|
|
88
88
|
// src/lib/openapi-to-json-schema.ts
|
|
89
89
|
import mergeJSONSchemaAllOf from "json-schema-merge-allof";
|
|
90
|
-
import
|
|
90
|
+
import jsonpointer2 from "jsonpointer";
|
|
91
91
|
import removeUndefinedObjects from "remove-undefined-objects";
|
|
92
|
+
|
|
93
|
+
// src/lib/refs.ts
|
|
94
|
+
import jsonpointer from "jsonpointer";
|
|
95
|
+
function encodePointer(str) {
|
|
96
|
+
return str.replaceAll("~", "~0").replaceAll("/", "~1");
|
|
97
|
+
}
|
|
98
|
+
function decodePointer(str) {
|
|
99
|
+
return str.replace(/~([01])/g, (_, digit) => digit === "0" ? "~" : "/");
|
|
100
|
+
}
|
|
101
|
+
function findRef($ref, definition) {
|
|
102
|
+
let currRef = $ref.trim();
|
|
103
|
+
if (currRef === "") {
|
|
104
|
+
return false;
|
|
105
|
+
}
|
|
106
|
+
if (currRef.startsWith("#")) {
|
|
107
|
+
currRef = decodeURIComponent(currRef.substring(1));
|
|
108
|
+
} else {
|
|
109
|
+
throw new Error(`Could not find a definition for ${$ref}.`);
|
|
110
|
+
}
|
|
111
|
+
const current = jsonpointer.get(definition, currRef);
|
|
112
|
+
if (current === void 0) {
|
|
113
|
+
throw new Error(`Could not find a definition for ${$ref}.`);
|
|
114
|
+
}
|
|
115
|
+
return current;
|
|
116
|
+
}
|
|
117
|
+
function dereferenceRef(value, definition, seenRefs) {
|
|
118
|
+
if (value === void 0) {
|
|
119
|
+
return void 0;
|
|
120
|
+
}
|
|
121
|
+
if (isRef(value)) {
|
|
122
|
+
if (!definition) {
|
|
123
|
+
return value;
|
|
124
|
+
}
|
|
125
|
+
const ref = value.$ref;
|
|
126
|
+
if (seenRefs?.has(ref)) {
|
|
127
|
+
return value;
|
|
128
|
+
}
|
|
129
|
+
const localSeenRefs = seenRefs || /* @__PURE__ */ new Set();
|
|
130
|
+
localSeenRefs.add(ref);
|
|
131
|
+
try {
|
|
132
|
+
const dereferenced = findRef(ref, definition);
|
|
133
|
+
if (isRef(dereferenced)) {
|
|
134
|
+
return dereferenceRef(dereferenced, definition, localSeenRefs);
|
|
135
|
+
}
|
|
136
|
+
const refName = ref.split("/").pop();
|
|
137
|
+
return {
|
|
138
|
+
...dereferenced,
|
|
139
|
+
// Because dereferencing will eliminate any lineage back to the original `$ref`,
|
|
140
|
+
// information that we might need at some point, we should preserve the original schema
|
|
141
|
+
// name through a custom extension.
|
|
142
|
+
"x-readme-ref-name": refName
|
|
143
|
+
};
|
|
144
|
+
} catch {
|
|
145
|
+
return value;
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
return value;
|
|
149
|
+
}
|
|
150
|
+
function getDereferencingOptions(circularRefs) {
|
|
151
|
+
return {
|
|
152
|
+
resolve: {
|
|
153
|
+
// We shouldn't be resolving external pointers at this point so just ignore them.
|
|
154
|
+
external: false
|
|
155
|
+
},
|
|
156
|
+
dereference: {
|
|
157
|
+
// If circular `$refs` are ignored they'll remain in the schema as `$ref: String`, otherwise
|
|
158
|
+
// `$ref` just won't exist. This, in tandem with `onCircular`, allows us to do easy and
|
|
159
|
+
// accumulate a list of circular references.
|
|
160
|
+
circular: "ignore",
|
|
161
|
+
onCircular: (path) => {
|
|
162
|
+
circularRefs.add(`#${path.split("#")[1]}`);
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
};
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
// src/lib/openapi-to-json-schema.ts
|
|
92
169
|
var UNSUPPORTED_SCHEMA_PROPS = [
|
|
93
170
|
"example",
|
|
94
171
|
// OpenAPI supports `example` but we're mapping it to `examples` in this library.
|
|
95
172
|
"externalDocs",
|
|
96
173
|
"xml"
|
|
97
174
|
];
|
|
98
|
-
function encodePointer(str) {
|
|
99
|
-
return str.replace("~", "~0").replace("/", "~1");
|
|
100
|
-
}
|
|
101
175
|
function getSchemaVersionString(schema, api) {
|
|
102
176
|
if (isOpenAPI30(api)) {
|
|
103
177
|
return "http://json-schema.org/draft-04/schema#";
|
|
@@ -145,7 +219,7 @@ function searchForValueByPropAndPointer(property, pointer, schemas = []) {
|
|
|
145
219
|
schema = schema.default;
|
|
146
220
|
}
|
|
147
221
|
try {
|
|
148
|
-
foundValue =
|
|
222
|
+
foundValue = jsonpointer2.get(schema, pointers[i]);
|
|
149
223
|
} catch {
|
|
150
224
|
}
|
|
151
225
|
if (foundValue !== void 0) {
|
|
@@ -187,9 +261,7 @@ function toJSONSchema(data, opts = {}) {
|
|
|
187
261
|
};
|
|
188
262
|
if (isRef(schema)) {
|
|
189
263
|
refLogger(schema.$ref, "ref");
|
|
190
|
-
return transformer(
|
|
191
|
-
$ref: schema.$ref
|
|
192
|
-
});
|
|
264
|
+
return transformer(schema);
|
|
193
265
|
}
|
|
194
266
|
if (isSchema(schema, isPolymorphicAllOfChild)) {
|
|
195
267
|
if ("allOf" in schema && Array.isArray(schema.allOf)) {
|
|
@@ -231,9 +303,7 @@ function toJSONSchema(data, opts = {}) {
|
|
|
231
303
|
}
|
|
232
304
|
if (isRef(schema)) {
|
|
233
305
|
refLogger(schema.$ref, "ref");
|
|
234
|
-
return transformer(
|
|
235
|
-
$ref: schema.$ref
|
|
236
|
-
});
|
|
306
|
+
return transformer(schema);
|
|
237
307
|
}
|
|
238
308
|
}
|
|
239
309
|
["anyOf", "oneOf"].forEach((polyType) => {
|
|
@@ -537,7 +607,7 @@ function toJSONSchema(data, opts = {}) {
|
|
|
537
607
|
}
|
|
538
608
|
if (isSchema(schema, isPolymorphicAllOfChild) && globalDefaults && Object.keys(globalDefaults).length > 0 && currentLocation) {
|
|
539
609
|
try {
|
|
540
|
-
const userJwtDefault =
|
|
610
|
+
const userJwtDefault = jsonpointer2.get(globalDefaults, currentLocation);
|
|
541
611
|
if (userJwtDefault) {
|
|
542
612
|
schema.default = userJwtDefault;
|
|
543
613
|
}
|
|
@@ -858,6 +928,9 @@ function getParametersAsJSONSchema(operation, api, opts) {
|
|
|
858
928
|
|
|
859
929
|
export {
|
|
860
930
|
cloneObject,
|
|
931
|
+
decodePointer,
|
|
932
|
+
dereferenceRef,
|
|
933
|
+
getDereferencingOptions,
|
|
861
934
|
isObject,
|
|
862
935
|
isPrimitive,
|
|
863
936
|
matches_mimetype_default,
|
|
@@ -867,4 +940,4 @@ export {
|
|
|
867
940
|
types,
|
|
868
941
|
getParametersAsJSONSchema
|
|
869
942
|
};
|
|
870
|
-
//# sourceMappingURL=chunk-
|
|
943
|
+
//# sourceMappingURL=chunk-5EP6HY2E.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/lib/clone-object.ts","../src/lib/matches-mimetype.ts","../src/lib/get-parameter-content-type.ts","../src/lib/helpers.ts","../src/lib/openapi-to-json-schema.ts","../src/lib/refs.ts","../src/operation/lib/get-parameters-as-json-schema.ts"],"sourcesContent":["export function cloneObject<T>(obj: T): T {\n if (typeof obj === 'undefined') {\n return undefined as T;\n }\n\n return JSON.parse(JSON.stringify(obj));\n}\n","function matchesMediaType(types: string[], mediaType: string): boolean {\n return types.some(type => {\n return mediaType.indexOf(type) > -1;\n });\n}\n\n// biome-ignore lint/style/noDefaultExport: This file has no other exports so this is fine.\nexport default {\n formUrlEncoded: (mimeType: string): boolean => {\n return matchesMediaType(['application/x-www-form-urlencoded'], mimeType);\n },\n\n json: (contentType: string): boolean => {\n return matchesMediaType(\n ['application/json', 'application/x-json', 'text/json', 'text/x-json', '+json'],\n contentType,\n );\n },\n\n multipart: (contentType: string): boolean => {\n return matchesMediaType(\n ['multipart/mixed', 'multipart/related', 'multipart/form-data', 'multipart/alternative'],\n contentType,\n );\n },\n\n wildcard: (contentType: string): boolean => {\n return contentType === '*/*';\n },\n\n xml: (contentType: string): boolean => {\n return matchesMediaType(\n [\n 'application/xml',\n 'application/xml-external-parsed-entity',\n 'application/xml-dtd',\n 'text/xml',\n 'text/xml-external-parsed-entity',\n '+xml',\n ],\n contentType,\n );\n },\n};\n","import matchesMimetype from './matches-mimetype.js';\n\n/**\n * Selects a content type from an array of content type keys, prioritizing `application/json`\n * and other JSON-like content types over other content types.\n *\n * When multiple content types are present:\n * - If there's exactly one content type, it's returned\n * - If there are multiple content types, JSON-like content types (e.g., `application/json`,\n * `application/vnd.api+json`) are prioritized\n * - If no JSON-like content types are present, the first content type is returned\n *\n * @param contentKeys - Array of content type keys (e.g., ['application/json', 'application/xml'])\n * @returns The selected content type, or undefined if the array is empty\n */\nexport function getParameterContentType(contentKeys: string[]): string | undefined {\n if (contentKeys.length === 0) {\n return undefined;\n }\n\n if (contentKeys.length === 1) {\n return contentKeys[0];\n }\n\n // We should always try to prioritize `application/json` over any other possible\n // content that might be present on this schema.\n const jsonLikeContentTypes = contentKeys.filter(k => matchesMimetype.json(k));\n if (jsonLikeContentTypes.length) {\n return jsonLikeContentTypes[0];\n }\n\n return contentKeys[0];\n}\n","import type { SchemaObject } from '../types.js';\n\nexport function hasSchemaType(schema: SchemaObject, discriminator: 'array' | 'object'): boolean {\n if (Array.isArray(schema.type)) {\n return schema.type.includes(discriminator);\n }\n\n return schema.type === discriminator;\n}\n\nexport function isObject(val: unknown): val is Record<string, unknown> {\n return typeof val === 'object' && val !== null && !Array.isArray(val);\n}\n\nexport function isPrimitive(val: unknown): val is boolean | number | string {\n return typeof val === 'string' || typeof val === 'number' || typeof val === 'boolean';\n}\n","import type { JSONSchema7TypeName } from 'json-schema';\nimport type { JSONSchema, OASDocument, RequestBodyObject, SchemaObject } from '../types.js';\n\nimport mergeJSONSchemaAllOf from 'json-schema-merge-allof';\nimport jsonpointer from 'jsonpointer';\nimport removeUndefinedObjects from 'remove-undefined-objects';\n\nimport { isOpenAPI30, isRef, isSchema } from '../types.js';\nimport { hasSchemaType, isObject, isPrimitive } from './helpers.js';\nimport { encodePointer } from './refs.js';\n\n/**\n * This list has been pulled from `openapi-schema-to-json-schema` but been slightly modified to fit\n * within the constraints in which ReadMe uses the output from this library in schema form\n * rendering as while properties like `readOnly` aren't represented within JSON Schema, we support\n * it within that library's handling of OpenAPI-friendly JSON Schema.\n *\n * @see {@link https://github.com/openapi-contrib/openapi-schema-to-json-schema/blob/main/src/consts.ts}\n */\nconst UNSUPPORTED_SCHEMA_PROPS = [\n 'example', // OpenAPI supports `example` but we're mapping it to `examples` in this library.\n 'externalDocs',\n 'xml',\n] as const;\n\nexport interface toJSONSchemaOptions {\n /**\n * Whether or not to extend descriptions with a list of any present enums.\n */\n addEnumsToDescriptions?: boolean;\n\n /**\n * Current location within the schema -- this is a JSON pointer.\n */\n currentLocation?: string;\n\n /**\n * Object containing a global set of defaults that we should apply to schemas that match it.\n */\n globalDefaults?: Record<string, unknown>;\n\n /**\n * If you wish to hide properties that are marked as being `readOnly`.\n */\n hideReadOnlyProperties?: boolean;\n\n /**\n * If you wish to hide properties that are marked as being `writeOnly`.\n */\n hideWriteOnlyProperties?: boolean;\n\n /**\n * Is this schema the child of a polymorphic `allOf` schema?\n */\n isPolymorphicAllOfChild?: boolean;\n\n /**\n * Array of parent `default` schemas to utilize when attempting to path together schema defaults.\n */\n prevDefaultSchemas?: SchemaObject[];\n\n /**\n * Array of parent `example` schemas to utilize when attempting to path together schema examples.\n */\n prevExampleSchemas?: SchemaObject[];\n\n /**\n * A function that's called anytime a (circular) `$ref` is found.\n */\n refLogger?: (ref: string, type: 'discriminator' | 'ref') => void;\n\n /**\n * With a transformer you can transform any data within a given schema, like say if you want\n * to rewrite a potentially unsafe `title` that might be eventually used as a JS variable\n * name, just make sure to return your transformed schema.\n */\n transformer?: (schema: SchemaObject) => SchemaObject;\n}\n\nexport function getSchemaVersionString(schema: SchemaObject, api: OASDocument): string {\n // If we're not on OpenAPI 3.1+ then we should fall back to the default schema version.\n if (isOpenAPI30(api)) {\n // This should remain as an HTTP url, not HTTPS.\n return 'http://json-schema.org/draft-04/schema#';\n }\n\n // If the schema indicates the version, prefer that.\n if (schema.$schema) {\n return schema.$schema;\n }\n\n // If the user defined a global schema version on their OAS document, prefer that.\n if (api.jsonSchemaDialect) {\n return api.jsonSchemaDialect;\n }\n\n return 'https://json-schema.org/draft/2020-12/schema#';\n}\n\nfunction isPolymorphicSchema(schema: SchemaObject): boolean {\n return 'allOf' in schema || 'anyOf' in schema || 'oneOf' in schema;\n}\n\nfunction isRequestBodySchema(schema: unknown): schema is RequestBodyObject {\n return 'content' in (schema as RequestBodyObject);\n}\n\n/**\n * Given a JSON pointer, a type of property to look for, and an array of schemas do a reverse\n * search through them until we find the JSON pointer, or part of it, within the array.\n *\n * This function will allow you to take a pointer like `/tags/name` and return back `buster` from\n * the following array:\n *\n * ```\n * [\n * {\n * example: {id: 20}\n * },\n * {\n * examples: {\n * distinctName: {\n * tags: {name: 'buster'}\n * }\n * }\n * }\n * ]\n * ```\n *\n * As with most things however, this is not without its quirks! If a deeply nested property shares\n * the same name as an example that's further up the stack (like `tags.id` and an example for `id`),\n * there's a chance that it'll be misidentified as having an example and receive the wrong value.\n *\n * That said, any example is usually better than no example though, so while it's quirky behavior\n * it shouldn't raise immediate cause for alarm.\n *\n * @see {@link https://tools.ietf.org/html/rfc6901}\n * @param property Specific type of schema property to look for a value for.\n * @param pointer JSON pointer to search for an example for.\n * @param schemas Array of previous schemas we've found relating to this pointer.\n */\nfunction searchForValueByPropAndPointer(\n property: 'default' | 'example',\n pointer: string,\n schemas: toJSONSchemaOptions['prevDefaultSchemas'] | toJSONSchemaOptions['prevExampleSchemas'] = [],\n) {\n if (!schemas.length || !pointer.length) {\n return undefined;\n }\n\n const locSplit = pointer.split('/').filter(Boolean).reverse();\n const pointers = [];\n\n let point = '';\n for (let i = 0; i < locSplit.length; i += 1) {\n point = `/${locSplit[i]}${point}`;\n pointers.push(point);\n }\n\n let foundValue: any;\n const rev = [...schemas].reverse();\n\n for (let i = 0; i < pointers.length; i += 1) {\n for (let ii = 0; ii < rev.length; ii += 1) {\n let schema = rev[ii];\n\n if (property === 'example') {\n if ('example' in schema) {\n schema = schema.example;\n } else {\n if (!Array.isArray(schema.examples) || !schema.examples.length) {\n continue;\n }\n\n // Prevent us from crashing if `examples` is a completely empty object.\n schema = [...schema.examples].shift();\n }\n } else {\n schema = schema.default;\n }\n\n try {\n foundValue = jsonpointer.get(schema, pointers[i]);\n } catch {\n // If the schema we're looking at is `{obj: null}` and our pointer is `/obj/propertyName`\n // `jsonpointer` will throw an error. If that happens, we should silently catch and toss it\n // and return no example.\n }\n\n if (foundValue !== undefined) {\n break;\n }\n }\n\n if (foundValue !== undefined) {\n break;\n }\n }\n\n return foundValue;\n}\n\n/**\n * Given an OpenAPI-flavored JSON Schema, make an effort to modify it so it's shaped more towards\n * stock JSON Schema.\n *\n * Why do this?\n *\n * 1. OpenAPI 3.0.x supports its own flavor of JSON Schema that isn't fully compatible with most\n * JSON Schema tooling (like `@readme/oas-form` or `@rjsf/core`).\n * 2. While validating an OpenAPI definition will prevent corrupted or improper schemas from\n * occuring, we have a lot of legacy schemas in ReadMe that were ingested before we had proper\n * validation in place, and as a result have some API definitions that will not pass validation\n * right now. In addition to reshaping OAS-JSON Schema into JSON Schema this library will also\n * fix these improper schemas: things like `type: object` having `items` instead of `properties`,\n * or `type: array` missing `items`.\n * 3. To ease the burden of polymorphic handling on our form rendering engine we make an attempt\n * to merge `allOf` schemas here.\n * 4. Additionally due to OpenAPI 3.0.x not supporting JSON Schema, in order to support the\n * `example` keyword that OAS supports, we need to do some work in here to remap it into\n * `examples`. However, since all we care about in respect to examples for usage within\n * `@readme/oas-form`, we're only retaining primitives. This *slightly* deviates from JSON\n * Schema in that JSON Schema allows for any schema to be an example, but since\n * `@readme/oas-form` can only actually **render** primitives, that's what we're retaining.\n * 5. Though OpenAPI 3.1 does support full JSON Schema, this library should be able to handle it\n * without any problems.\n *\n * And why use this over `@openapi-contrib/openapi-schema-to-json-schema`? Fortunately and\n * unfortunately we've got a lot of API definitions in our database that aren't currently valid so\n * we need to have a lot of bespoke handling for odd quirks, typos, and missing declarations that\n * might be present.\n *\n * @todo add support for `schema: false` and `not` cases.\n * @todo tighten up `data` to allow for `SchemaObject | ReferenceObject`\n * @see {@link https://json-schema.org/draft/2019-09/json-schema-validation.html}\n * @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#schema-object}\n * @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#schema-object}\n * @param data OpenAPI Schema Object to convert to pure JSON Schema.\n */\nexport function toJSONSchema(data: SchemaObject | boolean, opts: toJSONSchemaOptions = {}): SchemaObject {\n let schema = data === true ? {} : { ...data };\n const schemaAdditionalProperties = isSchema(schema) ? schema.additionalProperties : null;\n\n const {\n addEnumsToDescriptions,\n currentLocation,\n globalDefaults,\n hideReadOnlyProperties,\n hideWriteOnlyProperties,\n isPolymorphicAllOfChild,\n prevDefaultSchemas = [],\n prevExampleSchemas = [],\n refLogger,\n transformer,\n } = {\n addEnumsToDescriptions: false,\n currentLocation: '',\n globalDefaults: {},\n hideReadOnlyProperties: false,\n hideWriteOnlyProperties: false,\n isPolymorphicAllOfChild: false,\n prevDefaultSchemas: [] as toJSONSchemaOptions['prevDefaultSchemas'],\n prevExampleSchemas: [] as toJSONSchemaOptions['prevExampleSchemas'],\n refLogger: () => true,\n transformer: (s: SchemaObject) => s,\n ...opts,\n };\n\n // If this schema contains a `$ref`, it's circular and we shouldn't try to resolve it. Just\n // return and move along. We preserve any sibling properties (e.g. `description`, `deprecated`)\n // alongside the `$ref` pointer, as these are valid in OAS 3.1+ (JSON Schema 2020-12) and\n // commonly used in OAS 3.0 specs as well.\n if (isRef(schema)) {\n refLogger(schema.$ref, 'ref');\n\n return transformer(schema);\n }\n\n // If we don't have a set type, but are dealing with an `anyOf`, `oneOf`, or `allOf`\n // representation let's run through them and make sure they're good.\n if (isSchema(schema, isPolymorphicAllOfChild)) {\n // If this is an `allOf` schema we should make an attempt to merge so as to ease the burden on\n // the tooling that ingests these schemas.\n if ('allOf' in schema && Array.isArray(schema.allOf)) {\n try {\n schema = mergeJSONSchemaAllOf(schema as JSONSchema, {\n ignoreAdditionalProperties: true,\n resolvers: {\n // `merge-json-schema-allof` by default takes the first `description` when you're\n // merging an `allOf` but because generally when you're merging two schemas together\n // with an `allOf` you want data in the subsequent schemas to be applied to the first\n // and `description` should be a part of that.\n description: (obj: string[]) => {\n return obj.slice(-1)[0];\n },\n\n // `merge-json-schema-allof` doesn't support merging enum arrays but since that's a\n // safe and simple operation as enums always contain primitives we can handle it\n // ourselves with a custom resolver.\n //\n // We unfortunately need to cast our return value as `any[]` because the internal types\n // of `merge-json-schema-allof`'s `enum` resolver are not portable.\n enum: (obj: unknown[]) => {\n let arr: any[] = [];\n obj.forEach(e => {\n arr = arr.concat(e);\n });\n\n return arr;\n },\n\n // for any unknown keywords (e.g., `example`, `format`, `x-readme-ref-name`),\n // we fallback to using the title resolver (which uses the first value found).\n // https://github.com/mokkabonna/json-schema-merge-allof/blob/ea2e48ee34415022de5a50c236eb4793a943ad11/src/index.js#L292\n // https://github.com/mokkabonna/json-schema-merge-allof/blob/ea2e48ee34415022de5a50c236eb4793a943ad11/README.md?plain=1#L147\n defaultResolver: mergeJSONSchemaAllOf.options.resolvers.title,\n },\n }) as SchemaObject;\n } catch {\n // If we can't merge the `allOf` for whatever reason (like if one item is a `string` and\n // the other is a `object`) then we should completely remove it from the schema and continue\n // with whatever we've got. Why? If we don't, any tooling that's ingesting this will need\n // to account for the incompatible `allOf` and it may be subject to more breakages than\n // just not having it present would be.\n const { ...schemaWithoutAllOf } = schema;\n schema = schemaWithoutAllOf as SchemaObject;\n delete schema.allOf;\n }\n\n // If after merging the `allOf` this schema still contains a `$ref` then it's circular and\n // we shouldn't do anything else. Preserve sibling properties alongside the `$ref`.\n if (isRef(schema)) {\n refLogger(schema.$ref, 'ref');\n\n return transformer(schema);\n }\n }\n\n (['anyOf', 'oneOf'] as const).forEach((polyType: 'anyOf' | 'oneOf') => {\n if (polyType in schema && Array.isArray(schema[polyType])) {\n const discriminatorPropertyName =\n 'discriminator' in schema && schema.discriminator && isObject(schema.discriminator)\n ? (schema.discriminator as { propertyName?: string }).propertyName\n : undefined;\n\n schema[polyType].forEach((item, idx) => {\n if (!schema[polyType]?.[idx]) {\n // We should never hit this because `anyOf` and `oneOf` ara guaranteed by this point to\n // be arrays but TS isn't smart enough to carry this inferrence down to this block.\n return;\n }\n\n const polyOptions: toJSONSchemaOptions = {\n addEnumsToDescriptions,\n currentLocation: `${currentLocation}/${idx}`,\n globalDefaults,\n hideReadOnlyProperties,\n hideWriteOnlyProperties,\n isPolymorphicAllOfChild: false,\n prevDefaultSchemas,\n prevExampleSchemas,\n refLogger,\n transformer,\n };\n\n // When `properties` or `items` are present alongside a polymorphic schema instead of\n // letting whatever JSON Schema interpreter is handling these constructed schemas we can\n // guide its hand a bit by manually transforming it into an inferred `allOf` of the\n // `properties` + the polymorph schema.\n //\n // This `allOf` schema will be merged together when fed through `toJSONSchema`.\n if ('properties' in schema) {\n schema[polyType][idx] = toJSONSchema(\n { required: schema.required, allOf: [item, { properties: schema.properties }] } as SchemaObject,\n polyOptions,\n );\n } else if ('items' in schema) {\n schema[polyType][idx] = toJSONSchema(\n { allOf: [item, { items: schema.items }] } as SchemaObject,\n polyOptions,\n );\n } else {\n schema[polyType][idx] = toJSONSchema(item as SchemaObject, polyOptions);\n }\n\n // Ensure that we don't have any invalid `required` booleans lying around.\n if (\n isObject(schema[polyType][idx]) &&\n 'required' in (schema[polyType][idx] as SchemaObject) &&\n typeof (schema[polyType][idx] as SchemaObject).required === 'boolean'\n ) {\n delete (schema[polyType][idx] as SchemaObject).required;\n }\n\n // When a parent schema has a discriminator and child schemas inherit via allOf, the child\n // schemas can inherit the parent's discriminator, oneOf, and anyOf. We remove these\n // from child schemas to avoid nested discriminator UIs where each child incorrectly shows\n // all other children as options. This keeps the discriminator only at the parent level.\n if (discriminatorPropertyName && isObject(schema[polyType][idx])) {\n const childSchema = schema[polyType][idx] as SchemaObject;\n if ('discriminator' in childSchema) {\n delete (childSchema as Record<string, unknown>).discriminator;\n }\n if ('oneOf' in childSchema) {\n delete (childSchema as Record<string, unknown>).oneOf;\n }\n if ('anyOf' in childSchema) {\n delete (childSchema as Record<string, unknown>).anyOf;\n }\n }\n });\n }\n });\n\n if ('discriminator' in schema) {\n if ('mapping' in schema.discriminator && typeof schema.discriminator.mapping === 'object') {\n // Discriminator mappings aren't written as traditional `$ref` pointers so in order to log\n // them to the supplied `refLogger`.\n const mapping = schema.discriminator.mapping;\n Object.keys(mapping).forEach(k => {\n refLogger(mapping[k], 'discriminator');\n });\n }\n }\n }\n\n // If this schema is malformed for some reason, let's do our best to repair it.\n if (!('type' in schema) && !isPolymorphicSchema(schema) && !isRequestBodySchema(schema)) {\n if ('properties' in schema) {\n schema.type = 'object';\n } else if ('items' in schema) {\n schema.type = 'array';\n } else {\n // If there's still no `type` on the schema we should leave it alone because we don't have a\n // great way to know if it's part of a nested schema that should, and couldn't be merged,\n // into another, or it's just purely malformed.\n //\n // Whatever tooling that ingests the generated schema should handle it however it needs to.\n }\n }\n\n if ('type' in schema && schema.type !== undefined) {\n // `nullable` isn't a thing in JSON Schema but it was in OpenAPI 3.0 so we should retain and\n // translate it into something that's compatible with JSON Schema.\n if ('nullable' in schema) {\n if (schema.nullable) {\n if (Array.isArray(schema.type)) {\n schema.type.push('null');\n } else if (schema.type !== null && schema.type !== 'null') {\n schema.type = [schema.type, 'null'];\n }\n }\n\n delete schema.nullable;\n }\n\n if (schema.type === null) {\n // `type: null` is possible in JSON Schema but we're translating it to a string version\n // so we don't need to worry about asserting nullish types in our implementations of this\n // generated schema.\n (schema as SchemaObject).type = 'null';\n } else if (Array.isArray(schema.type)) {\n // @ts-expect-error -- `null` is not valid in JSON Schema but it can be done in OpenAPI 3.0.\n if (schema.type.includes(null)) {\n // @ts-expect-error -- `null` is not valid in JSON Schema but it can be done in OpenAPI 3.0.\n schema.type[schema.type.indexOf(null)] = 'null';\n }\n\n schema.type = Array.from(new Set(schema.type));\n\n // We don't need `type: [<type>]` when we can just as easily make it `type: <type>`.\n if (schema.type.length === 1) {\n schema.type = schema.type.shift();\n } else if (schema.type.includes('array') || schema.type.includes('boolean') || schema.type.includes('object')) {\n // If we have a `null` type but there's only two types present then we can remove `null`\n // as an option and flag the whole schema as `nullable`.\n const isNullable = schema.type.includes('null');\n\n if (schema.type.length === 2 && isNullable) {\n // If this is `array | null` or `object | null` then we don't need to do anything.\n } else {\n // If this mixed type has non-primitives then we for convenience of our implementation\n // we're moving them into a `oneOf`.\n const nonPrimitives: any[] = [];\n\n // Because arrays, booleans, and objects are not compatible with any other schem type\n // other than null we're moving them into an isolated `oneOf`, and as such want to take\n // with it its specific properties that may be present on our current schema.\n Object.entries({\n // https://json-schema.org/understanding-json-schema/reference/array.html\n array: [\n 'additionalItems',\n 'contains',\n 'items',\n 'maxContains',\n 'maxItems',\n 'minContains',\n 'minItems',\n 'prefixItems',\n 'uniqueItems',\n ],\n\n // https://json-schema.org/understanding-json-schema/reference/boolean.html\n boolean: [\n // Booleans don't have any boolean-specific properties.\n ],\n\n // https://json-schema.org/understanding-json-schema/reference/object.html\n object: [\n 'additionalProperties',\n 'maxProperties',\n 'minProperties',\n 'nullable',\n 'patternProperties',\n 'properties',\n 'propertyNames',\n 'required',\n ],\n } as Record<string, (keyof SchemaObject)[]>).forEach(([typeKey, keywords]) => {\n if (!schema.type?.includes(typeKey as JSONSchema7TypeName)) {\n return;\n }\n\n const reducedSchema: any = removeUndefinedObjects({\n type: isNullable ? [typeKey, 'null'] : typeKey,\n\n allowEmptyValue: (schema as any).allowEmptyValue ?? undefined,\n deprecated: schema.deprecated ?? undefined,\n description: schema.description ?? undefined,\n readOnly: schema.readOnly ?? undefined,\n title: schema.title ?? undefined,\n writeOnly: schema.writeOnly ?? undefined,\n });\n\n keywords.forEach(keyword => {\n if (keyword in schema) {\n reducedSchema[keyword] = schema[keyword];\n delete schema[keyword];\n }\n });\n\n nonPrimitives.push(reducedSchema);\n });\n\n schema.type = schema.type.filter(t => t !== 'array' && t !== 'boolean' && t !== 'object');\n if (schema.type.length === 1) {\n schema.type = schema.type.shift();\n }\n\n // Because we may have encountered a fully mixed non-primitive type like `array | object`\n // we only want to retain the existing schema object if we still have types remaining\n // in it.\n if (schema.type && schema.type.length > 1) {\n schema = { oneOf: [schema, ...nonPrimitives] };\n } else {\n schema = { oneOf: nonPrimitives };\n }\n }\n }\n }\n }\n\n if (isSchema(schema, isPolymorphicAllOfChild)) {\n if ('default' in schema && isObject(schema.default)) {\n prevDefaultSchemas.push({ default: schema.default });\n }\n\n // JSON Schema doesn't support OpenAPI-style examples so we need to reshape them a bit.\n if ('example' in schema) {\n // Only bother adding primitive examples.\n if (isPrimitive(schema.example)) {\n schema.examples = [schema.example];\n } else if (Array.isArray(schema.example)) {\n schema.examples = schema.example.filter(example => isPrimitive(example));\n if (!schema.examples.length) {\n delete schema.examples;\n }\n } else {\n prevExampleSchemas.push({ example: schema.example });\n }\n\n delete schema.example;\n } else if ('examples' in schema) {\n let reshapedExamples = false;\n if (typeof schema.examples === 'object' && schema.examples !== null && !Array.isArray(schema.examples)) {\n const examples: unknown[] = [];\n Object.keys(schema.examples).forEach(name => {\n const example = schema.examples?.[name as unknown as number];\n if ('$ref' in example) {\n // no-op because any `$ref` example here after dereferencing is circular so we should\n // ignore it\n refLogger(example.$ref, 'ref');\n } else if ('value' in example) {\n if (isPrimitive(example.value)) {\n examples.push(example.value);\n reshapedExamples = true;\n } else if (Array.isArray(example.value) && isPrimitive(example.value[0])) {\n examples.push(example.value[0]);\n reshapedExamples = true;\n } else {\n // If this example is neither a primitive or an array we should dump it into the\n // `prevExampleSchemas` array because we might be able to extract an example from it\n // further downstream.\n prevExampleSchemas.push({\n example: example.value,\n });\n }\n }\n });\n\n if (examples.length) {\n reshapedExamples = true;\n schema.examples = examples;\n }\n } else if (Array.isArray(schema.examples) && isPrimitive(schema.examples[0])) {\n // We haven't reshaped `examples` here, but since it's in a state that's preferrable to us\n // let's keep it around.\n reshapedExamples = true;\n }\n\n if (!reshapedExamples) {\n delete schema.examples;\n }\n }\n\n // If we didn't have any immediately defined examples, let's search backwards and see if we can\n // find one. But as we're only looking for primitive example, only try to search for one if\n // we're dealing with a primitive schema.\n if (!hasSchemaType(schema, 'array') && !hasSchemaType(schema, 'object') && !schema.examples) {\n const foundExample = searchForValueByPropAndPointer('example', currentLocation, prevExampleSchemas);\n if (foundExample) {\n // We can only really deal with primitives, so only promote those as the found example if\n // it is.\n if (isPrimitive(foundExample) || (Array.isArray(foundExample) && isPrimitive(foundExample[0]))) {\n schema.examples = [foundExample];\n }\n }\n }\n\n if (hasSchemaType(schema, 'array')) {\n if ('items' in schema && schema.items !== undefined) {\n if (!Array.isArray(schema.items) && Object.keys(schema.items).length === 1 && isRef(schema.items)) {\n // `items` contains a `$ref`, so since it's circular we should do a no-op here and log\n // and ignore it.\n refLogger(schema.items.$ref, 'ref');\n } else if (schema.items !== true) {\n // Run through the arrays contents and clean them up.\n schema.items = toJSONSchema(schema.items as SchemaObject, {\n addEnumsToDescriptions,\n currentLocation: `${currentLocation}/0`,\n globalDefaults,\n hideReadOnlyProperties,\n hideWriteOnlyProperties,\n prevExampleSchemas,\n refLogger,\n transformer,\n });\n\n // If we have a non-array `required` entry in our `items` schema then it's invalid and we\n // should remove it. We only support non-array boolean `required` properties inside object\n // properties.\n if (isObject(schema.items) && 'required' in schema.items && !Array.isArray(schema.items.required)) {\n delete schema.items.required;\n }\n }\n } else if ('properties' in schema || 'additionalProperties' in schema) {\n // This is a fix to handle cases where someone may have typod `items` as `properties` on an\n // array. Since throwing a complete failure isn't ideal, we can see that they meant for the\n // type to be `object`, so we can do our best to shape the data into what they were\n // intending it to be.\n schema.type = 'object';\n } else {\n // This is a fix to handle cases where we have a malformed array with no `items` property\n // present.\n (schema as any).items = {};\n }\n } else if (hasSchemaType(schema, 'object')) {\n if ('properties' in schema && schema.properties !== undefined) {\n Object.keys(schema.properties).forEach(prop => {\n if (\n Array.isArray(schema.properties?.[prop]) ||\n (typeof schema.properties?.[prop] === 'object' && schema.properties?.[prop] !== null)\n ) {\n const newPropSchema = toJSONSchema(schema.properties[prop] as SchemaObject, {\n addEnumsToDescriptions,\n currentLocation: `${currentLocation}/${encodePointer(prop)}`,\n globalDefaults,\n hideReadOnlyProperties,\n hideWriteOnlyProperties,\n prevDefaultSchemas,\n prevExampleSchemas,\n refLogger,\n transformer,\n });\n\n // If this property is read or write only then we should fully hide it from its parent schema.\n let propShouldBeUpdated = true;\n if ((hideReadOnlyProperties || hideWriteOnlyProperties) && !Object.keys(newPropSchema).length) {\n // We should only delete this schema if it wasn't already empty though. We do this\n // because we (un)fortunately have handling in our API Explorer form system for\n // schemas that are devoid of any `type` declaration.\n if (Object.keys(schema.properties[prop]).length > 0) {\n delete schema.properties[prop];\n propShouldBeUpdated = false;\n }\n }\n\n if (propShouldBeUpdated) {\n schema.properties[prop] = newPropSchema;\n\n /**\n * JSON Schema does not have any support for `required: <boolean>` but because some\n * of our users do this, and it does not throw OpenAPI validation errors thanks to\n * some extremely loose typings around `schema` in the official JSON Schema\n * definitions that the OAI offers, we're opting to support these users and upgrade\n * their invalid `required` definitions into ones that our tooling can interpret.\n *\n * @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/schemas/v3.1/schema.json#L1114-L1121}\n */\n if (\n isObject(newPropSchema) &&\n 'required' in newPropSchema &&\n typeof newPropSchema.required === 'boolean' &&\n newPropSchema.required === true\n ) {\n if ('required' in schema && Array.isArray(schema.required)) {\n schema.required.push(prop);\n } else {\n schema.required = [prop];\n }\n\n delete (schema.properties[prop] as SchemaObject).required;\n }\n }\n }\n });\n\n // If we want to hide all readOnly or writeOnly properites and it happens to be that this\n // object was comprised of only those then we shouldn't render this object.\n if (hideReadOnlyProperties || hideWriteOnlyProperties) {\n if (!Object.keys(schema.properties).length) {\n return transformer({});\n }\n }\n }\n\n if (typeof schemaAdditionalProperties === 'object' && schemaAdditionalProperties !== null) {\n // If this `additionalProperties` is completely empty and devoid of any sort of schema,\n // treat it as such. Otherwise let's recurse into it and see if we can sort it out.\n if (\n !('type' in schemaAdditionalProperties) &&\n !('$ref' in schemaAdditionalProperties) &&\n // We know it will be a schema object because it's dereferenced\n !isPolymorphicSchema(schemaAdditionalProperties as SchemaObject)\n ) {\n schema.additionalProperties = true;\n } else {\n // We know it will be a schema object because it's dereferenced\n schema.additionalProperties = toJSONSchema(schemaAdditionalProperties as SchemaObject, {\n addEnumsToDescriptions,\n currentLocation,\n globalDefaults,\n hideReadOnlyProperties,\n hideWriteOnlyProperties,\n prevDefaultSchemas,\n prevExampleSchemas,\n refLogger,\n transformer,\n });\n }\n }\n\n // Since neither `properties` and `additionalProperties` are actually required to be present\n // on an object, since we construct this schema work to build up a form we still need\n // *something* for the user to enter in for this object so we'll add back in\n // `additionalProperties` for that.\n if (!isPolymorphicSchema(schema) && !('properties' in schema) && !('additionalProperties' in schema)) {\n schema.additionalProperties = true;\n }\n }\n }\n\n /**\n * Users can pass in parameter defaults via JWT User Data. We're checking to see if the defaults\n * being passed in exist on endpoints via jsonpointer\n *\n * @see {@link https://docs.readme.com/docs/passing-data-to-jwt}\n */\n if (\n isSchema(schema, isPolymorphicAllOfChild) &&\n globalDefaults &&\n Object.keys(globalDefaults).length > 0 &&\n currentLocation\n ) {\n try {\n const userJwtDefault = jsonpointer.get(globalDefaults, currentLocation);\n if (userJwtDefault) {\n schema.default = userJwtDefault;\n }\n } catch {\n // If jsonpointer returns an error, we won't show any defaults for that path.\n }\n }\n\n // Only add a default value if we actually have one.\n if ('default' in schema && typeof schema.default !== 'undefined') {\n if (hasSchemaType(schema, 'object')) {\n // Defaults for `object` and types have been dereferenced into their children schemas already\n // above so we don't need to preserve this default anymore.\n delete schema.default;\n } else if (\n ('allowEmptyValue' in schema && schema.allowEmptyValue && schema.default === '') ||\n schema.default !== ''\n ) {\n // If we have `allowEmptyValue` present, and the default is actually an empty string, let it\n // through as it's allowed.\n } else {\n // If the default is empty and we don't want to allowEmptyValue, we need to remove the\n // default.\n delete schema.default;\n }\n } else if (prevDefaultSchemas.length) {\n const foundDefault = searchForValueByPropAndPointer('default', currentLocation, prevDefaultSchemas);\n\n // We shouldn't ever set an object default out of the parent lineage tree defaults because\n // the contents of that object will be set on the schema that they're a part of. Setting\n // that object as well would result us in duplicating the defaults for that schema in two\n // places.\n if (\n isPrimitive(foundDefault) ||\n foundDefault === null ||\n (Array.isArray(foundDefault) && hasSchemaType(schema, 'array'))\n ) {\n (schema as SchemaObject).default = foundDefault;\n }\n }\n\n if (isSchema(schema, isPolymorphicAllOfChild) && 'enum' in schema && Array.isArray(schema.enum)) {\n // Enums should not have duplicated items as those will break AJV validation.\n // If we ever target ES6 for typescript we can drop this array.from.\n // https://stackoverflow.com/questions/33464504/using-spread-syntax-and-new-set-with-typescript/56870548\n schema.enum = Array.from(new Set(schema.enum));\n\n // If we want to add enums to descriptions (like in the case of response JSON Schema)\n // generation we need to convert them into a list of Markdown tilda'd strings. We're also\n // filtering away empty and falsy strings here because adding empty `` blocks to the description\n // will serve nobody any good.\n if (addEnumsToDescriptions) {\n const enums = schema.enum\n .filter(v => v !== undefined && (typeof v !== 'string' || v.trim() !== ''))\n .map(str => `\\`${str}\\``)\n .join(' ');\n\n if (enums.length) {\n if ('description' in schema) {\n schema.description += `\\n\\n${enums}`;\n } else {\n schema.description = enums;\n }\n }\n }\n }\n\n // Clean up any remaining `items` or `properties` schema fragments lying around if there's also\n // polymorphism present.\n if ('anyOf' in schema || 'oneOf' in schema) {\n if ('properties' in schema) {\n delete schema.properties;\n }\n\n if ('items' in schema) {\n delete schema.items;\n }\n }\n\n // Remove unsupported JSON Schema props.\n for (let i = 0; i < UNSUPPORTED_SCHEMA_PROPS.length; i += 1) {\n // Using the as here because the purpose is to delete keys we don't expect, so of course the\n // typing won't work\n delete (schema as Record<string, unknown>)[UNSUPPORTED_SCHEMA_PROPS[i]];\n }\n\n // If we want to hide any `readOnly` or `writeOnly` schemas, and this one is that, then we\n // shouldn't return anything.\n if (hideReadOnlyProperties && 'readOnly' in schema && schema.readOnly === true) {\n return {};\n } else if (hideWriteOnlyProperties && 'writeOnly' in schema && schema.writeOnly === true) {\n return {};\n }\n\n return transformer(schema);\n}\n","import type { ParserOptions } from '@readme/openapi-parser';\nimport type { OASDocument, SchemaObject } from '../types.js';\n\nimport jsonpointer from 'jsonpointer';\n\nimport { isRef } from '../types.js';\n\n/**\n * Encode a string to be used as a JSON pointer.\n *\n * @see {@link https://tools.ietf.org/html/rfc6901}\n * @param str String to encode into string that can be used as a JSON pointer.\n */\nexport function encodePointer(str: string): string {\n return str.replaceAll('~', '~0').replaceAll('/', '~1');\n}\n\n/**\n * Decode a JSON pointer string.\n *\n * Per RFC 6901, `~0` is unescaped to `~` and `~1` to `/`. A single-pass replacement is required:\n * the sequence `~01` must decode to `~1` (tilde then one), not `~/`. Replacing `~1` before `~0`\n * would incorrectly turn `~01` into `~/`.\n *\n * @see {@link https://tools.ietf.org/html/rfc6901}\n * @param str String to decode a JSON pointer from\n */\nexport function decodePointer(str: string): string {\n return str.replace(/~([01])/g, (_, digit) => (digit === '0' ? '~' : '/'));\n}\n\n/**\n * Lookup a reference pointer within an a JSON object and return the schema that it resolves to.\n *\n * @param $ref Reference to look up a schema for.\n * @param definition OpenAPI definition to look for the `$ref` pointer in.\n */\nfunction findRef($ref: string, definition: OASDocument | SchemaObject): any {\n let currRef = $ref.trim();\n if (currRef === '') {\n // If this ref is empty, don't bother trying to look for it.\n return false;\n }\n\n if (currRef.startsWith('#')) {\n // Decode URI fragment representation.\n currRef = decodeURIComponent(currRef.substring(1));\n } else {\n throw new Error(`Could not find a definition for ${$ref}.`);\n }\n\n const current = jsonpointer.get(definition, currRef);\n if (current === undefined) {\n throw new Error(`Could not find a definition for ${$ref}.`);\n }\n\n return current;\n}\n\n/**\n * Dereference a `$ref` pointer if present, otherwise return the value as-is.\n *\n * This function handles `$ref` pointers on-the-fly without requiring full dereferencing and\n * prevents infinite loops by tracking seen `$ref` pointers and not re-processing circular\n * references.\n *\n * @param value The value that may contain a `$ref` pointer.\n * @param definition OpenAPI definition to look for the `$ref` pointer in.\n * @param seenRefs Optional Set to track `$ref` pointers that have already been processed to prevent circular references.\n * @returns The dereferenced value if it was a `$ref`, otherwise the original value. Returns the original `$ref` if it's circular.\n */\nexport function dereferenceRef<T>(value: T, definition?: OASDocument | SchemaObject, seenRefs?: Set<string>): T {\n if (value === undefined) {\n return undefined as T;\n }\n\n if (isRef(value)) {\n if (!definition) {\n return value as T;\n }\n\n const ref = value.$ref;\n\n // If we've seen this `$ref` before then it's circular and we should return the original `$ref`\n // to prevent infinite loops\n if (seenRefs?.has(ref)) {\n return value as T;\n }\n\n // Track this $ref as seen\n const localSeenRefs = seenRefs || new Set<string>();\n localSeenRefs.add(ref);\n\n try {\n const dereferenced = findRef(ref, definition);\n\n // If the dereferenced value is itself a `$ref` then recursively dereference it (but with\n // `seenRefs` tracking).\n if (isRef(dereferenced)) {\n return dereferenceRef(dereferenced, definition, localSeenRefs) as T;\n }\n\n const refName = ref.split('/').pop();\n return {\n ...dereferenced,\n\n // Because dereferencing will eliminate any lineage back to the original `$ref`,\n // information that we might need at some point, we should preserve the original schema\n // name through a custom extension.\n 'x-readme-ref-name': refName,\n } as T;\n } catch {\n // If dereferencing fails return the original `$ref`.\n return value as T;\n }\n }\n\n return value;\n}\n\n/**\n * Retrive our dereferencing configuration for `@readme/openapi-parser`.\n *\n */\nexport function getDereferencingOptions(circularRefs: Set<string>): Pick<ParserOptions, 'resolve' | 'dereference'> {\n return {\n resolve: {\n // We shouldn't be resolving external pointers at this point so just ignore them.\n external: false,\n },\n dereference: {\n // If circular `$refs` are ignored they'll remain in the schema as `$ref: String`, otherwise\n // `$ref` just won't exist. This, in tandem with `onCircular`, allows us to do easy and\n // accumulate a list of circular references.\n circular: 'ignore',\n\n onCircular: (path: string) => {\n // The circular references that are coming out of `json-schema-ref-parser` are prefixed\n // with the schema path (file path, URL, whatever) that the schema exists in. Because we\n // don't care about this information for this reporting mechanism, and only the `$ref`\n // pointer, we're removing it.\n circularRefs.add(`#${path.split('#')[1]}`);\n },\n },\n };\n}\n","import type { OpenAPIV3_1 } from 'openapi-types';\nimport type { toJSONSchemaOptions } from '../../lib/openapi-to-json-schema.js';\nimport type { ComponentsObject, ExampleObject, OASDocument, ParameterObject, SchemaObject } from '../../types.js';\nimport type { Operation } from '../index.js';\n\nimport { getExtension, PARAMETER_ORDERING } from '../../extensions.js';\nimport { cloneObject } from '../../lib/clone-object.js';\nimport { getParameterContentType } from '../../lib/get-parameter-content-type.js';\nimport { isPrimitive } from '../../lib/helpers.js';\nimport { getSchemaVersionString, toJSONSchema } from '../../lib/openapi-to-json-schema.js';\nimport { isRef } from '../../types.js';\n\nexport interface SchemaWrapper {\n $schema?: string;\n deprecatedProps?: SchemaWrapper;\n description?: string;\n label?: string;\n schema: SchemaObject;\n type: string;\n}\n\n/**\n * The order of this object determines how they will be sorted in the compiled JSON Schema\n * representation.\n *\n * @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#parameter-object}\n * @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#parameter-object}\n */\nexport const types: Record<keyof OASDocument, string> = {\n path: 'Path Params',\n query: 'Query Params',\n body: 'Body Params',\n cookie: 'Cookie Params',\n formData: 'Form Data',\n header: 'Headers',\n metadata: 'Metadata', // This a special type reserved for https://npm.im/api\n};\n\nexport interface getParametersAsJSONSchemaOptions {\n /**\n * Contains an object of user defined schema defaults.\n */\n globalDefaults?: Record<string, unknown>;\n\n /**\n * If you wish to hide properties that are marked as being `readOnly`.\n */\n hideReadOnlyProperties?: boolean;\n\n /**\n * If you wish to hide properties that are marked as being `writeOnly`.\n */\n hideWriteOnlyProperties?: boolean;\n\n /**\n * If you wish to include discriminator mapping `$ref` components alongside your\n * `discriminator` in schemas. Defaults to `true`.\n */\n includeDiscriminatorMappingRefs?: boolean;\n\n /**\n * If you want the output to be two objects: body (contains `body` and `formData` JSON\n * Schema) and metadata (contains `path`, `query`, `cookie`, and `header`).\n */\n mergeIntoBodyAndMetadata?: boolean;\n\n /**\n * If you wish to **not** split out deprecated properties into a separate `deprecatedProps`\n * object.\n */\n retainDeprecatedProperties?: boolean;\n\n /**\n * With a transformer you can transform any data within a given schema, like say if you want\n * to rewrite a potentially unsafe `title` that might be eventually used as a JS variable\n * name, just make sure to return your transformed schema.\n */\n transformer?: (schema: SchemaObject) => SchemaObject;\n}\n\nexport function getParametersAsJSONSchema(\n operation: Operation,\n api: OASDocument,\n opts?: getParametersAsJSONSchemaOptions,\n): SchemaWrapper[] | null {\n let hasCircularRefs = false;\n let hasDiscriminatorMappingRefs = false;\n\n function refLogger(ref: string, type: 'discriminator' | 'ref') {\n if (type === 'ref') {\n hasCircularRefs = true;\n } else {\n hasDiscriminatorMappingRefs = true;\n }\n }\n\n function getDeprecated(schema: SchemaObject, type: string) {\n // If we wish to retain deprecated properties then we shouldn't split them out into the\n // `deprecatedProps` object.\n if (opts?.retainDeprecatedProperties) {\n return null;\n }\n\n // If there's no properties, bail\n if (!schema || !schema.properties) return null;\n\n // Clone the original schema so this doesn't interfere with it\n const deprecatedBody = cloneObject(schema);\n\n // Booleans are not valid for required in draft 4, 7 or 2020. Not sure why the typing thinks\n // they are.\n const requiredParams = (schema.required || []) as string[];\n\n // Find all top-level deprecated properties from the schema - required and readOnly params are\n // excluded.\n const allDeprecatedProps: Record<string, SchemaObject> = {};\n\n Object.keys(deprecatedBody.properties || {}).forEach(key => {\n const deprecatedProp = deprecatedBody.properties?.[key] as SchemaObject;\n if (deprecatedProp.deprecated && !requiredParams.includes(key) && !deprecatedProp.readOnly) {\n allDeprecatedProps[key] = deprecatedProp;\n }\n });\n\n // We know this is the right type. todo: don't use as\n (deprecatedBody.properties as Record<string, SchemaObject>) = allDeprecatedProps;\n const deprecatedSchema = toJSONSchema(deprecatedBody, {\n globalDefaults: opts?.globalDefaults,\n hideReadOnlyProperties: opts?.hideReadOnlyProperties,\n hideWriteOnlyProperties: opts?.hideWriteOnlyProperties,\n prevExampleSchemas: [],\n refLogger,\n transformer: opts?.transformer,\n });\n\n // Check if the schema wasn't created or there's no deprecated properties\n if (Object.keys(deprecatedSchema).length === 0 || Object.keys(deprecatedSchema.properties || {}).length === 0) {\n return null;\n }\n\n // Remove deprecated properties from the original schema\n // Not using the clone here becuase we WANT this to affect the original\n Object.keys(schema.properties).forEach(key => {\n // We know this will always be a SchemaObject\n if ((schema.properties?.[key] as SchemaObject).deprecated && !requiredParams.includes(key)) {\n delete schema.properties?.[key];\n }\n });\n\n return {\n type,\n schema: isPrimitive(deprecatedSchema)\n ? deprecatedSchema\n : {\n ...deprecatedSchema,\n $schema: getSchemaVersionString(deprecatedSchema, api),\n },\n };\n }\n\n function transformRequestBody(): SchemaWrapper | null {\n const requestBody = operation.getRequestBody();\n if (!requestBody || !Array.isArray(requestBody)) return null;\n\n const [mediaType, mediaTypeObject, description] = requestBody;\n const type = mediaType === 'application/x-www-form-urlencoded' ? 'formData' : 'body';\n\n // If this schema is completely empty, don't bother processing it.\n if (!mediaTypeObject.schema || !Object.keys(mediaTypeObject.schema).length) {\n return null;\n }\n\n const prevExampleSchemas: toJSONSchemaOptions['prevExampleSchemas'] = [];\n if ('example' in mediaTypeObject) {\n prevExampleSchemas.push({ example: mediaTypeObject.example });\n } else if ('examples' in mediaTypeObject) {\n prevExampleSchemas.push({\n examples: Object.values(mediaTypeObject.examples || {})\n .map(example => {\n if (isRef(example)) {\n /** @todo add support for `ReferenceObject` */\n return undefined;\n }\n return example.value;\n })\n .filter((item): item is ExampleObject => item !== undefined),\n });\n }\n\n // We're cloning the request schema because we've had issues with request schemas that were\n // dereferenced being processed multiple times because their component is also processed.\n const requestSchema = cloneObject(mediaTypeObject.schema);\n\n const cleanedSchema = toJSONSchema(requestSchema, {\n globalDefaults: opts?.globalDefaults,\n hideReadOnlyProperties: opts?.hideReadOnlyProperties,\n hideWriteOnlyProperties: opts?.hideWriteOnlyProperties,\n prevExampleSchemas,\n refLogger,\n transformer: opts?.transformer,\n });\n\n // If this schema is **still** empty, don't bother returning it.\n if (!Object.keys(cleanedSchema).length) {\n return null;\n }\n\n return {\n type,\n label: types[type],\n schema: isPrimitive(cleanedSchema)\n ? cleanedSchema\n : {\n ...cleanedSchema,\n $schema: getSchemaVersionString(cleanedSchema, api),\n },\n deprecatedProps: getDeprecated(cleanedSchema, type) ?? undefined,\n ...(description ? { description } : {}),\n };\n }\n\n function transformComponents(): ComponentsObject {\n if (!('components' in api) || !api.components) {\n return false;\n }\n\n const components: Partial<ComponentsObject> = {\n ...Object.keys(api.components)\n .map(componentType => ({ [componentType]: {} }))\n .reduce((prev, next) => Object.assign(prev, next), {}),\n };\n\n Object.keys(api.components).forEach(componentType => {\n const cType = componentType as keyof ComponentsObject;\n if (typeof api.components?.[cType] === 'object' && !Array.isArray(api.components[cType])) {\n Object.keys(api.components?.[cType] || {}).forEach(schemaName => {\n const componentSchema = cloneObject(api.components?.[cType]?.[schemaName]);\n if (!components[cType]) {\n components[cType] = {};\n }\n\n components[cType][schemaName] = toJSONSchema(componentSchema as SchemaObject, {\n globalDefaults: opts?.globalDefaults,\n hideReadOnlyProperties: opts?.hideReadOnlyProperties,\n hideWriteOnlyProperties: opts?.hideWriteOnlyProperties,\n refLogger,\n transformer: opts?.transformer,\n });\n });\n }\n });\n\n // If none of our above component type placeholders got used let's clean them up.\n Object.keys(components).forEach(componentType => {\n const cType = componentType as keyof ComponentsObject;\n if (!Object.keys(components?.[cType] || {}).length) {\n delete components?.[cType];\n }\n });\n\n return components;\n }\n\n function transformParameters(): SchemaWrapper[] {\n const operationParams = operation.getParameters();\n\n const transformed = Object.keys(types)\n .map(type => {\n const required: string[] = [];\n\n // This `as` actually *could* be a ref, but we don't want refs to pass through here, so\n // `.in` will never match `type`\n const parameters = operationParams.filter(param => (param as ParameterObject).in === type);\n if (parameters.length === 0) {\n return null;\n }\n\n const properties = parameters.reduce((prev: Record<string, SchemaObject>, current: ParameterObject) => {\n let schema: SchemaObject = {};\n if ('schema' in current) {\n const currentSchema: SchemaObject = current.schema ? cloneObject(current.schema) : {};\n\n if (current.example) {\n // `example` can be present outside of the `schema` block so if it's there we should\n // pull it in so it can be handled and returned if it's valid.\n currentSchema.example = current.example;\n } else if (current.examples) {\n // `examples` isn't actually supported here in OAS 3.0, but we might as well support\n // it because `examples` is JSON Schema and that's fully supported in OAS 3.1.\n currentSchema.examples = current.examples as unknown as unknown[];\n }\n\n if (current.deprecated) currentSchema.deprecated = current.deprecated;\n\n const interimSchema = toJSONSchema(currentSchema, {\n currentLocation: `/${current.name}`,\n globalDefaults: opts?.globalDefaults,\n hideReadOnlyProperties: opts?.hideReadOnlyProperties,\n hideWriteOnlyProperties: opts?.hideWriteOnlyProperties,\n refLogger,\n transformer: opts?.transformer,\n });\n\n schema = isPrimitive(interimSchema)\n ? interimSchema\n : {\n ...interimSchema,\n\n // Note: this applies a `$schema` version to each field in the larger schema\n // object. It's not really **correct** but it's what we have to do because\n // there's a chance that the end user has indicated the schemas are different.\n $schema: getSchemaVersionString(currentSchema, api),\n };\n } else if ('content' in current && typeof current.content === 'object') {\n const contentKeys = Object.keys(current.content);\n if (contentKeys.length) {\n const contentType = getParameterContentType(contentKeys);\n if (\n contentType &&\n typeof current.content[contentType] === 'object' &&\n 'schema' in current.content[contentType]\n ) {\n const currentSchema: SchemaObject = current.content[contentType].schema\n ? cloneObject(current.content[contentType].schema)\n : {};\n\n if (current.example) {\n // `example` can be present outside of the `schema` block so if it's there we\n // should pull it in so it can be handled and returned if it's valid.\n currentSchema.example = current.example;\n } else if (current.examples) {\n // `examples` isn't actually supported here in OAS 3.0, but we might as well\n // support it because `examples` is JSON Schema and that's fully supported in OAS\n // 3.1.\n currentSchema.examples = current.examples as unknown as unknown[];\n }\n\n if (current.deprecated) currentSchema.deprecated = current.deprecated;\n\n const interimSchema = toJSONSchema(currentSchema, {\n currentLocation: `/${current.name}`,\n globalDefaults: opts?.globalDefaults,\n hideReadOnlyProperties: opts?.hideReadOnlyProperties,\n hideWriteOnlyProperties: opts?.hideWriteOnlyProperties,\n refLogger,\n transformer: opts?.transformer,\n });\n\n schema = isPrimitive(interimSchema)\n ? interimSchema\n : {\n ...interimSchema,\n\n // Note: this applies a `$schema` version to each field in the larger schema\n // object. It's not really **correct** but it's what we have to do because\n // there's a chance that the end user has indicated the schemas are different.\n $schema: getSchemaVersionString(currentSchema, api),\n };\n }\n }\n }\n\n // Parameter descriptions don't exist in `current.schema` so `constructSchema` will never\n // have access to it.\n if (current.description) {\n if (!isPrimitive(schema)) {\n schema.description = current.description;\n }\n }\n\n prev[current.name] = schema;\n\n if (current.required) {\n required.push(current.name);\n }\n\n return prev;\n }, {});\n\n // This typing is technically WRONG :( but it's the best we can do for now.\n const schema: OpenAPIV3_1.SchemaObject = {\n type: 'object',\n properties: properties as Record<string, OpenAPIV3_1.SchemaObject>,\n required,\n };\n\n return {\n type,\n label: types[type],\n schema,\n deprecatedProps: getDeprecated(schema, type) ?? undefined,\n };\n })\n .filter(item => item !== null);\n\n if (!opts?.mergeIntoBodyAndMetadata) {\n return transformed;\n } else if (!transformed.length) {\n return [];\n }\n\n // If we want to merge parameters into a single metadata entry then we need to pull all\n // available schemas and `deprecatedProps` (if we don't want to retain them via the\n // `retainDeprecatedProps` option) under one roof.\n const deprecatedProps = transformed.map(r => r.deprecatedProps?.schema || null).filter(Boolean);\n return [\n {\n type: 'metadata',\n label: types.metadata,\n schema: {\n allOf: transformed.map(r => r.schema),\n } as SchemaObject,\n deprecatedProps: deprecatedProps.length\n ? {\n type: 'metadata',\n schema: {\n allOf: deprecatedProps,\n } as SchemaObject,\n }\n : undefined,\n },\n ];\n }\n\n // If this operation neither has any parameters or a request body then we should return `null`\n // because there won't be any JSON Schema.\n if (!operation.hasParameters() && !operation.hasRequestBody()) {\n return null;\n }\n\n // `metadata` is `api` SDK specific, is not a part of the `PARAMETER_ORDERING` extension, and\n // should always be sorted last. We also define `formData` as `form` in the extension because\n // we don't want folks to have to deal with casing issues so we need to rewrite it to `formData`.\n const typeKeys = (getExtension(PARAMETER_ORDERING, api, operation) as string[]).map(k => k.toLowerCase());\n typeKeys[typeKeys.indexOf('form')] = 'formData';\n typeKeys.push('metadata');\n\n const jsonSchema = [transformRequestBody()]\n .concat(...transformParameters())\n .filter((item): item is SchemaWrapper => item !== null);\n\n // We should only include `components`, or even bother transforming components into JSON Schema,\n // if we either have circular refs or if we have discriminator mapping refs somewhere and want to\n // include them.\n const shouldIncludeComponents =\n hasCircularRefs || (hasDiscriminatorMappingRefs && opts?.includeDiscriminatorMappingRefs);\n\n const components = shouldIncludeComponents ? transformComponents() : false;\n\n return jsonSchema\n .map(group => {\n /**\n * Since this library assumes that the schema has already been dereferenced, adding every\n * component here that **isn't** circular adds a ton of bloat so it'd be cool if `components`\n * was just the remaining `$ref` pointers that are still being referenced.\n *\n * @todo\n */\n if (components && shouldIncludeComponents) {\n // Fixing typing and confused version mismatches\n (group.schema.components as ComponentsObject) = components;\n }\n\n // Delete deprecatedProps if it's null on the schema.\n if (!group.deprecatedProps) delete group.deprecatedProps;\n\n return group;\n })\n .sort((a, b) => {\n return typeKeys.indexOf(a.type) - typeKeys.indexOf(b.type);\n });\n}\n"],"mappings":";;;;;;;;;;;AAAO,SAAS,YAAe,KAAW;AACxC,MAAI,OAAO,QAAQ,aAAa;AAC9B,WAAO;AAAA,EACT;AAEA,SAAO,KAAK,MAAM,KAAK,UAAU,GAAG,CAAC;AACvC;;;ACNA,SAAS,iBAAiBA,QAAiB,WAA4B;AACrE,SAAOA,OAAM,KAAK,UAAQ;AACxB,WAAO,UAAU,QAAQ,IAAI,IAAI;AAAA,EACnC,CAAC;AACH;AAGA,IAAO,2BAAQ;AAAA,EACb,gBAAgB,CAAC,aAA8B;AAC7C,WAAO,iBAAiB,CAAC,mCAAmC,GAAG,QAAQ;AAAA,EACzE;AAAA,EAEA,MAAM,CAAC,gBAAiC;AACtC,WAAO;AAAA,MACL,CAAC,oBAAoB,sBAAsB,aAAa,eAAe,OAAO;AAAA,MAC9E;AAAA,IACF;AAAA,EACF;AAAA,EAEA,WAAW,CAAC,gBAAiC;AAC3C,WAAO;AAAA,MACL,CAAC,mBAAmB,qBAAqB,uBAAuB,uBAAuB;AAAA,MACvF;AAAA,IACF;AAAA,EACF;AAAA,EAEA,UAAU,CAAC,gBAAiC;AAC1C,WAAO,gBAAgB;AAAA,EACzB;AAAA,EAEA,KAAK,CAAC,gBAAiC;AACrC,WAAO;AAAA,MACL;AAAA,QACE;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,MACF;AAAA,MACA;AAAA,IACF;AAAA,E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