@kubb/plugin-oas 4.3.1 → 4.4.1
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/{Oas-DoN76W2_.js → Oas-CHC1IC5D.js} +5 -9
- package/dist/Oas-CHC1IC5D.js.map +1 -0
- package/dist/{Oas--cvTRMTA.cjs → Oas-CQrRP_NH.cjs} +13 -17
- package/dist/Oas-CQrRP_NH.cjs.map +1 -0
- package/dist/{OperationGenerator-XkW6FZJh.d.cts → OperationGenerator-CRZpkIpZ.d.ts} +182 -109
- package/dist/{OperationGenerator-ki8g970_.d.ts → OperationGenerator-S_1PevQN.d.cts} +182 -109
- package/dist/{Schema-CHstINXC.d.ts → Schema-CZsDEhET.d.cts} +7 -6
- package/dist/{Schema-BXYfUkqN.d.cts → Schema-DBvtiLS7.d.ts} +7 -6
- package/dist/{SchemaGenerator-DsK0wuii.cjs → SchemaGenerator-DWj6buY0.cjs} +22 -5
- package/dist/SchemaGenerator-DWj6buY0.cjs.map +1 -0
- package/dist/{SchemaGenerator-B07tXh1b.js → SchemaGenerator-b7XixzRv.js} +21 -4
- package/dist/SchemaGenerator-b7XixzRv.js.map +1 -0
- package/dist/{SchemaMapper-qjB3rBph.d.ts → SchemaMapper-CX7sIIuZ.d.cts} +5 -118
- package/dist/{SchemaMapper-MiRB5_Zp.d.cts → SchemaMapper-CtfTw3hq.d.ts} +5 -118
- package/dist/{SchemaMapper-CM1eXksi.js → SchemaMapper-Cx4X1al6.js} +1 -1
- package/dist/SchemaMapper-Cx4X1al6.js.map +1 -0
- package/dist/{SchemaMapper-CpAbmGiH.cjs → SchemaMapper-DoL-a6qq.cjs} +1 -1
- package/dist/SchemaMapper-DoL-a6qq.cjs.map +1 -0
- package/dist/chunk-BEV-X5tz.js +27 -0
- package/dist/components.cjs +1 -1
- package/dist/components.d.cts +8 -11
- package/dist/components.d.ts +8 -11
- package/dist/components.js +1 -1
- package/dist/generators-B27La9Vd.cjs +99 -0
- package/dist/generators-B27La9Vd.cjs.map +1 -0
- package/dist/generators-C61FxVIj.js +80 -0
- package/dist/generators-C61FxVIj.js.map +1 -0
- package/dist/generators.cjs +9 -3
- package/dist/generators.d.cts +3 -8
- package/dist/generators.d.ts +3 -8
- package/dist/generators.js +5 -4
- package/dist/{getFooter-pQXwqM81.cjs → getFooter-CwjCW4h5.cjs} +3 -3
- package/dist/{getFooter-pQXwqM81.cjs.map → getFooter-CwjCW4h5.cjs.map} +1 -1
- package/dist/{getFooter-CvTKkK7-.js → getFooter-D5MdeUVv.js} +2 -2
- package/dist/{getFooter-CvTKkK7-.js.map → getFooter-D5MdeUVv.js.map} +1 -1
- package/dist/{getSchemas-CvUX0jWa.js → getSchemas-Bdg6n9Qk.js} +1 -1
- package/dist/{getSchemas-CvUX0jWa.js.map → getSchemas-Bdg6n9Qk.js.map} +1 -1
- package/dist/{getSchemas-08CU8KWq.cjs → getSchemas-DY8s2CSl.cjs} +1 -1
- package/dist/{getSchemas-08CU8KWq.cjs.map → getSchemas-DY8s2CSl.cjs.map} +1 -1
- package/dist/hooks.cjs +12 -27
- package/dist/hooks.cjs.map +1 -1
- package/dist/hooks.d.cts +11 -31
- package/dist/hooks.d.ts +11 -31
- package/dist/hooks.js +9 -23
- package/dist/hooks.js.map +1 -1
- package/dist/index.cjs +37 -9
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +3 -9
- package/dist/index.d.ts +3 -9
- package/dist/index.js +33 -9
- package/dist/index.js.map +1 -1
- package/dist/mocks.cjs +1 -1
- package/dist/mocks.d.cts +1 -1
- package/dist/mocks.d.ts +1 -1
- package/dist/mocks.js +1 -1
- package/dist/{parseFromConfig-DSI6Meg0.js → parseFromConfig-CqiiLCPe.js} +1 -1
- package/dist/{parseFromConfig-DSI6Meg0.js.map → parseFromConfig-CqiiLCPe.js.map} +1 -1
- package/dist/{parseFromConfig-o3tU1XJt.cjs → parseFromConfig-RR31a98-.cjs} +1 -1
- package/dist/{parseFromConfig-o3tU1XJt.cjs.map → parseFromConfig-RR31a98-.cjs.map} +1 -1
- package/dist/utils-DYf-j63H.cjs +115 -0
- package/dist/utils-DYf-j63H.cjs.map +1 -0
- package/dist/utils-DaV25sy8.js +95 -0
- package/dist/utils-DaV25sy8.js.map +1 -0
- package/dist/utils.cjs +3 -3
- package/dist/utils.cjs.map +1 -1
- package/dist/utils.d.cts +4 -3
- package/dist/utils.d.ts +4 -3
- package/dist/utils.js +3 -3
- package/dist/utils.js.map +1 -1
- package/package.json +14 -11
- package/src/OperationGenerator.ts +36 -7
- package/src/SchemaGenerator.ts +26 -2
- package/src/SchemaMapper.ts +1 -1
- package/src/components/Oas.tsx +5 -12
- package/src/components/Operation.tsx +3 -3
- package/src/components/Schema.tsx +3 -4
- package/src/generators/createGenerator.ts +34 -0
- package/src/generators/createReactGenerator.ts +41 -0
- package/src/generators/index.ts +4 -0
- package/src/generators/jsonGenerator.ts +1 -1
- package/src/generators/types.ts +35 -0
- package/src/generators/utils.tsx +114 -0
- package/src/hooks/index.ts +1 -2
- package/src/hooks/useOas.ts +5 -11
- package/src/hooks/useOperation.ts +1 -1
- package/src/hooks/useOperationManager.ts +2 -2
- package/src/hooks/useSchema.ts +1 -1
- package/src/hooks/useSchemaManager.ts +1 -1
- package/src/index.ts +3 -5
- package/src/plugin.ts +2 -0
- package/src/types.ts +2 -2
- package/src/utils/getParams.ts +1 -1
- package/dist/Oas--cvTRMTA.cjs.map +0 -1
- package/dist/Oas-DoN76W2_.js.map +0 -1
- package/dist/SchemaGenerator-B07tXh1b.js.map +0 -1
- package/dist/SchemaGenerator-DsK0wuii.cjs.map +0 -1
- package/dist/SchemaMapper-CM1eXksi.js.map +0 -1
- package/dist/SchemaMapper-CpAbmGiH.cjs.map +0 -1
- package/dist/generators-BUNmB1lx.js +0 -154
- package/dist/generators-BUNmB1lx.js.map +0 -1
- package/dist/generators-CoiXCnDY.cjs +0 -175
- package/dist/generators-CoiXCnDY.cjs.map +0 -1
- package/src/generator.tsx +0 -139
- package/src/hooks/useOperations.ts +0 -40
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils-DaV25sy8.js","names":[],"sources":["../src/generators/utils.tsx"],"sourcesContent":["import type { PluginFactoryOptions } from '@kubb/core'\nimport type { Operation, SchemaObject } from '@kubb/oas'\nimport { App, createReactFabric, type Fabric } from '@kubb/react-fabric'\nimport { Oas } from '../components/Oas.tsx'\nimport type { OperationGenerator } from '../OperationGenerator.ts'\nimport type { SchemaGenerator, SchemaGeneratorOptions } from '../SchemaGenerator.ts'\nimport type { Schema } from '../SchemaMapper.ts'\nimport type { ReactGenerator } from './/createReactGenerator.ts'\n\ntype BuildOperationsOptions<TOptions extends PluginFactoryOptions> = {\n fabric: Fabric\n generator: ReactGenerator<any>\n /**\n * @deprecated\n */\n instance: Omit<OperationGenerator<TOptions>, 'build'>\n options: TOptions['resolvedOptions']\n}\n\nexport async function buildOperations<TOptions extends PluginFactoryOptions>(\n operations: Array<Operation>,\n { fabric, options, instance, generator }: BuildOperationsOptions<TOptions>,\n): Promise<void> {\n if (!generator.Operations) {\n return undefined\n }\n\n const { pluginManager, oas, plugin, mode } = instance.context\n\n function Component() {\n return (\n <App meta={{ pluginManager, plugin, mode, oas }}>\n <Oas generator={instance}>\n <generator.Operations operations={operations} instance={instance} options={options} />\n </Oas>\n </App>\n )\n }\n\n const fabricChild = createReactFabric()\n fabricChild.render(Component)\n\n await fabric.context.fileManager.add(...fabricChild.files)\n}\n\ntype BuildOperationOptions<TOptions extends PluginFactoryOptions> = BuildOperationsOptions<TOptions>\n\nexport async function buildOperation<TOptions extends PluginFactoryOptions>(\n operation: Operation,\n { fabric, options, instance, generator }: BuildOperationOptions<TOptions>,\n): Promise<void> {\n if (!generator.Operation) {\n return undefined\n }\n\n const { pluginManager, oas, plugin, mode } = instance.context\n\n function Component() {\n return (\n <App meta={{ pluginManager, plugin: { ...plugin, options }, mode, oas }}>\n <Oas generator={instance}>\n <Oas.Operation operation={operation}>\n <generator.Operation operation={operation} options={options} instance={instance} />\n </Oas.Operation>\n </Oas>\n </App>\n )\n }\n const fabricChild = createReactFabric()\n fabricChild.render(Component)\n\n await fabric.context.fileManager.add(...fabricChild.files)\n}\n\ntype BuildSchemaOptions<TOptions extends PluginFactoryOptions> = {\n fabric: Fabric\n generator: ReactGenerator<any>\n /**\n * @deprecated\n */\n instance: Omit<SchemaGenerator<SchemaGeneratorOptions, TOptions>, 'build'>\n options: TOptions['resolvedOptions']\n}\n\nexport async function buildSchema<TOptions extends PluginFactoryOptions>(\n schema: {\n name: string\n tree: Array<Schema>\n value: SchemaObject\n },\n { fabric, options, instance, generator }: BuildSchemaOptions<TOptions>,\n): Promise<void> {\n if (!generator.Schema) {\n return undefined\n }\n\n const { pluginManager, oas, plugin, mode } = instance.context\n\n function Component() {\n return (\n <App meta={{ pluginManager, plugin: { ...plugin, options }, mode, oas }}>\n <Oas>\n <Oas.Schema name={schema.name} schemaObject={schema.value} tree={schema.tree}>\n <generator.Schema schema={schema} options={options} instance={instance} />\n </Oas.Schema>\n </Oas>\n </App>\n )\n }\n const fabricChild = createReactFabric()\n fabricChild.render(Component)\n\n await fabric.context.fileManager.add(...fabricChild.files)\n}\n"],"mappings":";;;;;AAmBA,eAAsB,gBACpB,YACA,EAAE,QAAQ,SAAS,UAAU,aACd;AACf,KAAI,CAAC,UAAU,WACb;CAGF,MAAM,EAAE,eAAe,KAAK,QAAQ,SAAS,SAAS;CAEtD,SAAS,YAAY;AACnB,SACE,oBAAC;GAAI,MAAM;IAAE;IAAe;IAAQ;IAAM;IAAK;aAC7C,oBAAC;IAAI,WAAW;cACd,oBAAC,UAAU;KAAuB;KAAsB;KAAmB;MAAW;KAClF;IACF;;CAIV,MAAM,cAAc,mBAAmB;AACvC,aAAY,OAAO,UAAU;AAE7B,OAAM,OAAO,QAAQ,YAAY,IAAI,GAAG,YAAY,MAAM;;AAK5D,eAAsB,eACpB,WACA,EAAE,QAAQ,SAAS,UAAU,aACd;AACf,KAAI,CAAC,UAAU,UACb;CAGF,MAAM,EAAE,eAAe,KAAK,QAAQ,SAAS,SAAS;CAEtD,SAAS,YAAY;AACnB,SACE,oBAAC;GAAI,MAAM;IAAE;IAAe,QAAQ;KAAE,GAAG;KAAQ;KAAS;IAAE;IAAM;IAAK;aACrE,oBAAC;IAAI,WAAW;cACd,oBAAC,IAAI;KAAqB;eACxB,oBAAC,UAAU;MAAqB;MAAoB;MAAmB;OAAY;MACrE;KACZ;IACF;;CAGV,MAAM,cAAc,mBAAmB;AACvC,aAAY,OAAO,UAAU;AAE7B,OAAM,OAAO,QAAQ,YAAY,IAAI,GAAG,YAAY,MAAM;;AAa5D,eAAsB,YACpB,QAKA,EAAE,QAAQ,SAAS,UAAU,aACd;AACf,KAAI,CAAC,UAAU,OACb;CAGF,MAAM,EAAE,eAAe,KAAK,QAAQ,SAAS,SAAS;CAEtD,SAAS,YAAY;AACnB,SACE,oBAAC;GAAI,MAAM;IAAE;IAAe,QAAQ;KAAE,GAAG;KAAQ;KAAS;IAAE;IAAM;IAAK;aACrE,oBAAC,iBACC,oBAAC,IAAI;IAAO,MAAM,OAAO;IAAM,cAAc,OAAO;IAAO,MAAM,OAAO;cACtE,oBAAC,UAAU;KAAe;KAAiB;KAAmB;MAAY;KAC/D,GACT;IACF;;CAGV,MAAM,cAAc,mBAAmB;AACvC,aAAY,OAAO,UAAU;AAE7B,OAAM,OAAO,QAAQ,YAAY,IAAI,GAAG,YAAY,MAAM"}
|
package/dist/utils.cjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
const require_chunk = require('./chunk-CUT6urMc.cjs');
|
|
2
|
-
const require_getFooter = require('./getFooter-
|
|
3
|
-
const require_getSchemas = require('./getSchemas-
|
|
4
|
-
const require_parseFromConfig = require('./parseFromConfig-
|
|
2
|
+
const require_getFooter = require('./getFooter-CwjCW4h5.cjs');
|
|
3
|
+
const require_getSchemas = require('./getSchemas-DY8s2CSl.cjs');
|
|
4
|
+
const require_parseFromConfig = require('./parseFromConfig-RR31a98-.cjs');
|
|
5
5
|
let __kubb_core_transformers = require("@kubb/core/transformers");
|
|
6
6
|
__kubb_core_transformers = require_chunk.__toESM(__kubb_core_transformers);
|
|
7
7
|
let __kubb_core_utils = require("@kubb/core/utils");
|
package/dist/utils.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.cjs","names":["URLPath","transformers","data: FunctionParamsAST"],"sources":["../src/utils/getComments.ts","../src/utils/getParams.ts"],"sourcesContent":["import transformers from '@kubb/core/transformers'\nimport { URLPath } from '@kubb/core/utils'\n\nimport type { Operation } from '@kubb/oas'\n\nexport function getComments(operation: Operation): string[] {\n return [\n operation.getDescription() && `@description ${operation.getDescription()}`,\n operation.getSummary() && `@summary ${operation.getSummary()}`,\n operation.path && `{@link ${new URLPath(operation.path).URL}}`,\n operation.isDeprecated() && '@deprecated',\n ]\n .filter(Boolean)\n .map((text) => transformers.trim(text))\n}\n","import { isParameterObject } from '@kubb/oas'\n\nimport { camelCase, isValidVarName } from '@kubb/core/transformers'\nimport type { FunctionParamsAST } from '@kubb/core/utils'\nimport type { OasTypes } from '@kubb/oas'\nimport type { Params } from '@kubb/react/types'\nimport type { OperationSchema } from '../types.ts'\n/**\n *\n * @deprecated\n * TODO move to operationManager hook\n */\nexport function getASTParams(\n operationSchema: OperationSchema | undefined,\n {\n typed = false,\n override,\n }: {\n typed?: boolean\n override?: (data: FunctionParamsAST) => FunctionParamsAST\n } = {},\n): FunctionParamsAST[] {\n if (!operationSchema || !operationSchema.schema.properties || !operationSchema.name) {\n return []\n }\n\n return Object.entries(operationSchema.schema.properties).map(([name, schema]: [string, OasTypes.SchemaObject]) => {\n const isParam = isParameterObject(schema)\n const data: FunctionParamsAST = {\n name,\n enabled: !!name,\n required: isParam ? schema.required : true,\n type: typed ? `${operationSchema.name}[\"${name}\"]` : undefined,\n }\n\n return override ? override(data) : data\n })\n}\n\nexport function getPathParams(\n operationSchema: OperationSchema | undefined,\n options: {\n typed?: boolean\n casing?: 'camelcase'\n override?: (data: FunctionParamsAST) => FunctionParamsAST\n } = {},\n) {\n return getASTParams(operationSchema, options).reduce((acc, curr) => {\n if (curr.name && curr.enabled) {\n let name = isValidVarName(curr.name) ? curr.name : camelCase(curr.name)\n\n if (options.casing === 'camelcase') {\n name = camelCase(name)\n }\n\n acc[name] = {\n default: curr.default,\n type: curr.type,\n optional: !curr.required,\n }\n }\n\n return acc\n }, {} as Params)\n}\n"],"mappings":";;;;;;;;;;;;AAKA,SAAgB,YAAY,WAAgC;AAC1D,QAAO;EACL,UAAU,gBAAgB,IAAI,gBAAgB,UAAU,gBAAgB;EACxE,UAAU,YAAY,IAAI,YAAY,UAAU,YAAY;EAC5D,UAAU,QAAQ,UAAU,IAAIA,0BAAQ,UAAU,KAAK,CAAC,IAAI;EAC5D,UAAU,cAAc,IAAI;EAC7B,CACE,OAAO,QAAQ,CACf,KAAK,SAASC,iCAAa,KAAK,KAAK,CAAC;;;;;;;;;;ACD3C,SAAgB,aACd,iBACA,EACE,QAAQ,OACR,aAIE,EAAE,EACe;AACrB,KAAI,CAAC,mBAAmB,CAAC,gBAAgB,OAAO,cAAc,CAAC,gBAAgB,KAC7E,QAAO,EAAE;AAGX,QAAO,OAAO,QAAQ,gBAAgB,OAAO,WAAW,CAAC,KAAK,CAAC,MAAM,YAA6C;EAChH,MAAM,4CAA4B,OAAO;EACzC,MAAMC,OAA0B;GAC9B;GACA,SAAS,CAAC,CAAC;GACX,UAAU,UAAU,OAAO,WAAW;GACtC,MAAM,QAAQ,GAAG,gBAAgB,KAAK,IAAI,KAAK,MAAM;GACtD;AAED,SAAO,WAAW,SAAS,KAAK,GAAG;GACnC;;AAGJ,SAAgB,cACd,iBACA,UAII,EAAE,EACN;AACA,QAAO,aAAa,iBAAiB,QAAQ,CAAC,QAAQ,KAAK,SAAS;AAClE,MAAI,KAAK,QAAQ,KAAK,SAAS;GAC7B,IAAI,oDAAsB,KAAK,KAAK,GAAG,KAAK,+CAAiB,KAAK,KAAK;AAEvE,OAAI,QAAQ,WAAW,YACrB,gDAAiB,KAAK;AAGxB,OAAI,QAAQ;IACV,SAAS,KAAK;IACd,MAAM,KAAK;IACX,UAAU,CAAC,KAAK;IACjB;;AAGH,SAAO;IACN,EAAE,CAAW"}
|
|
1
|
+
{"version":3,"file":"utils.cjs","names":["URLPath","transformers","data: FunctionParamsAST"],"sources":["../src/utils/getComments.ts","../src/utils/getParams.ts"],"sourcesContent":["import transformers from '@kubb/core/transformers'\nimport { URLPath } from '@kubb/core/utils'\n\nimport type { Operation } from '@kubb/oas'\n\nexport function getComments(operation: Operation): string[] {\n return [\n operation.getDescription() && `@description ${operation.getDescription()}`,\n operation.getSummary() && `@summary ${operation.getSummary()}`,\n operation.path && `{@link ${new URLPath(operation.path).URL}}`,\n operation.isDeprecated() && '@deprecated',\n ]\n .filter(Boolean)\n .map((text) => transformers.trim(text))\n}\n","import { isParameterObject } from '@kubb/oas'\n\nimport { camelCase, isValidVarName } from '@kubb/core/transformers'\nimport type { FunctionParamsAST } from '@kubb/core/utils'\nimport type { OasTypes } from '@kubb/oas'\nimport type { Params } from '@kubb/react-fabric/types'\nimport type { OperationSchema } from '../types.ts'\n/**\n *\n * @deprecated\n * TODO move to operationManager hook\n */\nexport function getASTParams(\n operationSchema: OperationSchema | undefined,\n {\n typed = false,\n override,\n }: {\n typed?: boolean\n override?: (data: FunctionParamsAST) => FunctionParamsAST\n } = {},\n): FunctionParamsAST[] {\n if (!operationSchema || !operationSchema.schema.properties || !operationSchema.name) {\n return []\n }\n\n return Object.entries(operationSchema.schema.properties).map(([name, schema]: [string, OasTypes.SchemaObject]) => {\n const isParam = isParameterObject(schema)\n const data: FunctionParamsAST = {\n name,\n enabled: !!name,\n required: isParam ? schema.required : true,\n type: typed ? `${operationSchema.name}[\"${name}\"]` : undefined,\n }\n\n return override ? override(data) : data\n })\n}\n\nexport function getPathParams(\n operationSchema: OperationSchema | undefined,\n options: {\n typed?: boolean\n casing?: 'camelcase'\n override?: (data: FunctionParamsAST) => FunctionParamsAST\n } = {},\n) {\n return getASTParams(operationSchema, options).reduce((acc, curr) => {\n if (curr.name && curr.enabled) {\n let name = isValidVarName(curr.name) ? curr.name : camelCase(curr.name)\n\n if (options.casing === 'camelcase') {\n name = camelCase(name)\n }\n\n acc[name] = {\n default: curr.default,\n type: curr.type,\n optional: !curr.required,\n }\n }\n\n return acc\n }, {} as Params)\n}\n"],"mappings":";;;;;;;;;;;;AAKA,SAAgB,YAAY,WAAgC;AAC1D,QAAO;EACL,UAAU,gBAAgB,IAAI,gBAAgB,UAAU,gBAAgB;EACxE,UAAU,YAAY,IAAI,YAAY,UAAU,YAAY;EAC5D,UAAU,QAAQ,UAAU,IAAIA,0BAAQ,UAAU,KAAK,CAAC,IAAI;EAC5D,UAAU,cAAc,IAAI;EAC7B,CACE,OAAO,QAAQ,CACf,KAAK,SAASC,iCAAa,KAAK,KAAK,CAAC;;;;;;;;;;ACD3C,SAAgB,aACd,iBACA,EACE,QAAQ,OACR,aAIE,EAAE,EACe;AACrB,KAAI,CAAC,mBAAmB,CAAC,gBAAgB,OAAO,cAAc,CAAC,gBAAgB,KAC7E,QAAO,EAAE;AAGX,QAAO,OAAO,QAAQ,gBAAgB,OAAO,WAAW,CAAC,KAAK,CAAC,MAAM,YAA6C;EAChH,MAAM,4CAA4B,OAAO;EACzC,MAAMC,OAA0B;GAC9B;GACA,SAAS,CAAC,CAAC;GACX,UAAU,UAAU,OAAO,WAAW;GACtC,MAAM,QAAQ,GAAG,gBAAgB,KAAK,IAAI,KAAK,MAAM;GACtD;AAED,SAAO,WAAW,SAAS,KAAK,GAAG;GACnC;;AAGJ,SAAgB,cACd,iBACA,UAII,EAAE,EACN;AACA,QAAO,aAAa,iBAAiB,QAAQ,CAAC,QAAQ,KAAK,SAAS;AAClE,MAAI,KAAK,QAAQ,KAAK,SAAS;GAC7B,IAAI,oDAAsB,KAAK,KAAK,GAAG,KAAK,+CAAiB,KAAK,KAAK;AAEvE,OAAI,QAAQ,WAAW,YACrB,gDAAiB,KAAK;AAGxB,OAAI,QAAQ;IACV,SAAS,KAAK;IACd,MAAM,KAAK;IACX,UAAU,CAAC,KAAK;IACjB;;AAGH,SAAO;IACN,EAAE,CAAW"}
|
package/dist/utils.d.cts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import "./SchemaMapper-
|
|
1
|
+
import { A as Config, B as contentType, F as OasTypes, I as OpenAPIV3$1, L as OpenAPIV3_1, P as Oas, R as Operation, j as Output, v as OperationSchema, z as SchemaObject$1 } from "./OperationGenerator-S_1PevQN.cjs";
|
|
2
|
+
import "./SchemaMapper-CX7sIIuZ.cjs";
|
|
3
3
|
import { OASDocument, SchemaObject } from "oas/types";
|
|
4
4
|
import { OpenAPIV3 } from "openapi-types";
|
|
5
|
+
import { Params } from "@kubb/react-fabric/types";
|
|
5
6
|
|
|
6
7
|
//#region ../oas/src/utils.d.ts
|
|
7
8
|
|
|
@@ -47,7 +48,7 @@ declare function getPathParams(operationSchema: OperationSchema | undefined, opt
|
|
|
47
48
|
typed?: boolean;
|
|
48
49
|
casing?: 'camelcase';
|
|
49
50
|
override?: (data: FunctionParamsAST) => FunctionParamsAST;
|
|
50
|
-
}):
|
|
51
|
+
}): Params;
|
|
51
52
|
//#endregion
|
|
52
53
|
//#region src/utils/getSchemaFactory.d.ts
|
|
53
54
|
/**
|
package/dist/utils.d.ts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import "./SchemaMapper-
|
|
1
|
+
import { A as Config, B as contentType, F as OasTypes, I as OpenAPIV3$1, L as OpenAPIV3_1, P as Oas, R as Operation, j as Output, v as OperationSchema, z as SchemaObject$1 } from "./OperationGenerator-CRZpkIpZ.js";
|
|
2
|
+
import "./SchemaMapper-CtfTw3hq.js";
|
|
3
3
|
import { OASDocument, SchemaObject } from "oas/types";
|
|
4
4
|
import { OpenAPIV3 } from "openapi-types";
|
|
5
|
+
import { Params } from "@kubb/react-fabric/types";
|
|
5
6
|
|
|
6
7
|
//#region ../oas/src/utils.d.ts
|
|
7
8
|
|
|
@@ -47,7 +48,7 @@ declare function getPathParams(operationSchema: OperationSchema | undefined, opt
|
|
|
47
48
|
typed?: boolean;
|
|
48
49
|
casing?: 'camelcase';
|
|
49
50
|
override?: (data: FunctionParamsAST) => FunctionParamsAST;
|
|
50
|
-
}):
|
|
51
|
+
}): Params;
|
|
51
52
|
//#endregion
|
|
52
53
|
//#region src/utils/getSchemaFactory.d.ts
|
|
53
54
|
/**
|
package/dist/utils.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { n as getBanner, t as getFooter } from "./getFooter-
|
|
2
|
-
import { n as getSchemaFactory, t as getSchemas } from "./getSchemas-
|
|
3
|
-
import { t as parseFromConfig } from "./parseFromConfig-
|
|
1
|
+
import { n as getBanner, t as getFooter } from "./getFooter-D5MdeUVv.js";
|
|
2
|
+
import { n as getSchemaFactory, t as getSchemas } from "./getSchemas-Bdg6n9Qk.js";
|
|
3
|
+
import { t as parseFromConfig } from "./parseFromConfig-CqiiLCPe.js";
|
|
4
4
|
import transformers, { camelCase, isValidVarName } from "@kubb/core/transformers";
|
|
5
5
|
import { URLPath } from "@kubb/core/utils";
|
|
6
6
|
import { isOptional, isParameterObject } from "@kubb/oas";
|
package/dist/utils.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.js","names":["data: FunctionParamsAST"],"sources":["../src/utils/getComments.ts","../src/utils/getParams.ts"],"sourcesContent":["import transformers from '@kubb/core/transformers'\nimport { URLPath } from '@kubb/core/utils'\n\nimport type { Operation } from '@kubb/oas'\n\nexport function getComments(operation: Operation): string[] {\n return [\n operation.getDescription() && `@description ${operation.getDescription()}`,\n operation.getSummary() && `@summary ${operation.getSummary()}`,\n operation.path && `{@link ${new URLPath(operation.path).URL}}`,\n operation.isDeprecated() && '@deprecated',\n ]\n .filter(Boolean)\n .map((text) => transformers.trim(text))\n}\n","import { isParameterObject } from '@kubb/oas'\n\nimport { camelCase, isValidVarName } from '@kubb/core/transformers'\nimport type { FunctionParamsAST } from '@kubb/core/utils'\nimport type { OasTypes } from '@kubb/oas'\nimport type { Params } from '@kubb/react/types'\nimport type { OperationSchema } from '../types.ts'\n/**\n *\n * @deprecated\n * TODO move to operationManager hook\n */\nexport function getASTParams(\n operationSchema: OperationSchema | undefined,\n {\n typed = false,\n override,\n }: {\n typed?: boolean\n override?: (data: FunctionParamsAST) => FunctionParamsAST\n } = {},\n): FunctionParamsAST[] {\n if (!operationSchema || !operationSchema.schema.properties || !operationSchema.name) {\n return []\n }\n\n return Object.entries(operationSchema.schema.properties).map(([name, schema]: [string, OasTypes.SchemaObject]) => {\n const isParam = isParameterObject(schema)\n const data: FunctionParamsAST = {\n name,\n enabled: !!name,\n required: isParam ? schema.required : true,\n type: typed ? `${operationSchema.name}[\"${name}\"]` : undefined,\n }\n\n return override ? override(data) : data\n })\n}\n\nexport function getPathParams(\n operationSchema: OperationSchema | undefined,\n options: {\n typed?: boolean\n casing?: 'camelcase'\n override?: (data: FunctionParamsAST) => FunctionParamsAST\n } = {},\n) {\n return getASTParams(operationSchema, options).reduce((acc, curr) => {\n if (curr.name && curr.enabled) {\n let name = isValidVarName(curr.name) ? curr.name : camelCase(curr.name)\n\n if (options.casing === 'camelcase') {\n name = camelCase(name)\n }\n\n acc[name] = {\n default: curr.default,\n type: curr.type,\n optional: !curr.required,\n }\n }\n\n return acc\n }, {} as Params)\n}\n"],"mappings":";;;;;;;;AAKA,SAAgB,YAAY,WAAgC;AAC1D,QAAO;EACL,UAAU,gBAAgB,IAAI,gBAAgB,UAAU,gBAAgB;EACxE,UAAU,YAAY,IAAI,YAAY,UAAU,YAAY;EAC5D,UAAU,QAAQ,UAAU,IAAI,QAAQ,UAAU,KAAK,CAAC,IAAI;EAC5D,UAAU,cAAc,IAAI;EAC7B,CACE,OAAO,QAAQ,CACf,KAAK,SAAS,aAAa,KAAK,KAAK,CAAC;;;;;;;;;;ACD3C,SAAgB,aACd,iBACA,EACE,QAAQ,OACR,aAIE,EAAE,EACe;AACrB,KAAI,CAAC,mBAAmB,CAAC,gBAAgB,OAAO,cAAc,CAAC,gBAAgB,KAC7E,QAAO,EAAE;AAGX,QAAO,OAAO,QAAQ,gBAAgB,OAAO,WAAW,CAAC,KAAK,CAAC,MAAM,YAA6C;EAChH,MAAM,UAAU,kBAAkB,OAAO;EACzC,MAAMA,OAA0B;GAC9B;GACA,SAAS,CAAC,CAAC;GACX,UAAU,UAAU,OAAO,WAAW;GACtC,MAAM,QAAQ,GAAG,gBAAgB,KAAK,IAAI,KAAK,MAAM;GACtD;AAED,SAAO,WAAW,SAAS,KAAK,GAAG;GACnC;;AAGJ,SAAgB,cACd,iBACA,UAII,EAAE,EACN;AACA,QAAO,aAAa,iBAAiB,QAAQ,CAAC,QAAQ,KAAK,SAAS;AAClE,MAAI,KAAK,QAAQ,KAAK,SAAS;GAC7B,IAAI,OAAO,eAAe,KAAK,KAAK,GAAG,KAAK,OAAO,UAAU,KAAK,KAAK;AAEvE,OAAI,QAAQ,WAAW,YACrB,QAAO,UAAU,KAAK;AAGxB,OAAI,QAAQ;IACV,SAAS,KAAK;IACd,MAAM,KAAK;IACX,UAAU,CAAC,KAAK;IACjB;;AAGH,SAAO;IACN,EAAE,CAAW"}
|
|
1
|
+
{"version":3,"file":"utils.js","names":["data: FunctionParamsAST"],"sources":["../src/utils/getComments.ts","../src/utils/getParams.ts"],"sourcesContent":["import transformers from '@kubb/core/transformers'\nimport { URLPath } from '@kubb/core/utils'\n\nimport type { Operation } from '@kubb/oas'\n\nexport function getComments(operation: Operation): string[] {\n return [\n operation.getDescription() && `@description ${operation.getDescription()}`,\n operation.getSummary() && `@summary ${operation.getSummary()}`,\n operation.path && `{@link ${new URLPath(operation.path).URL}}`,\n operation.isDeprecated() && '@deprecated',\n ]\n .filter(Boolean)\n .map((text) => transformers.trim(text))\n}\n","import { isParameterObject } from '@kubb/oas'\n\nimport { camelCase, isValidVarName } from '@kubb/core/transformers'\nimport type { FunctionParamsAST } from '@kubb/core/utils'\nimport type { OasTypes } from '@kubb/oas'\nimport type { Params } from '@kubb/react-fabric/types'\nimport type { OperationSchema } from '../types.ts'\n/**\n *\n * @deprecated\n * TODO move to operationManager hook\n */\nexport function getASTParams(\n operationSchema: OperationSchema | undefined,\n {\n typed = false,\n override,\n }: {\n typed?: boolean\n override?: (data: FunctionParamsAST) => FunctionParamsAST\n } = {},\n): FunctionParamsAST[] {\n if (!operationSchema || !operationSchema.schema.properties || !operationSchema.name) {\n return []\n }\n\n return Object.entries(operationSchema.schema.properties).map(([name, schema]: [string, OasTypes.SchemaObject]) => {\n const isParam = isParameterObject(schema)\n const data: FunctionParamsAST = {\n name,\n enabled: !!name,\n required: isParam ? schema.required : true,\n type: typed ? `${operationSchema.name}[\"${name}\"]` : undefined,\n }\n\n return override ? override(data) : data\n })\n}\n\nexport function getPathParams(\n operationSchema: OperationSchema | undefined,\n options: {\n typed?: boolean\n casing?: 'camelcase'\n override?: (data: FunctionParamsAST) => FunctionParamsAST\n } = {},\n) {\n return getASTParams(operationSchema, options).reduce((acc, curr) => {\n if (curr.name && curr.enabled) {\n let name = isValidVarName(curr.name) ? curr.name : camelCase(curr.name)\n\n if (options.casing === 'camelcase') {\n name = camelCase(name)\n }\n\n acc[name] = {\n default: curr.default,\n type: curr.type,\n optional: !curr.required,\n }\n }\n\n return acc\n }, {} as Params)\n}\n"],"mappings":";;;;;;;;AAKA,SAAgB,YAAY,WAAgC;AAC1D,QAAO;EACL,UAAU,gBAAgB,IAAI,gBAAgB,UAAU,gBAAgB;EACxE,UAAU,YAAY,IAAI,YAAY,UAAU,YAAY;EAC5D,UAAU,QAAQ,UAAU,IAAI,QAAQ,UAAU,KAAK,CAAC,IAAI;EAC5D,UAAU,cAAc,IAAI;EAC7B,CACE,OAAO,QAAQ,CACf,KAAK,SAAS,aAAa,KAAK,KAAK,CAAC;;;;;;;;;;ACD3C,SAAgB,aACd,iBACA,EACE,QAAQ,OACR,aAIE,EAAE,EACe;AACrB,KAAI,CAAC,mBAAmB,CAAC,gBAAgB,OAAO,cAAc,CAAC,gBAAgB,KAC7E,QAAO,EAAE;AAGX,QAAO,OAAO,QAAQ,gBAAgB,OAAO,WAAW,CAAC,KAAK,CAAC,MAAM,YAA6C;EAChH,MAAM,UAAU,kBAAkB,OAAO;EACzC,MAAMA,OAA0B;GAC9B;GACA,SAAS,CAAC,CAAC;GACX,UAAU,UAAU,OAAO,WAAW;GACtC,MAAM,QAAQ,GAAG,gBAAgB,KAAK,IAAI,KAAK,MAAM;GACtD;AAED,SAAO,WAAW,SAAS,KAAK,GAAG;GACnC;;AAGJ,SAAgB,cACd,iBACA,UAII,EAAE,EACN;AACA,QAAO,aAAa,iBAAiB,QAAQ,CAAC,QAAQ,KAAK,SAAS;AAClE,MAAI,KAAK,QAAQ,KAAK,SAAS;GAC7B,IAAI,OAAO,eAAe,KAAK,KAAK,GAAG,KAAK,OAAO,UAAU,KAAK,KAAK;AAEvE,OAAI,QAAQ,WAAW,YACrB,QAAO,UAAU,KAAK;AAGxB,OAAI,QAAQ;IACV,SAAS,KAAK;IACd,MAAM,KAAK;IACX,UAAU,CAAC,KAAK;IACjB;;AAGH,SAAO;IACN,EAAE,CAAW"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kubb/plugin-oas",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.4.1",
|
|
4
4
|
"description": "OpenAPI Specification (OAS) plugin for Kubb, providing core functionality for parsing and processing OpenAPI/Swagger schemas for code generation.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"openapi",
|
|
@@ -78,21 +78,24 @@
|
|
|
78
78
|
"!/**/**.test.**",
|
|
79
79
|
"!/**/__tests__/**"
|
|
80
80
|
],
|
|
81
|
+
"size-limit": [
|
|
82
|
+
{
|
|
83
|
+
"path": "./dist/*.js",
|
|
84
|
+
"limit": "510 KiB",
|
|
85
|
+
"gzip": true
|
|
86
|
+
}
|
|
87
|
+
],
|
|
81
88
|
"dependencies": {
|
|
82
|
-
"@kubb/react-fabric": "0.
|
|
89
|
+
"@kubb/react-fabric": "0.2.10",
|
|
83
90
|
"@stoplight/yaml": "^4.3.0",
|
|
84
91
|
"p-limit": "^7.2.0",
|
|
85
92
|
"remeda": "^2.32.0",
|
|
86
|
-
"@kubb/core": "4.
|
|
87
|
-
"@kubb/oas": "4.
|
|
88
|
-
"@kubb/react": "4.3.1"
|
|
89
|
-
},
|
|
90
|
-
"devDependencies": {
|
|
91
|
-
"tsdown": "^0.15.9",
|
|
92
|
-
"typescript": "^5.9.3"
|
|
93
|
+
"@kubb/core": "4.4.1",
|
|
94
|
+
"@kubb/oas": "4.4.1"
|
|
93
95
|
},
|
|
96
|
+
"devDependencies": {},
|
|
94
97
|
"peerDependencies": {
|
|
95
|
-
"@kubb/react": "
|
|
98
|
+
"@kubb/react-fabric": "0.2.10"
|
|
96
99
|
},
|
|
97
100
|
"engines": {
|
|
98
101
|
"node": ">=20"
|
|
@@ -102,7 +105,7 @@
|
|
|
102
105
|
"registry": "https://registry.npmjs.org/"
|
|
103
106
|
},
|
|
104
107
|
"scripts": {
|
|
105
|
-
"build": "tsdown",
|
|
108
|
+
"build": "tsdown && size-limit",
|
|
106
109
|
"clean": "npx rimraf ./dist",
|
|
107
110
|
"lint": "bun biome lint .",
|
|
108
111
|
"lint:fix": "bun biome lint --fix --unsafe .",
|
|
@@ -1,17 +1,18 @@
|
|
|
1
|
+
import type { Plugin, PluginFactoryOptions, PluginManager } from '@kubb/core'
|
|
1
2
|
import { BaseGenerator, type FileMetaBase } from '@kubb/core'
|
|
2
3
|
import transformers from '@kubb/core/transformers'
|
|
3
|
-
|
|
4
|
-
import type {
|
|
5
|
-
import type {
|
|
6
|
-
import type { Plugin } from '@kubb/core'
|
|
7
|
-
import type { HttpMethod, Oas, OasTypes, Operation, SchemaObject, contentType } from '@kubb/oas'
|
|
8
|
-
import type { Generator } from './generator.tsx'
|
|
9
|
-
import type { Exclude, Include, OperationSchemas, Override } from './types.ts'
|
|
4
|
+
import type { KubbFile } from '@kubb/fabric-core/types'
|
|
5
|
+
import type { contentType, HttpMethod, Oas, OasTypes, Operation, SchemaObject } from '@kubb/oas'
|
|
6
|
+
import type { Fabric } from '@kubb/react-fabric'
|
|
10
7
|
import pLimit from 'p-limit'
|
|
8
|
+
import type { Generator } from './generators/types.ts'
|
|
9
|
+
import { buildOperation, buildOperations } from './generators/utils.tsx'
|
|
10
|
+
import type { Exclude, Include, OperationSchemas, Override } from './types.ts'
|
|
11
11
|
|
|
12
12
|
export type OperationMethodResult<TFileMeta extends FileMetaBase> = Promise<KubbFile.File<TFileMeta> | Array<KubbFile.File<TFileMeta>> | null>
|
|
13
13
|
|
|
14
14
|
type Context<TOptions, TPluginOptions extends PluginFactoryOptions> = {
|
|
15
|
+
fabric: Fabric
|
|
15
16
|
oas: Oas
|
|
16
17
|
exclude: Array<Exclude> | undefined
|
|
17
18
|
include: Array<Include> | undefined
|
|
@@ -226,6 +227,20 @@ export class OperationGenerator<
|
|
|
226
227
|
operationLimit(async () => {
|
|
227
228
|
const options = this.#getOptions(operation, method)
|
|
228
229
|
|
|
230
|
+
if (generator.type === 'react') {
|
|
231
|
+
await buildOperation(operation, {
|
|
232
|
+
fabric: this.context.fabric,
|
|
233
|
+
generator,
|
|
234
|
+
instance: this,
|
|
235
|
+
options: {
|
|
236
|
+
...this.options,
|
|
237
|
+
...options,
|
|
238
|
+
},
|
|
239
|
+
})
|
|
240
|
+
|
|
241
|
+
return []
|
|
242
|
+
}
|
|
243
|
+
|
|
229
244
|
const result = await generator.operation?.({
|
|
230
245
|
instance: this,
|
|
231
246
|
operation,
|
|
@@ -239,6 +254,20 @@ export class OperationGenerator<
|
|
|
239
254
|
const operationResults = await Promise.all(operationTasks)
|
|
240
255
|
const opResultsFlat = operationResults.flat()
|
|
241
256
|
|
|
257
|
+
if (generator.type === 'react') {
|
|
258
|
+
await buildOperations(
|
|
259
|
+
operations.map((op) => op.operation),
|
|
260
|
+
{
|
|
261
|
+
fabric: this.context.fabric,
|
|
262
|
+
generator,
|
|
263
|
+
instance: this,
|
|
264
|
+
options: this.options,
|
|
265
|
+
},
|
|
266
|
+
)
|
|
267
|
+
|
|
268
|
+
return []
|
|
269
|
+
}
|
|
270
|
+
|
|
242
271
|
const operationsResult = await generator.operations?.({
|
|
243
272
|
instance: this,
|
|
244
273
|
operations: operations.map((op) => op.operation),
|
package/src/SchemaGenerator.ts
CHANGED
|
@@ -1,13 +1,15 @@
|
|
|
1
1
|
import type { Plugin, PluginFactoryOptions, PluginManager, ResolveNameParams } from '@kubb/core'
|
|
2
2
|
import { BaseGenerator, type FileMetaBase } from '@kubb/core'
|
|
3
|
-
import type { KubbFile } from '@kubb/core/fs'
|
|
4
3
|
import transformers, { pascalCase } from '@kubb/core/transformers'
|
|
5
4
|
import { getUniqueName } from '@kubb/core/utils'
|
|
5
|
+
import type { KubbFile } from '@kubb/fabric-core/types'
|
|
6
6
|
import type { contentType, Oas, OpenAPIV3, SchemaObject } from '@kubb/oas'
|
|
7
7
|
import { isDiscriminator, isNullable, isReference } from '@kubb/oas'
|
|
8
|
+
import type { Fabric } from '@kubb/react-fabric'
|
|
8
9
|
import pLimit from 'p-limit'
|
|
9
10
|
import { isDeepEqual, isNumber, uniqueWith } from 'remeda'
|
|
10
|
-
import type { Generator } from './
|
|
11
|
+
import type { Generator } from './generators/types.ts'
|
|
12
|
+
import { buildSchema } from './generators/utils.tsx'
|
|
11
13
|
import type { Schema, SchemaKeywordMapper } from './SchemaMapper.ts'
|
|
12
14
|
import { isKeyword, schemaKeywords } from './SchemaMapper.ts'
|
|
13
15
|
import type { OperationSchema, Override, Refs } from './types.ts'
|
|
@@ -19,6 +21,7 @@ export type GetSchemaGeneratorOptions<T extends SchemaGenerator<any, any, any>>
|
|
|
19
21
|
export type SchemaMethodResult<TFileMeta extends FileMetaBase> = Promise<KubbFile.File<TFileMeta> | Array<KubbFile.File<TFileMeta>> | null>
|
|
20
22
|
|
|
21
23
|
type Context<TOptions, TPluginOptions extends PluginFactoryOptions> = {
|
|
24
|
+
fabric: Fabric
|
|
22
25
|
oas: Oas
|
|
23
26
|
pluginManager: PluginManager
|
|
24
27
|
/**
|
|
@@ -1116,6 +1119,27 @@ export class SchemaGenerator<
|
|
|
1116
1119
|
const options = this.#getOptions({ name })
|
|
1117
1120
|
const tree = this.parse({ name, schemaObject })
|
|
1118
1121
|
|
|
1122
|
+
if (generator.type === 'react') {
|
|
1123
|
+
await buildSchema(
|
|
1124
|
+
{
|
|
1125
|
+
name,
|
|
1126
|
+
value: schemaObject,
|
|
1127
|
+
tree,
|
|
1128
|
+
},
|
|
1129
|
+
{
|
|
1130
|
+
fabric: this.context.fabric,
|
|
1131
|
+
generator,
|
|
1132
|
+
instance: this,
|
|
1133
|
+
options: {
|
|
1134
|
+
...this.options,
|
|
1135
|
+
...options,
|
|
1136
|
+
},
|
|
1137
|
+
},
|
|
1138
|
+
)
|
|
1139
|
+
|
|
1140
|
+
return []
|
|
1141
|
+
}
|
|
1142
|
+
|
|
1119
1143
|
const result = await generator.schema?.({
|
|
1120
1144
|
instance: this,
|
|
1121
1145
|
schema: {
|
package/src/SchemaMapper.ts
CHANGED
package/src/components/Oas.tsx
CHANGED
|
@@ -1,15 +1,10 @@
|
|
|
1
|
-
import { createContext } from '@kubb/react'
|
|
2
|
-
|
|
1
|
+
import { createContext } from '@kubb/react-fabric'
|
|
2
|
+
import type { KubbNode } from '@kubb/react-fabric/types'
|
|
3
|
+
import type { OperationGenerator } from '../OperationGenerator.ts'
|
|
3
4
|
import { Operation } from './Operation.tsx'
|
|
4
5
|
import { Schema } from './Schema.tsx'
|
|
5
6
|
|
|
6
|
-
import type { Oas as OasType, Operation as OperationType } from '@kubb/oas'
|
|
7
|
-
import type { KubbNode } from '@kubb/react/types'
|
|
8
|
-
import type { OperationGenerator } from '../OperationGenerator.ts'
|
|
9
|
-
|
|
10
7
|
type Props = {
|
|
11
|
-
oas: OasType
|
|
12
|
-
operations?: OperationType[]
|
|
13
8
|
/**
|
|
14
9
|
* @deprecated
|
|
15
10
|
*/
|
|
@@ -18,8 +13,6 @@ type Props = {
|
|
|
18
13
|
}
|
|
19
14
|
|
|
20
15
|
type OasContextProps = {
|
|
21
|
-
oas?: OasType
|
|
22
|
-
operations?: OperationType[]
|
|
23
16
|
/**
|
|
24
17
|
* @deprecated
|
|
25
18
|
*/
|
|
@@ -28,8 +21,8 @@ type OasContextProps = {
|
|
|
28
21
|
|
|
29
22
|
const OasContext = createContext<OasContextProps>({})
|
|
30
23
|
|
|
31
|
-
export function Oas({
|
|
32
|
-
return <OasContext.Provider value={{
|
|
24
|
+
export function Oas({ children, generator }: Props): KubbNode {
|
|
25
|
+
return <OasContext.Provider value={{ generator }}>{children}</OasContext.Provider>
|
|
33
26
|
}
|
|
34
27
|
|
|
35
28
|
Oas.Context = OasContext
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { Operation as OperationType } from '@kubb/oas'
|
|
2
|
-
import { createContext } from '@kubb/react'
|
|
3
|
-
import type { KubbNode } from '@kubb/react/types'
|
|
2
|
+
import { createContext } from '@kubb/react-fabric'
|
|
3
|
+
import type { KubbNode } from '@kubb/react-fabric/types'
|
|
4
4
|
|
|
5
5
|
type Props = {
|
|
6
6
|
operation: OperationType
|
|
@@ -13,7 +13,7 @@ type OperationContextProps = {
|
|
|
13
13
|
|
|
14
14
|
const OperationContext = createContext<OperationContextProps>({})
|
|
15
15
|
|
|
16
|
-
export function Operation({ operation, children }: Props) {
|
|
16
|
+
export function Operation({ operation, children }: Props): KubbNode {
|
|
17
17
|
return <OperationContext.Provider value={{ operation }}>{children}</OperationContext.Provider>
|
|
18
18
|
}
|
|
19
19
|
|
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
import { createContext } from '@kubb/react'
|
|
2
|
-
|
|
3
1
|
import type { SchemaObject } from '@kubb/oas'
|
|
4
|
-
import
|
|
2
|
+
import { createContext } from '@kubb/react-fabric'
|
|
3
|
+
import type { Key, KubbNode } from '@kubb/react-fabric/types'
|
|
5
4
|
import type { Schema as SchemaType } from '../SchemaMapper.ts'
|
|
6
5
|
|
|
7
6
|
export type SchemaContextProps = {
|
|
@@ -32,7 +31,7 @@ const SchemaContext = createContext<SchemaContextProps>({
|
|
|
32
31
|
* @param schemaObject - The schema object to provide in context, if available.
|
|
33
32
|
* @param tree - An array representing the schema type hierarchy.
|
|
34
33
|
*/
|
|
35
|
-
export function Schema({ name, schemaObject, tree = [], children }: Props) {
|
|
34
|
+
export function Schema({ name, schemaObject, tree = [], children }: Props): KubbNode {
|
|
36
35
|
return <SchemaContext.Provider value={{ name, schemaObject, tree }}>{children}</SchemaContext.Provider>
|
|
37
36
|
}
|
|
38
37
|
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import type { PluginFactoryOptions } from '@kubb/core'
|
|
2
|
+
import type { KubbFile } from '@kubb/fabric-core/types'
|
|
3
|
+
import type { OperationProps, OperationsProps, SchemaProps } from './types.ts'
|
|
4
|
+
|
|
5
|
+
type UserGenerator<TOptions extends PluginFactoryOptions> = {
|
|
6
|
+
name: string
|
|
7
|
+
operations?: (props: OperationsProps<TOptions>) => Promise<KubbFile.File[]>
|
|
8
|
+
operation?: (props: OperationProps<TOptions>) => Promise<KubbFile.File[]>
|
|
9
|
+
schema?: (props: SchemaProps<TOptions>) => Promise<KubbFile.File[]>
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export type CoreGenerator<TOptions extends PluginFactoryOptions> = {
|
|
13
|
+
name: string
|
|
14
|
+
type: 'core'
|
|
15
|
+
operations: (props: OperationsProps<TOptions>) => Promise<KubbFile.File[]>
|
|
16
|
+
operation: (props: OperationProps<TOptions>) => Promise<KubbFile.File[]>
|
|
17
|
+
schema: (props: SchemaProps<TOptions>) => Promise<KubbFile.File[]>
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export function createGenerator<TOptions extends PluginFactoryOptions>(generator: UserGenerator<TOptions>): CoreGenerator<TOptions> {
|
|
21
|
+
return {
|
|
22
|
+
type: 'core',
|
|
23
|
+
async operations() {
|
|
24
|
+
return []
|
|
25
|
+
},
|
|
26
|
+
async operation() {
|
|
27
|
+
return []
|
|
28
|
+
},
|
|
29
|
+
async schema() {
|
|
30
|
+
return []
|
|
31
|
+
},
|
|
32
|
+
...generator,
|
|
33
|
+
}
|
|
34
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import type { PluginFactoryOptions } from '@kubb/core'
|
|
2
|
+
import type { KubbNode } from '@kubb/react-fabric/types'
|
|
3
|
+
import type { OperationProps, OperationsProps, SchemaProps } from './types.ts'
|
|
4
|
+
|
|
5
|
+
type UserGenerator<TOptions extends PluginFactoryOptions> = {
|
|
6
|
+
name: string
|
|
7
|
+
Operations?: (props: OperationsProps<TOptions>) => KubbNode
|
|
8
|
+
Operation?: (props: OperationProps<TOptions>) => KubbNode
|
|
9
|
+
Schema?: (props: SchemaProps<TOptions>) => KubbNode
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export type ReactGenerator<TOptions extends PluginFactoryOptions> = {
|
|
13
|
+
name: string
|
|
14
|
+
type: 'react'
|
|
15
|
+
Operations: (props: OperationsProps<TOptions>) => KubbNode
|
|
16
|
+
Operation: (props: OperationProps<TOptions>) => KubbNode
|
|
17
|
+
Schema: (props: SchemaProps<TOptions>) => KubbNode
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/****
|
|
21
|
+
* Creates a generator that uses React component functions to generate files for OpenAPI operations and schemas.
|
|
22
|
+
*
|
|
23
|
+
* The returned generator exposes async methods for generating files from operations, a single operation, or a schema, using the corresponding React components if provided. If a component is not defined, the method returns an empty array.
|
|
24
|
+
*
|
|
25
|
+
* @returns A generator object with async methods for operations, operation, and schema file generation.
|
|
26
|
+
*/
|
|
27
|
+
export function createReactGenerator<TOptions extends PluginFactoryOptions>(generator: UserGenerator<TOptions>): ReactGenerator<TOptions> {
|
|
28
|
+
return {
|
|
29
|
+
type: 'react',
|
|
30
|
+
Operations() {
|
|
31
|
+
return null
|
|
32
|
+
},
|
|
33
|
+
Operation() {
|
|
34
|
+
return null
|
|
35
|
+
},
|
|
36
|
+
Schema() {
|
|
37
|
+
return null
|
|
38
|
+
},
|
|
39
|
+
...generator,
|
|
40
|
+
}
|
|
41
|
+
}
|
package/src/generators/index.ts
CHANGED
|
@@ -1 +1,5 @@
|
|
|
1
|
+
export { createGenerator } from './createGenerator.ts'
|
|
2
|
+
export { createReactGenerator } from './createReactGenerator.ts'
|
|
1
3
|
export { jsonGenerator } from './jsonGenerator.ts'
|
|
4
|
+
export type { Generator } from './types.ts'
|
|
5
|
+
export { buildOperation, buildOperations, buildSchema } from './utils.tsx'
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { camelCase } from '@kubb/core/transformers'
|
|
2
|
-
import { createGenerator } from '../generator.tsx'
|
|
3
2
|
import type { PluginOas } from '../types.ts'
|
|
4
3
|
import { getBanner } from '../utils/getBanner.ts'
|
|
5
4
|
import { getFooter } from '../utils/getFooter.ts'
|
|
5
|
+
import { createGenerator } from './createGenerator.ts'
|
|
6
6
|
|
|
7
7
|
export const jsonGenerator = createGenerator<PluginOas>({
|
|
8
8
|
name: 'plugin-oas',
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import type { PluginFactoryOptions } from '@kubb/core'
|
|
2
|
+
import type { Operation, SchemaObject } from '@kubb/oas'
|
|
3
|
+
import type { OperationGenerator, Schema, SchemaGenerator, SchemaGeneratorOptions } from '@kubb/plugin-oas'
|
|
4
|
+
import type { CoreGenerator } from './createGenerator.ts'
|
|
5
|
+
import type { ReactGenerator } from './createReactGenerator.ts'
|
|
6
|
+
|
|
7
|
+
export type OperationsProps<TOptions extends PluginFactoryOptions> = {
|
|
8
|
+
/**
|
|
9
|
+
* @deprecated
|
|
10
|
+
*/
|
|
11
|
+
instance: Omit<OperationGenerator<TOptions>, 'build'>
|
|
12
|
+
options: TOptions['resolvedOptions']
|
|
13
|
+
operations: Array<Operation>
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export type OperationProps<TOptions extends PluginFactoryOptions> = {
|
|
17
|
+
/**
|
|
18
|
+
* @deprecated
|
|
19
|
+
*/
|
|
20
|
+
instance: Omit<OperationGenerator<TOptions>, 'build'>
|
|
21
|
+
options: TOptions['resolvedOptions']
|
|
22
|
+
operation: Operation
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export type SchemaProps<TOptions extends PluginFactoryOptions> = {
|
|
26
|
+
instance: Omit<SchemaGenerator<SchemaGeneratorOptions, TOptions>, 'build'>
|
|
27
|
+
options: TOptions['resolvedOptions']
|
|
28
|
+
schema: {
|
|
29
|
+
name: string
|
|
30
|
+
tree: Array<Schema>
|
|
31
|
+
value: SchemaObject
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export type Generator<TOptions extends PluginFactoryOptions> = CoreGenerator<TOptions> | ReactGenerator<TOptions>
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
import type { PluginFactoryOptions } from '@kubb/core'
|
|
2
|
+
import type { Operation, SchemaObject } from '@kubb/oas'
|
|
3
|
+
import { App, createReactFabric, type Fabric } from '@kubb/react-fabric'
|
|
4
|
+
import { Oas } from '../components/Oas.tsx'
|
|
5
|
+
import type { OperationGenerator } from '../OperationGenerator.ts'
|
|
6
|
+
import type { SchemaGenerator, SchemaGeneratorOptions } from '../SchemaGenerator.ts'
|
|
7
|
+
import type { Schema } from '../SchemaMapper.ts'
|
|
8
|
+
import type { ReactGenerator } from './/createReactGenerator.ts'
|
|
9
|
+
|
|
10
|
+
type BuildOperationsOptions<TOptions extends PluginFactoryOptions> = {
|
|
11
|
+
fabric: Fabric
|
|
12
|
+
generator: ReactGenerator<any>
|
|
13
|
+
/**
|
|
14
|
+
* @deprecated
|
|
15
|
+
*/
|
|
16
|
+
instance: Omit<OperationGenerator<TOptions>, 'build'>
|
|
17
|
+
options: TOptions['resolvedOptions']
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export async function buildOperations<TOptions extends PluginFactoryOptions>(
|
|
21
|
+
operations: Array<Operation>,
|
|
22
|
+
{ fabric, options, instance, generator }: BuildOperationsOptions<TOptions>,
|
|
23
|
+
): Promise<void> {
|
|
24
|
+
if (!generator.Operations) {
|
|
25
|
+
return undefined
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
const { pluginManager, oas, plugin, mode } = instance.context
|
|
29
|
+
|
|
30
|
+
function Component() {
|
|
31
|
+
return (
|
|
32
|
+
<App meta={{ pluginManager, plugin, mode, oas }}>
|
|
33
|
+
<Oas generator={instance}>
|
|
34
|
+
<generator.Operations operations={operations} instance={instance} options={options} />
|
|
35
|
+
</Oas>
|
|
36
|
+
</App>
|
|
37
|
+
)
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
const fabricChild = createReactFabric()
|
|
41
|
+
fabricChild.render(Component)
|
|
42
|
+
|
|
43
|
+
await fabric.context.fileManager.add(...fabricChild.files)
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
type BuildOperationOptions<TOptions extends PluginFactoryOptions> = BuildOperationsOptions<TOptions>
|
|
47
|
+
|
|
48
|
+
export async function buildOperation<TOptions extends PluginFactoryOptions>(
|
|
49
|
+
operation: Operation,
|
|
50
|
+
{ fabric, options, instance, generator }: BuildOperationOptions<TOptions>,
|
|
51
|
+
): Promise<void> {
|
|
52
|
+
if (!generator.Operation) {
|
|
53
|
+
return undefined
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
const { pluginManager, oas, plugin, mode } = instance.context
|
|
57
|
+
|
|
58
|
+
function Component() {
|
|
59
|
+
return (
|
|
60
|
+
<App meta={{ pluginManager, plugin: { ...plugin, options }, mode, oas }}>
|
|
61
|
+
<Oas generator={instance}>
|
|
62
|
+
<Oas.Operation operation={operation}>
|
|
63
|
+
<generator.Operation operation={operation} options={options} instance={instance} />
|
|
64
|
+
</Oas.Operation>
|
|
65
|
+
</Oas>
|
|
66
|
+
</App>
|
|
67
|
+
)
|
|
68
|
+
}
|
|
69
|
+
const fabricChild = createReactFabric()
|
|
70
|
+
fabricChild.render(Component)
|
|
71
|
+
|
|
72
|
+
await fabric.context.fileManager.add(...fabricChild.files)
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
type BuildSchemaOptions<TOptions extends PluginFactoryOptions> = {
|
|
76
|
+
fabric: Fabric
|
|
77
|
+
generator: ReactGenerator<any>
|
|
78
|
+
/**
|
|
79
|
+
* @deprecated
|
|
80
|
+
*/
|
|
81
|
+
instance: Omit<SchemaGenerator<SchemaGeneratorOptions, TOptions>, 'build'>
|
|
82
|
+
options: TOptions['resolvedOptions']
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
export async function buildSchema<TOptions extends PluginFactoryOptions>(
|
|
86
|
+
schema: {
|
|
87
|
+
name: string
|
|
88
|
+
tree: Array<Schema>
|
|
89
|
+
value: SchemaObject
|
|
90
|
+
},
|
|
91
|
+
{ fabric, options, instance, generator }: BuildSchemaOptions<TOptions>,
|
|
92
|
+
): Promise<void> {
|
|
93
|
+
if (!generator.Schema) {
|
|
94
|
+
return undefined
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
const { pluginManager, oas, plugin, mode } = instance.context
|
|
98
|
+
|
|
99
|
+
function Component() {
|
|
100
|
+
return (
|
|
101
|
+
<App meta={{ pluginManager, plugin: { ...plugin, options }, mode, oas }}>
|
|
102
|
+
<Oas>
|
|
103
|
+
<Oas.Schema name={schema.name} schemaObject={schema.value} tree={schema.tree}>
|
|
104
|
+
<generator.Schema schema={schema} options={options} instance={instance} />
|
|
105
|
+
</Oas.Schema>
|
|
106
|
+
</Oas>
|
|
107
|
+
</App>
|
|
108
|
+
)
|
|
109
|
+
}
|
|
110
|
+
const fabricChild = createReactFabric()
|
|
111
|
+
fabricChild.render(Component)
|
|
112
|
+
|
|
113
|
+
await fabric.context.fileManager.add(...fabricChild.files)
|
|
114
|
+
}
|
package/src/hooks/index.ts
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
export { useOas } from './useOas.ts'
|
|
2
2
|
export { useOperation } from './useOperation.ts'
|
|
3
|
-
export { useOperationManager } from './useOperationManager.ts'
|
|
4
3
|
export type { SchemaNames } from './useOperationManager.ts'
|
|
5
|
-
export {
|
|
4
|
+
export { useOperationManager } from './useOperationManager.ts'
|
|
6
5
|
export { useSchema } from './useSchema.ts'
|
|
7
6
|
export { useSchemaManager } from './useSchemaManager.ts'
|