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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;AAEuC,EAAA;AACH,EAAA;AACQ,EAAA;AAEJ,EAAA;AACL,IAAA;AACnC,EAAA;AAEqC,EAAA;AACO,EAAA;AACT,IAAA;AACnC,EAAA;AACF;AD7R8C;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-XS7VDTTT.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 * 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-options}\n * @example\n * {\n *  \"x-readme\": {\n *    \"oauth-options\": {\n *      \"scopeSeparator\": \",\",\n *      \"useInsecureClientAuthentication\": true\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\nexport interface Extensions {\n  [CODE_SAMPLES]: {\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  [DISABLE_TAG_SORTING]: boolean;\n  [EXPLORER_ENABLED]: boolean;\n  [HEADERS]: Record<string, number | string>[];\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  [PARAMETER_ORDERING]: ('body' | 'cookie' | 'form' | 'header' | 'path' | 'query')[];\n  [PROXY_ENABLED]: boolean;\n  [SAMPLES_LANGUAGES]: string[];\n  [SIMPLE_MODE]: boolean;\n}\n\nexport const extensionDefaults: Extensions = {\n  [CODE_SAMPLES]: undefined,\n  [DISABLE_TAG_SORTING]: false,\n  [EXPLORER_ENABLED]: true,\n  [HEADERS]: undefined,\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};\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  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"]}