@kubb/plugin-oas 3.0.13 → 3.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{OperationGenerator-Bw6sj3Eb.d.cts → OperationGenerator-DOz5MZ9x.d.cts} +1 -1
- package/dist/{OperationGenerator-Bw6sj3Eb.d.ts → OperationGenerator-DOz5MZ9x.d.ts} +1 -1
- package/dist/{Schema-BlGtSgNB.d.ts → Schema-7TmFtgpX.d.ts} +1 -1
- package/dist/{Schema-4FwWfdim.d.cts → Schema-BZf0c98o.d.cts} +1 -1
- package/dist/{chunk-EGYH3IFN.js → chunk-IHPQRZWD.js} +30 -20
- package/dist/chunk-IHPQRZWD.js.map +1 -0
- package/dist/{chunk-2RH3ZCNB.cjs → chunk-WSORDWRC.cjs} +30 -20
- package/dist/chunk-WSORDWRC.cjs.map +1 -0
- package/dist/components.d.cts +2 -2
- package/dist/components.d.ts +2 -2
- package/dist/generators.d.cts +1 -1
- package/dist/generators.d.ts +1 -1
- package/dist/hooks.cjs +17 -8
- package/dist/hooks.cjs.map +1 -1
- package/dist/hooks.d.cts +8 -7
- package/dist/hooks.d.ts +8 -7
- package/dist/hooks.js +16 -7
- package/dist/hooks.js.map +1 -1
- package/dist/index.cjs +5 -5
- package/dist/index.d.cts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +2 -2
- package/dist/utils.d.cts +2 -2
- package/dist/utils.d.ts +2 -2
- package/package.json +8 -8
- package/src/SchemaGenerator.ts +36 -18
- package/src/hooks/useOperationManager.ts +20 -7
- package/src/hooks/useSchemaManager.ts +5 -5
- package/src/types.ts +1 -1
- package/dist/chunk-2RH3ZCNB.cjs.map +0 -1
- package/dist/chunk-EGYH3IFN.js.map +0 -1
package/dist/hooks.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
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","Oas","Operation","useApp","Schema","SchemaGenerator","schemaKeywords"],"mappings":";;;;;;;AAMO,SAAS,MAAkB,GAAA;AAChC,EAAA,MAAM,EAAE,GAAA,EAAQ,GAAAA,gBAAA,CAAWC,sBAAI,OAAO,CAAA;AAEtC,EAAA,IAAI,CAAC,GAAK,EAAA;AACR,IAAM,MAAA,IAAI,MAAM,oBAAoB,CAAA;AAAA;AAGtC,EAAO,OAAA,GAAA;AACT;ACLO,SAAS,YAA8B,GAAA;AAC5C,EAAA,MAAM,EAAE,SAAA,EAAcD,GAAAA,gBAAAA,CAAWE,4BAAU,OAAO,CAAA;AAElD,EAAA,IAAI,CAAC,SAAW,EAAA;AACd,IAAM,MAAA,IAAI,MAAM,0BAA0B,CAAA;AAAA;AAG5C,EAAO,OAAA,SAAA;AACT;AC0CO,SAAS,mBAAiD,GAAA;AAC/D,EAAA,MAAM,EAAE,MAAA,EAAQ,aAAc,EAAA,GAAIC,YAAO,EAAA;AACzC,EAAA,MAAM,EAAE,SAAA,EAAcH,GAAAA,gBAAAA,CAAWC,sBAAI,OAAO,CAAA;AAE5C,EAAA,MAAM,OAAgD,GAAA,CAAC,SAAW,EAAA,EAAE,MAAS,GAAA,EAAA,EAAI,MAAS,GAAA,EAAA,EAAI,SAAY,GAAA,MAAA,CAAO,GAAK,EAAA,IAAA,EAAW,KAAA;AAC/H,IAAA,OAAO,cAAc,WAAY,CAAA;AAAA,MAC/B,IAAA,EAAM,GAAG,MAAM,CAAA,CAAA,EAAI,UAAU,cAAe,EAAC,IAAI,MAAM,CAAA,CAAA;AAAA,MACvD,SAAA;AAAA,MACA;AAAA,KACD,CAAA;AAAA,GACH;AAEA,EAAM,MAAA,UAAA,GAAsD,CAAC,SAAA,EAAW,MAAW,KAAA;AACjF,IAAA,IAAI,CAAC,SAAW,EAAA;AACd,MAAM,MAAA,IAAI,MAAM,CAA4B,0BAAA,CAAA,CAA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AAW,CAAA,IAAA,EAAMC,iCAAe,GAAG,CAAA;AAEhE,IAAA,OAAO,IACH,EAAA,GAAA,CAAI,CAAC,IAAA,EAAM,CAAM,KAAA;AACjB,MAAA,IAAI,CAAC,IAAK,CAAA,IAAA,CAAK,QAAQ,CAAC,IAAA,CAAK,KAAK,YAAc,EAAA;AAC9C,QAAO,OAAA,KAAA,CAAA;AAAA;AAGT,MAAO,OAAA;AAAA,QACL,IAAM,EAAA,CAAC,IAAK,CAAA,IAAA,CAAK,IAAI,CAAA;AAAA,QACrB,IAAA,EAAM,KAAK,IAAK,CAAA;AAAA,OAClB;AAAA,KACD,CACA,CAAA,MAAA,CAAO,OAAO,CAAA;AAAA,GACnB;AAEA,EAAO,OAAA;AAAA,IACL,OAAA;AAAA,IACA,OAAA;AAAA,IACA;AAAA,GACF;AACF","file":"hooks.cjs","sourcesContent":["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\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 const responses = (schemas.responses || []).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 ...responses,\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 { plugin, pluginManager } = 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"]}
|
|
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","Oas","Operation","useApp","Schema","SchemaGenerator","schemaKeywords"],"mappings":";;;;;;;AAMO,SAAS,MAAkB,GAAA;AAChC,EAAA,MAAM,EAAE,GAAA,EAAQ,GAAAA,gBAAA,CAAWC,sBAAI,OAAO,CAAA;AAEtC,EAAA,IAAI,CAAC,GAAK,EAAA;AACR,IAAM,MAAA,IAAI,MAAM,oBAAoB,CAAA;AAAA;AAGtC,EAAO,OAAA,GAAA;AACT;ACLO,SAAS,YAA8B,GAAA;AAC5C,EAAA,MAAM,EAAE,SAAA,EAAcD,GAAAA,gBAAAA,CAAWE,4BAAU,OAAO,CAAA;AAElD,EAAA,IAAI,CAAC,SAAW,EAAA;AACd,IAAM,MAAA,IAAI,MAAM,0BAA0B,CAAA;AAAA;AAG5C,EAAO,OAAA,SAAA;AACT;AC4CO,SAAS,mBAAiD,GAAA;AAC/D,EAAA,MAAM,EAAE,MAAA,EAAQ,aAAc,EAAA,GAAIC,YAAO,EAAA;AACzC,EAAA,MAAM,EAAE,SAAA,EAAcH,GAAAA,gBAAAA,CAAWC,sBAAI,OAAO,CAAA;AAE5C,EAAA,MAAM,OAAgD,GAAA,CAAC,SAAW,EAAA,EAAE,MAAS,GAAA,EAAA,EAAI,MAAS,GAAA,EAAA,EAAI,SAAY,GAAA,MAAA,CAAO,GAAK,EAAA,IAAA,EAAW,KAAA;A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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, Group, Plugin, ResolveNameParams } from '@kubb/core'\n\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 group?: 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 group?: 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 getGroup: (operation: Operation, group: Group | undefined) => string | undefined\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 getGroup: UseOperationManagerResult['getGroup'] = (operation, group) => {\n if (group?.type === 'tag') {\n return operation.getTags().at(0)?.name\n }\n\n if (group?.type === 'path') {\n return operation.path\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 const getFile: UseOperationManagerResult['getFile'] = (\n operation,\n { prefix, suffix, pluginKey = plugin.key, group = getGroup(operation, (plugin.options as { group?: Group })?.group), extname = '.ts' } = {},\n ) => {\n const name = getName(operation, { type: 'file', pluginKey, prefix, suffix })\n\n const file = pluginManager.getFile({\n name,\n extname,\n pluginKey,\n options: { type: 'file', pluginKey, group },\n })\n\n return {\n ...file,\n meta: {\n ...file.meta,\n name,\n pluginKey,\n group,\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 const responses = (schemas.responses || []).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 ...responses,\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 getGroup,\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 group?: 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; group?: 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 { plugin, pluginManager } = 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\n const getFile: UseSchemaManagerResult['getFile'] = (name, { mode = 'split', pluginKey = plugin.key, extname = '.ts', group } = {}) => {\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, group },\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/hooks.d.cts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { Oas, Operation, HttpMethod } from '@kubb/oas';
|
|
2
|
-
import { Plugin, ResolveNameParams, FileMetaBase } from '@kubb/core';
|
|
2
|
+
import { Plugin, ResolveNameParams, Group, FileMetaBase } from '@kubb/core';
|
|
3
3
|
import * as KubbFile from '@kubb/fs/types';
|
|
4
4
|
import { Mode } from '@kubb/fs/types';
|
|
5
|
-
import { w as OperationSchemas, f as Schema } from './OperationGenerator-
|
|
6
|
-
import { a as SchemaContextProps } from './Schema-
|
|
5
|
+
import { w as OperationSchemas, f as Schema } from './OperationGenerator-DOz5MZ9x.cjs';
|
|
6
|
+
import { a as SchemaContextProps } from './Schema-BZf0c98o.cjs';
|
|
7
7
|
import '@kubb/react/types';
|
|
8
8
|
import 'react';
|
|
9
9
|
|
|
@@ -17,7 +17,7 @@ declare function useOperation(): Operation;
|
|
|
17
17
|
type FileMeta$1 = FileMetaBase & {
|
|
18
18
|
pluginKey: Plugin['key'];
|
|
19
19
|
name: string;
|
|
20
|
-
|
|
20
|
+
group?: string;
|
|
21
21
|
};
|
|
22
22
|
type SchemaNames = {
|
|
23
23
|
request: string | undefined;
|
|
@@ -43,7 +43,7 @@ type UseOperationManagerResult = {
|
|
|
43
43
|
suffix?: string;
|
|
44
44
|
pluginKey?: Plugin['key'];
|
|
45
45
|
extname?: KubbFile.Extname;
|
|
46
|
-
|
|
46
|
+
group?: string;
|
|
47
47
|
}) => KubbFile.File<FileMeta$1>;
|
|
48
48
|
groupSchemasByName: (operation: Operation, params: {
|
|
49
49
|
pluginKey?: Plugin['key'];
|
|
@@ -53,6 +53,7 @@ type UseOperationManagerResult = {
|
|
|
53
53
|
pluginKey?: Plugin['key'];
|
|
54
54
|
type?: ResolveNameParams['type'];
|
|
55
55
|
}) => OperationSchemas;
|
|
56
|
+
getGroup: (operation: Operation, group: Group | undefined) => string | undefined;
|
|
56
57
|
};
|
|
57
58
|
/**
|
|
58
59
|
* `useOperationManager` will return some helper functions that can be used to get the operation file, get the operation name.
|
|
@@ -85,7 +86,7 @@ declare function useSchema(): UseSchemaResult;
|
|
|
85
86
|
type FileMeta = FileMetaBase & {
|
|
86
87
|
pluginKey: Plugin['key'];
|
|
87
88
|
name: string;
|
|
88
|
-
|
|
89
|
+
group?: string;
|
|
89
90
|
};
|
|
90
91
|
type UseSchemaManagerResult = {
|
|
91
92
|
getName: (name: string, params: {
|
|
@@ -96,7 +97,7 @@ type UseSchemaManagerResult = {
|
|
|
96
97
|
pluginKey?: Plugin['key'];
|
|
97
98
|
mode?: Mode;
|
|
98
99
|
extname?: KubbFile.Extname;
|
|
99
|
-
|
|
100
|
+
group?: string;
|
|
100
101
|
}) => KubbFile.File<FileMeta>;
|
|
101
102
|
getImports: (tree: Array<Schema>) => Array<KubbFile.Import>;
|
|
102
103
|
};
|
package/dist/hooks.d.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { Oas, Operation, HttpMethod } from '@kubb/oas';
|
|
2
|
-
import { Plugin, ResolveNameParams, FileMetaBase } from '@kubb/core';
|
|
2
|
+
import { Plugin, ResolveNameParams, Group, FileMetaBase } from '@kubb/core';
|
|
3
3
|
import * as KubbFile from '@kubb/fs/types';
|
|
4
4
|
import { Mode } from '@kubb/fs/types';
|
|
5
|
-
import { w as OperationSchemas, f as Schema } from './OperationGenerator-
|
|
6
|
-
import { a as SchemaContextProps } from './Schema-
|
|
5
|
+
import { w as OperationSchemas, f as Schema } from './OperationGenerator-DOz5MZ9x.js';
|
|
6
|
+
import { a as SchemaContextProps } from './Schema-7TmFtgpX.js';
|
|
7
7
|
import '@kubb/react/types';
|
|
8
8
|
import 'react';
|
|
9
9
|
|
|
@@ -17,7 +17,7 @@ declare function useOperation(): Operation;
|
|
|
17
17
|
type FileMeta$1 = FileMetaBase & {
|
|
18
18
|
pluginKey: Plugin['key'];
|
|
19
19
|
name: string;
|
|
20
|
-
|
|
20
|
+
group?: string;
|
|
21
21
|
};
|
|
22
22
|
type SchemaNames = {
|
|
23
23
|
request: string | undefined;
|
|
@@ -43,7 +43,7 @@ type UseOperationManagerResult = {
|
|
|
43
43
|
suffix?: string;
|
|
44
44
|
pluginKey?: Plugin['key'];
|
|
45
45
|
extname?: KubbFile.Extname;
|
|
46
|
-
|
|
46
|
+
group?: string;
|
|
47
47
|
}) => KubbFile.File<FileMeta$1>;
|
|
48
48
|
groupSchemasByName: (operation: Operation, params: {
|
|
49
49
|
pluginKey?: Plugin['key'];
|
|
@@ -53,6 +53,7 @@ type UseOperationManagerResult = {
|
|
|
53
53
|
pluginKey?: Plugin['key'];
|
|
54
54
|
type?: ResolveNameParams['type'];
|
|
55
55
|
}) => OperationSchemas;
|
|
56
|
+
getGroup: (operation: Operation, group: Group | undefined) => string | undefined;
|
|
56
57
|
};
|
|
57
58
|
/**
|
|
58
59
|
* `useOperationManager` will return some helper functions that can be used to get the operation file, get the operation name.
|
|
@@ -85,7 +86,7 @@ declare function useSchema(): UseSchemaResult;
|
|
|
85
86
|
type FileMeta = FileMetaBase & {
|
|
86
87
|
pluginKey: Plugin['key'];
|
|
87
88
|
name: string;
|
|
88
|
-
|
|
89
|
+
group?: string;
|
|
89
90
|
};
|
|
90
91
|
type UseSchemaManagerResult = {
|
|
91
92
|
getName: (name: string, params: {
|
|
@@ -96,7 +97,7 @@ type UseSchemaManagerResult = {
|
|
|
96
97
|
pluginKey?: Plugin['key'];
|
|
97
98
|
mode?: Mode;
|
|
98
99
|
extname?: KubbFile.Extname;
|
|
99
|
-
|
|
100
|
+
group?: string;
|
|
100
101
|
}) => KubbFile.File<FileMeta>;
|
|
101
102
|
getImports: (tree: Array<Schema>) => Array<KubbFile.Import>;
|
|
102
103
|
};
|
package/dist/hooks.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { SchemaGenerator, schemaKeywords } from './chunk-
|
|
1
|
+
import { SchemaGenerator, schemaKeywords } from './chunk-IHPQRZWD.js';
|
|
2
2
|
import './chunk-XNCEFOE6.js';
|
|
3
3
|
import { Oas, Operation, Schema } from './chunk-GF26SDHQ.js';
|
|
4
4
|
import { useContext, useApp } from '@kubb/react';
|
|
@@ -27,6 +27,14 @@ function useOperationManager() {
|
|
|
27
27
|
type
|
|
28
28
|
});
|
|
29
29
|
};
|
|
30
|
+
const getGroup = (operation, group) => {
|
|
31
|
+
if (group?.type === "tag") {
|
|
32
|
+
return operation.getTags().at(0)?.name;
|
|
33
|
+
}
|
|
34
|
+
if (group?.type === "path") {
|
|
35
|
+
return operation.path;
|
|
36
|
+
}
|
|
37
|
+
};
|
|
30
38
|
const getSchemas = (operation, params) => {
|
|
31
39
|
if (!generator) {
|
|
32
40
|
throw new Error(`'generator' is not defined`);
|
|
@@ -39,13 +47,13 @@ function useOperationManager() {
|
|
|
39
47
|
})
|
|
40
48
|
});
|
|
41
49
|
};
|
|
42
|
-
const getFile = (operation, { prefix, suffix, pluginKey = plugin.key,
|
|
50
|
+
const getFile = (operation, { prefix, suffix, pluginKey = plugin.key, group = getGroup(operation, plugin.options?.group), extname = ".ts" } = {}) => {
|
|
43
51
|
const name = getName(operation, { type: "file", pluginKey, prefix, suffix });
|
|
44
52
|
const file = pluginManager.getFile({
|
|
45
53
|
name,
|
|
46
54
|
extname,
|
|
47
55
|
pluginKey,
|
|
48
|
-
options: { type: "file", pluginKey,
|
|
56
|
+
options: { type: "file", pluginKey, group }
|
|
49
57
|
});
|
|
50
58
|
return {
|
|
51
59
|
...file,
|
|
@@ -53,7 +61,7 @@ function useOperationManager() {
|
|
|
53
61
|
...file.meta,
|
|
54
62
|
name,
|
|
55
63
|
pluginKey,
|
|
56
|
-
|
|
64
|
+
group
|
|
57
65
|
}
|
|
58
66
|
};
|
|
59
67
|
};
|
|
@@ -129,7 +137,8 @@ function useOperationManager() {
|
|
|
129
137
|
getName,
|
|
130
138
|
getFile,
|
|
131
139
|
getSchemas,
|
|
132
|
-
groupSchemasByName
|
|
140
|
+
groupSchemasByName,
|
|
141
|
+
getGroup
|
|
133
142
|
};
|
|
134
143
|
}
|
|
135
144
|
function useOperations({ method, path } = {}) {
|
|
@@ -159,13 +168,13 @@ function useSchemaManager() {
|
|
|
159
168
|
type
|
|
160
169
|
});
|
|
161
170
|
};
|
|
162
|
-
const getFile = (name, { mode = "split", pluginKey = plugin.key, extname = ".ts",
|
|
171
|
+
const getFile = (name, { mode = "split", pluginKey = plugin.key, extname = ".ts", group } = {}) => {
|
|
163
172
|
const resolvedName = mode === "single" ? "" : getName(name, { type: "file", pluginKey });
|
|
164
173
|
const file = pluginManager.getFile({
|
|
165
174
|
name: resolvedName,
|
|
166
175
|
extname,
|
|
167
176
|
pluginKey,
|
|
168
|
-
options: { type: "file", pluginKey,
|
|
177
|
+
options: { type: "file", pluginKey, group }
|
|
169
178
|
});
|
|
170
179
|
return {
|
|
171
180
|
...file,
|
package/dist/hooks.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
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"],"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;AAAA;AAGtC,EAAO,OAAA,GAAA;AACT;ACLO,SAAS,YAA8B,GAAA;AAC5C,EAAA,MAAM,EAAE,SAAA,EAAcA,GAAAA,UAAAA,CAAW,UAAU,OAAO,CAAA;AAElD,EAAA,IAAI,CAAC,SAAW,EAAA;AACd,IAAM,MAAA,IAAI,MAAM,0BAA0B,CAAA;AAAA;AAG5C,EAAO,OAAA,SAAA;AACT;AC0CO,SAAS,mBAAiD,GAAA;AAC/D,EAAA,MAAM,EAAE,MAAA,EAAQ,aAAc,EAAA,GAAI,MAAO,EAAA;AACzC,EAAA,MAAM,EAAE,SAAA,EAAcA,GAAAA,UAAAA,CAAW,IAAI,OAAO,CAAA;AAE5C,EAAA,MAAM,OAAgD,GAAA,CAAC,SAAW,EAAA,EAAE,MA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,GAAO,cAAc,OAAQ,CAAA;AAAA,MACjC,IAAM,EAAA,YAAA;AAAA,MACN,OAAA;AAAA,MACA,SAAA;AAAA,MACA,OAAS,EAAA,EAAE,IAAM,EAAA,MAAA,EAAQ,WAAW,GAAI;AAAA,KACzC,CAAA;AAED,IAAO,OAAA;AAAA,MACL,GAAG,IAAA;AAAA,MACH,IAAM,EAAA;AAAA,QACJ,GAAG,IAAK,CAAA,IAAA;AAAA,QACR,IAAM,EAAA,YAAA;AAAA,QACN;AAAA;AACF,KACF;AAAA,GACF;AAEA,EAAM,MAAA,UAAA,GAAmD,CAAC,IAAS,KAAA;AACjE,IAAA,MAAM,IAAO,GAAA,eAAA,CAAgB,UAAW,CAAA,IAAA,EAAM,eAAe,GAAG,CAAA;AAEhE,IAAA,OAAO,IACH,EAAA,GAAA,CAAI,CAAC,IAAA,EAAM,CAAM,KAAA;AACjB,MAAA,IAAI,CAAC,IAAK,CAAA,IAAA,CAAK,QAAQ,CAAC,IAAA,CAAK,KAAK,YAAc,EAAA;AAC9C,QAAO,OAAA,KAAA,CAAA;AAAA;AAGT,MAAO,OAAA;AAAA,QACL,IAAM,EAAA,CAAC,IAAK,CAAA,IAAA,CAAK,IAAI,CAAA;AAAA,QACrB,IAAA,EAAM,KAAK,IAAK,CAAA;AAAA,OAClB;AAAA,KACD,CACA,CAAA,MAAA,CAAO,OAAO,CAAA;AAAA,GACnB;AAEA,EAAO,OAAA;AAAA,IACL,OAAA;AAAA,IACA,OAAA;AAAA,IACA;AAAA,GACF;AACF","file":"hooks.js","sourcesContent":["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\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 const responses = (schemas.responses || []).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 ...responses,\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 { plugin, pluginManager } = 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"]}
|
|
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"],"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;AAAA;AAGtC,EAAO,OAAA,GAAA;AACT;ACLO,SAAS,YAA8B,GAAA;AAC5C,EAAA,MAAM,EAAE,SAAA,EAAcA,GAAAA,UAAAA,CAAW,UAAU,OAAO,CAAA;AAElD,EAAA,IAAI,CAAC,SAAW,EAAA;AACd,IAAM,MAAA,IAAI,MAAM,0BAA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A;AAC9C,QAAO,OAAA,KAAA,CAAA;AAAA;AAGT,MAAO,OAAA;AAAA,QACL,IAAM,EAAA,CAAC,IAAK,CAAA,IAAA,CAAK,IAAI,CAAA;AAAA,QACrB,IAAA,EAAM,KAAK,IAAK,CAAA;AAAA,OAClB;AAAA,KACD,CACA,CAAA,MAAA,CAAO,OAAO,CAAA;AAAA,GACnB;AAEA,EAAO,OAAA;AAAA,IACL,OAAA;AAAA,IACA,OAAA;AAAA,IACA;AAAA,GACF;AACF","file":"hooks.js","sourcesContent":["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, Group, Plugin, ResolveNameParams } from '@kubb/core'\n\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 group?: 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 group?: 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 getGroup: (operation: Operation, group: Group | undefined) => string | undefined\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 getGroup: UseOperationManagerResult['getGroup'] = (operation, group) => {\n if (group?.type === 'tag') {\n return operation.getTags().at(0)?.name\n }\n\n if (group?.type === 'path') {\n return operation.path\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 const getFile: UseOperationManagerResult['getFile'] = (\n operation,\n { prefix, suffix, pluginKey = plugin.key, group = getGroup(operation, (plugin.options as { group?: Group })?.group), extname = '.ts' } = {},\n ) => {\n const name = getName(operation, { type: 'file', pluginKey, prefix, suffix })\n\n const file = pluginManager.getFile({\n name,\n extname,\n pluginKey,\n options: { type: 'file', pluginKey, group },\n })\n\n return {\n ...file,\n meta: {\n ...file.meta,\n name,\n pluginKey,\n group,\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 const responses = (schemas.responses || []).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 ...responses,\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 getGroup,\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 group?: 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; group?: 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 { plugin, pluginManager } = 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\n const getFile: UseSchemaManagerResult['getFile'] = (name, { mode = 'split', pluginKey = plugin.key, extname = '.ts', group } = {}) => {\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, group },\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
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
var chunkABOQ73FL_cjs = require('./chunk-ABOQ73FL.cjs');
|
|
4
4
|
var chunk2TGWPVZN_cjs = require('./chunk-2TGWPVZN.cjs');
|
|
5
5
|
require('./chunk-PADR76WZ.cjs');
|
|
6
|
-
var
|
|
6
|
+
var chunkWSORDWRC_cjs = require('./chunk-WSORDWRC.cjs');
|
|
7
7
|
var chunkQAFBZLJA_cjs = require('./chunk-QAFBZLJA.cjs');
|
|
8
8
|
require('./chunk-ZWHQ54JM.cjs');
|
|
9
9
|
var core = require('@kubb/core');
|
|
@@ -351,7 +351,7 @@ var pluginOas = core.createPlugin((options) => {
|
|
|
351
351
|
logger: this.logger
|
|
352
352
|
});
|
|
353
353
|
await oas.dereference();
|
|
354
|
-
const schemaGenerator = new
|
|
354
|
+
const schemaGenerator = new chunkWSORDWRC_cjs.SchemaGenerator(
|
|
355
355
|
{
|
|
356
356
|
unknownType: "unknown",
|
|
357
357
|
dateType: "date",
|
|
@@ -397,15 +397,15 @@ Object.defineProperty(exports, "createReactGenerator", {
|
|
|
397
397
|
});
|
|
398
398
|
Object.defineProperty(exports, "SchemaGenerator", {
|
|
399
399
|
enumerable: true,
|
|
400
|
-
get: function () { return
|
|
400
|
+
get: function () { return chunkWSORDWRC_cjs.SchemaGenerator; }
|
|
401
401
|
});
|
|
402
402
|
Object.defineProperty(exports, "isKeyword", {
|
|
403
403
|
enumerable: true,
|
|
404
|
-
get: function () { return
|
|
404
|
+
get: function () { return chunkWSORDWRC_cjs.isKeyword; }
|
|
405
405
|
});
|
|
406
406
|
Object.defineProperty(exports, "schemaKeywords", {
|
|
407
407
|
enumerable: true,
|
|
408
|
-
get: function () { return
|
|
408
|
+
get: function () { return chunkWSORDWRC_cjs.schemaKeywords; }
|
|
409
409
|
});
|
|
410
410
|
exports.OperationGenerator = OperationGenerator;
|
|
411
411
|
exports.pluginOas = pluginOas;
|
package/dist/index.d.cts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { O as Options, P as PluginOas } from './OperationGenerator-
|
|
2
|
-
export { A as API, E as Exclude, o as Generator, p as GeneratorOptions, G as GetSchemaGeneratorOptions, I as Include, b as OperationGenerator, a as OperationMethodResult, v as OperationSchema, w as OperationSchemas, x as OperationsByMethod, y as Override, R as ReactGeneratorOptions, r as Ref, t as Refs, q as ResolvePathOptions, u as Resolver, f as Schema, e as SchemaGenerator, S as SchemaGeneratorBuildOptions, c as SchemaGeneratorOptions, h as SchemaKeyword, i as SchemaKeywordBase, j as SchemaKeywordMapper, k as SchemaMapper, d as SchemaMethodResult, g as SchemaTree, m as createGenerator, n as createReactGenerator, l as isKeyword, s as schemaKeywords } from './OperationGenerator-
|
|
1
|
+
import { O as Options, P as PluginOas } from './OperationGenerator-DOz5MZ9x.cjs';
|
|
2
|
+
export { A as API, E as Exclude, o as Generator, p as GeneratorOptions, G as GetSchemaGeneratorOptions, I as Include, b as OperationGenerator, a as OperationMethodResult, v as OperationSchema, w as OperationSchemas, x as OperationsByMethod, y as Override, R as ReactGeneratorOptions, r as Ref, t as Refs, q as ResolvePathOptions, u as Resolver, f as Schema, e as SchemaGenerator, S as SchemaGeneratorBuildOptions, c as SchemaGeneratorOptions, h as SchemaKeyword, i as SchemaKeywordBase, j as SchemaKeywordMapper, k as SchemaMapper, d as SchemaMethodResult, g as SchemaTree, m as createGenerator, n as createReactGenerator, l as isKeyword, s as schemaKeywords } from './OperationGenerator-DOz5MZ9x.cjs';
|
|
3
3
|
import * as _kubb_core from '@kubb/core';
|
|
4
4
|
import '@kubb/fs/types';
|
|
5
5
|
import '@kubb/oas';
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { O as Options, P as PluginOas } from './OperationGenerator-
|
|
2
|
-
export { A as API, E as Exclude, o as Generator, p as GeneratorOptions, G as GetSchemaGeneratorOptions, I as Include, b as OperationGenerator, a as OperationMethodResult, v as OperationSchema, w as OperationSchemas, x as OperationsByMethod, y as Override, R as ReactGeneratorOptions, r as Ref, t as Refs, q as ResolvePathOptions, u as Resolver, f as Schema, e as SchemaGenerator, S as SchemaGeneratorBuildOptions, c as SchemaGeneratorOptions, h as SchemaKeyword, i as SchemaKeywordBase, j as SchemaKeywordMapper, k as SchemaMapper, d as SchemaMethodResult, g as SchemaTree, m as createGenerator, n as createReactGenerator, l as isKeyword, s as schemaKeywords } from './OperationGenerator-
|
|
1
|
+
import { O as Options, P as PluginOas } from './OperationGenerator-DOz5MZ9x.js';
|
|
2
|
+
export { A as API, E as Exclude, o as Generator, p as GeneratorOptions, G as GetSchemaGeneratorOptions, I as Include, b as OperationGenerator, a as OperationMethodResult, v as OperationSchema, w as OperationSchemas, x as OperationsByMethod, y as Override, R as ReactGeneratorOptions, r as Ref, t as Refs, q as ResolvePathOptions, u as Resolver, f as Schema, e as SchemaGenerator, S as SchemaGeneratorBuildOptions, c as SchemaGeneratorOptions, h as SchemaKeyword, i as SchemaKeywordBase, j as SchemaKeywordMapper, k as SchemaMapper, d as SchemaMethodResult, g as SchemaTree, m as createGenerator, n as createReactGenerator, l as isKeyword, s as schemaKeywords } from './OperationGenerator-DOz5MZ9x.js';
|
|
3
3
|
import * as _kubb_core from '@kubb/core';
|
|
4
4
|
import '@kubb/fs/types';
|
|
5
5
|
import '@kubb/oas';
|
package/dist/index.js
CHANGED
|
@@ -2,8 +2,8 @@ import { parseFromConfig } from './chunk-BG77DP54.js';
|
|
|
2
2
|
import { jsonGenerator } from './chunk-TNWNNVQW.js';
|
|
3
3
|
export { createGenerator, createReactGenerator } from './chunk-TNWNNVQW.js';
|
|
4
4
|
import './chunk-R47XMJ32.js';
|
|
5
|
-
import { SchemaGenerator } from './chunk-
|
|
6
|
-
export { SchemaGenerator, isKeyword, schemaKeywords } from './chunk-
|
|
5
|
+
import { SchemaGenerator } from './chunk-IHPQRZWD.js';
|
|
6
|
+
export { SchemaGenerator, isKeyword, schemaKeywords } from './chunk-IHPQRZWD.js';
|
|
7
7
|
import { getSchemas } from './chunk-XNCEFOE6.js';
|
|
8
8
|
import './chunk-GF26SDHQ.js';
|
|
9
9
|
import { createPlugin, FileManager, BaseGenerator } from '@kubb/core';
|
package/dist/utils.d.cts
CHANGED
|
@@ -2,8 +2,8 @@ import { Operation, Oas, SchemaObject, OpenAPIV3, OpenAPIV3_1 } from '@kubb/oas'
|
|
|
2
2
|
export { isOptional } from '@kubb/oas';
|
|
3
3
|
import { FunctionParamsAST } from '@kubb/core/utils';
|
|
4
4
|
import { Params } from '@kubb/react/types';
|
|
5
|
-
import { v as OperationSchema } from './OperationGenerator-
|
|
6
|
-
export { z as GetSchemasProps, B as getSchemas } from './OperationGenerator-
|
|
5
|
+
import { v as OperationSchema } from './OperationGenerator-DOz5MZ9x.cjs';
|
|
6
|
+
export { z as GetSchemasProps, B as getSchemas } from './OperationGenerator-DOz5MZ9x.cjs';
|
|
7
7
|
import { Config } from '@kubb/core';
|
|
8
8
|
import '@kubb/fs/types';
|
|
9
9
|
|
package/dist/utils.d.ts
CHANGED
|
@@ -2,8 +2,8 @@ import { Operation, Oas, SchemaObject, OpenAPIV3, OpenAPIV3_1 } from '@kubb/oas'
|
|
|
2
2
|
export { isOptional } from '@kubb/oas';
|
|
3
3
|
import { FunctionParamsAST } from '@kubb/core/utils';
|
|
4
4
|
import { Params } from '@kubb/react/types';
|
|
5
|
-
import { v as OperationSchema } from './OperationGenerator-
|
|
6
|
-
export { z as GetSchemasProps, B as getSchemas } from './OperationGenerator-
|
|
5
|
+
import { v as OperationSchema } from './OperationGenerator-DOz5MZ9x.js';
|
|
6
|
+
export { z as GetSchemasProps, B as getSchemas } from './OperationGenerator-DOz5MZ9x.js';
|
|
7
7
|
import { Config } from '@kubb/core';
|
|
8
8
|
import '@kubb/fs/types';
|
|
9
9
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kubb/plugin-oas",
|
|
3
|
-
"version": "3.0
|
|
3
|
+
"version": "3.1.0",
|
|
4
4
|
"description": "Generator swagger",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"typescript",
|
|
@@ -76,18 +76,18 @@
|
|
|
76
76
|
"dependencies": {
|
|
77
77
|
"@stoplight/yaml": "^4.3.0",
|
|
78
78
|
"remeda": "^2.17.4",
|
|
79
|
-
"@kubb/core": "3.0
|
|
80
|
-
"@kubb/fs": "3.0
|
|
81
|
-
"@kubb/oas": "3.0
|
|
82
|
-
"@kubb/react": "3.0
|
|
79
|
+
"@kubb/core": "3.1.0",
|
|
80
|
+
"@kubb/fs": "3.1.0",
|
|
81
|
+
"@kubb/oas": "3.1.0",
|
|
82
|
+
"@kubb/react": "3.1.0"
|
|
83
83
|
},
|
|
84
84
|
"devDependencies": {
|
|
85
|
-
"@types/react": "^18.3.
|
|
85
|
+
"@types/react": "^18.3.13",
|
|
86
86
|
"react": "^18.3.1",
|
|
87
87
|
"tsup": "^8.3.5",
|
|
88
88
|
"typescript": "^5.7.2",
|
|
89
|
-
"@kubb/config-ts": "3.0
|
|
90
|
-
"@kubb/config-tsup": "3.0
|
|
89
|
+
"@kubb/config-ts": "3.1.0",
|
|
90
|
+
"@kubb/config-tsup": "3.1.0"
|
|
91
91
|
},
|
|
92
92
|
"peerDependencies": {
|
|
93
93
|
"@kubb/react": "^3.0.0"
|
package/src/SchemaGenerator.ts
CHANGED
|
@@ -491,17 +491,13 @@ export class SchemaGenerator<
|
|
|
491
491
|
if (schemaWithoutOneOf.properties) {
|
|
492
492
|
const propertySchemas = this.parse({ schema: schemaWithoutOneOf, name, parentName })
|
|
493
493
|
|
|
494
|
-
|
|
495
|
-
{
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
}
|
|
502
|
-
}),
|
|
503
|
-
},
|
|
504
|
-
...baseItems,
|
|
494
|
+
union.args = [
|
|
495
|
+
...union.args.map((arg) => {
|
|
496
|
+
return {
|
|
497
|
+
keyword: schemaKeywords.and,
|
|
498
|
+
args: [arg, ...propertySchemas],
|
|
499
|
+
}
|
|
500
|
+
}),
|
|
505
501
|
]
|
|
506
502
|
}
|
|
507
503
|
|
|
@@ -557,14 +553,36 @@ export class SchemaGenerator<
|
|
|
557
553
|
}),
|
|
558
554
|
}
|
|
559
555
|
|
|
556
|
+
if (schemaWithoutAllOf.required) {
|
|
557
|
+
const schemas = schema.allOf
|
|
558
|
+
.map((item) => {
|
|
559
|
+
if (isReference(item)) {
|
|
560
|
+
return this.context.oas.get(item.$ref) as SchemaObject
|
|
561
|
+
}
|
|
562
|
+
})
|
|
563
|
+
.filter(Boolean)
|
|
564
|
+
|
|
565
|
+
const items = schemaWithoutAllOf.required
|
|
566
|
+
.map((key) => {
|
|
567
|
+
const schema = schemas.find((item) => item.properties && Object.keys(item.properties).find((propertyKey) => propertyKey === key))
|
|
568
|
+
|
|
569
|
+
if (schema?.properties?.[key]) {
|
|
570
|
+
return {
|
|
571
|
+
...schema,
|
|
572
|
+
properties: {
|
|
573
|
+
[key]: schema.properties[key],
|
|
574
|
+
},
|
|
575
|
+
required: [key],
|
|
576
|
+
}
|
|
577
|
+
}
|
|
578
|
+
})
|
|
579
|
+
.filter(Boolean)
|
|
580
|
+
|
|
581
|
+
and.args = [...(and.args || []), ...items.flatMap((item) => this.parse({ schema: item as SchemaObject, name, parentName }))]
|
|
582
|
+
}
|
|
583
|
+
|
|
560
584
|
if (schemaWithoutAllOf.properties) {
|
|
561
|
-
|
|
562
|
-
{
|
|
563
|
-
...and,
|
|
564
|
-
args: [...(and.args || []), ...this.parse({ schema: schemaWithoutAllOf, name, parentName })],
|
|
565
|
-
},
|
|
566
|
-
...baseItems,
|
|
567
|
-
]
|
|
585
|
+
and.args = [...(and.args || []), ...this.parse({ schema: schemaWithoutAllOf, name, parentName })]
|
|
568
586
|
}
|
|
569
587
|
|
|
570
588
|
return [and, ...baseItems]
|
|
@@ -2,7 +2,8 @@ import { useApp, useContext } from '@kubb/react'
|
|
|
2
2
|
|
|
3
3
|
import { Oas } from '../components/Oas.tsx'
|
|
4
4
|
|
|
5
|
-
import type { FileMetaBase, Plugin, ResolveNameParams } from '@kubb/core'
|
|
5
|
+
import type { FileMetaBase, Group, Plugin, ResolveNameParams } from '@kubb/core'
|
|
6
|
+
|
|
6
7
|
import type * as KubbFile from '@kubb/fs/types'
|
|
7
8
|
import type { Operation, Operation as OperationType } from '@kubb/oas'
|
|
8
9
|
import type { OperationSchemas } from '../types.ts'
|
|
@@ -10,7 +11,7 @@ import type { OperationSchemas } from '../types.ts'
|
|
|
10
11
|
type FileMeta = FileMetaBase & {
|
|
11
12
|
pluginKey: Plugin['key']
|
|
12
13
|
name: string
|
|
13
|
-
|
|
14
|
+
group?: string
|
|
14
15
|
}
|
|
15
16
|
|
|
16
17
|
export type SchemaNames = {
|
|
@@ -41,7 +42,7 @@ type UseOperationManagerResult = {
|
|
|
41
42
|
suffix?: string
|
|
42
43
|
pluginKey?: Plugin['key']
|
|
43
44
|
extname?: KubbFile.Extname
|
|
44
|
-
|
|
45
|
+
group?: string
|
|
45
46
|
},
|
|
46
47
|
) => KubbFile.File<FileMeta>
|
|
47
48
|
groupSchemasByName: (
|
|
@@ -52,6 +53,7 @@ type UseOperationManagerResult = {
|
|
|
52
53
|
},
|
|
53
54
|
) => SchemaNames
|
|
54
55
|
getSchemas: (operation: Operation, params?: { pluginKey?: Plugin['key']; type?: ResolveNameParams['type'] }) => OperationSchemas
|
|
56
|
+
getGroup: (operation: Operation, group: Group | undefined) => string | undefined
|
|
55
57
|
}
|
|
56
58
|
|
|
57
59
|
/**
|
|
@@ -69,6 +71,16 @@ export function useOperationManager(): UseOperationManagerResult {
|
|
|
69
71
|
})
|
|
70
72
|
}
|
|
71
73
|
|
|
74
|
+
const getGroup: UseOperationManagerResult['getGroup'] = (operation, group) => {
|
|
75
|
+
if (group?.type === 'tag') {
|
|
76
|
+
return operation.getTags().at(0)?.name
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
if (group?.type === 'path') {
|
|
80
|
+
return operation.path
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
|
|
72
84
|
const getSchemas: UseOperationManagerResult['getSchemas'] = (operation, params) => {
|
|
73
85
|
if (!generator) {
|
|
74
86
|
throw new Error(`'generator' is not defined`)
|
|
@@ -84,17 +96,17 @@ export function useOperationManager(): UseOperationManagerResult {
|
|
|
84
96
|
})
|
|
85
97
|
}
|
|
86
98
|
|
|
87
|
-
//TODO replace tag with group
|
|
88
99
|
const getFile: UseOperationManagerResult['getFile'] = (
|
|
89
100
|
operation,
|
|
90
|
-
{ prefix, suffix, pluginKey = plugin.key,
|
|
101
|
+
{ prefix, suffix, pluginKey = plugin.key, group = getGroup(operation, (plugin.options as { group?: Group })?.group), extname = '.ts' } = {},
|
|
91
102
|
) => {
|
|
92
103
|
const name = getName(operation, { type: 'file', pluginKey, prefix, suffix })
|
|
104
|
+
|
|
93
105
|
const file = pluginManager.getFile({
|
|
94
106
|
name,
|
|
95
107
|
extname,
|
|
96
108
|
pluginKey,
|
|
97
|
-
options: { type: 'file', pluginKey,
|
|
109
|
+
options: { type: 'file', pluginKey, group },
|
|
98
110
|
})
|
|
99
111
|
|
|
100
112
|
return {
|
|
@@ -103,7 +115,7 @@ export function useOperationManager(): UseOperationManagerResult {
|
|
|
103
115
|
...file.meta,
|
|
104
116
|
name,
|
|
105
117
|
pluginKey,
|
|
106
|
-
|
|
118
|
+
group,
|
|
107
119
|
},
|
|
108
120
|
}
|
|
109
121
|
}
|
|
@@ -198,5 +210,6 @@ export function useOperationManager(): UseOperationManagerResult {
|
|
|
198
210
|
getFile,
|
|
199
211
|
getSchemas,
|
|
200
212
|
groupSchemasByName,
|
|
213
|
+
getGroup,
|
|
201
214
|
}
|
|
202
215
|
}
|