oas 36.0.3 → 37.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +0 -5
- package/dist/analyzer/index.cjs +83 -28
- package/dist/analyzer/index.cjs.map +1 -1
- package/dist/analyzer/index.d.cts +3 -10
- package/dist/analyzer/index.d.ts +3 -10
- package/dist/analyzer/index.js +81 -26
- package/dist/analyzer/index.js.map +1 -1
- package/dist/analyzer/types.d.cts +0 -1
- package/dist/analyzer/types.d.ts +0 -1
- package/dist/{chunk-6MDVLJ3A.js → chunk-6APWNY54.js} +10 -24
- package/dist/chunk-6APWNY54.js.map +1 -0
- package/dist/{chunk-AYA3UT4L.cjs → chunk-6HXOZ5GY.cjs} +6 -3
- package/dist/chunk-6HXOZ5GY.cjs.map +1 -0
- package/dist/{chunk-RQZ2BPMU.js → chunk-I7R3WTTN.js} +199 -150
- package/dist/chunk-I7R3WTTN.js.map +1 -0
- package/dist/{chunk-S27IGTVG.js → chunk-LZNTJ4ZR.js} +5 -2
- package/dist/chunk-LZNTJ4ZR.js.map +1 -0
- package/dist/{chunk-SCWW2SNX.cjs → chunk-OWMXX4EB.cjs} +12 -26
- package/dist/chunk-OWMXX4EB.cjs.map +1 -0
- package/dist/{chunk-BJCTM2ME.cjs → chunk-QPYARJRD.cjs} +321 -272
- package/dist/chunk-QPYARJRD.cjs.map +1 -0
- package/dist/extensions.cjs +4 -2
- package/dist/extensions.cjs.map +1 -1
- package/dist/extensions.d.cts +1 -1
- package/dist/extensions.d.ts +1 -1
- package/dist/extensions.js +3 -1
- package/dist/index.cjs +634 -7
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +54 -136
- package/dist/index.d.ts +54 -136
- package/dist/index.js +633 -6
- package/dist/index.js.map +1 -1
- package/dist/operation/index.cjs +4 -4
- package/dist/operation/index.js +3 -3
- package/dist/reducer/index.cjs +8 -8
- package/dist/reducer/index.js +2 -2
- package/dist/utils.cjs +3 -3
- package/dist/utils.js +2 -2
- package/package.json +1 -2
- package/dist/chunk-4WJUHXQH.js +0 -866
- package/dist/chunk-4WJUHXQH.js.map +0 -1
- package/dist/chunk-6MDVLJ3A.js.map +0 -1
- package/dist/chunk-AYA3UT4L.cjs.map +0 -1
- package/dist/chunk-BJCTM2ME.cjs.map +0 -1
- package/dist/chunk-LJWHPW4H.cjs +0 -866
- package/dist/chunk-LJWHPW4H.cjs.map +0 -1
- package/dist/chunk-RQZ2BPMU.js.map +0 -1
- package/dist/chunk-S27IGTVG.js.map +0 -1
- package/dist/chunk-SCWW2SNX.cjs.map +0 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["/Users/erunion/code/readme/oas/packages/oas/dist/chunk-6HXOZ5GY.cjs","../src/extensions.ts"],"names":[],"mappings":"AAAA;AC+BO,IAAM,aAAA,EAAe,cAAA;AAoBrB,IAAM,iBAAA,EAAmB,kBAAA;AAwBzB,IAAM,QAAA,EAAU,SAAA;AAmBhB,IAAM,SAAA,EAAW,UAAA;AAmBjB,IAAM,gBAAA,EAAkB,iBAAA;AAkBxB,IAAM,cAAA,EAAgB,eAAA;AAuBtB,IAAM,mBAAA,EAAqB,oBAAA;AAoB3B,IAAM,cAAA,EAAgB,eAAA;AAiBtB,IAAM,kBAAA,EAAoB,mBAAA;AAc1B,IAAM,YAAA,EAAc,aAAA;AAepB,IAAM,oBAAA,EAAsB,qBAAA;AAe5B,IAAM,WAAA,EAAa,YAAA;AAmFnB,IAAM,kBAAA,EAAgC;AAAA,EAC3C,CAAC,YAAY,CAAA,EAAG,KAAA,CAAA;AAAA,EAChB,CAAC,mBAAmB,CAAA,EAAG,KAAA;AAAA,EACvB,CAAC,gBAAgB,CAAA,EAAG,IAAA;AAAA,EACpB,CAAC,OAAO,CAAA,EAAG,KAAA,CAAA;AAAA,EACX,CAAC,QAAQ,CAAA,EAAG,KAAA;AAAA,EACZ,CAAC,eAAe,CAAA,EAAG,IAAA;AAAA,EACnB,CAAC,aAAa,CAAA,EAAG,CAAC,CAAA;AAAA,EAClB,CAAC,kBAAkB,CAAA,EAAG,CAAC,MAAA,EAAQ,OAAA,EAAS,MAAA,EAAQ,QAAA,EAAU,MAAA,EAAQ,QAAQ,CAAA;AAAA,EAC1E,CAAC,aAAa,CAAA,EAAG,IAAA;AAAA,EACjB,CAAC,iBAAiB,CAAA,EAAG,CAAC,OAAA,EAAS,MAAA,EAAQ,MAAA,EAAQ,KAAA,EAAO,QAAA,EAAU,MAAA,EAAQ,QAAQ,CAAA;AAAA,EAChF,CAAC,WAAW,CAAA,EAAG,IAAA;AAAA,EACf,CAAC,UAAU,CAAA,EAAG,KAAA;AAChB,CAAA;AAMO,SAAS,gBAAA,CAAiB,SAAA,EAAsC,GAAA,EAA2B;AAChG,EAAA,OAAO,OAAA,CAAQ,IAAA,GAAO,UAAA,GAAa,GAAG,CAAA;AACxC;AAMO,SAAS,YAAA,CAAa,SAAA,EAAsC,GAAA,EAAkB,SAAA,EAA4B;AAC/G,EAAA,GAAA,CAAI,SAAA,EAAW;AACb,IAAA,GAAA,CAAI,SAAA,CAAU,YAAA,CAAa,UAAU,CAAA,EAAG;AACtC,MAAA,MAAM,KAAA,EAAO,SAAA,CAAU,YAAA,CAAa,UAAU,CAAA;AAC9C,MAAA,GAAA,CAAI,KAAA,GAAQ,OAAO,KAAA,IAAS,SAAA,GAAY,UAAA,GAAa,IAAA,EAAM;AACzD,QAAA,OAAO,IAAA,CAAK,SAA6B,CAAA;AAAA,MAC3C;AAAA,IACF;AAEA,IAAA,GAAA,CAAI,SAAA,CAAU,YAAA,CAAa,CAAA,EAAA,EAAK,SAAS,CAAA,CAAA;AACJ,MAAA;AACH,IAAA;AACO,MAAA;AACzC,IAAA;AACF,EAAA;AAIgC,EAAA;AACI,IAAA;AACpC,EAAA;AAEuC,EAAA;AACR,IAAA;AACW,IAAA;AACG,MAAA;AAC3C,IAAA;AACF,EAAA;AAE0C,EAAA;AACX,IAAA;AACW,EAAA;AAClB,IAAA;AACxB,EAAA;AAGoC,EAAA;AACoB,IAAA;AACxD,EAAA;AAEO,EAAA;AACT;AAUE;AAEe,EAAA;AACb,IAAA;AACF,EAAA;AAEuC,EAAA;AACH,EAAA;AACQ,EAAA;AAEJ,EAAA;AACL,IAAA;AACnC,EAAA;AAEqC,EAAA;AACO,EAAA;AACT,IAAA;AACnC,EAAA;AACF;ADhV8C;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA","file":"/Users/erunion/code/readme/oas/packages/oas/dist/chunk-6HXOZ5GY.cjs","sourcesContent":[null,"import type { Operation } from './operation/index.js';\nimport type { OASDocument } from './types.js';\n\n/**\n * Enables custom-written code samples to be set for your operations. Use this if you have specific\n * formatting that may not be followed by the auto-generated code samples. Custom code samples are\n * treated as static content.\n *\n * This extension only be placed at the operation level.\n *\n * @defaultValue []\n * @see {@link https://docs.readme.com/main/docs/openapi-extensions#custom-code-samples}\n * @example\n * {\n * \"x-readme\": {\n * \"code-samples\": [\n * {\n * \"language\": \"curl\",\n * \"code\": \"curl -X POST https://api.example.com/v2/alert\",\n * \"name\": \"Custom cURL snippet\",\n * \"install\": \"brew install curl\"\n * },\n * {\n * \"language\": \"php\",\n * \"code\": \"<?php echo \\\"This is our custom PHP code snippet.\\\"; ?>\",\n * \"name\": \"Custom PHP snippet\"\n * }\n * ]\n * }\n * }\n */\nexport const CODE_SAMPLES = 'code-samples';\n\n/**\n * Disables the API Explorer's \"Try It\" button, preventing users from making API requests from\n * within your docs. Users will still be able to fill out any entry fields (path or query\n * parameters, etc.), and code snippets will be auto-generated based on the user's input, however\n * to interact with your API the user will need to copy the code snippet and execute it outside of\n * your docs.\n *\n * This **does not** disable your API Reference documentation.\n *\n * @defaultValue true\n * @see {@link https://docs.readme.com/main/docs/openapi-extensions#disable-the-api-explorer}\n * @example\n * {\n * \"x-readme\": {\n * \"explorer-enabled\": true\n * }\n * }\n */\nexport const EXPLORER_ENABLED = 'explorer-enabled';\n\n/**\n * Adds static headers to add to each request. Use this when there are specific headers unique to\n * your API.\n *\n * @defaultValue []\n * @see {@link https://docs.readme.com/main/docs/openapi-extensions#static-headers}\n * @example\n * {\n * \"x-readme\": {\n * \"headers\": [\n * {\n * \"key\": \"X-Static-Header-One\",\n * \"value\": \"owlbert\"\n * },\n * {\n * \"key\": \"X-Static-Header-Two\",\n * \"value\": \"owlivia\"\n * }\n * ]\n * }\n * }\n */\nexport const HEADERS = 'headers';\n\n/**\n * Allows you to mark an API endpoint, or _every_ API endpoint if defined in the root, as being\n * internal and hidden from your public API reference.\n *\n * @defaultValue false\n * @see {@link https://docs.readme.com/main/docs/openapi-extensions#internal}\n * @example\n * {\n * \"x-internal\": true\n * }\n * @example\n * {\n * \"x-readme\": {\n * \"internal\": true\n * }\n * }\n */\nexport const INTERNAL = 'internal';\n\n/**\n * Disables API requests from the API Explorer's \"Try It\" button from being sent into our [API\n * Metrics](https://readme.com/metrics) for you and your users. Additionally on any API endpoint\n * that this is disabled on your users will not see lists or graphs of previous requests they've\n * made against that API endpoint — either through the API Explorer's interactivity or through one\n * of our [Metrics SDKs](https://docs.readme.com/main/docs/api-metrics-setup) (if you have those\n * installed on your API).\n *\n * @defaultValue true\n * @see {@link https://docs.readme.com/main/docs/openapi-extensions#disable-api-metrics}\n * @example\n * {\n * \"x-readme\": {\n * \"metrics-defaults\": false\n * }\n * }\n */\nexport const METRICS_ENABLED = 'metrics-enabled';\n\n/**\n * Configuration options for OAuth flows in the API Explorer.\n *\n * @defaultValue {}\n * @see {@link https://docs.readme.com/main/docs/openapi-extensions#oauth-configuration-options}\n * @example\n * {\n * \"x-readme\": {\n * \"oauth-options\": {\n * \"scopeSeparator\": \",\",\n * \"useInsecureClientAuthentication\": true,\n * \"usePkce\": false\n * }\n * }\n * }\n */\nexport const OAUTH_OPTIONS = 'oauth-options';\n\n/**\n * Controls the order of parameters on your API Reference pages.\n *\n * Your custom ordering **must** contain all of our available parameter types:\n *\n * - `path`: Path parameters\n * - `query`: Query parameters\n * - `body`: Non-`application/x-www-form-urlencoded` request body payloads\n * - `cookie`: Cookie parameters\n * - `form`: `application/x-www-form-urlencoded` request body payloads\n * - `header`: Header parameters\n *\n * @defaultValue ['path', 'query', 'body', 'cookie', 'form', 'header']\n * @see {@link https://docs.readme.com/main/docs/openapi-extensions#parameter-ordering}\n * @example\n * {\n * \"x-readme\": {\n * \"parameter-ordering\": ['path', 'query', 'header', 'cookie', 'body', 'form']\n * }\n * }\n */\nexport const PARAMETER_ORDERING = 'parameter-ordering';\n\n/**\n * Toggles the CORS proxy used when making API requests from within your docs (via the \"Try It\"\n * button). If your API is already set up to return CORS headers, you can safely disable this\n * feature.\n *\n * Disabling the CORS proxy will make the request directly from the user's browser and will prevent\n * [Metrics](https://docs.readme.com/main/docs/getting-started-with-metrics) data from being logged\n * by us unless [Metrics have already set up on your backend](https://docs.readme.com/main/docs/api-metrics-setup).\n *\n * @defaultValue true\n * @see {@link https://docs.readme.com/main/docs/openapi-extensions#cors-proxy-enabled}\n * @example\n * {\n * \"x-readme\": {\n * \"proxy-enabled\": true\n * }\n * }\n */\nexport const PROXY_ENABLED = 'proxy-enabled';\n\n/**\n * Toggles what languages are shown by default for code samples in the API Explorer. This only\n * affects what languages are initially shown to the user; if the user picks another language from\n * the three-dot menu, that language and the respective auto-generated code snippet will also appear\n * as an option in the API Explorer.\n *\n * @defaultValue ['shell', 'node', 'ruby', 'php', 'python', 'java', 'csharp']\n * @see {@link https://docs.readme.com/main/docs/openapi-extensions#code-sample-languages}\n * @example\n * {\n * \"x-readme\": {\n * \"samples-languages\": [\"shell\", \"node\", \"ruby\", \"javascript\", \"python\"]\n * }\n * }\n */\nexport const SAMPLES_LANGUAGES = 'samples-languages';\n\n/**\n * Toggles if you will see code snippets for ReadMe's SDK code generator tool `api`.\n *\n * @defaultValue true\n * @see {@link https://api.readme.dev}\n * @example\n * {\n * \"x-readme\": {\n * \"simple-mode\": false\n * }\n * }\n */\nexport const SIMPLE_MODE = 'simple-mode';\n\n/**\n * If `true`, tags are generated from the file top-down. If `false`, we sort the tags\n * based off the `tags` array in the OAS file.\n *\n * @defaultValue false\n * @see {@link https://docs.readme.com/main/docs/openapi-extensions#disable-tag-sorting}\n * @example\n * {\n * \"x-readme\": {\n * \"disable-tag-sorting\": true\n * }\n * }\n */\nexport const DISABLE_TAG_SORTING = 'disable-tag-sorting';\n\n/**\n * A customer-declared health/status URL for the API. When present, it's surfaced to AI agents as\n * the RFC 9727 `status` link relation in the project's `/.well-known/api-catalog`.\n *\n * @see {@link https://docs.readme.com/main/docs/openapi-extensions}\n * @see {@link https://www.rfc-editor.org/rfc/rfc9727}\n * @example\n * {\n * \"x-readme\": {\n * \"status-url\": \"https://status.example.com\"\n * }\n * }\n */\nexport const STATUS_URL = 'status-url';\n\nexport interface Extensions {\n [CODE_SAMPLES]:\n | {\n /**\n * Custom code snippet\n * @example \"curl -X POST https://api.example.com/v2/alert\"\n */\n code: string;\n /**\n * Corresponding response example\n * @see {@link https://docs.readme.com/main/docs/openapi-extensions#corresponding-response-examples}\n */\n correspondingExample?: string;\n /**\n * Library installation instructions\n * @example \"brew install httpie\"\n * @example \"npm install node-fetch@2 --save\"\n */\n install?: string;\n /**\n * Language for syntax highlighting\n * @example shell\n */\n language: string;\n /**\n * Optional title for code sample\n * @example \"Custom cURL snippet\"\n */\n name?: string;\n }[]\n | undefined;\n [DISABLE_TAG_SORTING]: boolean;\n [EXPLORER_ENABLED]: boolean;\n [HEADERS]: Record<string, number | string>[] | undefined;\n [INTERNAL]: boolean;\n [METRICS_ENABLED]: boolean;\n [OAUTH_OPTIONS]: {\n /**\n * Scope separator for passing scopes. This value will be URL-encoded.\n *\n * @example \",\"\n * @example \"+\"\n * @default \" \"\n * @see {@link https://datatracker.ietf.org/doc/html/rfc6749#section-3.3} Scope separators information from OAuth 2.0 specification\n */\n scopeSeparator?: string;\n\n /**\n * When enabled, the client credentials (i.e., `client_id` and `client_secret`) are sent in the request body (NOT recommended).\n * When disabled (the default), client credentials are sent using the HTTP Basic Authentication scheme.\n *\n * This is applicable for all requests to the token endpoint.\n *\n * @see {@link https://datatracker.ietf.org/doc/html/rfc6749#section-2.3.1}\n * @see {@link https://datatracker.ietf.org/doc/html/rfc6749#section-3.2}\n *\n * @example true\n * @default false\n */\n useInsecureClientAuthentication?: boolean;\n\n /**\n * When enabled, uses PKCE (Proof Key for Code Exchange) for the authorization code flow.\n * The client secret is replaced with an auto-generated code verifier and code challenge.\n * When disabled, uses the standard OAuth 2.0 authorization code flow with client credentials.\n *\n * @see {@link https://datatracker.ietf.org/doc/html/rfc7636#section-4.1}\n * @see {@link https://datatracker.ietf.org/doc/html/rfc7636#section-4.2}\n *\n * @example true\n * @default false\n */\n usePkce?: boolean;\n };\n [PARAMETER_ORDERING]: ('body' | 'cookie' | 'form' | 'header' | 'path' | 'query')[];\n [PROXY_ENABLED]: boolean;\n [SAMPLES_LANGUAGES]: string[];\n [SIMPLE_MODE]: boolean;\n [STATUS_URL]: string | undefined;\n}\n\nexport const extensionDefaults: Extensions = {\n [CODE_SAMPLES]: undefined,\n [DISABLE_TAG_SORTING]: false,\n [EXPLORER_ENABLED]: true,\n [HEADERS]: undefined,\n [INTERNAL]: false,\n [METRICS_ENABLED]: true,\n [OAUTH_OPTIONS]: {},\n [PARAMETER_ORDERING]: ['path', 'query', 'body', 'cookie', 'form', 'header'],\n [PROXY_ENABLED]: true,\n [SAMPLES_LANGUAGES]: ['shell', 'node', 'ruby', 'php', 'python', 'java', 'csharp'],\n [SIMPLE_MODE]: true,\n [STATUS_URL]: undefined,\n};\n\n/**\n * Determing if an OpenAPI definition has an extension set in its root schema.\n *\n */\nexport function hasRootExtension(extension: string | keyof Extensions, api: OASDocument): boolean {\n return Boolean(api && extension in api);\n}\n\n/**\n * Retrieve a custom specification extension off of the API definition.\n *\n */\nexport function getExtension(extension: string | keyof Extensions, api: OASDocument, operation?: Operation): any {\n if (operation) {\n if (operation.hasExtension('x-readme')) {\n const data = operation.getExtension('x-readme') as Extensions;\n if (data && typeof data === 'object' && extension in data) {\n return data[extension as keyof Extensions];\n }\n }\n\n if (operation.hasExtension(`x-${extension}`)) {\n return operation.getExtension(`x-${extension}`);\n } else if (operation.hasExtension(extension)) {\n return operation.getExtension(extension);\n }\n }\n\n // Because our `code-samples` extension is intended for operation-level use, if it's instead\n // placed at the API definition root level then we should ignore it and return our set defaults.\n if (extension === CODE_SAMPLES) {\n return extensionDefaults[extension];\n }\n\n if (hasRootExtension('x-readme', api)) {\n const data = api?.['x-readme'] as Extensions;\n if (data && typeof data === 'object' && extension in data) {\n return data[extension as keyof Extensions];\n }\n }\n\n if (hasRootExtension(`x-${extension}`, api)) {\n return api?.[`x-${extension}`];\n } else if (hasRootExtension(extension, api)) {\n return api?.[extension];\n }\n\n // If this is otherwise an extension of our own then we should return the default value for it.\n if (extension in extensionDefaults) {\n return extensionDefaults[extension as keyof Extensions];\n }\n\n return undefined;\n}\n\n/**\n * Validate that the data for an instanceof our `PARAMETER_ORDERING` extension is properly\n * configured.\n *\n * @private\n */\nexport function validateParameterOrdering(\n ordering: (typeof extensionDefaults)[typeof PARAMETER_ORDERING] | undefined,\n extension: string,\n): void {\n if (!ordering) {\n return;\n }\n\n const defaultValue = extensionDefaults[PARAMETER_ORDERING];\n const requiredLength = defaultValue.length;\n const defaultsHuman = `${defaultValue.slice(0, -1).join(', ')}, and ${defaultValue.slice(-1)}`;\n\n if (ordering.length !== requiredLength) {\n throw new TypeError(`\"${extension}\" must contain ${requiredLength} items comprised of: ${defaultsHuman}`);\n }\n\n const intersection = ordering.filter(value => defaultValue.includes(value.toLowerCase() as any));\n if (intersection.length !== requiredLength) {\n throw new TypeError(`\"${extension}\" must contain ${requiredLength} items comprised of: ${defaultsHuman}`);\n }\n}\n"]}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import {
|
|
2
|
+
SERVER_VARIABLE_REGEX,
|
|
2
3
|
applyDiscriminatorOneOfToUsedSchemas,
|
|
3
4
|
cloneObject,
|
|
4
5
|
collectRefsInSchema,
|
|
@@ -6,7 +7,6 @@ import {
|
|
|
6
7
|
dereferenceRef,
|
|
7
8
|
dereferenceRefDeep,
|
|
8
9
|
filterRequiredRefsToReferenced,
|
|
9
|
-
getDereferencingOptions,
|
|
10
10
|
getParametersAsJSONSchema,
|
|
11
11
|
getSchemaVersionString,
|
|
12
12
|
isObject,
|
|
@@ -15,16 +15,167 @@ import {
|
|
|
15
15
|
mergeReferencedSchemasIntoRoot,
|
|
16
16
|
supportedMethods,
|
|
17
17
|
toJSONSchema
|
|
18
|
-
} from "./chunk-
|
|
18
|
+
} from "./chunk-6APWNY54.js";
|
|
19
19
|
import {
|
|
20
20
|
getExtension
|
|
21
|
-
} from "./chunk-
|
|
21
|
+
} from "./chunk-LZNTJ4ZR.js";
|
|
22
22
|
import {
|
|
23
23
|
isRef
|
|
24
24
|
} from "./chunk-XG4HGNCN.js";
|
|
25
25
|
|
|
26
|
-
// src/
|
|
27
|
-
import {
|
|
26
|
+
// src/lib/urls.ts
|
|
27
|
+
import { match, pathToRegexp } from "path-to-regexp";
|
|
28
|
+
|
|
29
|
+
// src/lib/get-user-variable.ts
|
|
30
|
+
function getUserVariable(user, property, selectedApp) {
|
|
31
|
+
let key = user;
|
|
32
|
+
if ("keys" in user && Array.isArray(user.keys) && user.keys.length) {
|
|
33
|
+
if (selectedApp) {
|
|
34
|
+
key = user.keys.find((k) => k.name === selectedApp);
|
|
35
|
+
} else {
|
|
36
|
+
key = user.keys[0];
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
return key?.[property] || user[property] || null;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
// src/lib/urls.ts
|
|
43
|
+
function stripTrailingSlash(url) {
|
|
44
|
+
if (url[url.length - 1] === "/") {
|
|
45
|
+
return url.slice(0, -1);
|
|
46
|
+
}
|
|
47
|
+
return url;
|
|
48
|
+
}
|
|
49
|
+
function ensureProtocol(url) {
|
|
50
|
+
if (url.match(/^\/\//)) {
|
|
51
|
+
return `https:${url}`;
|
|
52
|
+
}
|
|
53
|
+
if (!url.match(/\/\//)) {
|
|
54
|
+
return `https://${url}`;
|
|
55
|
+
}
|
|
56
|
+
return url;
|
|
57
|
+
}
|
|
58
|
+
function normalizedURLFromServers(servers, selected) {
|
|
59
|
+
const exampleDotCom = "https://example.com";
|
|
60
|
+
let url;
|
|
61
|
+
try {
|
|
62
|
+
url = servers?.[selected]?.url;
|
|
63
|
+
if (!url) throw new Error("no url");
|
|
64
|
+
url = stripTrailingSlash(url);
|
|
65
|
+
if (url.startsWith("/") && !url.startsWith("//")) {
|
|
66
|
+
const urlWithOrigin = new URL(exampleDotCom);
|
|
67
|
+
urlWithOrigin.pathname = url;
|
|
68
|
+
url = urlWithOrigin.href;
|
|
69
|
+
}
|
|
70
|
+
} catch {
|
|
71
|
+
url = exampleDotCom;
|
|
72
|
+
}
|
|
73
|
+
return ensureProtocol(url);
|
|
74
|
+
}
|
|
75
|
+
function variablesFromServers(servers, selected = 0) {
|
|
76
|
+
return servers?.[selected]?.variables || {};
|
|
77
|
+
}
|
|
78
|
+
function defaultVariablesFromServers(servers, selected = 0, user = {}) {
|
|
79
|
+
const variables = variablesFromServers(servers, selected);
|
|
80
|
+
const defaults = {};
|
|
81
|
+
Object.keys(variables).forEach((key) => {
|
|
82
|
+
defaults[key] = getUserVariable(user, key) || variables[key].default || "";
|
|
83
|
+
});
|
|
84
|
+
return defaults;
|
|
85
|
+
}
|
|
86
|
+
function splitUrlFromServers(servers, selected = 0) {
|
|
87
|
+
const url = normalizedURLFromServers(servers, selected);
|
|
88
|
+
const variables = variablesFromServers(servers, selected);
|
|
89
|
+
return url.split(/({.+?})/).filter(Boolean).map((part, i) => {
|
|
90
|
+
const isVariable = part.match(/[{}]/);
|
|
91
|
+
const value = part.replace(/[{}]/g, "");
|
|
92
|
+
const key = `${value}-${i}`;
|
|
93
|
+
if (!isVariable) {
|
|
94
|
+
return {
|
|
95
|
+
type: "text",
|
|
96
|
+
value,
|
|
97
|
+
key
|
|
98
|
+
};
|
|
99
|
+
}
|
|
100
|
+
const variable = variables?.[value];
|
|
101
|
+
return {
|
|
102
|
+
type: "variable",
|
|
103
|
+
value,
|
|
104
|
+
key,
|
|
105
|
+
description: variable?.description,
|
|
106
|
+
enum: variable?.enum
|
|
107
|
+
};
|
|
108
|
+
});
|
|
109
|
+
}
|
|
110
|
+
function transformURLIntoRegex(url) {
|
|
111
|
+
return stripTrailingSlash(url.replace(SERVER_VARIABLE_REGEX, "([-_a-zA-Z0-9:.[\\]]+)"));
|
|
112
|
+
}
|
|
113
|
+
function normalizePath(path) {
|
|
114
|
+
return path.replace(/({?){(.*?)}(}?)/g, (str, ...args) => {
|
|
115
|
+
return `:${args[1].replace("-", "")}`;
|
|
116
|
+
}).replace(/::/, "\\::").split("?")[0];
|
|
117
|
+
}
|
|
118
|
+
function generatePathMatches(paths, pathName, origin) {
|
|
119
|
+
const prunedPathName = pathName.split("?")[0];
|
|
120
|
+
const matches = Object.keys(paths).map((path) => {
|
|
121
|
+
const cleanedPath = normalizePath(path);
|
|
122
|
+
let matchResult;
|
|
123
|
+
try {
|
|
124
|
+
const matchStatement = match(cleanedPath, { decode: decodeURIComponent });
|
|
125
|
+
matchResult = matchStatement(prunedPathName);
|
|
126
|
+
} catch {
|
|
127
|
+
return false;
|
|
128
|
+
}
|
|
129
|
+
const slugs = {};
|
|
130
|
+
if (matchResult && Object.keys(matchResult.params).length) {
|
|
131
|
+
Object.keys(matchResult.params).forEach((param) => {
|
|
132
|
+
slugs[`:${param}`] = matchResult.params[param];
|
|
133
|
+
});
|
|
134
|
+
}
|
|
135
|
+
return {
|
|
136
|
+
url: {
|
|
137
|
+
origin,
|
|
138
|
+
path: cleanedPath.replace(/\\::/, "::"),
|
|
139
|
+
nonNormalizedPath: path,
|
|
140
|
+
slugs
|
|
141
|
+
},
|
|
142
|
+
operation: paths[path],
|
|
143
|
+
match: matchResult
|
|
144
|
+
};
|
|
145
|
+
}).filter((item) => item !== false);
|
|
146
|
+
return matches.filter((p) => p.match);
|
|
147
|
+
}
|
|
148
|
+
function filterPathMethods(pathMatches, targetMethod) {
|
|
149
|
+
const regExp = pathToRegexp(targetMethod);
|
|
150
|
+
return pathMatches.map((p) => {
|
|
151
|
+
const captures = Object.keys(p.operation).filter((r) => regExp.regexp.exec(r));
|
|
152
|
+
if (captures.length) {
|
|
153
|
+
const method = captures[0];
|
|
154
|
+
p.url.method = method.toUpperCase();
|
|
155
|
+
return {
|
|
156
|
+
url: p.url,
|
|
157
|
+
operation: p.operation[method]
|
|
158
|
+
};
|
|
159
|
+
}
|
|
160
|
+
return false;
|
|
161
|
+
}).filter((item) => Boolean(item));
|
|
162
|
+
}
|
|
163
|
+
function findTargetPath(pathMatches) {
|
|
164
|
+
if (!pathMatches.length) {
|
|
165
|
+
return void 0;
|
|
166
|
+
}
|
|
167
|
+
let minCount = Object.keys(pathMatches[0].url.slugs).length;
|
|
168
|
+
let found;
|
|
169
|
+
for (let m = 0; m < pathMatches.length; m += 1) {
|
|
170
|
+
const selection = pathMatches[m];
|
|
171
|
+
const paramCount = Object.keys(selection.url.slugs).length;
|
|
172
|
+
if (paramCount <= minCount) {
|
|
173
|
+
minCount = paramCount;
|
|
174
|
+
found = selection;
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
return found;
|
|
178
|
+
}
|
|
28
179
|
|
|
29
180
|
// src/operation/lib/dedupe-common-parameters.ts
|
|
30
181
|
function dedupeCommonParameters(parameters, commonParameters) {
|
|
@@ -552,7 +703,7 @@ function getOperationId(path, method, operation, opts = {}) {
|
|
|
552
703
|
if (operationIdExists) {
|
|
553
704
|
operationId = sanitize(operationId);
|
|
554
705
|
}
|
|
555
|
-
operationId = operationId.replace(/^[0-9]/g, (
|
|
706
|
+
operationId = operationId.replace(/^[0-9]/g, (match2) => `_${match2}`);
|
|
556
707
|
operationId = operationId.charAt(0).toLowerCase() + operationId.slice(1);
|
|
557
708
|
if (operationId.startsWith(currMethod)) {
|
|
558
709
|
return operationId;
|
|
@@ -790,24 +941,6 @@ var Operation = class {
|
|
|
790
941
|
* Flattened out arrays of both request and response headers that are utilized on this operation.
|
|
791
942
|
*/
|
|
792
943
|
headers;
|
|
793
|
-
/**
|
|
794
|
-
* Internal storage array that the library utilizes to keep track of the times the
|
|
795
|
-
* {@see Operation.dereference} has been called so that if you initiate multiple promises they'll
|
|
796
|
-
* all end up returning the same data set once the initial dereference call completed.
|
|
797
|
-
*/
|
|
798
|
-
promises;
|
|
799
|
-
/**
|
|
800
|
-
* Internal storage array that the library utilizes to keep track of its `dereferencing` state so
|
|
801
|
-
* it doesn't initiate multiple dereferencing processes.
|
|
802
|
-
*/
|
|
803
|
-
dereferencing;
|
|
804
|
-
/**
|
|
805
|
-
* Have the component schemas within this API definition been decorated with our
|
|
806
|
-
* `x-readme-ref-name` extension?
|
|
807
|
-
*
|
|
808
|
-
* @see {@link decorateComponentSchemas}
|
|
809
|
-
*/
|
|
810
|
-
schemasDecorated = false;
|
|
811
944
|
constructor(oas, path, method, operation) {
|
|
812
945
|
this.oas = oas;
|
|
813
946
|
this.schema = operation;
|
|
@@ -823,12 +956,6 @@ var Operation = class {
|
|
|
823
956
|
request: [],
|
|
824
957
|
response: []
|
|
825
958
|
};
|
|
826
|
-
this.promises = [];
|
|
827
|
-
this.dereferencing = {
|
|
828
|
-
processing: false,
|
|
829
|
-
complete: false,
|
|
830
|
-
circularRefs: []
|
|
831
|
-
};
|
|
832
959
|
}
|
|
833
960
|
/**
|
|
834
961
|
* Retrieve the `summary` for this operation.
|
|
@@ -862,6 +989,35 @@ var Operation = class {
|
|
|
862
989
|
}
|
|
863
990
|
return void 0;
|
|
864
991
|
}
|
|
992
|
+
/**
|
|
993
|
+
* Retrieve the server objects that apply to this operation, using OpenAPI server precedence:
|
|
994
|
+
* operation-level servers, then path-item servers, then root-level servers.
|
|
995
|
+
*/
|
|
996
|
+
getServers() {
|
|
997
|
+
if (this.schema.servers?.length) {
|
|
998
|
+
return this.schema.servers;
|
|
999
|
+
}
|
|
1000
|
+
if (this.api.paths?.[this.path]) {
|
|
1001
|
+
const pathItem = dereferenceRef(this.api.paths[this.path], this.api);
|
|
1002
|
+
if (pathItem && !isRef(pathItem) && pathItem.servers?.length) {
|
|
1003
|
+
return pathItem.servers;
|
|
1004
|
+
}
|
|
1005
|
+
}
|
|
1006
|
+
return this.api.servers || [];
|
|
1007
|
+
}
|
|
1008
|
+
url(selected = 0, variables) {
|
|
1009
|
+
const url = normalizedURLFromServers(this.getServers(), selected);
|
|
1010
|
+
return this.oas.replaceUrl(url, variables || this.defaultVariables(selected)).trim();
|
|
1011
|
+
}
|
|
1012
|
+
variables(selected = 0) {
|
|
1013
|
+
return variablesFromServers(this.getServers(), selected);
|
|
1014
|
+
}
|
|
1015
|
+
defaultVariables(selected = 0) {
|
|
1016
|
+
return defaultVariablesFromServers(this.getServers(), selected, this.oas.user);
|
|
1017
|
+
}
|
|
1018
|
+
splitUrl(selected = 0) {
|
|
1019
|
+
return splitUrlFromServers(this.getServers(), selected);
|
|
1020
|
+
}
|
|
865
1021
|
/**
|
|
866
1022
|
* Retrieve the primary content type for this operation. If multiple exist, the first JSON-like
|
|
867
1023
|
* type will be returned.
|
|
@@ -1245,15 +1401,7 @@ var Operation = class {
|
|
|
1245
1401
|
*
|
|
1246
1402
|
*/
|
|
1247
1403
|
getParametersAsJSONSchema(opts = {}) {
|
|
1248
|
-
|
|
1249
|
-
throw new Error(
|
|
1250
|
-
"`.getParametersAsJSONSchema()` is not compatible with an operation or OpenAPI definition that has been run through `.dereference().`"
|
|
1251
|
-
);
|
|
1252
|
-
}
|
|
1253
|
-
if (!this.schemasDecorated) {
|
|
1254
|
-
decorateComponentSchemasWithRefName(this.api);
|
|
1255
|
-
this.schemasDecorated = true;
|
|
1256
|
-
}
|
|
1404
|
+
decorateComponentSchemasWithRefName(this.api);
|
|
1257
1405
|
return getParametersAsJSONSchema(this, this.api, {
|
|
1258
1406
|
includeDiscriminatorMappingRefs: true,
|
|
1259
1407
|
...opts
|
|
@@ -1273,15 +1421,7 @@ var Operation = class {
|
|
|
1273
1421
|
* this content-type, the function will return null.
|
|
1274
1422
|
*/
|
|
1275
1423
|
getResponseAsJSONSchema(statusCode, opts = {}) {
|
|
1276
|
-
|
|
1277
|
-
throw new Error(
|
|
1278
|
-
"`.getResponseAsJSONSchema()` is not compatible with an operation or OpenAPI definition that has been run through `.dereference().`"
|
|
1279
|
-
);
|
|
1280
|
-
}
|
|
1281
|
-
if (!this.schemasDecorated) {
|
|
1282
|
-
decorateComponentSchemasWithRefName(this.api);
|
|
1283
|
-
this.schemasDecorated = true;
|
|
1284
|
-
}
|
|
1424
|
+
decorateComponentSchemasWithRefName(this.api);
|
|
1285
1425
|
return getResponseAsJSONSchema(this, this.api, statusCode, {
|
|
1286
1426
|
includeDiscriminatorMappingRefs: true,
|
|
1287
1427
|
...opts
|
|
@@ -1627,107 +1767,6 @@ var Operation = class {
|
|
|
1627
1767
|
this.exampleGroups = groups;
|
|
1628
1768
|
return groups;
|
|
1629
1769
|
}
|
|
1630
|
-
/**
|
|
1631
|
-
* Dereference the current operation schema so it can be parsed free of worries of `$ref` schemas
|
|
1632
|
-
* and circular structures.
|
|
1633
|
-
*
|
|
1634
|
-
*/
|
|
1635
|
-
async dereference(opts) {
|
|
1636
|
-
if (this.dereferencing.complete) {
|
|
1637
|
-
return Promise.resolve(true);
|
|
1638
|
-
}
|
|
1639
|
-
if (this.dereferencing.processing) {
|
|
1640
|
-
return new Promise((resolve, reject) => {
|
|
1641
|
-
this.promises.push({ resolve, reject });
|
|
1642
|
-
});
|
|
1643
|
-
}
|
|
1644
|
-
this.dereferencing.processing = true;
|
|
1645
|
-
if (!this.schemasDecorated) {
|
|
1646
|
-
decorateComponentSchemasWithRefName(this.api);
|
|
1647
|
-
this.schemasDecorated = true;
|
|
1648
|
-
}
|
|
1649
|
-
const { api, schema, promises } = this;
|
|
1650
|
-
const circularRefs = /* @__PURE__ */ new Set();
|
|
1651
|
-
const dereferencingOptions = getDereferencingOptions(circularRefs);
|
|
1652
|
-
const parser = new $RefParser();
|
|
1653
|
-
return parser.dereference(
|
|
1654
|
-
"#/__INTERNAL__",
|
|
1655
|
-
{
|
|
1656
|
-
// Because `json-schema-ref-parser` will dereference this entire object as we only want
|
|
1657
|
-
// to dereference this operation schema we're attaching it to the `__INTERNAL__` key, and
|
|
1658
|
-
// later using that to extract our dereferenced schema. If we didn't do this then we run
|
|
1659
|
-
// the risk of any keyword in `schema` being overriden by `paths` and `components`.
|
|
1660
|
-
//
|
|
1661
|
-
// This solution isn't the best and still requires us to send `json-schema-ref-parser`
|
|
1662
|
-
// basically the entire API defintiion but because we don't know what `$ref` pointers in
|
|
1663
|
-
// `schema` reference, we can't know which parts of full API definition we could safely
|
|
1664
|
-
// exclude from this process.
|
|
1665
|
-
__INTERNAL__: structuredClone(schema),
|
|
1666
|
-
paths: api.paths ?? void 0,
|
|
1667
|
-
components: api.components ?? void 0
|
|
1668
|
-
},
|
|
1669
|
-
{
|
|
1670
|
-
...dereferencingOptions,
|
|
1671
|
-
dereference: {
|
|
1672
|
-
...dereferencingOptions.dereference,
|
|
1673
|
-
/**
|
|
1674
|
-
* Because we only want to dereference our `__INTERNAL__` schema, not the **entire**
|
|
1675
|
-
* API definition if the parser attemps to dereference anything but that then we
|
|
1676
|
-
* should bail out of that crawler.
|
|
1677
|
-
*
|
|
1678
|
-
* @fixme this may cause issues where a path references a schema within itself to be ignored.
|
|
1679
|
-
*/
|
|
1680
|
-
excludedPathMatcher: (path) => {
|
|
1681
|
-
if (path === "#/paths" || path.startsWith("#/paths/")) {
|
|
1682
|
-
return true;
|
|
1683
|
-
}
|
|
1684
|
-
return path === "#/components" || path.startsWith("#/components/");
|
|
1685
|
-
}
|
|
1686
|
-
}
|
|
1687
|
-
}
|
|
1688
|
-
).then((res) => {
|
|
1689
|
-
const dereferenced = res;
|
|
1690
|
-
this.schema = dereferenced.__INTERNAL__;
|
|
1691
|
-
this.promises = promises;
|
|
1692
|
-
this.dereferencing = {
|
|
1693
|
-
processing: false,
|
|
1694
|
-
complete: true,
|
|
1695
|
-
// We need to convert our `Set` to an array in order to match the typings.
|
|
1696
|
-
circularRefs: [...circularRefs]
|
|
1697
|
-
};
|
|
1698
|
-
if (opts?.cb) {
|
|
1699
|
-
opts.cb();
|
|
1700
|
-
}
|
|
1701
|
-
}).then(() => {
|
|
1702
|
-
return this.promises.map((deferred) => deferred.resolve());
|
|
1703
|
-
}).catch((err) => {
|
|
1704
|
-
this.dereferencing.processing = false;
|
|
1705
|
-
this.promises.map((deferred) => deferred.reject(err));
|
|
1706
|
-
throw err;
|
|
1707
|
-
});
|
|
1708
|
-
}
|
|
1709
|
-
/**
|
|
1710
|
-
* Determine if the current operation schema, or the OpenAPI definition it's part of, has been
|
|
1711
|
-
* dereferenced or not with `.dereference()`.
|
|
1712
|
-
*
|
|
1713
|
-
* @see Operation.dereference
|
|
1714
|
-
*/
|
|
1715
|
-
isDereferenced() {
|
|
1716
|
-
return this.oas.isDereferenced() || this.dereferencing.processing || this.dereferencing.complete;
|
|
1717
|
-
}
|
|
1718
|
-
/**
|
|
1719
|
-
* Retrieve any circular `$ref` pointers that maybe present within operation schema.
|
|
1720
|
-
*
|
|
1721
|
-
* This method requires that you first dereference the definition.
|
|
1722
|
-
*
|
|
1723
|
-
* @see Operation.dereference
|
|
1724
|
-
*/
|
|
1725
|
-
getCircularReferences() {
|
|
1726
|
-
if (!this.dereferencing.complete) {
|
|
1727
|
-
throw new Error(".dereference() must be called first in order for this method to obtain circular references.");
|
|
1728
|
-
}
|
|
1729
|
-
return this.dereferencing.circularRefs;
|
|
1730
|
-
}
|
|
1731
1770
|
};
|
|
1732
1771
|
var Callback = class extends Operation {
|
|
1733
1772
|
/**
|
|
@@ -1851,6 +1890,16 @@ var Webhook = class extends Operation {
|
|
|
1851
1890
|
};
|
|
1852
1891
|
|
|
1853
1892
|
export {
|
|
1893
|
+
getUserVariable,
|
|
1894
|
+
stripTrailingSlash,
|
|
1895
|
+
normalizedURLFromServers,
|
|
1896
|
+
variablesFromServers,
|
|
1897
|
+
defaultVariablesFromServers,
|
|
1898
|
+
splitUrlFromServers,
|
|
1899
|
+
transformURLIntoRegex,
|
|
1900
|
+
generatePathMatches,
|
|
1901
|
+
filterPathMethods,
|
|
1902
|
+
findTargetPath,
|
|
1854
1903
|
Operation,
|
|
1855
1904
|
Callback,
|
|
1856
1905
|
Webhook
|
|
@@ -1867,4 +1916,4 @@ export {
|
|
|
1867
1916
|
* @license Apache-2.0
|
|
1868
1917
|
* @see {@link https://github.com/swagger-api/swagger-ui/blob/master/src/core/plugins/samples/fn.js}
|
|
1869
1918
|
*/
|
|
1870
|
-
//# sourceMappingURL=chunk-
|
|
1919
|
+
//# sourceMappingURL=chunk-I7R3WTTN.js.map
|