@kubb/plugin-mcp 4.4.1 → 4.5.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/{SchemaGenerator-geilI4rJ.d.ts → OperationGenerator-Beq8iOZY.d.cts} +169 -175
- package/dist/components.d.cts +1 -1
- package/dist/components.d.ts +1 -1
- package/dist/{generators-8HowWmDg.cjs → generators-CSDgJv8G.cjs} +50 -23
- package/dist/generators-CSDgJv8G.cjs.map +1 -0
- package/dist/{generators-Bp0d1HbP.js → generators-DP6UAisL.js} +45 -19
- package/dist/generators-DP6UAisL.js.map +1 -0
- package/dist/generators.cjs +1 -1
- package/dist/generators.d.cts +2 -2
- package/dist/generators.d.ts +2 -2
- package/dist/generators.js +1 -1
- package/dist/{SchemaGenerator-Bu2D8QtI.d.cts → index-BlpJVG8h.d.ts} +169 -175
- package/dist/index.cjs +15 -2
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +14 -2
- package/dist/index.js.map +1 -1
- package/dist/{types-DXH0aZQO.d.ts → types-B4xu5uHh.d.cts} +9 -10
- package/dist/{types-BPcoHHAu.d.cts → types-Cy3TnfH5.d.ts} +9 -10
- package/package.json +9 -9
- package/src/generators/mcpGenerator.tsx +27 -8
- package/src/generators/serverGenerator.tsx +5 -5
- package/src/plugin.ts +25 -1
- package/src/types.ts +4 -3
- package/dist/generators-8HowWmDg.cjs.map +0 -1
- package/dist/generators-Bp0d1HbP.js.map +0 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"generators-DP6UAisL.js","names":[],"sources":["../src/generators/mcpGenerator.tsx","../src/generators/serverGenerator.tsx"],"sourcesContent":["import path from 'node:path'\nimport { Client } from '@kubb/plugin-client/components'\nimport { createReactGenerator } from '@kubb/plugin-oas/generators'\nimport { useOas, useOperationManager } from '@kubb/plugin-oas/hooks'\nimport { getBanner, getFooter } from '@kubb/plugin-oas/utils'\nimport { pluginTsName } from '@kubb/plugin-ts'\nimport { File } from '@kubb/react-fabric'\nimport type { PluginMcp } from '../types'\n\nexport const mcpGenerator = createReactGenerator<PluginMcp>({\n name: 'mcp',\n Operation({ config, operation, generator, plugin }) {\n const { options } = plugin\n const oas = useOas()\n\n const { getSchemas, getName, getFile } = useOperationManager(generator)\n\n const mcp = {\n name: getName(operation, { type: 'function', suffix: 'handler' }),\n file: getFile(operation),\n }\n\n const type = {\n file: getFile(operation, { pluginKey: [pluginTsName] }),\n schemas: getSchemas(operation, { pluginKey: [pluginTsName], type: 'type' }),\n }\n\n return (\n <File\n baseName={mcp.file.baseName}\n path={mcp.file.path}\n meta={mcp.file.meta}\n banner={getBanner({ oas, output: options.output })}\n footer={getFooter({ oas, output: options.output })}\n >\n {options.client.importPath ? (\n <>\n <File.Import name={'fetch'} path={options.client.importPath} />\n <File.Import name={['RequestConfig', 'ResponseErrorConfig']} path={options.client.importPath} isTypeOnly />\n {options.client.dataReturnType === 'full' && <File.Import name={['ResponseConfig']} path={options.client.importPath} isTypeOnly />}\n </>\n ) : (\n <>\n <File.Import name={'fetch'} root={mcp.file.path} path={path.resolve(config.root, config.output.path, '.kubb/fetcher.ts')} />\n <File.Import\n name={['RequestConfig', 'ResponseErrorConfig']}\n root={mcp.file.path}\n path={path.resolve(config.root, config.output.path, '.kubb/fetcher.ts')}\n isTypeOnly\n />\n {options.client.dataReturnType === 'full' && (\n <File.Import name={['ResponseConfig']} root={mcp.file.path} path={path.resolve(config.root, config.output.path, '.kubb/fetcher.ts')} isTypeOnly />\n )}\n </>\n )}\n <File.Import name={['CallToolResult']} path={'@modelcontextprotocol/sdk/types'} isTypeOnly />\n <File.Import\n name={[\n type.schemas.request?.name,\n type.schemas.response.name,\n type.schemas.pathParams?.name,\n type.schemas.queryParams?.name,\n type.schemas.headerParams?.name,\n ...(type.schemas.statusCodes?.map((item) => item.name) || []),\n ].filter(Boolean)}\n root={mcp.file.path}\n path={type.file.path}\n isTypeOnly\n />\n\n <Client\n name={mcp.name}\n isConfigurable={false}\n returnType={'Promise<CallToolResult>'}\n baseURL={options.client.baseURL}\n operation={operation}\n typeSchemas={type.schemas}\n zodSchemas={undefined}\n dataReturnType={options.client.dataReturnType || 'data'}\n paramsType={'object'}\n paramsCasing={'camelcase'}\n pathParamsType={'object'}\n parser={'client'}\n >\n {options.client.dataReturnType === 'data' &&\n `return {\n content: [\n {\n type: 'text',\n text: JSON.stringify(res.data)\n }\n ]\n }`}\n {options.client.dataReturnType === 'full' &&\n `return {\n content: [\n {\n type: 'text',\n text: JSON.stringify(res)\n }\n ]\n }`}\n </Client>\n </File>\n )\n },\n})\n","import { usePluginManager } from '@kubb/core/hooks'\nimport { createReactGenerator } from '@kubb/plugin-oas/generators'\nimport { useOas, useOperationManager } from '@kubb/plugin-oas/hooks'\nimport { getBanner, getFooter } from '@kubb/plugin-oas/utils'\nimport { pluginTsName } from '@kubb/plugin-ts'\nimport { pluginZodName } from '@kubb/plugin-zod'\nimport { File } from '@kubb/react-fabric'\nimport { Server } from '../components/Server'\nimport type { PluginMcp } from '../types'\n\nexport const serverGenerator = createReactGenerator<PluginMcp>({\n name: 'operations',\n Operations({ operations, generator, plugin }) {\n const pluginManager = usePluginManager()\n const { options } = plugin\n\n const oas = useOas()\n const { getFile, getName, getSchemas } = useOperationManager(generator)\n\n const name = 'server'\n const file = pluginManager.getFile({ name, extname: '.ts', pluginKey: plugin.key })\n\n const jsonFile = pluginManager.getFile({ name: '.mcp', extname: '.json', pluginKey: plugin.key })\n\n const operationsMapped = operations.map((operation) => {\n return {\n tool: {\n name: operation.getOperationId() || operation.getSummary() || `${operation.method.toUpperCase()} ${operation.path}`,\n description: operation.getDescription() || `Make a ${operation.method.toUpperCase()} request to ${operation.path}`,\n },\n mcp: {\n name: getName(operation, {\n type: 'function',\n suffix: 'handler',\n }),\n file: getFile(operation),\n },\n zod: {\n name: getName(operation, {\n type: 'function',\n pluginKey: [pluginZodName],\n }),\n schemas: getSchemas(operation, { pluginKey: [pluginZodName], type: 'function' }),\n file: getFile(operation, { pluginKey: [pluginZodName] }),\n },\n type: {\n schemas: getSchemas(operation, { pluginKey: [pluginTsName], type: 'type' }),\n },\n }\n })\n\n const imports = operationsMapped.flatMap(({ mcp, zod }) => {\n return [\n <File.Import key={mcp.name} name={[mcp.name]} root={file.path} path={mcp.file.path} />,\n <File.Import\n key={zod.name}\n name={[zod.schemas.request?.name, zod.schemas.pathParams?.name, zod.schemas.queryParams?.name, zod.schemas.headerParams?.name].filter(Boolean)}\n root={file.path}\n path={zod.file.path}\n />,\n ]\n })\n\n return (\n <>\n <File\n baseName={file.baseName}\n path={file.path}\n meta={file.meta}\n banner={getBanner({ oas, output: options.output, config: pluginManager.config })}\n footer={getFooter({ oas, output: options.output })}\n >\n <File.Import name={['McpServer']} path={'@modelcontextprotocol/sdk/server/mcp'} />\n <File.Import name={['StdioServerTransport']} path={'@modelcontextprotocol/sdk/server/stdio'} />\n\n {imports}\n <Server name={name} serverName={oas.api.info?.title} serverVersion={oas.getVersion()} operations={operationsMapped} />\n </File>\n\n <File baseName={jsonFile.baseName} path={jsonFile.path} meta={jsonFile.meta}>\n <File.Source name={name}>\n {`\n {\n \"mcpServers\": {\n \"${oas.api.info?.title || 'server'}\": {\n \"type\": \"stdio\",\n \"command\": \"npx\",\n \"args\": [\"tsx\", \"${file.path}\"]\n }\n }\n }\n `}\n </File.Source>\n </File>\n </>\n )\n },\n})\n"],"mappings":";;;;;;;;;;;;;AASA,MAAa,eAAe,qBAAgC;CAC1D,MAAM;CACN,UAAU,EAAE,QAAQ,WAAW,WAAW,UAAU;EAClD,MAAM,EAAE,YAAY;EACpB,MAAM,MAAM,QAAQ;EAEpB,MAAM,EAAE,YAAY,SAAS,YAAY,oBAAoB,UAAU;EAEvE,MAAM,MAAM;GACV,MAAM,QAAQ,WAAW;IAAE,MAAM;IAAY,QAAQ;IAAW,CAAC;GACjE,MAAM,QAAQ,UAAU;GACzB;EAED,MAAM,OAAO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;MAAoB;;IACjH,EAEP,oBAAC;GAAK,UAAU,SAAS;GAAU,MAAM,SAAS;GAAM,MAAM,SAAS;aACrE,oBAAC,KAAK;IAAa;cAChB;;;iBAGI,IAAI,IAAI,MAAM,SAAS,SAAS;;;mCAGd,KAAK,KAAK;;;;;KAKrB;IACT,IACN;;CAGR,CAAC"}
|
package/dist/generators.cjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
require('./Server-vKCXRjmg.cjs');
|
|
2
|
-
const require_generators = require('./generators-
|
|
2
|
+
const require_generators = require('./generators-CSDgJv8G.cjs');
|
|
3
3
|
|
|
4
4
|
exports.mcpGenerator = require_generators.mcpGenerator;
|
|
5
5
|
exports.serverGenerator = require_generators.serverGenerator;
|
package/dist/generators.d.cts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { n as PluginMcp } from "./types-
|
|
1
|
+
import { n as ReactGenerator } from "./OperationGenerator-Beq8iOZY.cjs";
|
|
2
|
+
import { n as PluginMcp } from "./types-B4xu5uHh.cjs";
|
|
3
3
|
|
|
4
4
|
//#region src/generators/mcpGenerator.d.ts
|
|
5
5
|
declare const mcpGenerator: ReactGenerator<PluginMcp>;
|
package/dist/generators.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { n as PluginMcp } from "./types-
|
|
1
|
+
import { n as ReactGenerator } from "./index-BlpJVG8h.js";
|
|
2
|
+
import { n as PluginMcp } from "./types-Cy3TnfH5.js";
|
|
3
3
|
|
|
4
4
|
//#region src/generators/mcpGenerator.d.ts
|
|
5
5
|
declare const mcpGenerator: ReactGenerator<PluginMcp>;
|
package/dist/generators.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { KubbFile } from "@kubb/fabric-core/types";
|
|
2
1
|
import { Fabric, FileManager } from "@kubb/react-fabric";
|
|
2
|
+
import { KubbFile } from "@kubb/fabric-core/types";
|
|
3
3
|
import { ConsolaInstance, LogLevel } from "consola";
|
|
4
4
|
import * as OasTypes from "oas/types";
|
|
5
5
|
import { HttpMethods as HttpMethod, OASDocument, SchemaObject, User } from "oas/types";
|
|
@@ -556,170 +556,6 @@ declare class Oas<const TOAS = unknown> extends BaseOas {
|
|
|
556
556
|
valdiate(): Promise<oas_normalize_lib_types0.ValidationResult>;
|
|
557
557
|
}
|
|
558
558
|
//#endregion
|
|
559
|
-
//#region ../plugin-oas/src/generators/createReactGenerator.d.ts
|
|
560
|
-
type ReactGenerator<TOptions extends PluginFactoryOptions> = {
|
|
561
|
-
name: string;
|
|
562
|
-
type: 'react';
|
|
563
|
-
Operations: (props: OperationsProps<TOptions>) => KubbNode;
|
|
564
|
-
Operation: (props: OperationProps<TOptions>) => KubbNode;
|
|
565
|
-
Schema: (props: SchemaProps$1<TOptions>) => KubbNode;
|
|
566
|
-
};
|
|
567
|
-
//#endregion
|
|
568
|
-
//#region ../plugin-oas/src/generators/types.d.ts
|
|
569
|
-
type OperationsProps<TOptions extends PluginFactoryOptions> = {
|
|
570
|
-
/**
|
|
571
|
-
* @deprecated
|
|
572
|
-
*/
|
|
573
|
-
instance: Omit<OperationGenerator<TOptions>, 'build'>;
|
|
574
|
-
options: TOptions['resolvedOptions'];
|
|
575
|
-
operations: Array<Operation$1>;
|
|
576
|
-
};
|
|
577
|
-
type OperationProps<TOptions extends PluginFactoryOptions> = {
|
|
578
|
-
/**
|
|
579
|
-
* @deprecated
|
|
580
|
-
*/
|
|
581
|
-
instance: Omit<OperationGenerator<TOptions>, 'build'>;
|
|
582
|
-
options: TOptions['resolvedOptions'];
|
|
583
|
-
operation: Operation$1;
|
|
584
|
-
};
|
|
585
|
-
type SchemaProps$1<TOptions extends PluginFactoryOptions> = {
|
|
586
|
-
instance: Omit<SchemaGenerator<SchemaGeneratorOptions, TOptions>, 'build'>;
|
|
587
|
-
options: TOptions['resolvedOptions'];
|
|
588
|
-
schema: {
|
|
589
|
-
name: string;
|
|
590
|
-
tree: Array<Schema>;
|
|
591
|
-
value: SchemaObject$1;
|
|
592
|
-
};
|
|
593
|
-
};
|
|
594
|
-
type Generator<TOptions extends PluginFactoryOptions> = CoreGenerator<TOptions> | ReactGenerator<TOptions>;
|
|
595
|
-
//#endregion
|
|
596
|
-
//#region ../plugin-oas/src/generators/createGenerator.d.ts
|
|
597
|
-
type CoreGenerator<TOptions extends PluginFactoryOptions> = {
|
|
598
|
-
name: string;
|
|
599
|
-
type: 'core';
|
|
600
|
-
operations: (props: OperationsProps<TOptions>) => Promise<KubbFile.File[]>;
|
|
601
|
-
operation: (props: OperationProps<TOptions>) => Promise<KubbFile.File[]>;
|
|
602
|
-
schema: (props: SchemaProps$1<TOptions>) => Promise<KubbFile.File[]>;
|
|
603
|
-
};
|
|
604
|
-
//#endregion
|
|
605
|
-
//#region ../plugin-oas/src/types.d.ts
|
|
606
|
-
type ResolvePathOptions = {
|
|
607
|
-
pluginKey?: Plugin['key'];
|
|
608
|
-
group?: {
|
|
609
|
-
tag?: string;
|
|
610
|
-
path?: string;
|
|
611
|
-
};
|
|
612
|
-
type?: ResolveNameParams['type'];
|
|
613
|
-
};
|
|
614
|
-
/**
|
|
615
|
-
* `propertyName` is the ref name + resolved with the nameResolver
|
|
616
|
-
* @example import { Pet } from './Pet'
|
|
617
|
-
*
|
|
618
|
-
* `originalName` is the original name used(in PascalCase), only used to remove duplicates
|
|
619
|
-
*
|
|
620
|
-
* `pluginKey` can be used to override the current plugin being used, handy when you want to import a type/schema out of another plugin
|
|
621
|
-
* @example import a type(plugin-ts) for a mock file(swagger-faker)
|
|
622
|
-
*/
|
|
623
|
-
type Ref = {
|
|
624
|
-
propertyName: string;
|
|
625
|
-
originalName: string;
|
|
626
|
-
path: KubbFile.OptionalPath;
|
|
627
|
-
pluginKey?: Plugin['key'];
|
|
628
|
-
};
|
|
629
|
-
type Refs = Record<string, Ref>;
|
|
630
|
-
type OperationSchema = {
|
|
631
|
-
/**
|
|
632
|
-
* Converted name, contains already `PathParams`, `QueryParams`, ...
|
|
633
|
-
*/
|
|
634
|
-
name: string;
|
|
635
|
-
schema: SchemaObject$1;
|
|
636
|
-
operation?: Operation$1;
|
|
637
|
-
/**
|
|
638
|
-
* OperationName in PascalCase, only being used in OperationGenerator
|
|
639
|
-
*/
|
|
640
|
-
operationName: string;
|
|
641
|
-
description?: string;
|
|
642
|
-
statusCode?: number;
|
|
643
|
-
keys?: string[];
|
|
644
|
-
keysToOmit?: string[];
|
|
645
|
-
withData?: boolean;
|
|
646
|
-
};
|
|
647
|
-
type OperationSchemas = {
|
|
648
|
-
pathParams?: OperationSchema & {
|
|
649
|
-
keysToOmit?: never;
|
|
650
|
-
};
|
|
651
|
-
queryParams?: OperationSchema & {
|
|
652
|
-
keysToOmit?: never;
|
|
653
|
-
};
|
|
654
|
-
headerParams?: OperationSchema & {
|
|
655
|
-
keysToOmit?: never;
|
|
656
|
-
};
|
|
657
|
-
request?: OperationSchema;
|
|
658
|
-
response: OperationSchema;
|
|
659
|
-
responses: Array<OperationSchema>;
|
|
660
|
-
statusCodes?: Array<OperationSchema>;
|
|
661
|
-
errors?: Array<OperationSchema>;
|
|
662
|
-
};
|
|
663
|
-
type ByTag = {
|
|
664
|
-
type: 'tag';
|
|
665
|
-
pattern: string | RegExp;
|
|
666
|
-
};
|
|
667
|
-
type ByOperationId = {
|
|
668
|
-
type: 'operationId';
|
|
669
|
-
pattern: string | RegExp;
|
|
670
|
-
};
|
|
671
|
-
type ByPath = {
|
|
672
|
-
type: 'path';
|
|
673
|
-
pattern: string | RegExp;
|
|
674
|
-
};
|
|
675
|
-
type ByMethod = {
|
|
676
|
-
type: 'method';
|
|
677
|
-
pattern: HttpMethod | RegExp;
|
|
678
|
-
};
|
|
679
|
-
type BySchemaName = {
|
|
680
|
-
type: 'schemaName';
|
|
681
|
-
pattern: string | RegExp;
|
|
682
|
-
};
|
|
683
|
-
type ByContentType = {
|
|
684
|
-
type: 'contentType';
|
|
685
|
-
pattern: string | RegExp;
|
|
686
|
-
};
|
|
687
|
-
type Exclude$1 = ByTag | ByOperationId | ByPath | ByMethod | ByContentType;
|
|
688
|
-
type Include = ByTag | ByOperationId | ByPath | ByMethod | ByContentType;
|
|
689
|
-
type Override<TOptions> = (ByTag | ByOperationId | ByPath | ByMethod | BySchemaName | ByContentType) & {
|
|
690
|
-
options: Partial<TOptions>;
|
|
691
|
-
};
|
|
692
|
-
//#endregion
|
|
693
|
-
//#region ../plugin-oas/src/OperationGenerator.d.ts
|
|
694
|
-
type Context$1<TOptions, TPluginOptions extends PluginFactoryOptions> = {
|
|
695
|
-
fabric: Fabric;
|
|
696
|
-
oas: Oas;
|
|
697
|
-
exclude: Array<Exclude$1> | undefined;
|
|
698
|
-
include: Array<Include> | undefined;
|
|
699
|
-
override: Array<Override<TOptions>> | undefined;
|
|
700
|
-
contentType: contentType | undefined;
|
|
701
|
-
pluginManager: PluginManager;
|
|
702
|
-
/**
|
|
703
|
-
* Current plugin
|
|
704
|
-
*/
|
|
705
|
-
plugin: Plugin<TPluginOptions>;
|
|
706
|
-
mode: KubbFile.Mode;
|
|
707
|
-
};
|
|
708
|
-
declare class OperationGenerator<TPluginOptions extends PluginFactoryOptions = PluginFactoryOptions, TFileMeta extends FileMetaBase = FileMetaBase> extends BaseGenerator<TPluginOptions['resolvedOptions'], Context$1<TPluginOptions['resolvedOptions'], TPluginOptions>> {
|
|
709
|
-
#private;
|
|
710
|
-
getSchemas(operation: Operation$1, {
|
|
711
|
-
resolveName
|
|
712
|
-
}?: {
|
|
713
|
-
resolveName?: (name: string) => string;
|
|
714
|
-
}): OperationSchemas;
|
|
715
|
-
getOperations(): Promise<Array<{
|
|
716
|
-
path: string;
|
|
717
|
-
method: HttpMethod;
|
|
718
|
-
operation: Operation$1;
|
|
719
|
-
}>>;
|
|
720
|
-
build(...generators: Array<Generator<TPluginOptions>>): Promise<Array<KubbFile.File<TFileMeta>>>;
|
|
721
|
-
}
|
|
722
|
-
//#endregion
|
|
723
559
|
//#region ../plugin-oas/src/SchemaMapper.d.ts
|
|
724
560
|
type SchemaKeywordMapper = {
|
|
725
561
|
object: {
|
|
@@ -937,8 +773,96 @@ type Schema = {
|
|
|
937
773
|
keyword: string;
|
|
938
774
|
} | SchemaKeywordMapper[keyof SchemaKeywordMapper];
|
|
939
775
|
//#endregion
|
|
776
|
+
//#region ../plugin-oas/src/types.d.ts
|
|
777
|
+
type ResolvePathOptions = {
|
|
778
|
+
pluginKey?: Plugin['key'];
|
|
779
|
+
group?: {
|
|
780
|
+
tag?: string;
|
|
781
|
+
path?: string;
|
|
782
|
+
};
|
|
783
|
+
type?: ResolveNameParams['type'];
|
|
784
|
+
};
|
|
785
|
+
/**
|
|
786
|
+
* `propertyName` is the ref name + resolved with the nameResolver
|
|
787
|
+
* @example import { Pet } from './Pet'
|
|
788
|
+
*
|
|
789
|
+
* `originalName` is the original name used(in PascalCase), only used to remove duplicates
|
|
790
|
+
*
|
|
791
|
+
* `pluginKey` can be used to override the current plugin being used, handy when you want to import a type/schema out of another plugin
|
|
792
|
+
* @example import a type(plugin-ts) for a mock file(swagger-faker)
|
|
793
|
+
*/
|
|
794
|
+
type Ref = {
|
|
795
|
+
propertyName: string;
|
|
796
|
+
originalName: string;
|
|
797
|
+
path: KubbFile.OptionalPath;
|
|
798
|
+
pluginKey?: Plugin['key'];
|
|
799
|
+
};
|
|
800
|
+
type Refs = Record<string, Ref>;
|
|
801
|
+
type OperationSchema = {
|
|
802
|
+
/**
|
|
803
|
+
* Converted name, contains already `PathParams`, `QueryParams`, ...
|
|
804
|
+
*/
|
|
805
|
+
name: string;
|
|
806
|
+
schema: SchemaObject$1;
|
|
807
|
+
operation?: Operation$1;
|
|
808
|
+
/**
|
|
809
|
+
* OperationName in PascalCase, only being used in OperationGenerator
|
|
810
|
+
*/
|
|
811
|
+
operationName: string;
|
|
812
|
+
description?: string;
|
|
813
|
+
statusCode?: number;
|
|
814
|
+
keys?: string[];
|
|
815
|
+
keysToOmit?: string[];
|
|
816
|
+
withData?: boolean;
|
|
817
|
+
};
|
|
818
|
+
type OperationSchemas = {
|
|
819
|
+
pathParams?: OperationSchema & {
|
|
820
|
+
keysToOmit?: never;
|
|
821
|
+
};
|
|
822
|
+
queryParams?: OperationSchema & {
|
|
823
|
+
keysToOmit?: never;
|
|
824
|
+
};
|
|
825
|
+
headerParams?: OperationSchema & {
|
|
826
|
+
keysToOmit?: never;
|
|
827
|
+
};
|
|
828
|
+
request?: OperationSchema;
|
|
829
|
+
response: OperationSchema;
|
|
830
|
+
responses: Array<OperationSchema>;
|
|
831
|
+
statusCodes?: Array<OperationSchema>;
|
|
832
|
+
errors?: Array<OperationSchema>;
|
|
833
|
+
};
|
|
834
|
+
type ByTag = {
|
|
835
|
+
type: 'tag';
|
|
836
|
+
pattern: string | RegExp;
|
|
837
|
+
};
|
|
838
|
+
type ByOperationId = {
|
|
839
|
+
type: 'operationId';
|
|
840
|
+
pattern: string | RegExp;
|
|
841
|
+
};
|
|
842
|
+
type ByPath = {
|
|
843
|
+
type: 'path';
|
|
844
|
+
pattern: string | RegExp;
|
|
845
|
+
};
|
|
846
|
+
type ByMethod = {
|
|
847
|
+
type: 'method';
|
|
848
|
+
pattern: HttpMethod | RegExp;
|
|
849
|
+
};
|
|
850
|
+
type BySchemaName = {
|
|
851
|
+
type: 'schemaName';
|
|
852
|
+
pattern: string | RegExp;
|
|
853
|
+
};
|
|
854
|
+
type ByContentType = {
|
|
855
|
+
type: 'contentType';
|
|
856
|
+
pattern: string | RegExp;
|
|
857
|
+
};
|
|
858
|
+
type Exclude$1 = ByTag | ByOperationId | ByPath | ByMethod | ByContentType;
|
|
859
|
+
type Include = ByTag | ByOperationId | ByPath | ByMethod | ByContentType;
|
|
860
|
+
type Override<TOptions> = (ByTag | ByOperationId | ByPath | ByMethod | BySchemaName | ByContentType) & {
|
|
861
|
+
options: Partial<TOptions>;
|
|
862
|
+
};
|
|
863
|
+
//#endregion
|
|
940
864
|
//#region ../plugin-oas/src/SchemaGenerator.d.ts
|
|
941
|
-
type Context<TOptions, TPluginOptions extends PluginFactoryOptions> = {
|
|
865
|
+
type Context$1<TOptions, TPluginOptions extends PluginFactoryOptions> = {
|
|
942
866
|
fabric: Fabric;
|
|
943
867
|
oas: Oas;
|
|
944
868
|
pluginManager: PluginManager;
|
|
@@ -971,15 +895,15 @@ type SchemaGeneratorOptions = {
|
|
|
971
895
|
* TODO TODO add docs
|
|
972
896
|
* @beta
|
|
973
897
|
*/
|
|
974
|
-
schema?: (schemaProps: SchemaProps, defaultSchemas: Schema[]) => Schema[] | undefined;
|
|
898
|
+
schema?: (schemaProps: SchemaProps$1, defaultSchemas: Schema[]) => Schema[] | undefined;
|
|
975
899
|
};
|
|
976
900
|
};
|
|
977
|
-
type SchemaProps = {
|
|
901
|
+
type SchemaProps$1 = {
|
|
978
902
|
schemaObject?: SchemaObject$1;
|
|
979
903
|
name?: string;
|
|
980
904
|
parentName?: string;
|
|
981
905
|
};
|
|
982
|
-
declare class SchemaGenerator<TOptions extends SchemaGeneratorOptions = SchemaGeneratorOptions, TPluginOptions extends PluginFactoryOptions = PluginFactoryOptions, TFileMeta extends FileMetaBase = FileMetaBase> extends BaseGenerator<TOptions, Context<TOptions, TPluginOptions>> {
|
|
906
|
+
declare class SchemaGenerator<TOptions extends SchemaGeneratorOptions = SchemaGeneratorOptions, TPluginOptions extends PluginFactoryOptions = PluginFactoryOptions, TFileMeta extends FileMetaBase = FileMetaBase> extends BaseGenerator<TOptions, Context$1<TOptions, TPluginOptions>> {
|
|
983
907
|
#private;
|
|
984
908
|
refs: Refs;
|
|
985
909
|
/**
|
|
@@ -987,15 +911,85 @@ declare class SchemaGenerator<TOptions extends SchemaGeneratorOptions = SchemaGe
|
|
|
987
911
|
* Delegates to getBaseTypeFromSchema internally and
|
|
988
912
|
* optionally adds a union with null.
|
|
989
913
|
*/
|
|
990
|
-
parse(props: SchemaProps): Schema[];
|
|
991
|
-
deepSearch<T extends keyof SchemaKeywordMapper>(tree: Schema[] | undefined, keyword: T): Array<SchemaKeywordMapper[T]>;
|
|
992
|
-
find<T extends keyof SchemaKeywordMapper>(tree: Schema[] | undefined, keyword: T): SchemaKeywordMapper[T] | undefined;
|
|
914
|
+
parse(props: SchemaProps$1): Schema[];
|
|
993
915
|
static deepSearch<T extends keyof SchemaKeywordMapper>(tree: Schema[] | undefined, keyword: T): Array<SchemaKeywordMapper[T]>;
|
|
994
|
-
static findInObject<T extends keyof SchemaKeywordMapper>(tree: Schema[] | undefined, keyword: T): SchemaKeywordMapper[T] | undefined;
|
|
995
916
|
static find<T extends keyof SchemaKeywordMapper>(tree: Schema[] | undefined, keyword: T): SchemaKeywordMapper[T] | undefined;
|
|
996
917
|
static combineObjects(tree: Schema[] | undefined): Schema[];
|
|
997
918
|
build(...generators: Array<Generator<TPluginOptions>>): Promise<Array<KubbFile.File<TFileMeta>>>;
|
|
998
919
|
}
|
|
999
920
|
//#endregion
|
|
1000
|
-
|
|
1001
|
-
|
|
921
|
+
//#region ../plugin-oas/src/generators/createGenerator.d.ts
|
|
922
|
+
type CoreGenerator<TOptions extends PluginFactoryOptions> = {
|
|
923
|
+
name: string;
|
|
924
|
+
type: 'core';
|
|
925
|
+
operations: (props: OperationsProps<TOptions>) => Promise<KubbFile.File[]>;
|
|
926
|
+
operation: (props: OperationProps<TOptions>) => Promise<KubbFile.File[]>;
|
|
927
|
+
schema: (props: SchemaProps<TOptions>) => Promise<KubbFile.File[]>;
|
|
928
|
+
};
|
|
929
|
+
//#endregion
|
|
930
|
+
//#region ../plugin-oas/src/generators/createReactGenerator.d.ts
|
|
931
|
+
type ReactGenerator<TOptions extends PluginFactoryOptions> = {
|
|
932
|
+
name: string;
|
|
933
|
+
type: 'react';
|
|
934
|
+
Operations: (props: OperationsProps<TOptions>) => KubbNode;
|
|
935
|
+
Operation: (props: OperationProps<TOptions>) => KubbNode;
|
|
936
|
+
Schema: (props: SchemaProps<TOptions>) => KubbNode;
|
|
937
|
+
};
|
|
938
|
+
//#endregion
|
|
939
|
+
//#region ../plugin-oas/src/generators/types.d.ts
|
|
940
|
+
type OperationsProps<TOptions extends PluginFactoryOptions> = {
|
|
941
|
+
config: Config;
|
|
942
|
+
generator: Omit<OperationGenerator<TOptions>, 'build'>;
|
|
943
|
+
plugin: Plugin<TOptions>;
|
|
944
|
+
operations: Array<Operation$1>;
|
|
945
|
+
};
|
|
946
|
+
type OperationProps<TOptions extends PluginFactoryOptions> = {
|
|
947
|
+
config: Config;
|
|
948
|
+
generator: Omit<OperationGenerator<TOptions>, 'build'>;
|
|
949
|
+
plugin: Plugin<TOptions>;
|
|
950
|
+
operation: Operation$1;
|
|
951
|
+
};
|
|
952
|
+
type SchemaProps<TOptions extends PluginFactoryOptions> = {
|
|
953
|
+
config: Config;
|
|
954
|
+
generator: Omit<SchemaGenerator<SchemaGeneratorOptions, TOptions>, 'build'>;
|
|
955
|
+
plugin: Plugin<TOptions>;
|
|
956
|
+
schema: {
|
|
957
|
+
name: string;
|
|
958
|
+
tree: Array<Schema>;
|
|
959
|
+
value: SchemaObject$1;
|
|
960
|
+
};
|
|
961
|
+
};
|
|
962
|
+
type Generator<TOptions extends PluginFactoryOptions> = CoreGenerator<TOptions> | ReactGenerator<TOptions>;
|
|
963
|
+
//#endregion
|
|
964
|
+
//#region ../plugin-oas/src/OperationGenerator.d.ts
|
|
965
|
+
type Context<TOptions, TPluginOptions extends PluginFactoryOptions> = {
|
|
966
|
+
fabric: Fabric;
|
|
967
|
+
oas: Oas;
|
|
968
|
+
exclude: Array<Exclude$1> | undefined;
|
|
969
|
+
include: Array<Include> | undefined;
|
|
970
|
+
override: Array<Override<TOptions>> | undefined;
|
|
971
|
+
contentType: contentType | undefined;
|
|
972
|
+
pluginManager: PluginManager;
|
|
973
|
+
/**
|
|
974
|
+
* Current plugin
|
|
975
|
+
*/
|
|
976
|
+
plugin: Plugin<TPluginOptions>;
|
|
977
|
+
mode: KubbFile.Mode;
|
|
978
|
+
};
|
|
979
|
+
declare class OperationGenerator<TPluginOptions extends PluginFactoryOptions = PluginFactoryOptions, TFileMeta extends FileMetaBase = FileMetaBase> extends BaseGenerator<TPluginOptions['resolvedOptions'], Context<TPluginOptions['resolvedOptions'], TPluginOptions>> {
|
|
980
|
+
#private;
|
|
981
|
+
getSchemas(operation: Operation$1, {
|
|
982
|
+
resolveName
|
|
983
|
+
}?: {
|
|
984
|
+
resolveName?: (name: string) => string;
|
|
985
|
+
}): OperationSchemas;
|
|
986
|
+
getOperations(): Promise<Array<{
|
|
987
|
+
path: string;
|
|
988
|
+
method: HttpMethod;
|
|
989
|
+
operation: Operation$1;
|
|
990
|
+
}>>;
|
|
991
|
+
build(...generators: Array<Generator<TPluginOptions>>): Promise<Array<KubbFile.File<TFileMeta>>>;
|
|
992
|
+
}
|
|
993
|
+
//#endregion
|
|
994
|
+
export { OperationSchemas as a, Oas as c, Output as d, PluginFactoryOptions as f, Include as i, contentType as l, UserPluginWithLifeCycle as m, ReactGenerator as n, Override as o, ResolveNameParams as p, Exclude$1 as r, ResolvePathOptions as s, Generator as t, Group as u };
|
|
995
|
+
//# sourceMappingURL=index-BlpJVG8h.d.ts.map
|
package/dist/index.cjs
CHANGED
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
const require_Server = require('./Server-vKCXRjmg.cjs');
|
|
2
|
-
const require_generators = require('./generators-
|
|
2
|
+
const require_generators = require('./generators-CSDgJv8G.cjs');
|
|
3
3
|
let node_path = require("node:path");
|
|
4
4
|
node_path = require_Server.__toESM(node_path);
|
|
5
5
|
let __kubb_core = require("@kubb/core");
|
|
6
6
|
__kubb_core = require_Server.__toESM(__kubb_core);
|
|
7
7
|
let __kubb_core_transformers = require("@kubb/core/transformers");
|
|
8
8
|
__kubb_core_transformers = require_Server.__toESM(__kubb_core_transformers);
|
|
9
|
+
let __kubb_core_utils = require("@kubb/core/utils");
|
|
10
|
+
__kubb_core_utils = require_Server.__toESM(__kubb_core_utils);
|
|
9
11
|
let __kubb_plugin_oas = require("@kubb/plugin-oas");
|
|
10
12
|
__kubb_plugin_oas = require_Server.__toESM(__kubb_plugin_oas);
|
|
11
13
|
let __kubb_plugin_ts = require("@kubb/plugin-ts");
|
|
@@ -26,7 +28,7 @@ const pluginMcp = (0, __kubb_core.createPlugin)((options) => {
|
|
|
26
28
|
output,
|
|
27
29
|
group,
|
|
28
30
|
client: {
|
|
29
|
-
|
|
31
|
+
client: "axios",
|
|
30
32
|
dataReturnType: "data",
|
|
31
33
|
...options.client
|
|
32
34
|
}
|
|
@@ -63,6 +65,17 @@ const pluginMcp = (0, __kubb_core.createPlugin)((options) => {
|
|
|
63
65
|
const oas = await swaggerPlugin.context.getOas();
|
|
64
66
|
const root = node_path.default.resolve(this.config.root, this.config.output.path);
|
|
65
67
|
const mode = (0, __kubb_core.getMode)(node_path.default.resolve(root, output.path));
|
|
68
|
+
const baseURL = await swaggerPlugin.context.getBaseURL();
|
|
69
|
+
if (baseURL) this.plugin.options.client.baseURL = baseURL;
|
|
70
|
+
const containsFetcher = this.fileManager.files.some((file) => file.baseName === "fetcher.ts");
|
|
71
|
+
if (!this.plugin.options.client.importPath && !containsFetcher) await this.addFile({
|
|
72
|
+
baseName: "fetcher.ts",
|
|
73
|
+
path: node_path.default.resolve(root, ".kubb/fetcher.ts"),
|
|
74
|
+
sources: [{
|
|
75
|
+
name: "fetcher",
|
|
76
|
+
value: (0, __kubb_core_utils.resolveModuleSource)(this.plugin.options.client.client === "fetch" ? "@kubb/plugin-client/templates/clients/fetch" : "@kubb/plugin-client/templates/clients/axios").source
|
|
77
|
+
}]
|
|
78
|
+
});
|
|
66
79
|
const files = await new __kubb_plugin_oas.OperationGenerator(this.plugin.options, {
|
|
67
80
|
fabric: this.fabric,
|
|
68
81
|
oas,
|
package/dist/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","names":["mcpGenerator","serverGenerator","pluginOasName","pluginTsName","pluginZodName","path","options","groupName: Group['name']","PluginManager","OperationGenerator"],"sources":["../src/plugin.ts"],"sourcesContent":["import path from 'node:path'\nimport { createPlugin, type Group, getBarrelFiles, getMode, type Plugin, PluginManager } from '@kubb/core'\nimport { camelCase } from '@kubb/core/transformers'\nimport type { PluginOas as SwaggerPluginOptions } from '@kubb/plugin-oas'\nimport { OperationGenerator, pluginOasName } from '@kubb/plugin-oas'\nimport { pluginTsName } from '@kubb/plugin-ts'\nimport { pluginZodName } from '@kubb/plugin-zod'\nimport { mcpGenerator, serverGenerator } from './generators'\nimport type { PluginMcp } from './types.ts'\n\nexport const pluginMcpName = 'plugin-mcp' satisfies PluginMcp['name']\n\nexport const pluginMcp = createPlugin<PluginMcp>((options) => {\n const {\n output = { path: 'mcp', barrelType: 'named' },\n group,\n exclude = [],\n include,\n override = [],\n transformers = {},\n generators = [mcpGenerator, serverGenerator].filter(Boolean),\n contentType,\n } = options\n\n return {\n name: pluginMcpName,\n options: {\n output,\n group,\n client: {\n
|
|
1
|
+
{"version":3,"file":"index.cjs","names":["mcpGenerator","serverGenerator","pluginOasName","pluginTsName","pluginZodName","path","options","groupName: Group['name']","PluginManager","OperationGenerator"],"sources":["../src/plugin.ts"],"sourcesContent":["import path from 'node:path'\nimport { createPlugin, type Group, getBarrelFiles, getMode, type Plugin, PluginManager } from '@kubb/core'\nimport { camelCase } from '@kubb/core/transformers'\nimport { resolveModuleSource } from '@kubb/core/utils'\nimport type { PluginOas as SwaggerPluginOptions } from '@kubb/plugin-oas'\nimport { OperationGenerator, pluginOasName } from '@kubb/plugin-oas'\nimport { pluginTsName } from '@kubb/plugin-ts'\nimport { pluginZodName } from '@kubb/plugin-zod'\nimport { mcpGenerator, serverGenerator } from './generators'\nimport type { PluginMcp } from './types.ts'\n\nexport const pluginMcpName = 'plugin-mcp' satisfies PluginMcp['name']\n\nexport const pluginMcp = createPlugin<PluginMcp>((options) => {\n const {\n output = { path: 'mcp', barrelType: 'named' },\n group,\n exclude = [],\n include,\n override = [],\n transformers = {},\n generators = [mcpGenerator, serverGenerator].filter(Boolean),\n contentType,\n } = options\n\n return {\n name: pluginMcpName,\n options: {\n output,\n group,\n client: {\n client: 'axios',\n dataReturnType: 'data',\n ...options.client,\n },\n },\n pre: [pluginOasName, pluginTsName, pluginZodName].filter(Boolean),\n resolvePath(baseName, pathMode, options) {\n const root = path.resolve(this.config.root, this.config.output.path)\n const mode = pathMode ?? getMode(path.resolve(root, output.path))\n\n if (mode === 'single') {\n /**\n * when output is a file then we will always append to the same file(output file), see fileManager.addOrAppend\n * Other plugins then need to call addOrAppend instead of just add from the fileManager class\n */\n return path.resolve(root, output.path)\n }\n\n if (group && (options?.group?.path || options?.group?.tag)) {\n const groupName: Group['name'] = group?.name\n ? group.name\n : (ctx) => {\n if (group?.type === 'path') {\n return `${ctx.group.split('/')[1]}`\n }\n return `${camelCase(ctx.group)}Requests`\n }\n\n return path.resolve(\n root,\n output.path,\n groupName({\n group: group.type === 'path' ? options.group.path! : options.group.tag!,\n }),\n baseName,\n )\n }\n\n return path.resolve(root, output.path, baseName)\n },\n resolveName(name, type) {\n const resolvedName = camelCase(name, {\n isFile: type === 'file',\n })\n\n if (type) {\n return transformers?.name?.(resolvedName, type) || resolvedName\n }\n\n return resolvedName\n },\n async buildStart() {\n const [swaggerPlugin]: [Plugin<SwaggerPluginOptions>] = PluginManager.getDependedPlugins<SwaggerPluginOptions>(this.plugins, [pluginOasName])\n\n const oas = await swaggerPlugin.context.getOas()\n const root = path.resolve(this.config.root, this.config.output.path)\n const mode = getMode(path.resolve(root, output.path))\n const baseURL = await swaggerPlugin.context.getBaseURL()\n\n if (baseURL) {\n this.plugin.options.client.baseURL = baseURL\n }\n\n const containsFetcher = this.fileManager.files.some((file) => file.baseName === 'fetcher.ts')\n\n if (!this.plugin.options.client.importPath && !containsFetcher) {\n // pre add bundled fetcher\n await this.addFile({\n baseName: 'fetcher.ts',\n path: path.resolve(root, '.kubb/fetcher.ts'),\n sources: [\n {\n name: 'fetcher',\n value: resolveModuleSource(\n this.plugin.options.client.client === 'fetch' ? '@kubb/plugin-client/templates/clients/fetch' : '@kubb/plugin-client/templates/clients/axios',\n ).source,\n },\n ],\n })\n }\n\n const operationGenerator = new OperationGenerator(this.plugin.options, {\n fabric: this.fabric,\n oas,\n pluginManager: this.pluginManager,\n plugin: this.plugin,\n contentType,\n exclude,\n include,\n override,\n mode,\n })\n\n const files = await operationGenerator.build(...generators)\n await this.addFile(...files)\n\n const barrelFiles = await getBarrelFiles(this.fileManager.files, {\n type: output.barrelType ?? 'named',\n root,\n output,\n meta: {\n pluginKey: this.plugin.key,\n },\n logger: this.logger,\n })\n\n await this.addFile(...barrelFiles)\n },\n }\n})\n"],"mappings":";;;;;;;;;;;;;;;;;;AAWA,MAAa,gBAAgB;AAE7B,MAAa,2CAAqC,YAAY;CAC5D,MAAM,EACJ,SAAS;EAAE,MAAM;EAAO,YAAY;EAAS,EAC7C,OACA,UAAU,EAAE,EACZ,SACA,WAAW,EAAE,EACb,eAAe,EAAE,EACjB,aAAa,CAACA,iCAAcC,mCAAgB,CAAC,OAAO,QAAQ,EAC5D,gBACE;AAEJ,QAAO;EACL,MAAM;EACN,SAAS;GACP;GACA;GACA,QAAQ;IACN,QAAQ;IACR,gBAAgB;IAChB,GAAG,QAAQ;IACZ;GACF;EACD,KAAK;GAACC;GAAeC;GAAcC;GAAc,CAAC,OAAO,QAAQ;EACjE,YAAY,UAAU,UAAU,WAAS;GACvC,MAAM,OAAOC,kBAAK,QAAQ,KAAK,OAAO,MAAM,KAAK,OAAO,OAAO,KAAK;AAGpE,QAFa,qCAAoBA,kBAAK,QAAQ,MAAM,OAAO,KAAK,CAAC,MAEpD;;;;;AAKX,UAAOA,kBAAK,QAAQ,MAAM,OAAO,KAAK;AAGxC,OAAI,UAAUC,WAAS,OAAO,QAAQA,WAAS,OAAO,MAAM;IAC1D,MAAMC,YAA2B,OAAO,OACpC,MAAM,QACL,QAAQ;AACP,SAAI,OAAO,SAAS,OAClB,QAAO,GAAG,IAAI,MAAM,MAAM,IAAI,CAAC;AAEjC,YAAO,2CAAa,IAAI,MAAM,CAAC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,GAAG,MAAM;GAE5B,MAAM,cAAc,sCAAqB,KAAK,YAAY,OAAO;IAC/D,MAAM,OAAO,cAAc;IAC3B;IACA;IACA,MAAM,EACJ,WAAW,KAAK,OAAO,KACxB;IACD,QAAQ,KAAK;IACd,CAAC;AAEF,SAAM,KAAK,QAAQ,GAAG,YAAY;;EAErC;EACD"}
|
package/dist/index.d.cts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { m as UserPluginWithLifeCycle } from "./
|
|
2
|
-
import { n as PluginMcp, t as Options } from "./types-
|
|
1
|
+
import { m as UserPluginWithLifeCycle } from "./OperationGenerator-Beq8iOZY.cjs";
|
|
2
|
+
import { n as PluginMcp, t as Options } from "./types-B4xu5uHh.cjs";
|
|
3
3
|
|
|
4
4
|
//#region src/plugin.d.ts
|
|
5
5
|
declare const pluginMcpName = "plugin-mcp";
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { m as UserPluginWithLifeCycle } from "./
|
|
2
|
-
import { n as PluginMcp, t as Options } from "./types-
|
|
1
|
+
import { m as UserPluginWithLifeCycle } from "./index-BlpJVG8h.js";
|
|
2
|
+
import { n as PluginMcp, t as Options } from "./types-Cy3TnfH5.js";
|
|
3
3
|
|
|
4
4
|
//#region src/plugin.d.ts
|
|
5
5
|
declare const pluginMcpName = "plugin-mcp";
|
package/dist/index.js
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
import { n as mcpGenerator, t as serverGenerator } from "./generators-
|
|
1
|
+
import { n as mcpGenerator, t as serverGenerator } from "./generators-DP6UAisL.js";
|
|
2
2
|
import "./Server-DMDo69md.js";
|
|
3
3
|
import path from "node:path";
|
|
4
4
|
import { PluginManager, createPlugin, getBarrelFiles, getMode } from "@kubb/core";
|
|
5
5
|
import { camelCase } from "@kubb/core/transformers";
|
|
6
|
+
import { resolveModuleSource } from "@kubb/core/utils";
|
|
6
7
|
import { OperationGenerator, pluginOasName } from "@kubb/plugin-oas";
|
|
7
8
|
import { pluginTsName } from "@kubb/plugin-ts";
|
|
8
9
|
import { pluginZodName } from "@kubb/plugin-zod";
|
|
@@ -20,7 +21,7 @@ const pluginMcp = createPlugin((options) => {
|
|
|
20
21
|
output,
|
|
21
22
|
group,
|
|
22
23
|
client: {
|
|
23
|
-
|
|
24
|
+
client: "axios",
|
|
24
25
|
dataReturnType: "data",
|
|
25
26
|
...options.client
|
|
26
27
|
}
|
|
@@ -57,6 +58,17 @@ const pluginMcp = createPlugin((options) => {
|
|
|
57
58
|
const oas = await swaggerPlugin.context.getOas();
|
|
58
59
|
const root = path.resolve(this.config.root, this.config.output.path);
|
|
59
60
|
const mode = getMode(path.resolve(root, output.path));
|
|
61
|
+
const baseURL = await swaggerPlugin.context.getBaseURL();
|
|
62
|
+
if (baseURL) this.plugin.options.client.baseURL = baseURL;
|
|
63
|
+
const containsFetcher = this.fileManager.files.some((file) => file.baseName === "fetcher.ts");
|
|
64
|
+
if (!this.plugin.options.client.importPath && !containsFetcher) await this.addFile({
|
|
65
|
+
baseName: "fetcher.ts",
|
|
66
|
+
path: path.resolve(root, ".kubb/fetcher.ts"),
|
|
67
|
+
sources: [{
|
|
68
|
+
name: "fetcher",
|
|
69
|
+
value: resolveModuleSource(this.plugin.options.client.client === "fetch" ? "@kubb/plugin-client/templates/clients/fetch" : "@kubb/plugin-client/templates/clients/axios").source
|
|
70
|
+
}]
|
|
71
|
+
});
|
|
60
72
|
const files = await new OperationGenerator(this.plugin.options, {
|
|
61
73
|
fabric: this.fabric,
|
|
62
74
|
oas,
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":["options","groupName: Group['name']"],"sources":["../src/plugin.ts"],"sourcesContent":["import path from 'node:path'\nimport { createPlugin, type Group, getBarrelFiles, getMode, type Plugin, PluginManager } from '@kubb/core'\nimport { camelCase } from '@kubb/core/transformers'\nimport type { PluginOas as SwaggerPluginOptions } from '@kubb/plugin-oas'\nimport { OperationGenerator, pluginOasName } from '@kubb/plugin-oas'\nimport { pluginTsName } from '@kubb/plugin-ts'\nimport { pluginZodName } from '@kubb/plugin-zod'\nimport { mcpGenerator, serverGenerator } from './generators'\nimport type { PluginMcp } from './types.ts'\n\nexport const pluginMcpName = 'plugin-mcp' satisfies PluginMcp['name']\n\nexport const pluginMcp = createPlugin<PluginMcp>((options) => {\n const {\n output = { path: 'mcp', barrelType: 'named' },\n group,\n exclude = [],\n include,\n override = [],\n transformers = {},\n generators = [mcpGenerator, serverGenerator].filter(Boolean),\n contentType,\n } = options\n\n return {\n name: pluginMcpName,\n options: {\n output,\n group,\n client: {\n
|
|
1
|
+
{"version":3,"file":"index.js","names":["options","groupName: Group['name']"],"sources":["../src/plugin.ts"],"sourcesContent":["import path from 'node:path'\nimport { createPlugin, type Group, getBarrelFiles, getMode, type Plugin, PluginManager } from '@kubb/core'\nimport { camelCase } from '@kubb/core/transformers'\nimport { resolveModuleSource } from '@kubb/core/utils'\nimport type { PluginOas as SwaggerPluginOptions } from '@kubb/plugin-oas'\nimport { OperationGenerator, pluginOasName } from '@kubb/plugin-oas'\nimport { pluginTsName } from '@kubb/plugin-ts'\nimport { pluginZodName } from '@kubb/plugin-zod'\nimport { mcpGenerator, serverGenerator } from './generators'\nimport type { PluginMcp } from './types.ts'\n\nexport const pluginMcpName = 'plugin-mcp' satisfies PluginMcp['name']\n\nexport const pluginMcp = createPlugin<PluginMcp>((options) => {\n const {\n output = { path: 'mcp', barrelType: 'named' },\n group,\n exclude = [],\n include,\n override = [],\n transformers = {},\n generators = [mcpGenerator, serverGenerator].filter(Boolean),\n contentType,\n } = options\n\n return {\n name: pluginMcpName,\n options: {\n output,\n group,\n client: {\n client: 'axios',\n dataReturnType: 'data',\n ...options.client,\n },\n },\n pre: [pluginOasName, pluginTsName, pluginZodName].filter(Boolean),\n resolvePath(baseName, pathMode, options) {\n const root = path.resolve(this.config.root, this.config.output.path)\n const mode = pathMode ?? getMode(path.resolve(root, output.path))\n\n if (mode === 'single') {\n /**\n * when output is a file then we will always append to the same file(output file), see fileManager.addOrAppend\n * Other plugins then need to call addOrAppend instead of just add from the fileManager class\n */\n return path.resolve(root, output.path)\n }\n\n if (group && (options?.group?.path || options?.group?.tag)) {\n const groupName: Group['name'] = group?.name\n ? group.name\n : (ctx) => {\n if (group?.type === 'path') {\n return `${ctx.group.split('/')[1]}`\n }\n return `${camelCase(ctx.group)}Requests`\n }\n\n return path.resolve(\n root,\n output.path,\n groupName({\n group: group.type === 'path' ? options.group.path! : options.group.tag!,\n }),\n baseName,\n )\n }\n\n return path.resolve(root, output.path, baseName)\n },\n resolveName(name, type) {\n const resolvedName = camelCase(name, {\n isFile: type === 'file',\n })\n\n if (type) {\n return transformers?.name?.(resolvedName, type) || resolvedName\n }\n\n return resolvedName\n },\n async buildStart() {\n const [swaggerPlugin]: [Plugin<SwaggerPluginOptions>] = PluginManager.getDependedPlugins<SwaggerPluginOptions>(this.plugins, [pluginOasName])\n\n const oas = await swaggerPlugin.context.getOas()\n const root = path.resolve(this.config.root, this.config.output.path)\n const mode = getMode(path.resolve(root, output.path))\n const baseURL = await swaggerPlugin.context.getBaseURL()\n\n if (baseURL) {\n this.plugin.options.client.baseURL = baseURL\n }\n\n const containsFetcher = this.fileManager.files.some((file) => file.baseName === 'fetcher.ts')\n\n if (!this.plugin.options.client.importPath && !containsFetcher) {\n // pre add bundled fetcher\n await this.addFile({\n baseName: 'fetcher.ts',\n path: path.resolve(root, '.kubb/fetcher.ts'),\n sources: [\n {\n name: 'fetcher',\n value: resolveModuleSource(\n this.plugin.options.client.client === 'fetch' ? '@kubb/plugin-client/templates/clients/fetch' : '@kubb/plugin-client/templates/clients/axios',\n ).source,\n },\n ],\n })\n }\n\n const operationGenerator = new OperationGenerator(this.plugin.options, {\n fabric: this.fabric,\n oas,\n pluginManager: this.pluginManager,\n plugin: this.plugin,\n contentType,\n exclude,\n include,\n override,\n mode,\n })\n\n const files = await operationGenerator.build(...generators)\n await this.addFile(...files)\n\n const barrelFiles = await getBarrelFiles(this.fileManager.files, {\n type: output.barrelType ?? 'named',\n root,\n output,\n meta: {\n pluginKey: this.plugin.key,\n },\n logger: this.logger,\n })\n\n await this.addFile(...barrelFiles)\n },\n }\n})\n"],"mappings":";;;;;;;;;;;AAWA,MAAa,gBAAgB;AAE7B,MAAa,YAAY,cAAyB,YAAY;CAC5D,MAAM,EACJ,SAAS;EAAE,MAAM;EAAO,YAAY;EAAS,EAC7C,OACA,UAAU,EAAE,EACZ,SACA,WAAW,EAAE,EACb,eAAe,EAAE,EACjB,aAAa,CAAC,cAAc,gBAAgB,CAAC,OAAO,QAAQ,EAC5D,gBACE;AAEJ,QAAO;EACL,MAAM;EACN,SAAS;GACP;GACA;GACA,QAAQ;IACN,QAAQ;IACR,gBAAgB;IAChB,GAAG,QAAQ;IACZ;GACF;EACD,KAAK;GAAC;GAAe;GAAc;GAAc,CAAC,OAAO,QAAQ;EACjE,YAAY,UAAU,UAAU,WAAS;GACvC,MAAM,OAAO,KAAK,QAAQ,KAAK,OAAO,MAAM,KAAK,OAAO,OAAO,KAAK;AAGpE,QAFa,YAAY,QAAQ,KAAK,QAAQ,MAAM,OAAO,KAAK,CAAC,MAEpD;;;;;AAKX,UAAO,KAAK,QAAQ,MAAM,OAAO,KAAK;AAGxC,OAAI,UAAUA,WAAS,OAAO,QAAQA,WAAS,OAAO,MAAM;IAC1D,MAAMC,YAA2B,OAAO,OACpC,MAAM,QACL,QAAQ;AACP,SAAI,OAAO,SAAS,OAClB,QAAO,GAAG,IAAI,MAAM,MAAM,IAAI,CAAC;AAEjC,YAAO,GAAG,UAAU,IAAI,MAAM,CAAC;;AAGrC,WAAO,KAAK,QACV,MACA,OAAO,MACP,UAAU,EACR,OAAO,MAAM,SAAS,SAASD,UAAQ,MAAM,OAAQA,UAAQ,MAAM,KACpE,CAAC,EACF,SACD;;AAGH,UAAO,KAAK,QAAQ,MAAM,OAAO,MAAM,SAAS;;EAElD,YAAY,MAAM,MAAM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