@kubb/plugin-oas 3.0.0-alpha.9 → 3.0.0-beta.10
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 +14 -5
- package/dist/OperationGenerator-Dko8Xtd7.d.cts +561 -0
- package/dist/OperationGenerator-Dko8Xtd7.d.ts +561 -0
- package/dist/{Schema-B1vcPGiK.d.ts → Schema-C2cbPYX1.d.cts} +1 -12
- package/dist/{Schema-DoSFh7Qd.d.cts → Schema-CbtIvprh.d.ts} +1 -12
- package/dist/chunk-2TGWPVZN.cjs +92 -0
- package/dist/chunk-2TGWPVZN.cjs.map +1 -0
- package/dist/chunk-A3ROGKLW.cjs +752 -0
- package/dist/chunk-A3ROGKLW.cjs.map +1 -0
- package/dist/chunk-ABOQ73FL.cjs +36 -0
- package/dist/chunk-ABOQ73FL.cjs.map +1 -0
- package/dist/chunk-BG77DP54.js +30 -0
- package/dist/chunk-BG77DP54.js.map +1 -0
- package/dist/chunk-GF26SDHQ.js +28 -0
- package/dist/chunk-GF26SDHQ.js.map +1 -0
- package/dist/chunk-JA75IPYU.js +744 -0
- package/dist/chunk-JA75IPYU.js.map +1 -0
- package/dist/chunk-PADR76WZ.cjs +4 -0
- package/dist/chunk-PADR76WZ.cjs.map +1 -0
- package/dist/chunk-QAFBZLJA.cjs +48 -0
- package/dist/{chunk-SZDO532A.js.map → chunk-QAFBZLJA.cjs.map} +1 -1
- package/dist/chunk-R47XMJ32.js +3 -0
- package/dist/chunk-R47XMJ32.js.map +1 -0
- package/dist/chunk-TNWNNVQW.js +88 -0
- package/dist/chunk-TNWNNVQW.js.map +1 -0
- package/dist/chunk-XNCEFOE6.js +45 -0
- package/dist/chunk-XNCEFOE6.js.map +1 -0
- package/dist/chunk-ZWHQ54JM.cjs +32 -0
- package/dist/chunk-ZWHQ54JM.cjs.map +1 -0
- package/dist/components.cjs +20 -12
- package/dist/components.cjs.map +1 -1
- package/dist/components.d.cts +3 -6
- package/dist/components.d.ts +3 -6
- package/dist/components.js +3 -12
- package/dist/components.js.map +1 -1
- package/dist/generators.cjs +14 -0
- package/dist/generators.cjs.map +1 -0
- package/dist/generators.d.cts +9 -0
- package/dist/generators.d.ts +9 -0
- package/dist/generators.js +5 -0
- package/dist/generators.js.map +1 -0
- package/dist/hooks.cjs +90 -57
- package/dist/hooks.cjs.map +1 -1
- package/dist/hooks.d.cts +37 -10
- package/dist/hooks.d.ts +37 -10
- package/dist/hooks.js +79 -53
- package/dist/hooks.js.map +1 -1
- package/dist/index.cjs +142 -189
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +2 -5
- package/dist/index.d.ts +2 -5
- package/dist/index.js +82 -156
- package/dist/index.js.map +1 -1
- package/dist/utils.cjs +32 -45
- package/dist/utils.cjs.map +1 -1
- package/dist/utils.d.cts +4 -13
- package/dist/utils.d.ts +4 -13
- package/dist/utils.js +8 -44
- package/dist/utils.js.map +1 -1
- package/package.json +20 -14
- package/src/OperationGenerator.ts +30 -39
- package/src/SchemaGenerator.ts +70 -11
- package/src/SchemaMapper.ts +24 -5
- package/src/components/Schema.tsx +1 -99
- package/src/generator.tsx +22 -18
- package/src/generators/index.ts +1 -0
- package/src/generators/jsonGenerator.ts +32 -0
- package/src/hooks/index.ts +2 -0
- package/src/hooks/useOperationManager.ts +56 -31
- package/src/hooks/useSchemaManager.ts +77 -0
- package/src/index.ts +2 -4
- package/src/plugin.ts +69 -56
- package/src/types.ts +29 -22
- package/src/utils/getParams.ts +1 -1
- package/src/utils/getSchemaFactory.ts +1 -1
- package/src/utils/index.ts +0 -1
- package/src/utils/parseFromConfig.ts +7 -7
- package/dist/OperationGenerator-By5WOmWB.d.ts +0 -165
- package/dist/OperationGenerator-Gd1X7wUz.d.cts +0 -165
- package/dist/SchemaMapper-sGcY1xL5.d.cts +0 -247
- package/dist/SchemaMapper-sGcY1xL5.d.ts +0 -247
- package/dist/chunk-75BIOXB7.cjs +0 -7
- package/dist/chunk-75BIOXB7.cjs.map +0 -1
- package/dist/chunk-IAUV3UKH.cjs +0 -3965
- package/dist/chunk-IAUV3UKH.cjs.map +0 -1
- package/dist/chunk-M347763D.js +0 -3965
- package/dist/chunk-M347763D.js.map +0 -1
- package/dist/chunk-N7EEVJA6.js +0 -35
- package/dist/chunk-N7EEVJA6.js.map +0 -1
- package/dist/chunk-NU4F7G47.cjs +0 -89
- package/dist/chunk-NU4F7G47.cjs.map +0 -1
- package/dist/chunk-O76YQFZB.cjs +0 -35
- package/dist/chunk-O76YQFZB.cjs.map +0 -1
- package/dist/chunk-SQ64ESS4.js +0 -7
- package/dist/chunk-SQ64ESS4.js.map +0 -1
- package/dist/chunk-SZDO532A.js +0 -89
- package/dist/types-CZTUCaE5.d.cts +0 -145
- package/dist/types-CZTUCaE5.d.ts +0 -145
- package/src/utils/refSorter.ts +0 -13
package/dist/hooks.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/hooks/index.ts","../src/hooks/useOas.ts","../src/hooks/useOperation.ts","../src/hooks/useOperationManager.ts","../src/hooks/useOperations.ts"],"sourcesContent":["export { useOas } from './useOas.ts'\nexport { useOperation } from './useOperation.ts'\nexport { useOperationManager } from './useOperationManager.ts'\nexport { useOperations } from './useOperations.ts'\nexport { useSchema } from './useSchema.ts'\n","import { useContext } from '@kubb/react'\n\nimport { Oas } from '../components/Oas.tsx'\n\nimport type { Oas as OasType } from '@kubb/oas'\n\nexport function useOas(): OasType {\n const { oas } = useContext(Oas.Context)\n\n if (!oas) {\n throw new Error('Oas is not defined')\n }\n\n return oas\n}\n","import { useContext } from '@kubb/react'\n\nimport { Operation } from '../components/Operation.tsx'\n\nimport type { Operation as OperationType } from '@kubb/oas'\n\n/**\n * `useOperation` will return the current `Operation`\n */\nexport function useOperation(): OperationType {\n const { operation } = useContext(Operation.Context)\n\n if (!operation) {\n throw new Error('Operation is not defined')\n }\n\n return operation\n}\n","import { useApp, useContext } from '@kubb/react'\n\nimport { Oas } from '../components/Oas.tsx'\n\nimport type { FileMetaBase, Plugin, ResolveNameParams } from '@kubb/core'\nimport type * as KubbFile from '@kubb/fs/types'\nimport type { Operation, Operation as OperationType } from '@kubb/oas'\nimport type { OperationSchemas } from '../types.ts'\n\ntype FileMeta = FileMetaBase & {\n pluginKey: Plugin['key']\n name: string\n tag?: string\n}\n\ntype SchemaNames = {\n request: string | undefined\n parameters: {\n path: string | undefined\n query: string | undefined\n header: string | undefined\n }\n responses: { default?: string } & Record<number | string, string>\n errors: Record<number | string, string>\n}\n\ntype UseOperationManagerResult = {\n getName: (operation: OperationType, params: { pluginKey?: Plugin['key']; type: ResolveNameParams['type'] }) => string\n getFile: (operation: OperationType, params?: { pluginKey?: Plugin['key']; extName?: KubbFile.Extname }) => KubbFile.File<FileMeta>\n groupSchemasByName: (operation: OperationType, params: { pluginKey?: Plugin['key']; type: ResolveNameParams['type'] }) => SchemaNames\n getSchemas: (\n operation: Operation,\n params?: { pluginKey?: Plugin['key']; type?: ResolveNameParams['type'] },\n forStatusCode?: string | number,\n ) => OperationSchemas\n}\n\n/**\n * `useOperationManager` will return some helper functions that can be used to get the operation file, get the operation name.\n */\nexport function useOperationManager(): UseOperationManagerResult {\n const { plugin, pluginManager } = useApp()\n const { generator } = useContext(Oas.Context)\n\n if (!generator) {\n throw new Error(`'generator' is not defined`)\n }\n\n const getName: UseOperationManagerResult['getName'] = (operation, { pluginKey = plugin.key, type }) => {\n return pluginManager.resolveName({\n name: operation.getOperationId(),\n pluginKey,\n type,\n })\n }\n\n const getFile: UseOperationManagerResult['getFile'] = (operation, { pluginKey = plugin.key, extName = '.ts' } = {}) => {\n // needed for the `output.group`\n const tag = operation.getTags().at(0)?.name\n //TODO replace with group\n const name = getName(operation, { type: 'file', pluginKey })\n\n const file = pluginManager.getFile({\n name,\n extName,\n pluginKey,\n options: { type: 'file', pluginKey, tag },\n })\n\n return {\n ...file,\n meta: {\n ...file.meta,\n name,\n pluginKey,\n tag,\n },\n }\n }\n\n const groupSchemasByName: UseOperationManagerResult['groupSchemasByName'] = (operation, { pluginKey = plugin.key, type }) => {\n const schemas = generator.getSchemas(operation)\n\n const errors = (schemas.errors || []).reduce(\n (prev, acc) => {\n if (!acc.statusCode) {\n return prev\n }\n\n prev[acc.statusCode] = pluginManager.resolveName({\n name: acc.name,\n pluginKey,\n type,\n })\n\n return prev\n },\n {} as Record<number, string>,\n )\n\n return {\n request: schemas.request?.name\n ? pluginManager.resolveName({\n name: schemas.request.name,\n pluginKey,\n type,\n })\n : undefined,\n parameters: {\n path: schemas.pathParams?.name\n ? pluginManager.resolveName({\n name: schemas.pathParams.name,\n pluginKey,\n type,\n })\n : undefined,\n query: schemas.queryParams?.name\n ? pluginManager.resolveName({\n name: schemas.queryParams.name,\n pluginKey,\n type,\n })\n : undefined,\n header: schemas.headerParams?.name\n ? pluginManager.resolveName({\n name: schemas.headerParams.name,\n pluginKey,\n type,\n })\n : undefined,\n },\n responses: {\n [schemas.response.statusCode || 'default']: pluginManager.resolveName({\n name: schemas.response.name,\n pluginKey,\n type,\n }),\n ['default']: pluginManager.resolveName({\n name: schemas.response.name,\n pluginKey,\n type,\n }),\n ...errors,\n },\n errors,\n }\n }\n\n return {\n getName,\n getFile,\n getSchemas: (operation, params, forStatusCode) =>\n generator.getSchemas(operation, {\n forStatusCode,\n resolveName: (name) =>\n pluginManager.resolveName({\n name,\n pluginKey: params?.pluginKey,\n type: params?.type,\n }),\n }),\n groupSchemasByName,\n }\n}\n","import { useContext } from '@kubb/react'\n\nimport { Oas } from '../components/Oas.tsx'\n\nimport type { HttpMethod, Operation } from '@kubb/oas'\n\ntype UseOperationsProps = {\n /**\n * Filter based on path\n * Weight: 2\n */\n path?: string\n /**\n * Filter based on method\n * Weight: 1\n */\n method?: HttpMethod\n}\n\n/**\n * `useOperations` will return all the Operations\n */\nexport function useOperations({ method, path }: UseOperationsProps = {}): Operation[] {\n const { operations } = useContext(Oas.Context)\n\n if (!operations) {\n throw new Error('Operations is not defined')\n }\n let items = operations\n\n if (path) {\n items = items.filter((item) => item.path === path)\n }\n\n if (method) {\n items = items.filter((item) => item.method === method)\n }\n\n return items\n}\n"],"mappings":";;;;;;;;;;AAAA;;;ACAA;AAAA,SAAS,kBAAkB;AAMpB,SAAS,SAAkB;AAChC,QAAM,EAAE,IAAI,IAAI,WAAW,IAAI,OAAO;AAEtC,MAAI,CAAC,KAAK;AACR,UAAM,IAAI,MAAM,oBAAoB;AAAA,EACtC;AAEA,SAAO;AACT;;;ACdA;AAAA,SAAS,cAAAA,mBAAkB;AASpB,SAAS,eAA8B;AAC5C,QAAM,EAAE,UAAU,IAAIC,YAAW,UAAU,OAAO;AAElD,MAAI,CAAC,WAAW;AACd,UAAM,IAAI,MAAM,0BAA0B;AAAA,EAC5C;AAEA,SAAO;AACT;;;ACjBA;AAAA,SAAS,QAAQ,cAAAC,mBAAkB;AAwC5B,SAAS,sBAAiD;AAC/D,QAAM,EAAE,QAAQ,cAAc,IAAI,OAAO;AACzC,QAAM,EAAE,UAAU,IAAIC,YAAW,IAAI,OAAO;AAE5C,MAAI,CAAC,WAAW;AACd,UAAM,IAAI,MAAM,4BAA4B;AAAA,EAC9C;AAEA,QAAM,UAAgD,CAAC,WAAW,EAAE,YAAY,OAAO,KAAK,KAAK,MAAM;AACrG,WAAO,cAAc,YAAY;AAAA,MAC/B,MAAM,UAAU,eAAe;AAAA,MAC/B;AAAA,MACA;AAAA,IACF,CAAC;AAAA,EACH;AAEA,QAAM,UAAgD,CAAC,WAAW,EAAE,YAAY,OAAO,KAAK,UAAU,MAAM,IAAI,CAAC,MAAM;AAErH,UAAM,MAAM,UAAU,QAAQ,EAAE,GAAG,CAAC,GAAG;AAEvC,UAAM,OAAO,QAAQ,WAAW,EAAE,MAAM,QAAQ,UAAU,CAAC;AAE3D,UAAM,OAAO,cAAc,QAAQ;AAAA,MACjC;AAAA,MACA;AAAA,MACA;AAAA,MACA,SAAS,EAAE,MAAM,QAAQ,WAAW,IAAI;AAAA,IAC1C,CAAC;AAED,WA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GAAG,cAAc,YAAY;AAAA,UACrC,MAAM,QAAQ,SAAS;AAAA,UACvB;AAAA,UACA;AAAA,QACF,CAAC;AAAA,QACD,GAAG;AAAA,MACL;AAAA,MACA;AAAA,IACF;AAAA,EACF;AAEA,SAAO;AAAA,IACL;AAAA,IACA;AAAA,IACA,YAAY,CAAC,WAAW,QAAQ,kBAC9B,UAAU,WAAW,WAAW;AAAA,MAC9B;AAAA,MACA,aAAa,CAAC,SACZ,cAAc,YAAY;AAAA,QACxB;AAAA,QACA,WAAW,QAAQ;AAAA,QACnB,MAAM,QAAQ;AAAA,MAChB,CAAC;AAAA,IACL,CAAC;AAAA,IACH;AAAA,EACF;AACF;;;ACnKA;AAAA,SAAS,cAAAC,mBAAkB;AAsBpB,SAAS,cAAc,EAAE,QAAQ,KAAK,IAAwB,CAAC,GAAgB;AACpF,QAAM,EAAE,WAAW,IAAIC,YAAW,IAAI,OAAO;AAE7C,MAAI,CAAC,YAAY;AACf,UAAM,IAAI,MAAM,2BAA2B;AAAA,EAC7C;AACA,MAAI,QAAQ;AAEZ,MAAI,MAAM;AACR,YAAQ,MAAM,OAAO,CAAC,SAAS,KAAK,SAAS,IAAI;AAAA,EACnD;AAEA,MAAI,QAAQ;AACV,YAAQ,MAAM,OAAO,CAAC,SAAS,KAAK,WAAW,MAAM;AAAA,EACvD;AAEA,SAAO;AACT;","names":["useContext","useContext","useContext","useContext","useContext","useContext"]}
|
|
1
|
+
{"version":3,"sources":["../src/hooks/useOas.ts","../src/hooks/useOperation.ts","../src/hooks/useOperationManager.ts","../src/hooks/useOperations.ts","../src/hooks/useSchema.ts","../src/hooks/useSchemaManager.ts"],"names":["useContext","useApp","mode"],"mappings":";;;;;AAMO,SAAS,MAAkB,GAAA;AAChC,EAAA,MAAM,EAAE,GAAA,EAAQ,GAAA,UAAA,CAAW,IAAI,OAAO,CAAA;AAEtC,EAAA,IAAI,CAAC,GAAK,EAAA;AACR,IAAM,MAAA,IAAI,MAAM,oBAAoB,CAAA;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ext } from '@kubb/react'\n\nimport { Oas } from '../components/Oas.tsx'\n\nimport type { Oas as OasType } from '@kubb/oas'\n\nexport function useOas(): OasType {\n const { oas } = useContext(Oas.Context)\n\n if (!oas) {\n throw new Error('Oas is not defined')\n }\n\n return oas\n}\n","import { useContext } from '@kubb/react'\n\nimport { Operation } from '../components/Operation.tsx'\n\nimport type { Operation as OperationType } from '@kubb/oas'\n\n/**\n * `useOperation` will return the current `Operation`\n */\nexport function useOperation(): OperationType {\n const { operation } = useContext(Operation.Context)\n\n if (!operation) {\n throw new Error('Operation is not defined')\n }\n\n return operation\n}\n","import { useApp, useContext } from '@kubb/react'\n\nimport { Oas } from '../components/Oas.tsx'\n\nimport type { FileMetaBase, Plugin, ResolveNameParams } from '@kubb/core'\nimport type * as KubbFile from '@kubb/fs/types'\nimport type { Operation, Operation as OperationType } from '@kubb/oas'\nimport type { OperationSchemas } from '../types.ts'\n\ntype FileMeta = FileMetaBase & {\n pluginKey: Plugin['key']\n name: string\n tag?: string\n}\n\nexport type SchemaNames = {\n request: string | undefined\n parameters: {\n path: string | undefined\n query: string | undefined\n header: string | undefined\n }\n responses: { default?: string } & Record<number | string, string>\n errors: Record<number | string, string>\n}\n\ntype UseOperationManagerResult = {\n getName: (\n operation: OperationType,\n params: {\n prefix?: string\n suffix?: string\n pluginKey?: Plugin['key']\n type: ResolveNameParams['type']\n },\n ) => string\n getFile: (\n operation: OperationType,\n params?: {\n prefix?: string\n suffix?: string\n pluginKey?: Plugin['key']\n extname?: KubbFile.Extname\n tag?: string\n },\n ) => KubbFile.File<FileMeta>\n groupSchemasByName: (\n operation: OperationType,\n params: {\n pluginKey?: Plugin['key']\n type: ResolveNameParams['type']\n },\n ) => SchemaNames\n getSchemas: (operation: Operation, params?: { pluginKey?: Plugin['key']; type?: ResolveNameParams['type'] }) => OperationSchemas\n}\n\n/**\n * `useOperationManager` will return some helper functions that can be used to get the operation file, get the operation name.\n */\nexport function useOperationManager(): UseOperationManagerResult {\n const { plugin, pluginManager } = useApp()\n const { generator } = useContext(Oas.Context)\n\n const getName: UseOperationManagerResult['getName'] = (operation, { prefix = '', suffix = '', pluginKey = plugin.key, type }) => {\n return pluginManager.resolveName({\n name: `${prefix} ${operation.getOperationId()} ${suffix}`,\n pluginKey,\n type,\n })\n }\n\n const getSchemas: UseOperationManagerResult['getSchemas'] = (operation, params) => {\n if (!generator) {\n throw new Error(`'generator' is not defined`)\n }\n\n return generator.getSchemas(operation, {\n resolveName: (name) =>\n pluginManager.resolveName({\n name,\n pluginKey: params?.pluginKey,\n type: params?.type,\n }),\n })\n }\n\n //TODO replace tag with group\n const getFile: UseOperationManagerResult['getFile'] = (\n operation,\n { prefix, suffix, pluginKey = plugin.key, tag = operation.getTags().at(0)?.name, extname = '.ts' } = {},\n ) => {\n const name = getName(operation, { type: 'file', pluginKey, prefix, suffix })\n const file = pluginManager.getFile({\n name,\n extname,\n pluginKey,\n options: { type: 'file', pluginKey, tag },\n })\n\n return {\n ...file,\n meta: {\n ...file.meta,\n name,\n pluginKey,\n tag,\n },\n }\n }\n\n const groupSchemasByName: UseOperationManagerResult['groupSchemasByName'] = (operation, { pluginKey = plugin.key, type }) => {\n if (!generator) {\n throw new Error(`'generator' is not defined`)\n }\n\n const schemas = generator.getSchemas(operation)\n\n const errors = (schemas.errors || []).reduce(\n (prev, acc) => {\n if (!acc.statusCode) {\n return prev\n }\n\n prev[acc.statusCode] = pluginManager.resolveName({\n name: acc.name,\n pluginKey,\n type,\n })\n\n return prev\n },\n {} as Record<number, string>,\n )\n\n return {\n request: schemas.request?.name\n ? pluginManager.resolveName({\n name: schemas.request.name,\n pluginKey,\n type,\n })\n : undefined,\n parameters: {\n path: schemas.pathParams?.name\n ? pluginManager.resolveName({\n name: schemas.pathParams.name,\n pluginKey,\n type,\n })\n : undefined,\n query: schemas.queryParams?.name\n ? pluginManager.resolveName({\n name: schemas.queryParams.name,\n pluginKey,\n type,\n })\n : undefined,\n header: schemas.headerParams?.name\n ? pluginManager.resolveName({\n name: schemas.headerParams.name,\n pluginKey,\n type,\n })\n : undefined,\n },\n responses: {\n [schemas.response.statusCode || 'default']: pluginManager.resolveName({\n name: schemas.response.name,\n pluginKey,\n type,\n }),\n ['default']: pluginManager.resolveName({\n name: schemas.response.name,\n pluginKey,\n type,\n }),\n ...errors,\n },\n errors,\n }\n }\n\n return {\n getName,\n getFile,\n getSchemas,\n groupSchemasByName,\n }\n}\n","import { useContext } from '@kubb/react'\n\nimport { Oas } from '../components/Oas.tsx'\n\nimport type { HttpMethod, Operation } from '@kubb/oas'\n\ntype UseOperationsProps = {\n /**\n * Filter based on path\n * Weight: 2\n */\n path?: string\n /**\n * Filter based on method\n * Weight: 1\n */\n method?: HttpMethod\n}\n\n/**\n * `useOperations` will return all the Operations\n */\nexport function useOperations({ method, path }: UseOperationsProps = {}): Operation[] {\n const { operations } = useContext(Oas.Context)\n\n if (!operations) {\n throw new Error('Operations is not defined')\n }\n let items = operations\n\n if (path) {\n items = items.filter((item) => item.path === path)\n }\n\n if (method) {\n items = items.filter((item) => item.method === method)\n }\n\n return items\n}\n","import { useContext } from '@kubb/react'\n\nimport { Schema } from '../components/Schema.tsx'\n\nimport type { SchemaContextProps } from '../components/Schema.tsx'\n\ntype UseSchemaResult = SchemaContextProps\n\n/**\n * `useSchema` will return the current `schema properties`\n */\nexport function useSchema(): UseSchemaResult {\n const props = useContext(Schema.Context)\n\n return props as UseSchemaResult\n}\n","import { useApp } from '@kubb/react'\n\nimport type { FileMetaBase, Plugin, ResolveNameParams } from '@kubb/core'\nimport type * as KubbFile from '@kubb/fs/types'\nimport type { Mode } from '@kubb/fs/types'\nimport { SchemaGenerator } from '../SchemaGenerator.ts'\nimport { type Schema, schemaKeywords } from '../SchemaMapper'\n\ntype FileMeta = FileMetaBase & {\n pluginKey: Plugin['key']\n name: string\n tag?: string\n}\n\ntype UseSchemaManagerResult = {\n getName: (name: string, params: { pluginKey?: Plugin['key']; type: ResolveNameParams['type'] }) => string\n getFile: (name: string, params?: { pluginKey?: Plugin['key']; mode?: Mode; extname?: KubbFile.Extname; tag?: string }) => KubbFile.File<FileMeta>\n getImports: (tree: Array<Schema>) => Array<KubbFile.Import>\n}\n\n/**\n * `useSchemaManager` will return some helper functions that can be used to get the schema file, get the schema name.\n */\nexport function useSchemaManager(): UseSchemaManagerResult {\n const { mode, plugin, pluginManager, fileManager } = useApp()\n\n const getName: UseSchemaManagerResult['getName'] = (name, { pluginKey = plugin.key, type }) => {\n return pluginManager.resolveName({\n name,\n pluginKey,\n type,\n })\n }\n //TODO replace tag with group\n const getFile: UseSchemaManagerResult['getFile'] = (name, { mode = 'split', pluginKey = plugin.key, extname = '.ts', tag } = {}) => {\n const resolvedName = mode === 'single' ? '' : getName(name, { type: 'file', pluginKey })\n\n const file = pluginManager.getFile({\n name: resolvedName,\n extname,\n pluginKey,\n options: { type: 'file', pluginKey, tag },\n })\n\n return {\n ...file,\n meta: {\n ...file.meta,\n name: resolvedName,\n pluginKey,\n },\n }\n }\n\n const getImports: UseSchemaManagerResult['getImports'] = (tree) => {\n const refs = SchemaGenerator.deepSearch(tree, schemaKeywords.ref)\n\n return refs\n ?.map((item, i) => {\n if (!item.args.path || !item.args.isImportable) {\n return undefined\n }\n\n return {\n name: [item.args.name],\n path: item.args.path,\n }\n })\n .filter(Boolean)\n }\n\n return {\n getName,\n getFile,\n getImports,\n }\n}\n"]}
|
package/dist/index.cjs
CHANGED
|
@@ -1,28 +1,21 @@
|
|
|
1
|
-
|
|
1
|
+
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
4
|
-
require('./chunk-
|
|
3
|
+
var chunkABOQ73FL_cjs = require('./chunk-ABOQ73FL.cjs');
|
|
4
|
+
var chunk2TGWPVZN_cjs = require('./chunk-2TGWPVZN.cjs');
|
|
5
|
+
require('./chunk-PADR76WZ.cjs');
|
|
6
|
+
var chunkA3ROGKLW_cjs = require('./chunk-A3ROGKLW.cjs');
|
|
7
|
+
var chunkQAFBZLJA_cjs = require('./chunk-QAFBZLJA.cjs');
|
|
8
|
+
require('./chunk-ZWHQ54JM.cjs');
|
|
9
|
+
var core = require('@kubb/core');
|
|
10
|
+
var transformers = require('@kubb/core/transformers');
|
|
11
|
+
var path = require('path');
|
|
5
12
|
|
|
13
|
+
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
6
14
|
|
|
15
|
+
var transformers__default = /*#__PURE__*/_interopDefault(transformers);
|
|
16
|
+
var path__default = /*#__PURE__*/_interopDefault(path);
|
|
7
17
|
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
var _chunkIAUV3UKHcjs = require('./chunk-IAUV3UKH.cjs');
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
var _chunkNU4F7G47cjs = require('./chunk-NU4F7G47.cjs');
|
|
17
|
-
|
|
18
|
-
// src/index.ts
|
|
19
|
-
_chunkNU4F7G47cjs.init_cjs_shims.call(void 0, );
|
|
20
|
-
|
|
21
|
-
// src/OperationGenerator.ts
|
|
22
|
-
_chunkNU4F7G47cjs.init_cjs_shims.call(void 0, );
|
|
23
|
-
var _core = require('@kubb/core');
|
|
24
|
-
var _transformers = require('@kubb/core/transformers'); var _transformers2 = _interopRequireDefault(_transformers);
|
|
25
|
-
var OperationGenerator = class extends _core.BaseGenerator {
|
|
18
|
+
var OperationGenerator = class extends core.BaseGenerator {
|
|
26
19
|
#operationsByMethod = {};
|
|
27
20
|
get operationsByMethod() {
|
|
28
21
|
return this.#operationsByMethod;
|
|
@@ -32,9 +25,9 @@ var OperationGenerator = class extends _core.BaseGenerator {
|
|
|
32
25
|
}
|
|
33
26
|
#getOptions(operation, method) {
|
|
34
27
|
const { override = [] } = this.context;
|
|
35
|
-
return
|
|
28
|
+
return override.find(({ pattern, type }) => {
|
|
36
29
|
if (type === "tag") {
|
|
37
|
-
return !!
|
|
30
|
+
return !!operation.getTags()[0]?.name.match(pattern);
|
|
38
31
|
}
|
|
39
32
|
if (type === "operationId") {
|
|
40
33
|
return !!operation.getOperationId().match(pattern);
|
|
@@ -46,18 +39,14 @@ var OperationGenerator = class extends _core.BaseGenerator {
|
|
|
46
39
|
return !!method.match(pattern);
|
|
47
40
|
}
|
|
48
41
|
return false;
|
|
49
|
-
})
|
|
42
|
+
})?.options || {};
|
|
50
43
|
}
|
|
51
|
-
/**
|
|
52
|
-
*
|
|
53
|
-
* @deprecated
|
|
54
|
-
*/
|
|
55
44
|
#isExcluded(operation, method) {
|
|
56
45
|
const { exclude = [] } = this.context;
|
|
57
46
|
let matched = false;
|
|
58
47
|
exclude.forEach(({ pattern, type }) => {
|
|
59
48
|
if (type === "tag" && !matched) {
|
|
60
|
-
matched = !!
|
|
49
|
+
matched = !!operation.getTags()[0]?.name.match(pattern);
|
|
61
50
|
}
|
|
62
51
|
if (type === "operationId" && !matched) {
|
|
63
52
|
matched = !!operation.getOperationId().match(pattern);
|
|
@@ -71,16 +60,12 @@ var OperationGenerator = class extends _core.BaseGenerator {
|
|
|
71
60
|
});
|
|
72
61
|
return matched;
|
|
73
62
|
}
|
|
74
|
-
/**
|
|
75
|
-
*
|
|
76
|
-
* @deprecated
|
|
77
|
-
*/
|
|
78
63
|
#isIncluded(operation, method) {
|
|
79
64
|
const { include = [] } = this.context;
|
|
80
65
|
let matched = false;
|
|
81
66
|
include.forEach(({ pattern, type }) => {
|
|
82
67
|
if (type === "tag" && !matched) {
|
|
83
|
-
matched = !!
|
|
68
|
+
matched = !!operation.getTags()[0]?.name.match(pattern);
|
|
84
69
|
}
|
|
85
70
|
if (type === "operationId" && !matched) {
|
|
86
71
|
matched = !!operation.getOperationId().match(pattern);
|
|
@@ -95,15 +80,12 @@ var OperationGenerator = class extends _core.BaseGenerator {
|
|
|
95
80
|
return matched;
|
|
96
81
|
}
|
|
97
82
|
getSchemas(operation, {
|
|
98
|
-
forStatusCode,
|
|
99
83
|
resolveName = (name) => name
|
|
100
84
|
} = {}) {
|
|
101
85
|
const pathParamsSchema = this.context.oas.getParametersSchema(operation, "path");
|
|
102
86
|
const queryParamsSchema = this.context.oas.getParametersSchema(operation, "query");
|
|
103
87
|
const headerParamsSchema = this.context.oas.getParametersSchema(operation, "header");
|
|
104
88
|
const requestSchema = this.context.oas.getRequestSchema(operation);
|
|
105
|
-
const responseStatusCode = forStatusCode || operation.schema.responses && Object.keys(operation.schema.responses).find((key) => key.startsWith("2")) || 200;
|
|
106
|
-
const responseSchema = this.context.oas.getResponseSchema(operation, responseStatusCode);
|
|
107
89
|
const statusCodes = operation.getResponseStatusCodes().map((statusCode) => {
|
|
108
90
|
let name = statusCode;
|
|
109
91
|
if (name === "default") {
|
|
@@ -111,63 +93,69 @@ var OperationGenerator = class extends _core.BaseGenerator {
|
|
|
111
93
|
}
|
|
112
94
|
const schema = this.context.oas.getResponseSchema(operation, statusCode);
|
|
113
95
|
return {
|
|
114
|
-
name: resolveName(
|
|
115
|
-
description:
|
|
96
|
+
name: resolveName(transformers__default.default.pascalCase(`${operation.getOperationId()} ${name}`)),
|
|
97
|
+
description: operation.getResponseByStatusCode(statusCode)?.description,
|
|
116
98
|
schema,
|
|
117
99
|
operation,
|
|
118
|
-
operationName:
|
|
100
|
+
operationName: transformers__default.default.pascalCase(`${operation.getOperationId()}`),
|
|
119
101
|
statusCode: name === "error" ? void 0 : Number(statusCode),
|
|
120
|
-
keys:
|
|
102
|
+
keys: schema?.properties ? Object.keys(schema.properties) : void 0,
|
|
103
|
+
keysToOmit: schema?.properties ? Object.keys(schema.properties).filter((key) => {
|
|
104
|
+
const item = schema.properties?.[key];
|
|
105
|
+
return item?.writeOnly;
|
|
106
|
+
}) : void 0
|
|
121
107
|
};
|
|
122
108
|
});
|
|
109
|
+
const hasResponses = statusCodes.some((item) => item.statusCode?.toString().startsWith("2"));
|
|
123
110
|
return {
|
|
124
111
|
pathParams: pathParamsSchema ? {
|
|
125
|
-
name: resolveName(
|
|
112
|
+
name: resolveName(transformers__default.default.pascalCase(`${operation.getOperationId()} PathParams`)),
|
|
126
113
|
operation,
|
|
127
|
-
operationName:
|
|
114
|
+
operationName: transformers__default.default.pascalCase(`${operation.getOperationId()}`),
|
|
128
115
|
schema: pathParamsSchema,
|
|
129
116
|
keys: pathParamsSchema.properties ? Object.keys(pathParamsSchema.properties) : void 0
|
|
130
117
|
} : void 0,
|
|
131
118
|
queryParams: queryParamsSchema ? {
|
|
132
|
-
name: resolveName(
|
|
119
|
+
name: resolveName(transformers__default.default.pascalCase(`${operation.getOperationId()} QueryParams`)),
|
|
133
120
|
operation,
|
|
134
|
-
operationName:
|
|
121
|
+
operationName: transformers__default.default.pascalCase(`${operation.getOperationId()}`),
|
|
135
122
|
schema: queryParamsSchema,
|
|
136
123
|
keys: queryParamsSchema.properties ? Object.keys(queryParamsSchema.properties) : []
|
|
137
124
|
} : void 0,
|
|
138
125
|
headerParams: headerParamsSchema ? {
|
|
139
|
-
name: resolveName(
|
|
126
|
+
name: resolveName(transformers__default.default.pascalCase(`${operation.getOperationId()} HeaderParams`)),
|
|
140
127
|
operation,
|
|
141
|
-
operationName:
|
|
128
|
+
operationName: transformers__default.default.pascalCase(`${operation.getOperationId()}`),
|
|
142
129
|
schema: headerParamsSchema,
|
|
143
130
|
keys: headerParamsSchema.properties ? Object.keys(headerParamsSchema.properties) : void 0
|
|
144
131
|
} : void 0,
|
|
145
132
|
request: requestSchema ? {
|
|
146
|
-
name: resolveName(
|
|
147
|
-
description:
|
|
133
|
+
name: resolveName(transformers__default.default.pascalCase(`${operation.getOperationId()} ${operation.method === "get" ? "queryRequest" : "mutationRequest"}`)),
|
|
134
|
+
description: operation.schema.requestBody?.description,
|
|
148
135
|
operation,
|
|
149
|
-
operationName:
|
|
136
|
+
operationName: transformers__default.default.pascalCase(`${operation.getOperationId()}`),
|
|
150
137
|
schema: requestSchema,
|
|
151
138
|
keys: requestSchema.properties ? Object.keys(requestSchema.properties) : void 0,
|
|
152
139
|
keysToOmit: requestSchema.properties ? Object.keys(requestSchema.properties).filter((key) => {
|
|
153
|
-
const item =
|
|
154
|
-
return
|
|
140
|
+
const item = requestSchema.properties?.[key];
|
|
141
|
+
return item?.readOnly;
|
|
155
142
|
}) : void 0
|
|
156
143
|
} : void 0,
|
|
157
144
|
response: {
|
|
158
|
-
name: resolveName(
|
|
159
|
-
description: _optionalChain([operation, 'access', _32 => _32.getResponseAsJSONSchema, 'call', _33 => _33(responseStatusCode), 'optionalAccess', _34 => _34.at, 'call', _35 => _35(0), 'optionalAccess', _36 => _36.description]),
|
|
145
|
+
name: resolveName(transformers__default.default.pascalCase(`${operation.getOperationId()} ${operation.method === "get" ? "queryResponse" : "mutationResponse"}`)),
|
|
160
146
|
operation,
|
|
161
|
-
operationName:
|
|
162
|
-
schema:
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
147
|
+
operationName: transformers__default.default.pascalCase(`${operation.getOperationId()}`),
|
|
148
|
+
schema: {
|
|
149
|
+
oneOf: hasResponses ? statusCodes.filter((item) => item.statusCode?.toString().startsWith("2")).map((item) => {
|
|
150
|
+
return {
|
|
151
|
+
...item.schema,
|
|
152
|
+
$ref: resolveName(transformers__default.default.pascalCase(`${operation.getOperationId()} ${item.statusCode}`))
|
|
153
|
+
};
|
|
154
|
+
}) : void 0
|
|
155
|
+
}
|
|
169
156
|
},
|
|
170
|
-
|
|
157
|
+
responses: statusCodes.filter((item) => item.statusCode?.toString().startsWith("2")),
|
|
158
|
+
errors: statusCodes.filter((item) => item.statusCode?.toString().startsWith("4") || item.statusCode?.toString().startsWith("5")),
|
|
171
159
|
statusCodes
|
|
172
160
|
};
|
|
173
161
|
}
|
|
@@ -201,14 +189,14 @@ var OperationGenerator = class extends _core.BaseGenerator {
|
|
|
201
189
|
const promises = Object.keys(this.operationsByMethod).reduce((acc, path2) => {
|
|
202
190
|
const methods = this.operationsByMethod[path2] ? Object.keys(this.operationsByMethod[path2]) : [];
|
|
203
191
|
methods.forEach((method) => {
|
|
204
|
-
const { operation } =
|
|
192
|
+
const { operation } = this.operationsByMethod[path2]?.[method];
|
|
205
193
|
const options = this.#getOptions(operation, method);
|
|
206
194
|
const methodToCall = this[method];
|
|
207
195
|
if (typeof methodToCall === "function") {
|
|
208
|
-
const promiseMethod =
|
|
196
|
+
const promiseMethod = methodToCall?.call(this, operation, {
|
|
209
197
|
...this.options,
|
|
210
198
|
...options
|
|
211
|
-
})
|
|
199
|
+
});
|
|
212
200
|
if (promiseMethod) {
|
|
213
201
|
acc.push(promiseMethod);
|
|
214
202
|
}
|
|
@@ -220,35 +208,35 @@ var OperationGenerator = class extends _core.BaseGenerator {
|
|
|
220
208
|
if (promiseOperation) {
|
|
221
209
|
acc.push(promiseOperation);
|
|
222
210
|
}
|
|
223
|
-
|
|
224
|
-
const promise =
|
|
211
|
+
generators?.forEach((generator) => {
|
|
212
|
+
const promise = generator.operation?.({
|
|
225
213
|
instance: this,
|
|
226
214
|
operation,
|
|
227
215
|
options: {
|
|
228
216
|
...this.options,
|
|
229
217
|
...options
|
|
230
218
|
}
|
|
231
|
-
})
|
|
219
|
+
});
|
|
232
220
|
if (promise) {
|
|
233
221
|
acc.push(promise);
|
|
234
222
|
}
|
|
235
|
-
})
|
|
223
|
+
});
|
|
236
224
|
});
|
|
237
225
|
return acc;
|
|
238
226
|
}, []);
|
|
239
227
|
const operations = Object.values(this.operationsByMethod).map((item) => Object.values(item).map((item2) => item2.operation));
|
|
240
228
|
promises.push(this.all(operations.flat().filter(Boolean), this.operationsByMethod));
|
|
241
|
-
|
|
242
|
-
const promise =
|
|
229
|
+
generators?.forEach((generator) => {
|
|
230
|
+
const promise = generator.operations?.({
|
|
243
231
|
instance: this,
|
|
244
232
|
operations: operations.flat().filter(Boolean),
|
|
245
233
|
operationsByMethod: this.operationsByMethod,
|
|
246
234
|
options: this.options
|
|
247
|
-
})
|
|
235
|
+
});
|
|
248
236
|
if (promise) {
|
|
249
237
|
promises.push(promise);
|
|
250
238
|
}
|
|
251
|
-
})
|
|
239
|
+
});
|
|
252
240
|
const files = await Promise.all(promises);
|
|
253
241
|
return files.flat().filter(Boolean);
|
|
254
242
|
}
|
|
@@ -295,164 +283,129 @@ var OperationGenerator = class extends _core.BaseGenerator {
|
|
|
295
283
|
return [];
|
|
296
284
|
}
|
|
297
285
|
};
|
|
298
|
-
|
|
299
|
-
// src/plugin.ts
|
|
300
|
-
_chunkNU4F7G47cjs.init_cjs_shims.call(void 0, );
|
|
301
|
-
var _path = require('path'); var _path2 = _interopRequireDefault(_path);
|
|
302
|
-
|
|
303
|
-
|
|
304
286
|
var pluginOasName = "plugin-oas";
|
|
305
|
-
var pluginOas =
|
|
287
|
+
var pluginOas = core.createPlugin((options) => {
|
|
306
288
|
const {
|
|
307
|
-
output = {
|
|
308
|
-
|
|
309
|
-
|
|
289
|
+
output = {
|
|
290
|
+
path: "schemas"
|
|
291
|
+
},
|
|
310
292
|
validate = true,
|
|
293
|
+
generators = [chunk2TGWPVZN_cjs.jsonGenerator],
|
|
311
294
|
serverIndex = 0,
|
|
312
295
|
contentType,
|
|
313
296
|
oasClass
|
|
314
297
|
} = options;
|
|
315
|
-
const getOas = async ({ config, logger
|
|
298
|
+
const getOas = async ({ config, logger }) => {
|
|
316
299
|
try {
|
|
317
|
-
const oas = await
|
|
300
|
+
const oas = await chunkABOQ73FL_cjs.parseFromConfig(config, oasClass);
|
|
318
301
|
if (validate) {
|
|
319
302
|
await oas.valdiate();
|
|
320
303
|
}
|
|
321
304
|
return oas;
|
|
322
305
|
} catch (e) {
|
|
323
306
|
const error = e;
|
|
324
|
-
logger.emit("warning",
|
|
325
|
-
return
|
|
307
|
+
logger.emit("warning", error?.message);
|
|
308
|
+
return chunkABOQ73FL_cjs.parseFromConfig(config, oasClass);
|
|
326
309
|
}
|
|
327
310
|
};
|
|
328
311
|
return {
|
|
329
312
|
name: pluginOasName,
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
} : {
|
|
334
|
-
exportType: "barrelNamed",
|
|
335
|
-
...output
|
|
313
|
+
options: {
|
|
314
|
+
output,
|
|
315
|
+
...options
|
|
336
316
|
},
|
|
337
|
-
options,
|
|
338
317
|
context() {
|
|
339
318
|
const { config, logger } = this;
|
|
340
319
|
return {
|
|
341
|
-
getOas(
|
|
342
|
-
return getOas({ config, logger
|
|
320
|
+
getOas() {
|
|
321
|
+
return getOas({ config, logger });
|
|
343
322
|
},
|
|
344
323
|
async getSchemas({ includes } = {}) {
|
|
345
324
|
const oas = await this.getOas();
|
|
346
|
-
return
|
|
325
|
+
return chunkQAFBZLJA_cjs.getSchemas({ oas, contentType, includes });
|
|
347
326
|
},
|
|
348
327
|
async getBaseURL() {
|
|
349
328
|
const oasInstance = await this.getOas();
|
|
350
|
-
|
|
351
|
-
return baseURL;
|
|
329
|
+
return oasInstance.api.servers?.at(serverIndex)?.url;
|
|
352
330
|
},
|
|
353
331
|
contentType
|
|
354
332
|
};
|
|
355
333
|
},
|
|
334
|
+
resolvePath(baseName, pathMode, options2) {
|
|
335
|
+
const root = path__default.default.resolve(this.config.root, this.config.output.path);
|
|
336
|
+
const mode = pathMode ?? core.FileManager.getMode(path__default.default.resolve(root, output.path));
|
|
337
|
+
if (mode === "single") {
|
|
338
|
+
return path__default.default.resolve(root, output.path);
|
|
339
|
+
}
|
|
340
|
+
return path__default.default.resolve(root, output.path, baseName);
|
|
341
|
+
},
|
|
356
342
|
async buildStart() {
|
|
357
343
|
if (!output) {
|
|
358
344
|
return;
|
|
359
345
|
}
|
|
360
346
|
const oas = await getOas({
|
|
361
347
|
config: this.config,
|
|
362
|
-
logger: this.logger
|
|
363
|
-
formatOptions: {
|
|
364
|
-
filterSet: filter,
|
|
365
|
-
sortSet: sort
|
|
366
|
-
}
|
|
348
|
+
logger: this.logger
|
|
367
349
|
});
|
|
368
350
|
await oas.dereference();
|
|
369
|
-
const
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
}
|
|
387
|
-
]
|
|
388
|
-
});
|
|
389
|
-
};
|
|
390
|
-
const promises = Object.entries(schemas).map(mapSchema);
|
|
391
|
-
await Promise.all(promises);
|
|
392
|
-
}
|
|
393
|
-
};
|
|
394
|
-
});
|
|
395
|
-
|
|
396
|
-
// src/generator.tsx
|
|
397
|
-
_chunkNU4F7G47cjs.init_cjs_shims.call(void 0, );
|
|
398
|
-
var import_jsx_runtime = _chunkNU4F7G47cjs.__toESM.call(void 0, _chunkIAUV3UKHcjs.require_jsx_runtime.call(void 0, ), 1);
|
|
399
|
-
var _react = require('@kubb/react');
|
|
400
|
-
function createGenerator(parseOptions) {
|
|
401
|
-
return parseOptions;
|
|
402
|
-
}
|
|
403
|
-
function createReactGenerator(parseOptions) {
|
|
404
|
-
return {
|
|
405
|
-
...parseOptions,
|
|
406
|
-
async operations({ instance, options, operations, operationsByMethod }) {
|
|
407
|
-
if (!parseOptions.Operations) {
|
|
408
|
-
return [];
|
|
409
|
-
}
|
|
410
|
-
const { pluginManager, oas, plugin, mode } = instance.context;
|
|
411
|
-
const root = _react.createRoot.call(void 0, {
|
|
412
|
-
logger: pluginManager.logger
|
|
413
|
-
});
|
|
414
|
-
root.render(
|
|
415
|
-
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(_react.App, { pluginManager, plugin, mode, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(_chunkIAUV3UKHcjs.Oas, { oas, operations, generator: instance, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(parseOptions.Operations, { operations, instance, operationsByMethod, options }) }) })
|
|
416
|
-
);
|
|
417
|
-
return root.files;
|
|
418
|
-
},
|
|
419
|
-
async operation({ instance, operation, options }) {
|
|
420
|
-
if (!parseOptions.Operation) {
|
|
421
|
-
return [];
|
|
422
|
-
}
|
|
423
|
-
const { pluginManager, oas, plugin, mode } = instance.context;
|
|
424
|
-
const root = _react.createRoot.call(void 0, {
|
|
425
|
-
logger: pluginManager.logger
|
|
426
|
-
});
|
|
427
|
-
root.render(
|
|
428
|
-
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(_react.App, { pluginManager, plugin: { ...plugin, options }, mode, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(_chunkIAUV3UKHcjs.Oas, { oas, operations: [operation], generator: instance, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(_chunkIAUV3UKHcjs.Oas.Operation, { operation, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(parseOptions.Operation, { operation, options, instance }) }) }) })
|
|
351
|
+
const schemaGenerator = new chunkA3ROGKLW_cjs.SchemaGenerator(
|
|
352
|
+
{
|
|
353
|
+
unknownType: "unknown",
|
|
354
|
+
dateType: "date",
|
|
355
|
+
transformers: {},
|
|
356
|
+
...this.plugin.options
|
|
357
|
+
},
|
|
358
|
+
{
|
|
359
|
+
oas,
|
|
360
|
+
pluginManager: this.pluginManager,
|
|
361
|
+
plugin: this.plugin,
|
|
362
|
+
contentType,
|
|
363
|
+
include: void 0,
|
|
364
|
+
override: void 0,
|
|
365
|
+
mode: "split",
|
|
366
|
+
output: output.path
|
|
367
|
+
}
|
|
429
368
|
);
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
369
|
+
const schemaFiles = await schemaGenerator.build(...generators);
|
|
370
|
+
await this.addFile(...schemaFiles);
|
|
371
|
+
const operationGenerator = new OperationGenerator(this.plugin.options, {
|
|
372
|
+
oas,
|
|
373
|
+
pluginManager: this.pluginManager,
|
|
374
|
+
plugin: this.plugin,
|
|
375
|
+
contentType,
|
|
376
|
+
exclude: void 0,
|
|
377
|
+
include: void 0,
|
|
378
|
+
override: void 0,
|
|
379
|
+
mode: "split"
|
|
439
380
|
});
|
|
440
|
-
const
|
|
441
|
-
|
|
442
|
-
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(_react.App, { pluginManager, plugin: { ...plugin, options }, mode, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(_chunkIAUV3UKHcjs.Oas, { oas, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(_chunkIAUV3UKHcjs.Oas.Schema, { name, value: schema, tree, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(parseOptions.Schema, { schema, options, instance, name }) }) }) })
|
|
443
|
-
);
|
|
444
|
-
return root.files;
|
|
381
|
+
const operationFiles = await operationGenerator.build(...generators);
|
|
382
|
+
await this.addFile(...operationFiles);
|
|
445
383
|
}
|
|
446
384
|
};
|
|
447
|
-
}
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
385
|
+
});
|
|
456
386
|
|
|
457
|
-
|
|
387
|
+
Object.defineProperty(exports, "createGenerator", {
|
|
388
|
+
enumerable: true,
|
|
389
|
+
get: function () { return chunk2TGWPVZN_cjs.createGenerator; }
|
|
390
|
+
});
|
|
391
|
+
Object.defineProperty(exports, "createReactGenerator", {
|
|
392
|
+
enumerable: true,
|
|
393
|
+
get: function () { return chunk2TGWPVZN_cjs.createReactGenerator; }
|
|
394
|
+
});
|
|
395
|
+
Object.defineProperty(exports, "SchemaGenerator", {
|
|
396
|
+
enumerable: true,
|
|
397
|
+
get: function () { return chunkA3ROGKLW_cjs.SchemaGenerator; }
|
|
398
|
+
});
|
|
399
|
+
Object.defineProperty(exports, "isKeyword", {
|
|
400
|
+
enumerable: true,
|
|
401
|
+
get: function () { return chunkA3ROGKLW_cjs.isKeyword; }
|
|
402
|
+
});
|
|
403
|
+
Object.defineProperty(exports, "schemaKeywords", {
|
|
404
|
+
enumerable: true,
|
|
405
|
+
get: function () { return chunkA3ROGKLW_cjs.schemaKeywords; }
|
|
406
|
+
});
|
|
407
|
+
exports.OperationGenerator = OperationGenerator;
|
|
408
|
+
exports.pluginOas = pluginOas;
|
|
409
|
+
exports.pluginOasName = pluginOasName;
|
|
410
|
+
//# sourceMappingURL=index.cjs.map
|
|
458
411
|
//# sourceMappingURL=index.cjs.map
|