@mintlify/msft-sdk 1.1.24 → 1.1.25
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/api-playground/ApiPlayground/Request/PlaygroundModal.js +46 -45
- package/dist/api-playground/ApiPlayground/Request/PlaygroundModal.js.map +1 -1
- package/dist/api-playground/ApiPlayground/Request/index.js +18 -18
- package/dist/api-playground/ApiPlayground/Request/index.js.map +1 -1
- package/dist/api-playground/ApiPlayground/components/EndpointsMenu.js +20 -21
- package/dist/api-playground/ApiPlayground/components/EndpointsMenu.js.map +1 -1
- package/dist/api-playground/ApiPlayground/components/EndpointsMenuLink.js +10 -11
- package/dist/api-playground/ApiPlayground/components/EndpointsMenuLink.js.map +1 -1
- package/dist/api-playground/ApiPlayground/index.js +30 -30
- package/dist/api-playground/ApiPlayground/index.js.map +1 -1
- package/dist/api-playground-2/constants/index.js +12 -3
- package/dist/api-playground-2/constants/index.js.map +1 -1
- package/dist/api-playground-2/schemaGraph/addUniqueKeysToSchema.js +41 -0
- package/dist/api-playground-2/schemaGraph/addUniqueKeysToSchema.js.map +1 -0
- package/dist/api-playground-2/schemaGraph/errors.js +19 -0
- package/dist/api-playground-2/schemaGraph/errors.js.map +1 -0
- package/dist/api-playground-2/schemaGraph/getApiReferenceDataFromGraph.js +26 -0
- package/dist/api-playground-2/schemaGraph/getApiReferenceDataFromGraph.js.map +1 -0
- package/dist/api-playground-2/schemaGraph/getDocumentProperties.js +58 -0
- package/dist/api-playground-2/schemaGraph/getDocumentProperties.js.map +1 -0
- package/dist/api-playground-2/schemaGraph/getSchemaGraphOperationData.js +77 -0
- package/dist/api-playground-2/schemaGraph/getSchemaGraphOperationData.js.map +1 -0
- package/dist/api-playground-2/schemaGraph/getSchemaGraphSchemaData.js +16 -0
- package/dist/api-playground-2/schemaGraph/getSchemaGraphSchemaData.js.map +1 -0
- package/dist/api-playground-2/schemaGraph/processExamples.js +111 -34
- package/dist/api-playground-2/schemaGraph/processExamples.js.map +1 -1
- package/dist/api-playground-2/schemaGraph/reduceCompositions.js +283 -0
- package/dist/api-playground-2/schemaGraph/reduceCompositions.js.map +1 -0
- package/dist/api-playground-2/schemaGraph/resolveGraphNode.js +61 -0
- package/dist/api-playground-2/schemaGraph/resolveGraphNode.js.map +1 -0
- package/dist/api-playground-2/schemaGraph/resolveOperationWithDependencies.js +149 -0
- package/dist/api-playground-2/schemaGraph/resolveOperationWithDependencies.js.map +1 -0
- package/dist/api-playground-2/schemaGraph/resolveSchemaWithDependencies.js +33 -0
- package/dist/api-playground-2/schemaGraph/resolveSchemaWithDependencies.js.map +1 -0
- package/dist/api-playground-2/schemaGraph/sortSchemaByRequired.js +35 -0
- package/dist/api-playground-2/schemaGraph/sortSchemaByRequired.js.map +1 -0
- package/dist/api-playground-2/schemaGraph/utils.js +144 -98
- package/dist/api-playground-2/schemaGraph/utils.js.map +1 -1
- package/dist/common/parseApiTargetFromMetadata.js +24 -0
- package/dist/common/parseApiTargetFromMetadata.js.map +1 -0
- package/dist/common/parseOpenApiString.js +42 -0
- package/dist/common/parseOpenApiString.js.map +1 -0
- package/dist/components/Api/ApiReferenceProvider.js +6 -15
- package/dist/components/Api/ApiReferenceProvider.js.map +1 -1
- package/dist/components/nav-tree/index.js +135 -109
- package/dist/components/nav-tree/index.js.map +1 -1
- package/dist/contexts/ConfigContext.js +61 -12
- package/dist/contexts/ConfigContext.js.map +1 -1
- package/dist/contexts/MDXContentContext.js +0 -1
- package/dist/contexts/MDXContentContext.js.map +1 -1
- package/dist/index.d.ts +125 -9
- package/dist/index.js +156 -144
- package/dist/index.js.map +1 -1
- package/dist/styles.css +1 -1
- package/package.json +1 -1
- package/dist/hooks/useCurrentPath.js +0 -17
- package/dist/hooks/useCurrentPath.js.map +0 -1
- package/dist/utils/decodeSlug.js +0 -8
- package/dist/utils/decodeSlug.js.map +0 -1
- package/dist/utils/optionallyAddLeadingSlash.js +0 -7
- package/dist/utils/optionallyAddLeadingSlash.js.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"processExamples.js","sources":["../../../src/api-playground-2/schemaGraph/processExamples.ts"],"sourcesContent":["import type { MdxCodeExampleData } from '@mintlify/common';\nimport { ExampleObject, ExampleOrRefObject, MediaObject, SchemaObject } from '@mintlify/validation';\nimport parse from 'html-react-parser';\n\nimport type {\n ApiReferenceDataV2,\n CodeExample,\n SchemaGeneratedExample,\n} from '@/api-playground-2/types';\n\nimport { isSchemaObject } from './utils';\n\n// duplicated from shiki/index.ts\nexport function getLanguageFromClassName(className: string | undefined, fallback?: string): string {\n const match = /language-(\\w+)/.exec(className ?? '');\n return match ? match[1] ?? 'text' : fallback ?? 'text';\n}\n\nexport const mdxCodeExampleToExamples = (mdxCodeExampleData: MdxCodeExampleData): CodeExample[] => {\n const examples: CodeExample[] = [];\n const dropdown = mdxCodeExampleData.attributes?.some(\n (attr) => attr.name === 'dropdown' && attr.value !== 'false'\n );\n mdxCodeExampleData.children?.map((child) => {\n const jsx = parse(child.html ?? '');\n const lang =\n typeof jsx === 'object' && !Array.isArray(jsx) && jsx.type === 'pre'\n ? jsx.props.language ?? getLanguageFromClassName(jsx.props.className, child.filename)\n : undefined;\n examples.push({\n dropdown,\n language: lang,\n code: jsx,\n filename: child.filename,\n });\n });\n return examples;\n};\n\n// same logic as in OpenApiToEndpointConverter convertExamples\nexport const generateExamplesFromSchema = (\n content: Record<string, MediaObject>\n): Record<string, MediaObject> => {\n Object.entries(content).forEach(([contentType, mediaObject]) => {\n const examples: Record<string, SchemaGeneratedExample> = {};\n if (mediaObject.examples) {\n Object.entries(mediaObject.examples).forEach(\n ([exampleName, example]: [string, ExampleOrRefObject]) => {\n if (!('$ref' in example)) {\n examples[exampleName] = {\n title: exampleName,\n description: example.description,\n value: example.value,\n };\n }\n }\n );\n if (content[contentType]) {\n content[contentType].examples = examples;\n }\n } else if (mediaObject.example) {\n examples['Example'] = {\n title: 'Example',\n value: mediaObject.example,\n };\n if (content[contentType]) {\n content[contentType].examples = examples;\n }\n } else if (isSchemaObject(mediaObject.schema)) {\n examples['Example'] = generateExampleFromSchema(mediaObject.schema);\n if (content[contentType]) {\n content[contentType].examples = examples;\n }\n }\n });\n return content;\n};\n\nexport const generateExampleFromSchema = (schema: SchemaObject): SchemaGeneratedExample => {\n const example: SchemaGeneratedExample = {\n title: 'Example',\n value: undefined,\n };\n if (schema.example !== undefined) {\n example.value = schema.example;\n return example;\n }\n if (schema.default !== undefined) {\n example.value = schema.default;\n return example;\n }\n\n if (schema.enum) {\n example.value = schema.enum[0];\n return example;\n }\n\n // Handle oneOf - generate example from first option\n if (schema.oneOf && Array.isArray(schema.oneOf) && schema.oneOf.length > 0) {\n const firstOption = schema.oneOf[0];\n if (isSchemaObject(firstOption)) {\n return generateExampleFromSchema(firstOption);\n }\n }\n\n switch (schema.type) {\n case 'string':\n example.value = generateStringExample(schema);\n return example;\n case 'boolean':\n example.value = true;\n return example;\n case 'number':\n case 'integer':\n example.value = generateNumericExample(schema);\n return example;\n case 'object':\n example.value = Object.fromEntries(\n Object.entries(schema.properties ?? {}).map(([propName, subschema]) => [\n propName,\n \n generateExampleFromSchema(subschema as SchemaObject).value,\n ])\n );\n return example;\n case 'array':\n \n example.value = [generateExampleFromSchema(schema.items as SchemaObject).value];\n return example;\n default:\n example.value = '<unknown>';\n return example;\n }\n};\n\nconst generateNumericExample = (schema: SchemaObject): number => {\n // if schema type is integer, make sure example is integer\n const format: (n: number) => number = schema.type === 'integer' ? Math.floor : (n) => n;\n\n if (schema.minimum !== undefined && schema.maximum !== undefined) {\n return format((schema.minimum + schema.maximum) / 2);\n } else if (schema.minimum !== undefined) {\n return format(schema.minimum + 1);\n } else if (schema.maximum !== undefined) {\n return 123 < schema.maximum ? 123 : format(schema.maximum - 1);\n } else {\n return 123;\n }\n};\n\nconst generateStringExample = (schema: SchemaObject): string => {\n switch (schema.format?.toLowerCase()) {\n case 'byte':\n case 'base64':\n return 'aSDinaTvuI8gbWludGxpZnk=';\n case 'date':\n return '2023-12-25';\n case 'date-time':\n return '2023-11-07T05:31:56Z';\n case 'email':\n return 'jsmith@example.com';\n case 'uuid':\n return '3c90c3cc-0d44-4b50-8888-8dd25736052a';\n case 'ipv4':\n return '127.0.0.1';\n case 'ipv6':\n return '2606:4700:3108::ac42:2835';\n default:\n return '<string>';\n }\n};\n\nexport const getFirstExampleValue = (\n content: Record<string, MediaObject>\n): ExampleObject | undefined => {\n const firstContentType = Object.keys(content)[0];\n if (firstContentType) {\n const contentTypeObject = content[firstContentType];\n const examples = Object.values(contentTypeObject?.examples ?? {});\n const firstExample = examples[0];\n if (firstExample && 'value' in firstExample) {\n return firstExample.value;\n }\n }\n return undefined;\n};\n\nexport const getFirstWebhookExample = (apiReferenceData: ApiReferenceDataV2): CodeExample[] => {\n const requestExamples: CodeExample[] = [];\n if (apiReferenceData.dependencies?.requestBody?.content) {\n const firstExample = getFirstExampleValue(apiReferenceData.dependencies.requestBody.content);\n if (firstExample) {\n requestExamples.push({\n language: 'json',\n filename: 'Example Request Body',\n code: JSON.stringify(firstExample.value, null, 2),\n });\n }\n }\n return requestExamples;\n};\n"],"names":["getLanguageFromClassName","className","fallback","match","mdxCodeExampleToExamples","mdxCodeExampleData","examples","dropdown","_a","attr","_b","child","jsx","parse","lang","getFirstExampleValue","content","firstContentType","contentTypeObject","firstExample","getFirstWebhookExample","apiReferenceData","requestExamples"],"mappings":";AAaO,SAASA,EAAyBC,GAA+BC,GAA2B;AACjG,QAAMC,IAAQ,iBAAiB,KAAKF,KAAa,EAAE;AACnD,SAAOE,IAAQA,EAAM,CAAC,KAAK,SAASD,KAAY;AAClD;AAEO,MAAME,IAA2B,CAACC,MAA0D;;AACjG,QAAMC,IAA0B,CAAA,GAC1BC,KAAWC,IAAAH,EAAmB,eAAnB,gBAAAG,EAA+B;AAAA,IAC9C,CAACC,MAASA,EAAK,SAAS,cAAcA,EAAK,UAAU;AAAA;AAEvD,UAAAC,IAAAL,EAAmB,aAAnB,QAAAK,EAA6B,IAAI,CAACC,MAAU;AAC1C,UAAMC,IAAMC,EAAMF,EAAM,QAAQ,EAAE,GAC5BG,IACJ,OAAOF,KAAQ,YAAY,CAAC,MAAM,QAAQA,CAAG,KAAKA,EAAI,SAAS,QAC3DA,EAAI,MAAM,YAAYZ,EAAyBY,EAAI,MAAM,WAAWD,EAAM,QAAQ,IAClF;AACN,IAAAL,EAAS,KAAK;AAAA,MACZ,UAAAC;AAAA,MACA,UAAUO;AAAA,MACV,MAAMF;AAAA,MACN,UAAUD,EAAM;AAAA,IAAA,CACjB;AAAA,EACH,IACOL;AACT,GAuIaS,IAAuB,CAClCC,MAC8B;AAC9B,QAAMC,IAAmB,OAAO,KAAKD,CAAO,EAAE,CAAC;AAC/C,MAAIC,GAAkB;AACpB,UAAMC,IAAoBF,EAAQC,CAAgB,GAE5CE,IADW,OAAO,QAAOD,KAAA,gBAAAA,EAAmB,aAAY,CAAA,CAAE,EAClC,CAAC;AAC/B,QAAIC,KAAgB,WAAWA;AAC7B,aAAOA,EAAa;AAAA,EAExB;AAEF,GAEaC,IAAyB,CAACC,MAAwD;;AAC7F,QAAMC,IAAiC,CAAA;AACvC,OAAIZ,KAAAF,IAAAa,EAAiB,iBAAjB,gBAAAb,EAA+B,gBAA/B,QAAAE,EAA4C,SAAS;AACvD,UAAMS,IAAeJ,EAAqBM,EAAiB,aAAa,YAAY,OAAO;AAC3F,IAAIF,KACFG,EAAgB,KAAK;AAAA,MACnB,UAAU;AAAA,MACV,UAAU;AAAA,MACV,MAAM,KAAK,UAAUH,EAAa,OAAO,MAAM,CAAC;AAAA,IAAA,CACjD;AAAA,EAEL;AACA,SAAOG;AACT;"}
|
|
1
|
+
{"version":3,"file":"processExamples.js","sources":["../../../src/api-playground-2/schemaGraph/processExamples.ts"],"sourcesContent":["import type { MdxCodeExampleData } from '@mintlify/common';\nimport { ExampleObject, ExampleOrRefObject, MediaObject, SchemaObject } from '@mintlify/validation';\nimport parse from 'html-react-parser';\n\nimport type {\n ApiReferenceDataV2,\n CodeExample,\n SchemaGeneratedExample,\n} from '@/api-playground-2/types';\n\nimport { isSchemaObject } from './utils';\n\n// duplicated from shiki/index.ts\nexport function getLanguageFromClassName(className: string | undefined, fallback?: string): string {\n const match = /language-(\\w+)/.exec(className ?? '');\n return match ? match[1] ?? 'text' : fallback ?? 'text';\n}\n\nexport const mdxCodeExampleToExamples = (mdxCodeExampleData: MdxCodeExampleData): CodeExample[] => {\n const examples: CodeExample[] = [];\n const dropdown = mdxCodeExampleData.attributes?.some(\n (attr) => attr.name === 'dropdown' && attr.value !== 'false'\n );\n mdxCodeExampleData.children?.map((child) => {\n const jsx = parse(child.html ?? '');\n const lang =\n typeof jsx === 'object' && !Array.isArray(jsx) && jsx.type === 'pre'\n ? jsx.props.language ?? getLanguageFromClassName(jsx.props.className, child.filename)\n : undefined;\n examples.push({\n dropdown,\n language: lang,\n code: jsx,\n filename: child.filename,\n });\n });\n return examples;\n};\n\n// same logic as in OpenApiToEndpointConverter convertExamples\nexport const generateExamplesFromSchema = (\n content: Record<string, MediaObject>\n): Record<string, MediaObject> => {\n Object.entries(content).forEach(([contentType, mediaObject]) => {\n const examples: Record<string, SchemaGeneratedExample> = {};\n if (mediaObject.examples) {\n Object.entries(mediaObject.examples).forEach(\n ([exampleName, example]: [string, ExampleOrRefObject]) => {\n if (!('$ref' in example)) {\n examples[exampleName] = {\n title: exampleName,\n description: example.description,\n value: example.value,\n };\n }\n }\n );\n if (content[contentType]) {\n content[contentType].examples = examples;\n }\n } else if (mediaObject.example) {\n examples['Example'] = {\n title: 'Example',\n value: mediaObject.example,\n };\n if (content[contentType]) {\n content[contentType].examples = examples;\n }\n } else if (isSchemaObject(mediaObject.schema)) {\n examples['Example'] = generateExampleFromSchema(mediaObject.schema);\n if (content[contentType]) {\n content[contentType].examples = examples;\n }\n }\n });\n return content;\n};\n\nexport const generateExampleFromSchema = (schema: SchemaObject): SchemaGeneratedExample => {\n const example: SchemaGeneratedExample = {\n title: 'Example',\n value: undefined,\n };\n if (schema.example !== undefined) {\n example.value = schema.example;\n return example;\n }\n if (schema.default !== undefined) {\n example.value = schema.default;\n return example;\n }\n\n if (schema.enum) {\n example.value = schema.enum[0];\n return example;\n }\n\n // Handle oneOf - generate example from first option\n if (schema.oneOf && Array.isArray(schema.oneOf) && schema.oneOf.length > 0) {\n const firstOption = schema.oneOf[0];\n if (isSchemaObject(firstOption)) {\n return generateExampleFromSchema(firstOption);\n }\n }\n\n switch (schema.type) {\n case 'string':\n example.value = generateStringExample(schema);\n return example;\n case 'boolean':\n example.value = true;\n return example;\n case 'number':\n case 'integer':\n example.value = generateNumericExample(schema);\n return example;\n case 'object':\n example.value = Object.fromEntries(\n Object.entries(schema.properties ?? {}).map(([propName, subschema]) => [\n propName,\n \n generateExampleFromSchema(subschema as SchemaObject).value,\n ])\n );\n return example;\n case 'array':\n \n example.value = [generateExampleFromSchema(schema.items as SchemaObject).value];\n return example;\n default:\n example.value = '<unknown>';\n return example;\n }\n};\n\nconst generateNumericExample = (schema: SchemaObject): number => {\n // if schema type is integer, make sure example is integer\n const format: (n: number) => number = schema.type === 'integer' ? Math.floor : (n) => n;\n\n if (schema.minimum !== undefined && schema.maximum !== undefined) {\n return format((schema.minimum + schema.maximum) / 2);\n } else if (schema.minimum !== undefined) {\n return format(schema.minimum + 1);\n } else if (schema.maximum !== undefined) {\n return 123 < schema.maximum ? 123 : format(schema.maximum - 1);\n } else {\n return 123;\n }\n};\n\nconst generateStringExample = (schema: SchemaObject): string => {\n switch (schema.format?.toLowerCase()) {\n case 'byte':\n case 'base64':\n return 'aSDinaTvuI8gbWludGxpZnk=';\n case 'date':\n return '2023-12-25';\n case 'date-time':\n return '2023-11-07T05:31:56Z';\n case 'email':\n return 'jsmith@example.com';\n case 'uuid':\n return '3c90c3cc-0d44-4b50-8888-8dd25736052a';\n case 'ipv4':\n return '127.0.0.1';\n case 'ipv6':\n return '2606:4700:3108::ac42:2835';\n default:\n return '<string>';\n }\n};\n\nexport const getFirstExampleValue = (\n content: Record<string, MediaObject>\n): ExampleObject | undefined => {\n const firstContentType = Object.keys(content)[0];\n if (firstContentType) {\n const contentTypeObject = content[firstContentType];\n const examples = Object.values(contentTypeObject?.examples ?? {});\n const firstExample = examples[0];\n if (firstExample && 'value' in firstExample) {\n return firstExample.value;\n }\n }\n return undefined;\n};\n\nexport const getFirstWebhookExample = (apiReferenceData: ApiReferenceDataV2): CodeExample[] => {\n const requestExamples: CodeExample[] = [];\n if (apiReferenceData.dependencies?.requestBody?.content) {\n const firstExample = getFirstExampleValue(apiReferenceData.dependencies.requestBody.content);\n if (firstExample) {\n requestExamples.push({\n language: 'json',\n filename: 'Example Request Body',\n code: JSON.stringify(firstExample.value, null, 2),\n });\n }\n }\n return requestExamples;\n};\n"],"names":["getLanguageFromClassName","className","fallback","match","mdxCodeExampleToExamples","mdxCodeExampleData","examples","dropdown","_a","attr","_b","child","jsx","parse","lang","generateExamplesFromSchema","content","contentType","mediaObject","exampleName","example","isSchemaObject","generateExampleFromSchema","schema","firstOption","generateStringExample","generateNumericExample","propName","subschema","format","n","getFirstExampleValue","firstContentType","contentTypeObject","firstExample","getFirstWebhookExample","apiReferenceData","requestExamples"],"mappings":";;AAaO,SAASA,EAAyBC,GAA+BC,GAA2B;AACjG,QAAMC,IAAQ,iBAAiB,KAAKF,KAAa,EAAE;AACnD,SAAOE,IAAQA,EAAM,CAAC,KAAK,SAASD,KAAY;AAClD;AAEO,MAAME,IAA2B,CAACC,MAA0D;;AACjG,QAAMC,IAA0B,CAAA,GAC1BC,KAAWC,IAAAH,EAAmB,eAAnB,gBAAAG,EAA+B;AAAA,IAC9C,CAACC,MAASA,EAAK,SAAS,cAAcA,EAAK,UAAU;AAAA;AAEvD,UAAAC,IAAAL,EAAmB,aAAnB,QAAAK,EAA6B,IAAI,CAACC,MAAU;AAC1C,UAAMC,IAAMC,EAAMF,EAAM,QAAQ,EAAE,GAC5BG,IACJ,OAAOF,KAAQ,YAAY,CAAC,MAAM,QAAQA,CAAG,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C,KAAK;AAAA,IACL,KAAK;AACH,aAAO;AAAA,IACT,KAAK;AACH,aAAO;AAAA,IACT,KAAK;AACH,aAAO;AAAA,IACT,KAAK;AACH,aAAO;AAAA,IACT,KAAK;AACH,aAAO;AAAA,IACT,KAAK;AACH,aAAO;AAAA,IACT,KAAK;AACH,aAAO;AAAA,IACT;AACE,aAAO;AAAA,EAAA;AAEb,GAEauB,IAAuB,CAClCf,MAC8B;AAC9B,QAAMgB,IAAmB,OAAO,KAAKhB,CAAO,EAAE,CAAC;AAC/C,MAAIgB,GAAkB;AACpB,UAAMC,IAAoBjB,EAAQgB,CAAgB,GAE5CE,IADW,OAAO,QAAOD,KAAA,gBAAAA,EAAmB,aAAY,CAAA,CAAE,EAClC,CAAC;AAC/B,QAAIC,KAAgB,WAAWA;AAC7B,aAAOA,EAAa;AAAA,EAExB;AAEF,GAEaC,IAAyB,CAACC,MAAwD;;AAC7F,QAAMC,IAAiC,CAAA;AACvC,OAAI3B,KAAAF,IAAA4B,EAAiB,iBAAjB,gBAAA5B,EAA+B,gBAA/B,QAAAE,EAA4C,SAAS;AACvD,UAAMwB,IAAeH,EAAqBK,EAAiB,aAAa,YAAY,OAAO;AAC3F,IAAIF,KACFG,EAAgB,KAAK;AAAA,MACnB,UAAU;AAAA,MACV,UAAU;AAAA,MACV,MAAM,KAAK,UAAUH,EAAa,OAAO,MAAM,CAAC;AAAA,IAAA,CACjD;AAAA,EAEL;AACA,SAAOG;AACT;"}
|
|
@@ -0,0 +1,283 @@
|
|
|
1
|
+
import { MAX_SCHEMA_COMBINATION_SIZE as b } from "../constants/index.js";
|
|
2
|
+
import { handleExistingError as M, ImpossibleSchemaError as y } from "./errors.js";
|
|
3
|
+
import { flattenSchemaOneOfs as c, isCircularRef as x, shouldTruncateForSize as E, createEmptyReducedSchema as w, createUnknownReducedSchema as L, combine as p, takeLast as m, isReducedSchema as P } from "./utils.js";
|
|
4
|
+
function k({
|
|
5
|
+
schema: e,
|
|
6
|
+
depth: i,
|
|
7
|
+
location: r,
|
|
8
|
+
flattenOneOfs: n = !0
|
|
9
|
+
}) {
|
|
10
|
+
const l = O({
|
|
11
|
+
schema: e,
|
|
12
|
+
depth: i,
|
|
13
|
+
location: r,
|
|
14
|
+
safeParse: !1,
|
|
15
|
+
path: ["#"]
|
|
16
|
+
});
|
|
17
|
+
return n ? c(l) : l;
|
|
18
|
+
}
|
|
19
|
+
function O({
|
|
20
|
+
schema: e,
|
|
21
|
+
depth: i,
|
|
22
|
+
location: r,
|
|
23
|
+
safeParse: n = !1,
|
|
24
|
+
path: l = ["#"]
|
|
25
|
+
}) {
|
|
26
|
+
try {
|
|
27
|
+
if (x(e))
|
|
28
|
+
return { oneOf: [e] };
|
|
29
|
+
if (E(e))
|
|
30
|
+
return { oneOf: [{ type: "any" }] };
|
|
31
|
+
if (e.oneOf && e.oneOf.length > 0 ? e.oneOf = S({
|
|
32
|
+
schemaArray: e.oneOf,
|
|
33
|
+
depth: i,
|
|
34
|
+
location: r,
|
|
35
|
+
path: [...l, "oneOf"]
|
|
36
|
+
}) : e.oneOf = [], e.anyOf && e.anyOf.length > 0 && (e.anyOf = S({
|
|
37
|
+
schemaArray: e.anyOf,
|
|
38
|
+
depth: i,
|
|
39
|
+
location: r,
|
|
40
|
+
path: [...l, "anyOf"]
|
|
41
|
+
})), e.allOf && e.allOf.length > 0) {
|
|
42
|
+
const d = e.allOf.map(
|
|
43
|
+
(u, t) => O({
|
|
44
|
+
schema: u,
|
|
45
|
+
depth: i + 1,
|
|
46
|
+
location: r,
|
|
47
|
+
safeParse: n,
|
|
48
|
+
path: [...l, "allOf", t.toString()]
|
|
49
|
+
})
|
|
50
|
+
).reduce(
|
|
51
|
+
(u, t) => v(u, t, i + 1),
|
|
52
|
+
w()
|
|
53
|
+
);
|
|
54
|
+
e.oneOf = s(e.oneOf, d.oneOf, i);
|
|
55
|
+
}
|
|
56
|
+
if (e.properties)
|
|
57
|
+
for (const d in e.properties) {
|
|
58
|
+
const u = e.properties[d];
|
|
59
|
+
if (x(u)) {
|
|
60
|
+
e.properties[d] = { oneOf: [u] };
|
|
61
|
+
continue;
|
|
62
|
+
}
|
|
63
|
+
if (u.readOnly && r === "request" || u.writeOnly && r === "response") {
|
|
64
|
+
delete e.properties[d];
|
|
65
|
+
continue;
|
|
66
|
+
}
|
|
67
|
+
const t = [...l, "properties", d];
|
|
68
|
+
try {
|
|
69
|
+
e.properties[d] = O({
|
|
70
|
+
schema: u,
|
|
71
|
+
depth: i + 1,
|
|
72
|
+
location: r,
|
|
73
|
+
safeParse: n,
|
|
74
|
+
path: t
|
|
75
|
+
});
|
|
76
|
+
} catch (f) {
|
|
77
|
+
M(f, t, n, "error reducing property schema"), e.properties[d] = { oneOf: [{}] };
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
if ("items" in e && e.items && !x(e.items))
|
|
81
|
+
try {
|
|
82
|
+
e.items = O({
|
|
83
|
+
schema: e.items,
|
|
84
|
+
depth: i + 1,
|
|
85
|
+
location: r,
|
|
86
|
+
safeParse: n,
|
|
87
|
+
path: [...l, "items"]
|
|
88
|
+
});
|
|
89
|
+
} catch (d) {
|
|
90
|
+
M(d, [...l, "items"], n, "error reducing items schema"), e.items = L();
|
|
91
|
+
}
|
|
92
|
+
if (e.additionalProperties && typeof e.additionalProperties == "object" && !x(e.additionalProperties))
|
|
93
|
+
try {
|
|
94
|
+
e.additionalProperties = O({
|
|
95
|
+
schema: e.additionalProperties,
|
|
96
|
+
depth: i + 1,
|
|
97
|
+
location: r,
|
|
98
|
+
safeParse: n,
|
|
99
|
+
path: [...l, "additionalProperties"]
|
|
100
|
+
});
|
|
101
|
+
} catch (d) {
|
|
102
|
+
e.additionalProperties = !(d instanceof y);
|
|
103
|
+
}
|
|
104
|
+
e.anyOf && e.anyOf.length > 0 && (e.oneOf = s(e.oneOf, e.anyOf, i));
|
|
105
|
+
const o = C(e);
|
|
106
|
+
return {
|
|
107
|
+
oneOf: s(e.oneOf, o, i)
|
|
108
|
+
};
|
|
109
|
+
} catch (o) {
|
|
110
|
+
return o instanceof Error && console.error("Error processing schema:", o.message), { oneOf: [{ type: "any" }] };
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
function S({
|
|
114
|
+
schemaArray: e,
|
|
115
|
+
depth: i,
|
|
116
|
+
location: r,
|
|
117
|
+
path: n = ["#"]
|
|
118
|
+
}) {
|
|
119
|
+
const l = e.flatMap((o, d) => {
|
|
120
|
+
try {
|
|
121
|
+
return O({
|
|
122
|
+
schema: o,
|
|
123
|
+
depth: i + 1,
|
|
124
|
+
location: r,
|
|
125
|
+
safeParse: !1,
|
|
126
|
+
path: [...n, d.toString()]
|
|
127
|
+
}).oneOf;
|
|
128
|
+
} catch (u) {
|
|
129
|
+
if (u instanceof y)
|
|
130
|
+
return [];
|
|
131
|
+
throw u;
|
|
132
|
+
}
|
|
133
|
+
});
|
|
134
|
+
if (l.length === 0)
|
|
135
|
+
throw new y(n, "no valid options in schema");
|
|
136
|
+
return l;
|
|
137
|
+
}
|
|
138
|
+
function s(e, i, r) {
|
|
139
|
+
if (e.length * i.length > b)
|
|
140
|
+
return [{}];
|
|
141
|
+
if (e.length === 0 && i.length === 0)
|
|
142
|
+
return [{}];
|
|
143
|
+
if (e.length === 0)
|
|
144
|
+
return i;
|
|
145
|
+
if (i.length === 0)
|
|
146
|
+
return e;
|
|
147
|
+
const l = e.flatMap((o) => i.flatMap((d) => {
|
|
148
|
+
try {
|
|
149
|
+
return [I(o, d, r + 1)];
|
|
150
|
+
} catch (u) {
|
|
151
|
+
if (u instanceof y)
|
|
152
|
+
return [];
|
|
153
|
+
throw u;
|
|
154
|
+
}
|
|
155
|
+
}));
|
|
156
|
+
return l.length, l;
|
|
157
|
+
}
|
|
158
|
+
function v(e, i, r) {
|
|
159
|
+
return {
|
|
160
|
+
oneOf: s(
|
|
161
|
+
e.oneOf ?? [],
|
|
162
|
+
i.oneOf ?? [],
|
|
163
|
+
r
|
|
164
|
+
)
|
|
165
|
+
};
|
|
166
|
+
}
|
|
167
|
+
function I(e, i, r) {
|
|
168
|
+
let n = e.type, l = i.type;
|
|
169
|
+
if (n === "integer" && l === "number" ? l = "integer" : n === "number" && l === "integer" && (n = "integer"), n && l && n !== l)
|
|
170
|
+
throw new y([], `mismatched type in composition: "${n}" "${l}"`);
|
|
171
|
+
for (const t of [e, i])
|
|
172
|
+
typeof t.exclusiveMaximum == "number" && (t.maximum === void 0 || t.maximum >= t.exclusiveMaximum ? (t.maximum = t.exclusiveMaximum, t.exclusiveMaximum = !0) : t.exclusiveMaximum = void 0), typeof t.exclusiveMinimum == "number" && (t.minimum === void 0 || t.minimum <= t.exclusiveMinimum ? (t.minimum = t.exclusiveMinimum, t.exclusiveMinimum = !0) : t.exclusiveMinimum = void 0);
|
|
173
|
+
const o = {
|
|
174
|
+
title: m(e, i, "title"),
|
|
175
|
+
description: m(e, i, "description"),
|
|
176
|
+
format: m(e, i, "format"),
|
|
177
|
+
default: m(e, i, "default"),
|
|
178
|
+
multipleOf: p(e, i, "multipleOf", q),
|
|
179
|
+
maximum: p(e, i, "maximum", Math.min),
|
|
180
|
+
minimum: p(e, i, "minimum", Math.max),
|
|
181
|
+
maxLength: p(e, i, "maxLength", Math.min),
|
|
182
|
+
minLength: p(e, i, "minLength", Math.max),
|
|
183
|
+
pattern: m(e, i, "pattern"),
|
|
184
|
+
maxItems: p(e, i, "maxItems", Math.min),
|
|
185
|
+
minItems: p(e, i, "minItems", Math.max),
|
|
186
|
+
uniqueItems: m(e, i, "uniqueItems"),
|
|
187
|
+
maxProperties: p(e, i, "maxProperties", Math.min),
|
|
188
|
+
minProperties: p(e, i, "minProperties", Math.max),
|
|
189
|
+
required: p(
|
|
190
|
+
e,
|
|
191
|
+
i,
|
|
192
|
+
"required",
|
|
193
|
+
(t, f) => f.concat(t.filter((a) => !f.includes(a)))
|
|
194
|
+
),
|
|
195
|
+
enum: p(e, i, "enum", (t, f) => f.filter((a) => t.includes(a))),
|
|
196
|
+
const: p(e, i, "const", (t, f) => f ?? t),
|
|
197
|
+
readOnly: e.readOnly && i.readOnly,
|
|
198
|
+
writeOnly: e.writeOnly && i.writeOnly,
|
|
199
|
+
deprecated: e.deprecated || i.deprecated
|
|
200
|
+
};
|
|
201
|
+
for (const t of [e, i])
|
|
202
|
+
Object.keys(t).forEach((f) => {
|
|
203
|
+
f.startsWith("x-") && (o[f] = m(
|
|
204
|
+
e,
|
|
205
|
+
i,
|
|
206
|
+
f
|
|
207
|
+
));
|
|
208
|
+
});
|
|
209
|
+
Object.entries(o).forEach(([t, f]) => {
|
|
210
|
+
f === void 0 && delete o[t];
|
|
211
|
+
});
|
|
212
|
+
const d = j(e, i);
|
|
213
|
+
d !== void 0 && (o.example = d), o.maximum !== void 0 && (o.exclusiveMaximum = (e.maximum === o.maximum ? e.exclusiveMaximum : void 0) || (i.maximum === o.maximum ? i.exclusiveMaximum : void 0)), o.minimum !== void 0 && (o.exclusiveMinimum = (e.minimum === o.minimum ? e.exclusiveMinimum : void 0) || (i.minimum === o.minimum ? i.exclusiveMinimum : void 0));
|
|
214
|
+
const u = n ?? l;
|
|
215
|
+
if (u === "array")
|
|
216
|
+
return {
|
|
217
|
+
type: "array",
|
|
218
|
+
items: v(
|
|
219
|
+
"items" in e && e.items ? e.items : {},
|
|
220
|
+
"items" in i && i.items ? i.items : {},
|
|
221
|
+
r + 1
|
|
222
|
+
),
|
|
223
|
+
...o
|
|
224
|
+
};
|
|
225
|
+
if (e.properties && i.properties) {
|
|
226
|
+
const t = { ...e.properties };
|
|
227
|
+
Object.entries(i.properties).forEach(([f, a]) => {
|
|
228
|
+
const g = t[f];
|
|
229
|
+
g ? t[f] = v(g, a, r + 1) : t[f] = a;
|
|
230
|
+
}), o.properties = t;
|
|
231
|
+
} else (e.properties || i.properties) && (o.properties = {
|
|
232
|
+
...e.properties,
|
|
233
|
+
...i.properties
|
|
234
|
+
});
|
|
235
|
+
if (e.additionalProperties === !1 || i.additionalProperties === !1)
|
|
236
|
+
o.additionalProperties = !1;
|
|
237
|
+
else {
|
|
238
|
+
const t = P(e.additionalProperties) ? e.additionalProperties : void 0, f = P(i.additionalProperties) ? i.additionalProperties : void 0;
|
|
239
|
+
t && f ? o.additionalProperties = v(
|
|
240
|
+
t,
|
|
241
|
+
f,
|
|
242
|
+
r + 1
|
|
243
|
+
) : t ? o.additionalProperties = t : f ? o.additionalProperties = f : (e.additionalProperties === !0 || i.additionalProperties === !0) && (o.additionalProperties = !0);
|
|
244
|
+
}
|
|
245
|
+
return u ? { type: u, ...o } : o;
|
|
246
|
+
}
|
|
247
|
+
function C(e) {
|
|
248
|
+
if (e.nullable) {
|
|
249
|
+
const r = { ...e };
|
|
250
|
+
delete r.oneOf, delete r.anyOf, delete r.allOf, delete r.nullable;
|
|
251
|
+
const n = { ...e };
|
|
252
|
+
return delete n.oneOf, delete n.anyOf, delete n.allOf, delete n.nullable, n.type = "null", [r, n];
|
|
253
|
+
}
|
|
254
|
+
if (Array.isArray(e.type)) {
|
|
255
|
+
if (e.type.length === 0) {
|
|
256
|
+
const r = { ...e };
|
|
257
|
+
return delete r.oneOf, delete r.anyOf, delete r.allOf, delete r.type, [r];
|
|
258
|
+
}
|
|
259
|
+
return e.type.map((r) => {
|
|
260
|
+
const n = { ...e };
|
|
261
|
+
return delete n.oneOf, delete n.anyOf, delete n.allOf, n.type = r, n;
|
|
262
|
+
});
|
|
263
|
+
}
|
|
264
|
+
const i = { ...e };
|
|
265
|
+
return delete i.oneOf, delete i.anyOf, delete i.allOf, [i];
|
|
266
|
+
}
|
|
267
|
+
function j(e, i) {
|
|
268
|
+
const r = "examples" in e ? e.examples : void 0, n = "examples" in i ? i.examples : void 0, l = (r == null ? void 0 : r[0]) !== void 0 ? r[0] : e.example, o = (n == null ? void 0 : n[0]) !== void 0 ? n[0] : i.example;
|
|
269
|
+
return l && o && typeof l == "object" && typeof o == "object" && !Array.isArray(l) && !Array.isArray(o) ? {
|
|
270
|
+
...l,
|
|
271
|
+
...o
|
|
272
|
+
} : o !== void 0 ? o : l;
|
|
273
|
+
}
|
|
274
|
+
function q(e, i) {
|
|
275
|
+
return Math.abs(e * i) / A(e, i);
|
|
276
|
+
}
|
|
277
|
+
function A(e, i) {
|
|
278
|
+
return i === 0 ? e : A(i, e % i);
|
|
279
|
+
}
|
|
280
|
+
export {
|
|
281
|
+
k as reduceExpandedSchema
|
|
282
|
+
};
|
|
283
|
+
//# sourceMappingURL=reduceCompositions.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"reduceCompositions.js","sources":["../../../src/api-playground-2/schemaGraph/reduceCompositions.ts"],"sourcesContent":["import { type SchemaObject } from '@mintlify/validation';\nimport type { OpenAPIV3, OpenAPIV3_1 } from 'openapi-types';\n\nimport { CIRCULAR_REF_KEY, MAX_SCHEMA_COMBINATION_SIZE } from '@/api-playground-2/constants';\nimport type { ResolvedSchemaObject, ReducedSchema, Location } from '@/api-playground-2/types';\n\nimport { handleExistingError, ImpossibleSchemaError } from './errors';\nimport {\n takeLast,\n combine,\n createEmptyReducedSchema,\n createUnknownReducedSchema,\n isReducedSchema,\n flattenSchemaOneOfs,\n isCircularRef,\n shouldTruncateForSize,\n} from './utils';\n\n/**\n * Entrypoint function for performing reduction on an OpenAPI schema. Reduction means that\n * the schema is transformed into its *reduced form*. In this form, the schema and any subschemas\n * are represented by a schema with one property, `oneOf`, whose items are guaranteed NOT to have a\n * `oneOf`, `anyOf`, or `allOf` property.\n */\nexport function reduceExpandedSchema({\n schema,\n depth,\n location,\n flattenOneOfs = true,\n}: {\n schema: SchemaObject;\n depth: number;\n location?: Location;\n flattenOneOfs?: boolean;\n}): SchemaObject {\n const reduced = reduceCompositions({\n schema,\n depth,\n location,\n safeParse: false,\n path: ['#'],\n });\n\n return flattenOneOfs ? flattenSchemaOneOfs(reduced) : reduced;\n}\n\nfunction reduceCompositions({\n schema,\n depth,\n location,\n safeParse = false,\n path = ['#'],\n}: {\n schema: OpenAPIV3_1.SchemaObject | { [CIRCULAR_REF_KEY]: string };\n depth: number;\n location?: Location;\n safeParse?: boolean;\n path?: string[];\n}): ReducedSchema {\n try {\n // Handle circular reference - preserve it as-is\n if (isCircularRef(schema)) {\n return { oneOf: [schema] };\n }\n\n if (shouldTruncateForSize(schema)) {\n // TODO - Api Playground Refactor: find the problematic property and truncate only that subschema instead of making the entire schema any\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n return { oneOf: [{ type: 'any' as any }] };\n }\n\n if (schema.oneOf && schema.oneOf.length > 0) {\n schema.oneOf = reduceOptionsCompositions({\n schemaArray: schema.oneOf,\n depth,\n location,\n path: [...path, 'oneOf'],\n });\n } else {\n // Always give reduced schema a oneOf\n schema.oneOf = [];\n }\n\n if (schema.anyOf && schema.anyOf.length > 0) {\n schema.anyOf = reduceOptionsCompositions({\n schemaArray: schema.anyOf,\n depth,\n location,\n path: [...path, 'anyOf'],\n });\n }\n\n // Take the schema's allOf options\n // Recursively reduce each of them\n // Take the reduced allOf array and multiply it to turn it into a large oneOf array\n // Now multiply our current \"oneOf\"\n if (schema.allOf && schema.allOf.length > 0) {\n const totalAllOf = schema.allOf\n .map((subschema, index) =>\n reduceCompositions({\n schema: subschema,\n depth: depth + 1,\n location,\n safeParse,\n path: [...path, 'allOf', index.toString()],\n })\n )\n .reduce<ReducedSchema>(\n (accumulator, current) => combineReducedSchemas(accumulator, current, depth + 1),\n createEmptyReducedSchema()\n );\n schema.oneOf = multiplySchemaArrays(schema.oneOf, totalAllOf.oneOf, depth);\n }\n\n if (schema.properties) {\n for (const key in schema.properties) {\n \n const subschema = schema.properties[key] as OpenAPIV3_1.SchemaObject;\n\n // Convert circular refs to reduced schema\n if (isCircularRef(subschema)) {\n schema.properties[key] = { oneOf: [subschema] };\n continue;\n }\n\n // remove readOnly and writeOnly properties BEFORE we combine anything\n if (\n (subschema.readOnly && location === 'request') ||\n (subschema.writeOnly && location === 'response')\n ) {\n delete schema.properties[key];\n continue;\n }\n\n const propertyPath = [...path, 'properties', key];\n try {\n schema.properties[key] = reduceCompositions({\n schema: subschema,\n depth: depth + 1,\n location,\n safeParse,\n path: propertyPath,\n });\n } catch (error) {\n handleExistingError(error, propertyPath, safeParse, 'error reducing property schema');\n schema.properties[key] = { oneOf: [{}] }; // an \"any\" schema\n }\n }\n }\n\n if ('items' in schema && schema.items) {\n // Preserve circular refs without processing\n if (!isCircularRef(schema.items)) {\n try {\n schema.items = reduceCompositions({\n schema: schema.items,\n depth: depth + 1,\n location,\n safeParse,\n path: [...path, 'items'],\n });\n } catch (error) {\n handleExistingError(error, [...path, 'items'], safeParse, 'error reducing items schema');\n schema.items = createUnknownReducedSchema();\n }\n }\n }\n\n if (schema.additionalProperties && typeof schema.additionalProperties === 'object') {\n // Preserve circular refs without processing\n if (!isCircularRef(schema.additionalProperties)) {\n try {\n schema.additionalProperties = reduceCompositions({\n schema: schema.additionalProperties,\n depth: depth + 1,\n location,\n safeParse,\n path: [...path, 'additionalProperties'],\n });\n } catch (error) {\n schema.additionalProperties = error instanceof ImpossibleSchemaError ? false : true;\n }\n }\n }\n\n if (schema.anyOf && schema.anyOf.length > 0) {\n schema.oneOf = multiplySchemaArrays(schema.oneOf, schema.anyOf, depth);\n }\n\n const topLevelSchemaArray = generateTopLevelSchemaArray(schema);\n\n return {\n oneOf: multiplySchemaArrays(schema.oneOf, topLevelSchemaArray, depth),\n };\n } catch (error) {\n if (error instanceof Error) {\n console.error('Error processing schema:', error.message);\n }\n \n return { oneOf: [{ type: 'any' } as ResolvedSchemaObject] };\n }\n}\n\nfunction reduceOptionsCompositions({\n schemaArray,\n depth,\n location,\n path = ['#'],\n}: {\n schemaArray: SchemaObject[];\n depth: number;\n location?: Location;\n path?: string[];\n}): SchemaObject[] {\n const evaluatedArray = schemaArray.flatMap((subschema, index) => {\n try {\n const reduced = reduceCompositions({\n schema: subschema,\n depth: depth + 1,\n location,\n safeParse: false,\n path: [...path, index.toString()],\n });\n return reduced.oneOf;\n } catch (error) {\n if (error instanceof ImpossibleSchemaError) {\n return [];\n }\n throw error;\n }\n });\n\n if (evaluatedArray.length === 0) {\n throw new ImpossibleSchemaError(path, 'no valid options in schema');\n }\n\n return evaluatedArray;\n}\n\nfunction multiplySchemaArrays(a: SchemaObject[], b: SchemaObject[], depth: number): SchemaObject[] {\n const totalCombinations = a.length * b.length;\n if (totalCombinations > MAX_SCHEMA_COMBINATION_SIZE) {\n return [{}];\n }\n\n if (a.length === 0 && b.length === 0) {\n return [{}];\n }\n if (a.length === 0) {\n return b;\n }\n if (b.length === 0) {\n return a;\n }\n\n const product = a.flatMap((schema1) => {\n return b.flatMap((schema2) => {\n try {\n const combinedSchema = combineTopLevelSchemas(schema1, schema2, depth + 1);\n return [combinedSchema];\n } catch (error) {\n if (error instanceof ImpossibleSchemaError) {\n return [];\n }\n throw error;\n }\n });\n });\n\n if (product.length === 0) {\n // throw new ImpossibleSchemaError(\n // [],\n // 'impossible schema combination',\n // `schema 1: ${JSON.stringify(a, null, 2)}`,\n // `schema 2: ${JSON.stringify(b, null, 2)}`\n // );\n }\n\n return product;\n}\n\nfunction combineReducedSchemas(\n schema1: OpenAPIV3_1.SchemaObject | OpenAPIV3_1.ReferenceObject,\n schema2: OpenAPIV3_1.SchemaObject | OpenAPIV3_1.ReferenceObject,\n depth: number\n): ReducedSchema {\n return {\n oneOf: multiplySchemaArrays(\n \n ((schema1 as OpenAPIV3_1.SchemaObject).oneOf ?? []) as OpenAPIV3_1.SchemaObject[],\n \n ((schema2 as OpenAPIV3_1.SchemaObject).oneOf ?? []) as OpenAPIV3_1.SchemaObject[],\n depth\n ),\n };\n}\n\nfunction combineTopLevelSchemas(\n schema1: SchemaObject,\n schema2: SchemaObject,\n depth: number\n): OpenAPIV3_1.SchemaObject {\n let type1 = schema1.type;\n let type2 = schema2.type;\n\n if (type1 === 'integer' && type2 === 'number') {\n type2 = 'integer';\n } else if (type1 === 'number' && type2 === 'integer') {\n type1 = 'integer';\n }\n\n if (type1 && type2 && type1 !== type2) {\n throw new ImpossibleSchemaError([], `mismatched type in composition: \"${type1}\" \"${type2}\"`);\n }\n\n for (const schema of [schema1, schema2]) {\n if (typeof schema.exclusiveMaximum === 'number') {\n if (schema.maximum === undefined || schema.maximum >= schema.exclusiveMaximum) {\n schema.maximum = schema.exclusiveMaximum;\n schema.exclusiveMaximum = true;\n } else {\n schema.exclusiveMaximum = undefined;\n }\n }\n\n if (typeof schema.exclusiveMinimum === 'number') {\n if (schema.minimum === undefined || schema.minimum <= schema.exclusiveMinimum) {\n schema.minimum = schema.exclusiveMinimum;\n schema.exclusiveMinimum = true;\n } else {\n schema.exclusiveMinimum = undefined;\n }\n }\n }\n\n // missing properties here from BaseSchemaObject because we have no UI reflecting them:\n // not\n // discriminator\n // xml\n // externalDocs\n const combinedSchema: SchemaObject = {\n title: takeLast(schema1, schema2, 'title'),\n description: takeLast(schema1, schema2, 'description'),\n format: takeLast(schema1, schema2, 'format'),\n default: takeLast(schema1, schema2, 'default'),\n multipleOf: combine(schema1, schema2, 'multipleOf', leastCommonMultiple),\n maximum: combine(schema1, schema2, 'maximum', Math.min),\n minimum: combine(schema1, schema2, 'minimum', Math.max),\n maxLength: combine(schema1, schema2, 'maxLength', Math.min),\n minLength: combine(schema1, schema2, 'minLength', Math.max),\n pattern: takeLast(schema1, schema2, 'pattern'),\n maxItems: combine(schema1, schema2, 'maxItems', Math.min),\n minItems: combine(schema1, schema2, 'minItems', Math.max),\n uniqueItems: takeLast(schema1, schema2, 'uniqueItems'),\n maxProperties: combine(schema1, schema2, 'maxProperties', Math.min),\n minProperties: combine(schema1, schema2, 'minProperties', Math.max),\n required: combine(schema1, schema2, 'required', (a, b) =>\n b.concat(a.filter((value) => !b.includes(value)))\n ),\n enum: combine(schema1, schema2, 'enum', (a, b) => b.filter((value) => a.includes(value))),\n const: combine(schema1, schema2, 'const', (a, b) => b ?? a),\n readOnly: schema1.readOnly && schema2.readOnly,\n writeOnly: schema1.writeOnly && schema2.writeOnly,\n deprecated: schema1.deprecated || schema2.deprecated,\n };\n\n for (const schema of [schema1, schema2]) {\n Object.keys(schema).forEach((key) => {\n if (key.startsWith('x-')) {\n \n combinedSchema[key as keyof SchemaObject] = takeLast(\n schema1,\n schema2,\n \n key as keyof SchemaObject\n );\n }\n });\n }\n\n // Delete undefined values\n Object.entries(combinedSchema).forEach(([key, value]) => {\n if (value === undefined) {\n \n delete combinedSchema[key as keyof SchemaObject];\n }\n });\n\n const example = mergeExamples(schema1, schema2);\n if (example !== undefined) {\n combinedSchema.example = example;\n }\n\n if (combinedSchema.maximum !== undefined) {\n combinedSchema.exclusiveMaximum =\n (schema1.maximum === combinedSchema.maximum ? schema1.exclusiveMaximum : undefined) ||\n (schema2.maximum === combinedSchema.maximum ? schema2.exclusiveMaximum : undefined);\n }\n\n if (combinedSchema.minimum !== undefined) {\n combinedSchema.exclusiveMinimum =\n (schema1.minimum === combinedSchema.minimum ? schema1.exclusiveMinimum : undefined) ||\n (schema2.minimum === combinedSchema.minimum ? schema2.exclusiveMinimum : undefined);\n }\n\n const type = type1 ?? type2;\n if (type === 'array') {\n return {\n type: 'array',\n items: combineReducedSchemas(\n 'items' in schema1 && schema1.items ? schema1.items : {},\n 'items' in schema2 && schema2.items ? schema2.items : {},\n depth + 1\n ),\n ...combinedSchema,\n };\n }\n\n if (schema1.properties && schema2.properties) {\n const combinedProperties = { ...schema1.properties };\n Object.entries(schema2.properties).forEach(([property, schema]) => {\n const schema1Property = combinedProperties[property];\n if (schema1Property) {\n combinedProperties[property] = combineReducedSchemas(schema1Property, schema, depth + 1);\n } else {\n combinedProperties[property] = schema;\n }\n });\n combinedSchema.properties = combinedProperties;\n } else if (schema1.properties || schema2.properties) {\n combinedSchema.properties = {\n ...schema1.properties,\n ...schema2.properties,\n };\n }\n\n if (schema1.additionalProperties === false || schema2.additionalProperties === false) {\n combinedSchema.additionalProperties = false;\n } else {\n const leftAdditional = isReducedSchema(schema1.additionalProperties)\n ? schema1.additionalProperties\n : undefined;\n const rightAdditional = isReducedSchema(schema2.additionalProperties)\n ? schema2.additionalProperties\n : undefined;\n\n if (leftAdditional && rightAdditional) {\n combinedSchema.additionalProperties = combineReducedSchemas(\n leftAdditional,\n rightAdditional,\n depth + 1\n );\n } else if (leftAdditional) {\n combinedSchema.additionalProperties = leftAdditional;\n } else if (rightAdditional) {\n combinedSchema.additionalProperties = rightAdditional;\n } else if (schema1.additionalProperties === true || schema2.additionalProperties === true) {\n combinedSchema.additionalProperties = true;\n }\n }\n\n return type ? { type, ...combinedSchema } : combinedSchema;\n}\n\nfunction generateTopLevelSchemaArray(schema: OpenAPIV3_1.SchemaObject): OpenAPIV3_1.SchemaObject[] {\n \n if ((schema as OpenAPIV3.SchemaObject).nullable) {\n const typedSchema = { ...schema };\n delete typedSchema.oneOf;\n delete typedSchema.anyOf;\n delete typedSchema.allOf;\n \n delete (typedSchema as OpenAPIV3.SchemaObject).nullable;\n\n const nullSchema = { ...schema };\n delete nullSchema.oneOf;\n delete nullSchema.anyOf;\n delete nullSchema.allOf;\n \n delete (nullSchema as OpenAPIV3.SchemaObject).nullable;\n nullSchema.type = 'null';\n\n return [typedSchema, nullSchema];\n }\n\n if (Array.isArray(schema.type)) {\n if (schema.type.length === 0) {\n const topLevelSchema = { ...schema };\n delete topLevelSchema.oneOf;\n delete topLevelSchema.anyOf;\n delete topLevelSchema.allOf;\n delete topLevelSchema.type;\n return [topLevelSchema];\n }\n\n return schema.type.map((typeString) => {\n const topLevelSchema = { ...schema };\n delete topLevelSchema.oneOf;\n delete topLevelSchema.anyOf;\n delete topLevelSchema.allOf;\n topLevelSchema.type = typeString;\n return topLevelSchema;\n });\n }\n\n const topLevelSchema = { ...schema };\n delete topLevelSchema.oneOf;\n delete topLevelSchema.anyOf;\n delete topLevelSchema.allOf;\n return [topLevelSchema];\n}\n\nfunction mergeExamples(\n schema1: SchemaObject,\n schema2: SchemaObject\n): SchemaObject['example'] | undefined {\n // literally exactly the same as combineExamples in packages/validation/src/openapi/utils.ts\n const examples1 =\n \n 'examples' in schema1 ? (schema1 as OpenAPIV3_1.SchemaObject).examples : undefined;\n const examples2 =\n \n 'examples' in schema2 ? (schema2 as OpenAPIV3_1.SchemaObject).examples : undefined;\n\n const example1 = examples1?.[0] !== undefined ? examples1[0] : schema1.example;\n const example2 = examples2?.[0] !== undefined ? examples2[0] : schema2.example;\n\n if (\n example1 &&\n example2 &&\n typeof example1 === 'object' &&\n typeof example2 === 'object' &&\n !Array.isArray(example1) &&\n !Array.isArray(example2)\n ) {\n return {\n \n ...(example1 as Record<string, unknown>),\n \n ...(example2 as Record<string, unknown>),\n };\n }\n\n // null is a valid example\n return example2 !== undefined ? example2 : example1;\n}\n\nfunction leastCommonMultiple(a: number, b: number): number {\n return Math.abs(a * b) / greatestCommonDivisor(a, b);\n}\n\nfunction greatestCommonDivisor(a: number, b: number): number {\n return b === 0 ? a : greatestCommonDivisor(b, a % b);\n}\n"],"names":["reduceExpandedSchema","schema","depth","location","flattenOneOfs","reduced","reduceCompositions","flattenSchemaOneOfs","safeParse","path","isCircularRef","shouldTruncateForSize","reduceOptionsCompositions","totalAllOf","subschema","index","accumulator","current","combineReducedSchemas","createEmptyReducedSchema","multiplySchemaArrays","key","propertyPath","error","handleExistingError","createUnknownReducedSchema","ImpossibleSchemaError","topLevelSchemaArray","generateTopLevelSchemaArray","schemaArray","evaluatedArray","a","b","MAX_SCHEMA_COMBINATION_SIZE","product","schema1","schema2","combineTopLevelSchemas","type1","type2","combinedSchema","takeLast","combine","leastCommonMultiple","value","example","mergeExamples","type","combinedProperties","property","schema1Property","leftAdditional","isReducedSchema","rightAdditional","typedSchema","nullSchema","topLevelSchema","typeString","examples1","examples2","example1","example2","greatestCommonDivisor"],"mappings":";;;AAwBO,SAASA,EAAqB;AAAA,EACnC,QAAAC;AAAA,EACA,OAAAC;AAAA,EACA,UAAAC;AAAA,EACA,eAAAC,IAAgB;AAClB,GAKiB;AACf,QAAMC,IAAUC,EAAmB;AAAA,IACjC,QAAAL;AAAA,IACA,OAAAC;AAAA,IACA,UAAAC;AAAA,IACA,WAAW;AA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AAEA,SAASjB,EAAoBZ,GAAWC,GAAmB;AACzD,SAAO,KAAK,IAAID,IAAIC,CAAC,IAAI8B,EAAsB/B,GAAGC,CAAC;AACrD;AAEA,SAAS8B,EAAsB/B,GAAWC,GAAmB;AAC3D,SAAOA,MAAM,IAAID,IAAI+B,EAAsB9B,GAAGD,IAAIC,CAAC;AACrD;"}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { CIRCULAR_REF_KEY as g } from "../constants/index.js";
|
|
2
|
+
import { reduceExpandedSchema as A } from "./reduceCompositions.js";
|
|
3
|
+
const E = ({
|
|
4
|
+
uuidObjectHashMap: n,
|
|
5
|
+
hashedNodeMap: i,
|
|
6
|
+
id: t
|
|
7
|
+
}) => {
|
|
8
|
+
if (!t || !n[t]) return;
|
|
9
|
+
const f = n[t];
|
|
10
|
+
if (f)
|
|
11
|
+
return i[f];
|
|
12
|
+
}, v = ({
|
|
13
|
+
uuidObjectHashMap: n,
|
|
14
|
+
hashedNodeMap: i,
|
|
15
|
+
id: t,
|
|
16
|
+
location: f,
|
|
17
|
+
flattenOneOfs: x = !0
|
|
18
|
+
}) => {
|
|
19
|
+
if (!t) return;
|
|
20
|
+
const p = /* @__PURE__ */ new Map(), h = /* @__PURE__ */ new Set(), m = (e) => typeof e == "string" && e in n, a = (e, R, j) => {
|
|
21
|
+
if (p.has(e)) return p.get(e);
|
|
22
|
+
if (h.has(e)) return { [g]: e };
|
|
23
|
+
h.add(e);
|
|
24
|
+
const r = E({ uuidObjectHashMap: n, hashedNodeMap: i, id: e });
|
|
25
|
+
if (!r) return e;
|
|
26
|
+
const s = o(r);
|
|
27
|
+
return p.set(e, s), s;
|
|
28
|
+
}, o = (e, R, j) => {
|
|
29
|
+
if (e == null) return e;
|
|
30
|
+
if (m(e)) return a(e);
|
|
31
|
+
if (Array.isArray(e)) return e.map((r) => o(r));
|
|
32
|
+
if (typeof e == "object") {
|
|
33
|
+
const r = e;
|
|
34
|
+
if (typeof r.$ref == "string" && m(r.$ref)) {
|
|
35
|
+
const c = a(r.$ref);
|
|
36
|
+
if (c && typeof c == "object") {
|
|
37
|
+
const d = { ...c };
|
|
38
|
+
for (const [y, $] of Object.entries(r))
|
|
39
|
+
y !== "$ref" && (d[y] = o($));
|
|
40
|
+
return d;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
const s = {};
|
|
44
|
+
for (const [c, d] of Object.entries(r))
|
|
45
|
+
s[c] = o(d);
|
|
46
|
+
return s;
|
|
47
|
+
}
|
|
48
|
+
return e;
|
|
49
|
+
}, b = o(t);
|
|
50
|
+
return A({
|
|
51
|
+
schema: b,
|
|
52
|
+
depth: 0,
|
|
53
|
+
location: f,
|
|
54
|
+
flattenOneOfs: x
|
|
55
|
+
});
|
|
56
|
+
};
|
|
57
|
+
export {
|
|
58
|
+
v as deeplyResolveGraphNode,
|
|
59
|
+
E as resolveGraphNode
|
|
60
|
+
};
|
|
61
|
+
//# sourceMappingURL=resolveGraphNode.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"resolveGraphNode.js","sources":["../../../src/api-playground-2/schemaGraph/resolveGraphNode.ts"],"sourcesContent":["import {\n type GraphNode,\n type HashedNodeMap,\n type UUID,\n type UUIDObjectHashMap,\n type SchemaObject,\n} from '@mintlify/validation';\n\nimport { CIRCULAR_REF_KEY } from '@/api-playground-2/constants';\nimport type { Location } from '@/api-playground-2/types';\n\nimport { reduceExpandedSchema } from './reduceCompositions';\n\n/**\n * Find a single node within the OpenAPI schema graph by its UUID. We can't know, from the graph,\n * the type of the returned node—it's up to the caller to properly specify the type.\n */\nexport const resolveGraphNode = <T extends GraphNode>({\n uuidObjectHashMap,\n hashedNodeMap,\n id,\n}: {\n uuidObjectHashMap: UUIDObjectHashMap;\n hashedNodeMap: HashedNodeMap;\n id?: UUID;\n}): T | undefined => {\n if (!id || !uuidObjectHashMap[id]) return undefined;\n const hashId = uuidObjectHashMap[id];\n if (!hashId) return undefined;\n \n return hashedNodeMap[hashId] as T | undefined;\n};\n\n/**\n * Find a single node within the OpenAPI schema graph, and recursively expand everything within its\n * subtree by following any resolvable UUIDs back through the graph.\n *\n * This function handles schema composition (anyOf, oneOf, allOf) through the use of reduceExpandedSchema,\n * which does some fun math and reshapes a schema such that there are only `oneOf` properties with\n * arrays of schemas within them.\n *\n * We only use the flattenOneOfs flag when testing against the v1 SchemaConverter, otherwise we want to recursively\n * remove oneOfs in the schema reduction.\n */\nexport const deeplyResolveGraphNode = <T extends GraphNode>({\n uuidObjectHashMap,\n hashedNodeMap,\n id,\n location,\n flattenOneOfs = true,\n}: {\n uuidObjectHashMap: UUIDObjectHashMap;\n hashedNodeMap: HashedNodeMap;\n id?: UUID;\n location?: Location;\n flattenOneOfs?: boolean;\n}): T | undefined => {\n if (!id) return undefined;\n\n const memo = new Map<UUID, unknown>();\n const visited = new Set<UUID>();\n\n const isResolvableUuid = (value: unknown): value is UUID =>\n typeof value === 'string' && value in uuidObjectHashMap;\n\n // Given a UUID, return the *fully-expanded* graph node at that UUID. We also memoize the result\n // + mark it as visited, to save work and to prevent infinite recursion, respectively.\n const resolveByUuid = (uuid: UUID, depth: number, currentLocation?: Location): unknown => {\n // If we've already deeply expanded this UUID, return it\n if (memo.has(uuid)) return memo.get(uuid);\n\n // If we've already visited this UUID but we haven't memoized it, then another call to this function\n // has already started expanding it; return a circular reference marker with the UUID.\n if (visited.has(uuid)) return { [CIRCULAR_REF_KEY]: uuid };\n\n // Visit the node: mark as visited, resolve the node, expand it, and memoize the result.\n visited.add(uuid);\n const node = resolveGraphNode<GraphNode>({ uuidObjectHashMap, hashedNodeMap, id: uuid });\n if (!node) return uuid;\n const expanded = expand(node, depth + 1, currentLocation);\n memo.set(uuid, expanded);\n\n return expanded;\n };\n\n // Recursive function -- for all properties of the object, expand the value if it is a UUID; return\n // the fully expanded objects all the way back up to the top.\n const expand = (value: unknown, depth: number, currentLocation?: Location): unknown => {\n if (value == null) return value;\n if (isResolvableUuid(value)) return resolveByUuid(value, depth, currentLocation);\n if (Array.isArray(value)) return value.map((item) => expand(item, depth + 1, currentLocation));\n if (typeof value === 'object') {\n \n const obj = value as Record<string, unknown>;\n\n // if the object contains a $ref, resolve it with any adjacent properties\n if (typeof obj.$ref === 'string' && isResolvableUuid(obj.$ref)) {\n const resolvedRef = resolveByUuid(obj.$ref, depth, currentLocation);\n if (resolvedRef && typeof resolvedRef === 'object') {\n \n const expandedObj: Record<string, unknown> = { ...resolvedRef } as Record<\n string,\n unknown\n >;\n // skip $ref, already expanded\n for (const [k, v] of Object.entries(obj)) {\n if (k !== '$ref') {\n expandedObj[k] = expand(v, depth + 1, currentLocation);\n }\n }\n\n return expandedObj;\n }\n }\n\n // Otherwise, recursively expand all properties\n \n const expandedObj: Record<string, unknown> = {};\n for (const [k, v] of Object.entries(obj)) {\n expandedObj[k] = expand(v, depth + 1, currentLocation);\n }\n\n return expandedObj;\n }\n return value;\n };\n\n // expand the schema by resolving all UUIDs into their full object graph\n \n const expanded = expand(id, 0, location) as SchemaObject;\n\n // reduce the expanded schema, converting any compositions into a single `oneOf` property\n const reduced = reduceExpandedSchema({\n schema: expanded,\n depth: 0,\n location,\n flattenOneOfs,\n });\n\n \n return reduced as T | undefined;\n};\n"],"names":["resolveGraphNode","uuidObjectHashMap","hashedNodeMap","id","hashId","deeplyResolveGraphNode","location","flattenOneOfs","memo","visited","isResolvableUuid","value","resolveByUuid","uuid","depth","currentLocation","CIRCULAR_REF_KEY","node","expanded","expand","item","obj","resolvedRef","expandedObj","k","v","reduceExpandedSchema"],"mappings":";;AAiBO,MAAMA,IAAmB,CAAsB;AAAA,EACpD,mBAAAC;AAAA,EACA,eAAAC;AAAA,EACA,IAAAC;AACF,MAIqB;AACnB,MAAI,CAACA,KAAM,CAACF,EAAkBE,CAAE,EAAG;AACnC,QAAMC,IAASH,EAAkBE,CAAE;AACnC,MAAKC;AAEL,WAAOF,EAAcE,CAAM;AAC7B,GAaaC,IAAyB,CAAsB;AAAA,EAC1D,mBAAAJ;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,QACT;AAAA,MACF;AAIA,YAAMA,IAAuC,CAAA;AAC7C,iBAAW,CAACC,GAAGC,CAAC,KAAK,OAAO,QAAQJ,CAAG;AACrC,QAAAE,EAAYC,CAAC,IAAIL,EAAOM,CAA6B;AAGvD,aAAOF;AAAA,IACT;AACA,WAAOZ;AAAA,EACT,GAIMO,IAAWC,EAAOhB,CAAe;AAWvC,SARgBuB,EAAqB;AAAA,IACnC,QAAQR;AAAA,IACR,OAAO;AAAA,IACP,UAAAZ;AAAA,IACA,eAAAC;AAAA,EAAA,CACD;AAIH;"}
|
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
import { CIRCULAR_REF_KEY as b } from "../constants/index.js";
|
|
2
|
+
import { reduceExpandedSchema as h } from "./reduceCompositions.js";
|
|
3
|
+
import { sortSchemaByRequired as l } from "./sortSchemaByRequired.js";
|
|
4
|
+
import { flattenSingleOneOf as v, isSchemaObject as u, isCircularRef as j } from "./utils.js";
|
|
5
|
+
import { addUniqueKeysToSchema as p } from "./addUniqueKeysToSchema.js";
|
|
6
|
+
import { generateExamplesFromSchema as q } from "./processExamples.js";
|
|
7
|
+
import { resolveGraphNode as R, deeplyResolveGraphNode as d } from "./resolveGraphNode.js";
|
|
8
|
+
const _ = ({
|
|
9
|
+
operationId: m,
|
|
10
|
+
uuidObjectHashMap: o,
|
|
11
|
+
hashedNodeMap: n
|
|
12
|
+
}) => {
|
|
13
|
+
const e = R({
|
|
14
|
+
uuidObjectHashMap: o,
|
|
15
|
+
hashedNodeMap: n,
|
|
16
|
+
id: m
|
|
17
|
+
});
|
|
18
|
+
if (!e)
|
|
19
|
+
return;
|
|
20
|
+
const t = /* @__PURE__ */ new Map(), r = /* @__PURE__ */ new Map(), c = e.parameters;
|
|
21
|
+
c == null || c.forEach((a) => {
|
|
22
|
+
if (typeof a != "string") return;
|
|
23
|
+
const f = B(a, o, n);
|
|
24
|
+
f && "name" in f && "in" in f && t.set(a, f);
|
|
25
|
+
});
|
|
26
|
+
let s;
|
|
27
|
+
const i = e.requestBody;
|
|
28
|
+
i && typeof i == "string" && (s = g(i, o, n), s && (s.content = q(s.content)));
|
|
29
|
+
const E = e.responses;
|
|
30
|
+
E && Object.values(E).forEach((a) => {
|
|
31
|
+
if (typeof a != "string") return;
|
|
32
|
+
const f = y(a, o, n);
|
|
33
|
+
f && f.content && (f.content = q(f.content)), f && r.set(a, f);
|
|
34
|
+
});
|
|
35
|
+
const O = {
|
|
36
|
+
operation: e,
|
|
37
|
+
parameters: Object.fromEntries(t),
|
|
38
|
+
requestBody: s,
|
|
39
|
+
responses: Object.fromEntries(r)
|
|
40
|
+
}, S = C(O, o, n);
|
|
41
|
+
return {
|
|
42
|
+
operation: e,
|
|
43
|
+
dependencies: {
|
|
44
|
+
parameters: Object.fromEntries(t),
|
|
45
|
+
requestBody: s,
|
|
46
|
+
responses: Object.fromEntries(r)
|
|
47
|
+
},
|
|
48
|
+
schemas: Object.keys(S).length > 0 ? S : void 0
|
|
49
|
+
};
|
|
50
|
+
};
|
|
51
|
+
function g(m, o, n) {
|
|
52
|
+
let e = d({
|
|
53
|
+
uuidObjectHashMap: o,
|
|
54
|
+
hashedNodeMap: n,
|
|
55
|
+
id: m
|
|
56
|
+
});
|
|
57
|
+
if (e)
|
|
58
|
+
return e = v(e), Object.values(e.content).forEach((t) => {
|
|
59
|
+
if (t.schema && u(t.schema)) {
|
|
60
|
+
let r = h({
|
|
61
|
+
schema: t.schema,
|
|
62
|
+
depth: 0,
|
|
63
|
+
location: "request"
|
|
64
|
+
});
|
|
65
|
+
r = l(r), r = p(r, ""), t.schema = r;
|
|
66
|
+
}
|
|
67
|
+
}), e;
|
|
68
|
+
}
|
|
69
|
+
function y(m, o, n) {
|
|
70
|
+
let e = d({
|
|
71
|
+
uuidObjectHashMap: o,
|
|
72
|
+
hashedNodeMap: n,
|
|
73
|
+
id: m
|
|
74
|
+
});
|
|
75
|
+
if (e)
|
|
76
|
+
return e = v(e), e.content && Object.values(e.content).forEach((t) => {
|
|
77
|
+
if (t.schema && u(t.schema)) {
|
|
78
|
+
let r = h({
|
|
79
|
+
schema: t.schema,
|
|
80
|
+
depth: 0,
|
|
81
|
+
location: "response"
|
|
82
|
+
});
|
|
83
|
+
r = l(r), r = p(r, ""), t.schema = r;
|
|
84
|
+
}
|
|
85
|
+
}), e;
|
|
86
|
+
}
|
|
87
|
+
function B(m, o, n) {
|
|
88
|
+
let e = d({
|
|
89
|
+
uuidObjectHashMap: o,
|
|
90
|
+
hashedNodeMap: n,
|
|
91
|
+
id: m
|
|
92
|
+
});
|
|
93
|
+
if (e) {
|
|
94
|
+
if (e = v(e), "schema" in e && e.schema && u(e.schema)) {
|
|
95
|
+
let t = h({
|
|
96
|
+
schema: e.schema,
|
|
97
|
+
depth: 0,
|
|
98
|
+
location: "request"
|
|
99
|
+
});
|
|
100
|
+
t = l(t), t = p(t, ""), e.schema = t;
|
|
101
|
+
}
|
|
102
|
+
return "content" in e && e.content && Object.values(e.content).forEach((t) => {
|
|
103
|
+
if (t.schema && u(t.schema)) {
|
|
104
|
+
let r = h({
|
|
105
|
+
schema: t.schema,
|
|
106
|
+
depth: 0,
|
|
107
|
+
location: "request"
|
|
108
|
+
});
|
|
109
|
+
r = l(r), r = p(r, ""), t.schema = r;
|
|
110
|
+
}
|
|
111
|
+
}), e;
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
function C(m, o, n, e = /* @__PURE__ */ new Set()) {
|
|
115
|
+
const t = {}, r = (c) => {
|
|
116
|
+
if (c != null) {
|
|
117
|
+
if (j(c)) {
|
|
118
|
+
const s = c[b];
|
|
119
|
+
if (!e.has(s)) {
|
|
120
|
+
e.add(s);
|
|
121
|
+
let i = d({
|
|
122
|
+
uuidObjectHashMap: o,
|
|
123
|
+
hashedNodeMap: n,
|
|
124
|
+
id: s
|
|
125
|
+
});
|
|
126
|
+
if (!i) return;
|
|
127
|
+
i = h({
|
|
128
|
+
schema: i,
|
|
129
|
+
depth: 0,
|
|
130
|
+
location: "request"
|
|
131
|
+
}), i = l(i), t[s] = i, r(i);
|
|
132
|
+
}
|
|
133
|
+
return;
|
|
134
|
+
}
|
|
135
|
+
if (Array.isArray(c)) {
|
|
136
|
+
c.forEach(r);
|
|
137
|
+
return;
|
|
138
|
+
}
|
|
139
|
+
if (typeof c == "object")
|
|
140
|
+
for (const s of Object.values(c))
|
|
141
|
+
r(s);
|
|
142
|
+
}
|
|
143
|
+
};
|
|
144
|
+
return r(m), t;
|
|
145
|
+
}
|
|
146
|
+
export {
|
|
147
|
+
_ as resolveOperationWithDependencies
|
|
148
|
+
};
|
|
149
|
+
//# sourceMappingURL=resolveOperationWithDependencies.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"resolveOperationWithDependencies.js","sources":["../../../src/api-playground-2/schemaGraph/resolveOperationWithDependencies.ts"],"sourcesContent":["import type {\n HashedNodeMap,\n HttpMethod,\n Operation,\n ParameterObject,\n RequestBodyObject,\n ResponseObject,\n ParameterOrRef,\n UUID,\n UUIDObjectHashMap,\n MediaObject,\n SchemaObject,\n} from '@mintlify/validation';\n\nimport { CIRCULAR_REF_KEY } from '@/api-playground-2/constants';\nimport { reduceExpandedSchema } from '@/api-playground-2/schemaGraph/reduceCompositions';\nimport { sortSchemaByRequired } from '@/api-playground-2/schemaGraph/sortSchemaByRequired';\nimport {\n flattenSingleOneOf,\n isSchemaObject,\n isCircularRef,\n} from '@/api-playground-2/schemaGraph/utils';\n\nimport { addUniqueKeysToSchema } from './addUniqueKeysToSchema';\nimport { generateExamplesFromSchema } from './processExamples';\nimport { deeplyResolveGraphNode, resolveGraphNode } from './resolveGraphNode';\n\nexport type ResolvedEndpoint = {\n deprecated: boolean;\n description: string;\n method: HttpMethod;\n path: string;\n request: {\n body: UUID | undefined;\n parameters: UUID[] | undefined;\n security: UUID[] | undefined;\n };\n // e.g. { '200': 'uuid-here', '400': 'uuid-here' }\n response: Record<string, UUID> | undefined;\n type: 'path' | 'webhook';\n};\n\nexport type ResolvedOperationData = {\n operation: Operation;\n dependencies: {\n parameters?: Record<UUID, ParameterObject>;\n requestBody?: RequestBodyObject;\n responses?: Record<UUID, ResponseObject>;\n };\n schemas?: Record<UUID, SchemaObject>;\n};\n\nexport const resolveOperationWithDependencies = ({\n operationId,\n uuidObjectHashMap,\n hashedNodeMap,\n}: {\n operationId: UUID;\n uuidObjectHashMap: UUIDObjectHashMap;\n hashedNodeMap: HashedNodeMap;\n}): ResolvedOperationData | undefined => {\n const operation = resolveGraphNode<Operation>({\n uuidObjectHashMap,\n hashedNodeMap,\n id: operationId,\n });\n\n if (!operation) {\n return undefined;\n }\n\n const parameters = new Map<UUID, ParameterObject>();\n const responses = new Map<UUID, ResponseObject>();\n\n const parameterIds = operation.parameters;\n parameterIds?.forEach((paramId) => {\n if (typeof paramId !== 'string') return;\n const parameter = resolveParameter(paramId, uuidObjectHashMap, hashedNodeMap);\n if (parameter && 'name' in parameter && 'in' in parameter) {\n parameters.set(paramId, parameter);\n }\n });\n\n let requestBody: RequestBodyObject | undefined;\n const requestBodyId = operation.requestBody;\n if (requestBodyId && typeof requestBodyId === 'string') {\n requestBody = resolveRequestBody(requestBodyId, uuidObjectHashMap, hashedNodeMap);\n\n if (requestBody) {\n requestBody.content = generateExamplesFromSchema(requestBody.content);\n }\n }\n\n const responsesMap = operation.responses;\n if (responsesMap) {\n Object.values(responsesMap).forEach((responseId) => {\n if (typeof responseId !== 'string') return;\n const response = resolveResponse(responseId, uuidObjectHashMap, hashedNodeMap);\n\n if (response && response.content) {\n response.content = generateExamplesFromSchema(response.content);\n }\n\n if (response) {\n responses.set(responseId, response);\n }\n });\n }\n\n // Collect all schemas with circular references\n const allResolvedObjects = {\n operation,\n parameters: Object.fromEntries(parameters),\n requestBody,\n responses: Object.fromEntries(responses),\n };\n\n const schemas = collectCircularSchemas(allResolvedObjects, uuidObjectHashMap, hashedNodeMap);\n\n // we're using Maps above for the ergonomics, but we convert to JS objects at return time\n // for better serialization.\n return {\n operation,\n dependencies: {\n parameters: Object.fromEntries(parameters),\n requestBody,\n responses: Object.fromEntries(responses),\n },\n schemas: Object.keys(schemas).length > 0 ? schemas : undefined,\n };\n};\n\nfunction resolveRequestBody(\n requestBodyId: UUID,\n uuidObjectHashMap: UUIDObjectHashMap,\n hashedNodeMap: HashedNodeMap\n): RequestBodyObject | undefined {\n let requestBody = deeplyResolveGraphNode<RequestBodyObject>({\n uuidObjectHashMap,\n hashedNodeMap,\n id: requestBodyId,\n });\n if (!requestBody) return undefined;\n\n requestBody = flattenSingleOneOf<RequestBodyObject>(requestBody);\n\n Object.values(requestBody.content).forEach((mediaType) => {\n if (mediaType.schema && isSchemaObject(mediaType.schema)) {\n let resolvedSchema = reduceExpandedSchema({\n schema: mediaType.schema,\n depth: 0,\n location: 'request',\n });\n resolvedSchema = sortSchemaByRequired(resolvedSchema);\n resolvedSchema = addUniqueKeysToSchema(resolvedSchema, '');\n // replace the schema id with the resolved schema\n \n (mediaType as MediaObject).schema = resolvedSchema;\n }\n });\n\n return requestBody;\n}\n\nfunction resolveResponse(\n responseId: UUID,\n uuidObjectHashMap: UUIDObjectHashMap,\n hashedNodeMap: HashedNodeMap\n): ResponseObject | undefined {\n let response = deeplyResolveGraphNode<ResponseObject>({\n uuidObjectHashMap,\n hashedNodeMap,\n id: responseId,\n });\n if (!response) return undefined;\n\n response = flattenSingleOneOf<ResponseObject>(response);\n\n if (response.content) {\n Object.values(response.content).forEach((mediaType) => {\n if (mediaType.schema && isSchemaObject(mediaType.schema)) {\n let resolvedSchema = reduceExpandedSchema({\n schema: mediaType.schema,\n depth: 0,\n location: 'response',\n });\n resolvedSchema = sortSchemaByRequired(resolvedSchema);\n resolvedSchema = addUniqueKeysToSchema(resolvedSchema, '');\n // replace the schema id with the resolved schema\n \n (mediaType as MediaObject).schema = resolvedSchema;\n }\n });\n }\n\n return response;\n}\n\nfunction resolveParameter(\n parameterId: UUID,\n uuidObjectHashMap: UUIDObjectHashMap,\n hashedNodeMap: HashedNodeMap\n): ParameterOrRef | undefined {\n let parameter = deeplyResolveGraphNode<ParameterOrRef>({\n uuidObjectHashMap,\n hashedNodeMap,\n id: parameterId,\n });\n if (!parameter) return undefined;\n\n parameter = flattenSingleOneOf<ParameterOrRef>(parameter);\n\n if ('schema' in parameter && parameter.schema && isSchemaObject(parameter.schema)) {\n let resolvedSchema = reduceExpandedSchema({\n schema: parameter.schema,\n depth: 0,\n location: 'request',\n });\n resolvedSchema = sortSchemaByRequired(resolvedSchema);\n resolvedSchema = addUniqueKeysToSchema(resolvedSchema, '');\n // replace the schema id with the resolved schema\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n (parameter as any).schema = resolvedSchema;\n }\n\n if ('content' in parameter && parameter.content) {\n Object.values(parameter.content).forEach((mediaType) => {\n if (mediaType.schema && isSchemaObject(mediaType.schema)) {\n let resolvedSchema = reduceExpandedSchema({\n schema: mediaType.schema,\n depth: 0,\n location: 'request',\n });\n resolvedSchema = sortSchemaByRequired(resolvedSchema);\n resolvedSchema = addUniqueKeysToSchema(resolvedSchema, '');\n // replace the schema id with the resolved schema\n \n (mediaType as MediaObject).schema = resolvedSchema;\n }\n });\n }\n\n return parameter;\n}\n\n/**\n * Collect all schemas that have circular references by walking through the resolved objects.\n * Returns a map of UUID -> SchemaObject for schemas that contain circular refs.\n */\nfunction collectCircularSchemas(\n obj: unknown,\n uuidObjectHashMap: UUIDObjectHashMap,\n hashedNodeMap: HashedNodeMap,\n visited = new Set<UUID>()\n): Record<UUID, SchemaObject> {\n const schemas: Record<UUID, SchemaObject> = {};\n\n const collect = (value: unknown): void => {\n if (value == null) return;\n\n // If we encounter a circular ref, collect the referenced schema\n if (isCircularRef(value)) {\n const uuid = value[CIRCULAR_REF_KEY];\n if (!visited.has(uuid)) {\n visited.add(uuid);\n let node = deeplyResolveGraphNode<SchemaObject>({\n uuidObjectHashMap,\n hashedNodeMap,\n id: uuid,\n });\n\n if (!node) return;\n\n node = reduceExpandedSchema({\n schema: node,\n depth: 0,\n location: 'request',\n });\n node = sortSchemaByRequired(node);\n\n schemas[uuid] = node;\n // Recursively collect from this schema too\n collect(node);\n }\n return;\n }\n\n if (Array.isArray(value)) {\n value.forEach(collect);\n return;\n }\n\n if (typeof value === 'object') {\n for (const v of Object.values(value)) {\n collect(v);\n }\n }\n };\n\n collect(obj);\n return schemas;\n}\n"],"names":["resolveOperationWithDependencies","operationId","uuidObjectHashMap","hashedNodeMap","operation","resolveGraphNode","parameters","responses","parameterIds","paramId","parameter","resolveParameter","requestBody","requestBodyId","resolveRequestBody","generateExamplesFromSchema","responsesMap","responseId","response","resolveResponse","allResolvedObjects","schemas","collectCircularSchemas","deeplyResolveGraphNode","flattenSingleOneOf","mediaType","isSchemaObject","resolvedSchema","reduceExpandedSchema","sortSchemaByRequired","addUniqueKeysToSchema","parameterId","obj","visited","collect","value","isCircularRef","uuid","CIRCULAR_REF_KEY","node","v"],"mappings":";;;;;;;AAoDO,MAAMA,IAAmC,CAAC;AAAA,EAC/C,aAAAC;AAAA,EACA,mBAAAC;AAAA,EACA,eAAAC;AACF,MAIyC;AACvC,QAAMC,IAAYC,EAA4B;AAAA,IAC5C,mBAAAH;AAAA,IACA,eAAAC;AAAA,IACA,IAAIF;AAAA,EAAA,CACL;AAED,MAAI,CAACG;AACH;AAGF,QAAME,wBAAiB,IAAA,GACjBC,wBAAgB,IAAA,GAEhBC,IAAeJ,EAAU;AAC/B,EAAAI,KAAA,QAAAA,EAAc,QAAQ,CAACC,MAAY;AACjC,QAAI,OAAOA,KAAY,SAAU;AACjC,UAAMC,IAAYC,EAAiBF,GAASP,GAAmBC,CAAa;AAC5E,IAAIO,KAAa,UAAUA,KAAa,QAAQA,KAC9CJ,EAAW,IAAIG,GAASC,CAAS;AAAA,EAErC;AAEA,MAAIE;AACJ,QAAMC,IAAgBT,EAAU;AAChC,EAAIS,KAAiB,OAAOA,KAAkB,aAC5CD,IAAcE,EAAmBD,GAAeX,GAAmBC,CAAa,GAE5ES,MACFA,EAAY,UAAUG,EAA2BH,EAAY,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