@kubb/plugin-oas 3.0.14 → 3.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{OperationGenerator-Bw6sj3Eb.d.cts → OperationGenerator-DSwDeEnz.d.cts} +1 -21
- package/dist/{OperationGenerator-Bw6sj3Eb.d.ts → OperationGenerator-DSwDeEnz.d.ts} +1 -21
- package/dist/{Schema-BlGtSgNB.d.ts → Schema-CWTFm7te.d.ts} +1 -1
- package/dist/{Schema-4FwWfdim.d.cts → Schema-akZJu96S.d.cts} +1 -1
- package/dist/components.d.cts +2 -2
- package/dist/components.d.ts +2 -2
- package/dist/generators.d.cts +1 -1
- package/dist/generators.d.ts +1 -1
- package/dist/hooks.cjs +15 -6
- package/dist/hooks.cjs.map +1 -1
- package/dist/hooks.d.cts +8 -7
- package/dist/hooks.d.ts +8 -7
- package/dist/hooks.js +15 -6
- package/dist/hooks.js.map +1 -1
- package/dist/index.cjs +20 -46
- 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 +20 -46
- package/dist/index.js.map +1 -1
- package/dist/utils.cjs +4 -1
- package/dist/utils.cjs.map +1 -1
- package/dist/utils.d.cts +3 -2
- package/dist/utils.d.ts +3 -2
- package/dist/utils.js +4 -1
- package/dist/utils.js.map +1 -1
- package/package.json +8 -8
- package/src/OperationGenerator.ts +20 -51
- package/src/hooks/useOperationManager.ts +20 -7
- package/src/hooks/useSchemaManager.ts +5 -5
- package/src/types.ts +1 -1
- package/src/utils/getParams.ts +7 -1
package/dist/utils.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/utils/getComments.ts","../src/utils/getParams.ts"],"names":["URLPath","transformers","isParameterObject","isValidVarName","camelCase"],"mappings":";;;;;;;;;;;;AAKO,SAAS,YAAY,SAAgC,EAAA;AAC1D,EAAO,OAAA;AAAA,IACL,UAAU,cAAe,E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AAA,eAAA,EACA,
|
|
1
|
+
{"version":3,"sources":["../src/utils/getComments.ts","../src/utils/getParams.ts"],"names":["URLPath","transformers","isParameterObject","isValidVarName","camelCase"],"mappings":";;;;;;;;;;;;AAKO,SAAS,YAAY,SAAgC,EAAA;AAC1D,EAAO,OAAA;AAAA,IACL,UAAU,cAAe,EAAA,IAAK,CAAgB,aAAA,EAAA,SAAA,CAAU,gBAAgB,CAAA,CAAA;AAAA,IACxE,UAAU,UAAW,EAAA,IAAK,CAAY,SAAA,EAAA,SAAA,CAAU,YAAY,CAAA,CAAA;AAAA,IAC5D,SAAA,CAAU,QAAQ,CAAU,OAAA,EAAA,IAAIA,cAAQ,SAAU,CAAA,IAAI,EAAE,GAAG,CAAA,CAAA,CAAA;AAAA,IAC3D,SAAA,CAAU,cAAkB,IAAA;AAAA,GAC9B,CACG,MAAO,CAAA,OAAO,CACd,CAAA,GAAA,CAAI,CAAC,IAAS,KAAAC,6BAAA,CAAa,IAAK,CAAA,IAAI,CAAC,CAAA;AAC1C;ACFO,SAAS,aACd,eACA,EAAA;AAAA,EACE,KAAQ,GAAA,KAAA;AAAA,EACR;AACF,CAAA,GAGI,EACiB,EAAA;AACrB,EAAI,IAAA,CAAC,mBAAmB,CAAC,eAAA,CAAgB,OAAO,UAAc,IAAA,CAAC,gBAAgB,IAAM,EAAA;AACnF,IAAA,OAAO,EAAC;AAAA;AAGV,EAAO,OAAA,MAAA,CAAO,OAAQ,CAAA,eAAA,CAAgB,MAAO,CAAA,UAAU,CAAE,CAAA,GAAA,CAAI,CAAC,CAAC,IAAM,EAAA,MAAM,CAAuC,KAAA;AAChH,IAAM,MAAA,OAAA,GAAUC,sBAAkB,MAAM,CAAA;AACxC,IAAA,MAAM,IAA0B,GAAA;AAAA,MAC9B,IAAA;AAAA,MACA,OAAA,EAAS,CAAC,CAAC,IAAA;AAAA,MACX,QAAA,EAAU,OAAU,GAAA,MAAA,CAAO,QAAW,GAAA,IAAA;AAAA,MACtC,MAAM,KAAQ,GAAA,CAAA,EAAG,gBAAgB,IAAI,CAAA,EAAA,EAAK,IAAI,CAAO,EAAA,CAAA,GAAA,KAAA;AAAA,KACvD;AAEA,IAAO,OAAA,QAAA,GAAW,QAAS,CAAA,IAAI,CAAI,GAAA,IAAA;AAAA,GACpC,CAAA;AACH;AAEO,SAAS,aACd,CAAA,eAAA,EACA,OAII,GAAA,EACJ,EAAA;AACA,EAAA,OAAO,aAAa,eAAiB,EAAA,OAAO,EAAE,MAAO,CAAA,CAAC,KAAK,IAAS,KAAA;AAClE,IAAI,IAAA,IAAA,CAAK,IAAQ,IAAA,IAAA,CAAK,OAAS,EAAA;AAC7B,MAAI,IAAA,IAAA,GAAOC,4BAAe,IAAK,CAAA,IAAI,IAAI,IAAK,CAAA,IAAA,GAAOC,sBAAU,CAAA,IAAA,CAAK,IAAI,CAAA;AAEtE,MAAI,IAAA,OAAA,CAAQ,WAAW,WAAa,EAAA;AAClC,QAAA,IAAA,GAAOA,uBAAU,IAAI,CAAA;AAAA;AAGvB,MAAA,GAAA,CAAI,IAAI,CAAI,GAAA;AAAA,QACV,SAAS,IAAK,CAAA,OAAA;AAAA,QACd,MAAM,IAAK,CAAA,IAAA;AAAA,QACX,QAAA,EAAU,CAAC,IAAK,CAAA;AAAA,OAClB;AAAA;AAGF,IAAO,OAAA,GAAA;AAAA,GACT,EAAG,EAAY,CAAA;AACjB","file":"utils.cjs","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"]}
|
package/dist/utils.d.cts
CHANGED
|
@@ -2,8 +2,8 @@ import { Operation, Oas, SchemaObject, OpenAPIV3, OpenAPIV3_1 } from '@kubb/oas'
|
|
|
2
2
|
export { isOptional } from '@kubb/oas';
|
|
3
3
|
import { FunctionParamsAST } from '@kubb/core/utils';
|
|
4
4
|
import { Params } from '@kubb/react/types';
|
|
5
|
-
import { v as OperationSchema } from './OperationGenerator-
|
|
6
|
-
export { z as GetSchemasProps, B as getSchemas } from './OperationGenerator-
|
|
5
|
+
import { v as OperationSchema } from './OperationGenerator-DSwDeEnz.cjs';
|
|
6
|
+
export { z as GetSchemasProps, B as getSchemas } from './OperationGenerator-DSwDeEnz.cjs';
|
|
7
7
|
import { Config } from '@kubb/core';
|
|
8
8
|
import '@kubb/fs/types';
|
|
9
9
|
|
|
@@ -20,6 +20,7 @@ declare function getASTParams(operationSchema: OperationSchema | undefined, { ty
|
|
|
20
20
|
}): FunctionParamsAST[];
|
|
21
21
|
declare function getPathParams(operationSchema: OperationSchema | undefined, options?: {
|
|
22
22
|
typed?: boolean;
|
|
23
|
+
casing?: 'camelcase';
|
|
23
24
|
override?: (data: FunctionParamsAST) => FunctionParamsAST;
|
|
24
25
|
}): Params;
|
|
25
26
|
|
package/dist/utils.d.ts
CHANGED
|
@@ -2,8 +2,8 @@ import { Operation, Oas, SchemaObject, OpenAPIV3, OpenAPIV3_1 } from '@kubb/oas'
|
|
|
2
2
|
export { isOptional } from '@kubb/oas';
|
|
3
3
|
import { FunctionParamsAST } from '@kubb/core/utils';
|
|
4
4
|
import { Params } from '@kubb/react/types';
|
|
5
|
-
import { v as OperationSchema } from './OperationGenerator-
|
|
6
|
-
export { z as GetSchemasProps, B as getSchemas } from './OperationGenerator-
|
|
5
|
+
import { v as OperationSchema } from './OperationGenerator-DSwDeEnz.js';
|
|
6
|
+
export { z as GetSchemasProps, B as getSchemas } from './OperationGenerator-DSwDeEnz.js';
|
|
7
7
|
import { Config } from '@kubb/core';
|
|
8
8
|
import '@kubb/fs/types';
|
|
9
9
|
|
|
@@ -20,6 +20,7 @@ declare function getASTParams(operationSchema: OperationSchema | undefined, { ty
|
|
|
20
20
|
}): FunctionParamsAST[];
|
|
21
21
|
declare function getPathParams(operationSchema: OperationSchema | undefined, options?: {
|
|
22
22
|
typed?: boolean;
|
|
23
|
+
casing?: 'camelcase';
|
|
23
24
|
override?: (data: FunctionParamsAST) => FunctionParamsAST;
|
|
24
25
|
}): Params;
|
|
25
26
|
|
package/dist/utils.js
CHANGED
|
@@ -34,7 +34,10 @@ function getASTParams(operationSchema, {
|
|
|
34
34
|
function getPathParams(operationSchema, options = {}) {
|
|
35
35
|
return getASTParams(operationSchema, options).reduce((acc, curr) => {
|
|
36
36
|
if (curr.name && curr.enabled) {
|
|
37
|
-
|
|
37
|
+
let name = isValidVarName(curr.name) ? curr.name : camelCase(curr.name);
|
|
38
|
+
if (options.casing === "camelcase") {
|
|
39
|
+
name = camelCase(name);
|
|
40
|
+
}
|
|
38
41
|
acc[name] = {
|
|
39
42
|
default: curr.default,
|
|
40
43
|
type: curr.type,
|
package/dist/utils.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/utils/getComments.ts","../src/utils/getParams.ts"],"names":[],"mappings":";;;;;;;AAKO,SAAS,YAAY,SAAgC,EAAA;AAC1D,EAAO,OAAA;AAAA,IACL,UAAU,cAAe,EAAA,IAAK,CAAgB,aAAA,EAAA,SAAA,CAAU,gBAAgB,CAAA,CAAA;AAAA,IACxE,UAAU,UAAW,EAAA,IAAK,CAAY,SAAA,EAAA,SAAA,CAAU,YAAY,CAAA,CAAA;AAAA,IAC5D,SAAA,CAAU,QAAQ,CAAU,OAAA,EAAA,IAAI,QAAQ,SAAU,CAAA,IAAI,EAAE,GAAG,CAAA,CAAA,CAAA;AAAA,IAC3D,SAAA,CAAU,cAAkB,IAAA;AAAA,GAC9B,CACG,MAAO,CAAA,OAAO,CACd,CAAA,GAAA,CAAI,CAAC,IAAS,KAAA,YAAA,CAAa,IAAK,CAAA,IAAI,CAAC,CAAA;AAC1C;ACFO,SAAS,aACd,eACA,EAAA;AAAA,EACE,KAAQ,GAAA,KAAA;AAAA,EACR;AACF,CAAA,GAGI,EACiB,EAAA;AACrB,EAAI,IAAA,CAAC,mBAAmB,CAAC,eAAA,CAAgB,OAAO,UAAc,IAAA,CAAC,gBAAgB,IAAM,EAAA;AACnF,IAAA,OAAO,EAAC;AAAA;AAGV,EAAO,OAAA,MAAA,CAAO,OAAQ,CAAA,eAAA,CAAgB,MAAO,CAAA,UAAU,CAAE,CAAA,GAAA,CAAI,CAA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AAO,OAAA,GAAA;AAAA,GACT,EAAG,EAAY,CAAA;AACjB","file":"utils.js","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"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kubb/plugin-oas",
|
|
3
|
-
"version": "3.0
|
|
3
|
+
"version": "3.2.0",
|
|
4
4
|
"description": "Generator swagger",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"typescript",
|
|
@@ -76,18 +76,18 @@
|
|
|
76
76
|
"dependencies": {
|
|
77
77
|
"@stoplight/yaml": "^4.3.0",
|
|
78
78
|
"remeda": "^2.17.4",
|
|
79
|
-
"@kubb/core": "3.0
|
|
80
|
-
"@kubb/fs": "3.0
|
|
81
|
-
"@kubb/oas": "3.0
|
|
82
|
-
"@kubb/react": "3.0
|
|
79
|
+
"@kubb/core": "3.2.0",
|
|
80
|
+
"@kubb/fs": "3.2.0",
|
|
81
|
+
"@kubb/oas": "3.2.0",
|
|
82
|
+
"@kubb/react": "3.2.0"
|
|
83
83
|
},
|
|
84
84
|
"devDependencies": {
|
|
85
|
-
"@types/react": "^18.3.
|
|
85
|
+
"@types/react": "^18.3.16",
|
|
86
86
|
"react": "^18.3.1",
|
|
87
87
|
"tsup": "^8.3.5",
|
|
88
88
|
"typescript": "^5.7.2",
|
|
89
|
-
"@kubb/config-ts": "3.0
|
|
90
|
-
"@kubb/config-tsup": "3.0
|
|
89
|
+
"@kubb/config-ts": "3.2.0",
|
|
90
|
+
"@kubb/config-tsup": "3.2.0"
|
|
91
91
|
},
|
|
92
92
|
"peerDependencies": {
|
|
93
93
|
"@kubb/react": "^3.0.0"
|
|
@@ -48,7 +48,7 @@ export class OperationGenerator<
|
|
|
48
48
|
}
|
|
49
49
|
|
|
50
50
|
if (type === 'operationId') {
|
|
51
|
-
return !!operation.getOperationId().match(pattern)
|
|
51
|
+
return !!operation.getOperationId({ friendlyCase: true }).match(pattern)
|
|
52
52
|
}
|
|
53
53
|
|
|
54
54
|
if (type === 'path') {
|
|
@@ -74,7 +74,7 @@ export class OperationGenerator<
|
|
|
74
74
|
}
|
|
75
75
|
|
|
76
76
|
if (type === 'operationId' && !matched) {
|
|
77
|
-
matched = !!operation.getOperationId().match(pattern)
|
|
77
|
+
matched = !!operation.getOperationId({ friendlyCase: true }).match(pattern)
|
|
78
78
|
}
|
|
79
79
|
|
|
80
80
|
if (type === 'path' && !matched) {
|
|
@@ -99,7 +99,7 @@ export class OperationGenerator<
|
|
|
99
99
|
}
|
|
100
100
|
|
|
101
101
|
if (type === 'operationId' && !matched) {
|
|
102
|
-
matched = !!operation.getOperationId().match(pattern)
|
|
102
|
+
matched = !!operation.getOperationId({ friendlyCase: true }).match(pattern)
|
|
103
103
|
}
|
|
104
104
|
|
|
105
105
|
if (type === 'path' && !matched) {
|
|
@@ -135,11 +135,11 @@ export class OperationGenerator<
|
|
|
135
135
|
const schema = this.context.oas.getResponseSchema(operation, statusCode)
|
|
136
136
|
|
|
137
137
|
return {
|
|
138
|
-
name: resolveName(transformers.pascalCase(`${operation.getOperationId()} ${name}`)),
|
|
138
|
+
name: resolveName(transformers.pascalCase(`${operation.getOperationId({ friendlyCase: true })} ${name}`)),
|
|
139
139
|
description: (operation.getResponseByStatusCode(statusCode) as OasTypes.ResponseObject)?.description,
|
|
140
140
|
schema,
|
|
141
141
|
operation,
|
|
142
|
-
operationName: transformers.pascalCase(`${operation.getOperationId()}`),
|
|
142
|
+
operationName: transformers.pascalCase(`${operation.getOperationId({ friendlyCase: true })}`),
|
|
143
143
|
statusCode: name === 'error' ? undefined : Number(statusCode),
|
|
144
144
|
keys: schema?.properties ? Object.keys(schema.properties) : undefined,
|
|
145
145
|
keysToOmit: schema?.properties
|
|
@@ -155,37 +155,39 @@ export class OperationGenerator<
|
|
|
155
155
|
return {
|
|
156
156
|
pathParams: pathParamsSchema
|
|
157
157
|
? {
|
|
158
|
-
name: resolveName(transformers.pascalCase(`${operation.getOperationId()} PathParams`)),
|
|
158
|
+
name: resolveName(transformers.pascalCase(`${operation.getOperationId({ friendlyCase: true })} PathParams`)),
|
|
159
159
|
operation,
|
|
160
|
-
operationName: transformers.pascalCase(`${operation.getOperationId()}`),
|
|
160
|
+
operationName: transformers.pascalCase(`${operation.getOperationId({ friendlyCase: true })}`),
|
|
161
161
|
schema: pathParamsSchema,
|
|
162
162
|
keys: pathParamsSchema.properties ? Object.keys(pathParamsSchema.properties) : undefined,
|
|
163
163
|
}
|
|
164
164
|
: undefined,
|
|
165
165
|
queryParams: queryParamsSchema
|
|
166
166
|
? {
|
|
167
|
-
name: resolveName(transformers.pascalCase(`${operation.getOperationId()} QueryParams`)),
|
|
167
|
+
name: resolveName(transformers.pascalCase(`${operation.getOperationId({ friendlyCase: true })} QueryParams`)),
|
|
168
168
|
operation,
|
|
169
|
-
operationName: transformers.pascalCase(`${operation.getOperationId()}`),
|
|
169
|
+
operationName: transformers.pascalCase(`${operation.getOperationId({ friendlyCase: true })}`),
|
|
170
170
|
schema: queryParamsSchema,
|
|
171
171
|
keys: queryParamsSchema.properties ? Object.keys(queryParamsSchema.properties) : [],
|
|
172
172
|
}
|
|
173
173
|
: undefined,
|
|
174
174
|
headerParams: headerParamsSchema
|
|
175
175
|
? {
|
|
176
|
-
name: resolveName(transformers.pascalCase(`${operation.getOperationId()} HeaderParams`)),
|
|
176
|
+
name: resolveName(transformers.pascalCase(`${operation.getOperationId({ friendlyCase: true })} HeaderParams`)),
|
|
177
177
|
operation,
|
|
178
|
-
operationName: transformers.pascalCase(`${operation.getOperationId()}`),
|
|
178
|
+
operationName: transformers.pascalCase(`${operation.getOperationId({ friendlyCase: true })}`),
|
|
179
179
|
schema: headerParamsSchema,
|
|
180
180
|
keys: headerParamsSchema.properties ? Object.keys(headerParamsSchema.properties) : undefined,
|
|
181
181
|
}
|
|
182
182
|
: undefined,
|
|
183
183
|
request: requestSchema
|
|
184
184
|
? {
|
|
185
|
-
name: resolveName(
|
|
185
|
+
name: resolveName(
|
|
186
|
+
transformers.pascalCase(`${operation.getOperationId({ friendlyCase: true })} ${operation.method === 'get' ? 'queryRequest' : 'mutationRequest'}`),
|
|
187
|
+
),
|
|
186
188
|
description: (operation.schema.requestBody as OasTypes.RequestBodyObject)?.description,
|
|
187
189
|
operation,
|
|
188
|
-
operationName: transformers.pascalCase(`${operation.getOperationId()}`),
|
|
190
|
+
operationName: transformers.pascalCase(`${operation.getOperationId({ friendlyCase: true })}`),
|
|
189
191
|
schema: requestSchema,
|
|
190
192
|
keys: requestSchema.properties ? Object.keys(requestSchema.properties) : undefined,
|
|
191
193
|
keysToOmit: requestSchema.properties
|
|
@@ -198,9 +200,11 @@ export class OperationGenerator<
|
|
|
198
200
|
}
|
|
199
201
|
: undefined,
|
|
200
202
|
response: {
|
|
201
|
-
name: resolveName(
|
|
203
|
+
name: resolveName(
|
|
204
|
+
transformers.pascalCase(`${operation.getOperationId({ friendlyCase: true })} ${operation.method === 'get' ? 'queryResponse' : 'mutationResponse'}`),
|
|
205
|
+
),
|
|
202
206
|
operation,
|
|
203
|
-
operationName: transformers.pascalCase(`${operation.getOperationId()}`),
|
|
207
|
+
operationName: transformers.pascalCase(`${operation.getOperationId({ friendlyCase: true })}`),
|
|
204
208
|
schema: {
|
|
205
209
|
oneOf: hasResponses
|
|
206
210
|
? statusCodes
|
|
@@ -208,7 +212,7 @@ export class OperationGenerator<
|
|
|
208
212
|
.map((item) => {
|
|
209
213
|
return {
|
|
210
214
|
...item.schema,
|
|
211
|
-
$ref: resolveName(transformers.pascalCase(`${operation.getOperationId()} ${item.statusCode}`)),
|
|
215
|
+
$ref: resolveName(transformers.pascalCase(`${operation.getOperationId({ friendlyCase: true })} ${item.statusCode}`)),
|
|
212
216
|
}
|
|
213
217
|
})
|
|
214
218
|
: undefined,
|
|
@@ -330,41 +334,6 @@ export class OperationGenerator<
|
|
|
330
334
|
async operation(operation: Operation, options: TPluginOptions['resolvedOptions']): OperationMethodResult<TFileMeta> {
|
|
331
335
|
return []
|
|
332
336
|
}
|
|
333
|
-
|
|
334
|
-
/**
|
|
335
|
-
* GET
|
|
336
|
-
*/
|
|
337
|
-
async get(operation: Operation, options: TPluginOptions['resolvedOptions']): OperationMethodResult<TFileMeta> {
|
|
338
|
-
return []
|
|
339
|
-
}
|
|
340
|
-
|
|
341
|
-
/**
|
|
342
|
-
* POST
|
|
343
|
-
*/
|
|
344
|
-
async post(operation: Operation, options: TPluginOptions['resolvedOptions']): OperationMethodResult<TFileMeta> {
|
|
345
|
-
return []
|
|
346
|
-
}
|
|
347
|
-
/**
|
|
348
|
-
* PATCH
|
|
349
|
-
*/
|
|
350
|
-
async patch(operation: Operation, options: TPluginOptions['resolvedOptions']): OperationMethodResult<TFileMeta> {
|
|
351
|
-
return []
|
|
352
|
-
}
|
|
353
|
-
|
|
354
|
-
/**
|
|
355
|
-
* PUT
|
|
356
|
-
*/
|
|
357
|
-
async put(operation: Operation, options: TPluginOptions['resolvedOptions']): OperationMethodResult<TFileMeta> {
|
|
358
|
-
return []
|
|
359
|
-
}
|
|
360
|
-
|
|
361
|
-
/**
|
|
362
|
-
* DELETE
|
|
363
|
-
*/
|
|
364
|
-
async delete(operation: Operation, options: TPluginOptions['resolvedOptions']): OperationMethodResult<TFileMeta> {
|
|
365
|
-
return []
|
|
366
|
-
}
|
|
367
|
-
|
|
368
337
|
/**
|
|
369
338
|
* Combination of GET, POST, PATCH, PUT, DELETE
|
|
370
339
|
*/
|
|
@@ -2,7 +2,8 @@ import { useApp, useContext } from '@kubb/react'
|
|
|
2
2
|
|
|
3
3
|
import { Oas } from '../components/Oas.tsx'
|
|
4
4
|
|
|
5
|
-
import type { FileMetaBase, Plugin, ResolveNameParams } from '@kubb/core'
|
|
5
|
+
import type { FileMetaBase, Group, Plugin, ResolveNameParams } from '@kubb/core'
|
|
6
|
+
|
|
6
7
|
import type * as KubbFile from '@kubb/fs/types'
|
|
7
8
|
import type { Operation, Operation as OperationType } from '@kubb/oas'
|
|
8
9
|
import type { OperationSchemas } from '../types.ts'
|
|
@@ -10,7 +11,7 @@ import type { OperationSchemas } from '../types.ts'
|
|
|
10
11
|
type FileMeta = FileMetaBase & {
|
|
11
12
|
pluginKey: Plugin['key']
|
|
12
13
|
name: string
|
|
13
|
-
|
|
14
|
+
group?: string
|
|
14
15
|
}
|
|
15
16
|
|
|
16
17
|
export type SchemaNames = {
|
|
@@ -41,7 +42,7 @@ type UseOperationManagerResult = {
|
|
|
41
42
|
suffix?: string
|
|
42
43
|
pluginKey?: Plugin['key']
|
|
43
44
|
extname?: KubbFile.Extname
|
|
44
|
-
|
|
45
|
+
group?: string
|
|
45
46
|
},
|
|
46
47
|
) => KubbFile.File<FileMeta>
|
|
47
48
|
groupSchemasByName: (
|
|
@@ -52,6 +53,7 @@ type UseOperationManagerResult = {
|
|
|
52
53
|
},
|
|
53
54
|
) => SchemaNames
|
|
54
55
|
getSchemas: (operation: Operation, params?: { pluginKey?: Plugin['key']; type?: ResolveNameParams['type'] }) => OperationSchemas
|
|
56
|
+
getGroup: (operation: Operation, group: Group | undefined) => string | undefined
|
|
55
57
|
}
|
|
56
58
|
|
|
57
59
|
/**
|
|
@@ -69,6 +71,16 @@ export function useOperationManager(): UseOperationManagerResult {
|
|
|
69
71
|
})
|
|
70
72
|
}
|
|
71
73
|
|
|
74
|
+
const getGroup: UseOperationManagerResult['getGroup'] = (operation, group) => {
|
|
75
|
+
if (group?.type === 'tag') {
|
|
76
|
+
return operation.getTags().at(0)?.name
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
if (group?.type === 'path') {
|
|
80
|
+
return operation.path
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
|
|
72
84
|
const getSchemas: UseOperationManagerResult['getSchemas'] = (operation, params) => {
|
|
73
85
|
if (!generator) {
|
|
74
86
|
throw new Error(`'generator' is not defined`)
|
|
@@ -84,17 +96,17 @@ export function useOperationManager(): UseOperationManagerResult {
|
|
|
84
96
|
})
|
|
85
97
|
}
|
|
86
98
|
|
|
87
|
-
//TODO replace tag with group
|
|
88
99
|
const getFile: UseOperationManagerResult['getFile'] = (
|
|
89
100
|
operation,
|
|
90
|
-
{ prefix, suffix, pluginKey = plugin.key,
|
|
101
|
+
{ prefix, suffix, pluginKey = plugin.key, group = getGroup(operation, (plugin.options as { group?: Group })?.group), extname = '.ts' } = {},
|
|
91
102
|
) => {
|
|
92
103
|
const name = getName(operation, { type: 'file', pluginKey, prefix, suffix })
|
|
104
|
+
|
|
93
105
|
const file = pluginManager.getFile({
|
|
94
106
|
name,
|
|
95
107
|
extname,
|
|
96
108
|
pluginKey,
|
|
97
|
-
options: { type: 'file', pluginKey,
|
|
109
|
+
options: { type: 'file', pluginKey, group },
|
|
98
110
|
})
|
|
99
111
|
|
|
100
112
|
return {
|
|
@@ -103,7 +115,7 @@ export function useOperationManager(): UseOperationManagerResult {
|
|
|
103
115
|
...file.meta,
|
|
104
116
|
name,
|
|
105
117
|
pluginKey,
|
|
106
|
-
|
|
118
|
+
group,
|
|
107
119
|
},
|
|
108
120
|
}
|
|
109
121
|
}
|
|
@@ -198,5 +210,6 @@ export function useOperationManager(): UseOperationManagerResult {
|
|
|
198
210
|
getFile,
|
|
199
211
|
getSchemas,
|
|
200
212
|
groupSchemasByName,
|
|
213
|
+
getGroup,
|
|
201
214
|
}
|
|
202
215
|
}
|
|
@@ -9,12 +9,12 @@ import { type Schema, schemaKeywords } from '../SchemaMapper'
|
|
|
9
9
|
type FileMeta = FileMetaBase & {
|
|
10
10
|
pluginKey: Plugin['key']
|
|
11
11
|
name: string
|
|
12
|
-
|
|
12
|
+
group?: string
|
|
13
13
|
}
|
|
14
14
|
|
|
15
15
|
type UseSchemaManagerResult = {
|
|
16
16
|
getName: (name: string, params: { pluginKey?: Plugin['key']; type: ResolveNameParams['type'] }) => string
|
|
17
|
-
getFile: (name: string, params?: { pluginKey?: Plugin['key']; mode?: Mode; extname?: KubbFile.Extname;
|
|
17
|
+
getFile: (name: string, params?: { pluginKey?: Plugin['key']; mode?: Mode; extname?: KubbFile.Extname; group?: string }) => KubbFile.File<FileMeta>
|
|
18
18
|
getImports: (tree: Array<Schema>) => Array<KubbFile.Import>
|
|
19
19
|
}
|
|
20
20
|
|
|
@@ -31,15 +31,15 @@ export function useSchemaManager(): UseSchemaManagerResult {
|
|
|
31
31
|
type,
|
|
32
32
|
})
|
|
33
33
|
}
|
|
34
|
-
|
|
35
|
-
const getFile: UseSchemaManagerResult['getFile'] = (name, { mode = 'split', pluginKey = plugin.key, extname = '.ts',
|
|
34
|
+
|
|
35
|
+
const getFile: UseSchemaManagerResult['getFile'] = (name, { mode = 'split', pluginKey = plugin.key, extname = '.ts', group } = {}) => {
|
|
36
36
|
const resolvedName = mode === 'single' ? '' : getName(name, { type: 'file', pluginKey })
|
|
37
37
|
|
|
38
38
|
const file = pluginManager.getFile({
|
|
39
39
|
name: resolvedName,
|
|
40
40
|
extname,
|
|
41
41
|
pluginKey,
|
|
42
|
-
options: { type: 'file', pluginKey,
|
|
42
|
+
options: { type: 'file', pluginKey, group },
|
|
43
43
|
})
|
|
44
44
|
|
|
45
45
|
return {
|
package/src/types.ts
CHANGED
package/src/utils/getParams.ts
CHANGED
|
@@ -41,12 +41,18 @@ export function getPathParams(
|
|
|
41
41
|
operationSchema: OperationSchema | undefined,
|
|
42
42
|
options: {
|
|
43
43
|
typed?: boolean
|
|
44
|
+
casing?: 'camelcase'
|
|
44
45
|
override?: (data: FunctionParamsAST) => FunctionParamsAST
|
|
45
46
|
} = {},
|
|
46
47
|
) {
|
|
47
48
|
return getASTParams(operationSchema, options).reduce((acc, curr) => {
|
|
48
49
|
if (curr.name && curr.enabled) {
|
|
49
|
-
|
|
50
|
+
let name = isValidVarName(curr.name) ? curr.name : camelCase(curr.name)
|
|
51
|
+
|
|
52
|
+
if (options.casing === 'camelcase') {
|
|
53
|
+
name = camelCase(name)
|
|
54
|
+
}
|
|
55
|
+
|
|
50
56
|
acc[name] = {
|
|
51
57
|
default: curr.default,
|
|
52
58
|
type: curr.type,
|