We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 1bbbfdc commit 83878ebCopy full SHA for 83878eb
bin/index.js
@@ -20,6 +20,7 @@ const params = program
20
.option('--exportServices <value>', 'Write services to disk', true)
21
.option('--exportModels <value>', 'Write models to disk', true)
22
.option('--exportSchemas <value>', 'Write schemas to disk', false)
23
+ .option('--exportOptions <value>', `Write function's options to disk`, false)
24
.option('--indent <value>', 'Indentation options [4, 2, tabs]', '4')
25
.option('--postfixServices <value>', 'Service name postfix', 'Service')
26
.option('--postfixModels <value>', 'Model name postfix')
@@ -41,6 +42,7 @@ if (OpenAPI) {
41
42
exportServices: JSON.parse(params.exportServices) === true,
43
exportModels: JSON.parse(params.exportModels) === true,
44
exportSchemas: JSON.parse(params.exportSchemas) === true,
45
+ exportOptions: JSON.parse(params.exportOptions) === true,
46
indent: params.indent,
47
postfixServices: params.postfixServices,
48
postfixModels: params.postfixModels,
bin/index.spec.js
@@ -32,6 +32,8 @@ describe('bin', () => {
32
'true',
33
'--exportSchemas',
34
35
+ '--exportOptions',
36
+ 'true',
37
'--indent',
38
'4',
39
'--postfixServices',
src/client/interfaces/Operation.d.ts
@@ -5,6 +5,7 @@ import type { OperationResponse } from './OperationResponse';
5
export interface Operation extends OperationParameters {
6
service: string;
7
name: string;
8
+ optionsTypeName: string;
9
summary: string | null;
10
description: string | null;
11
deprecated: boolean;
src/index.ts
@@ -23,6 +23,7 @@ export type Options = {
exportServices?: boolean;
exportModels?: boolean;
exportSchemas?: boolean;
+ exportOptions?: boolean;
27
indent?: Indent;
28
postfixServices?: string;
29
postfixModels?: string;
@@ -44,6 +45,7 @@ export type Options = {
* @param exportServices Generate services
* @param exportModels Generate models
* @param exportSchemas Generate schemas
+ * @param exportOptions Generate function's options
49
* @param indent Indentation options (4, 2 or tab)
50
* @param postfixServices Service name postfix
51
* @param postfixModels Model name postfix
@@ -61,6 +63,7 @@ export const generate = async ({
61
63
exportServices = true,
62
64
exportModels = true,
65
exportSchemas = false,
66
+ exportOptions = false,
67
indent = Indent.SPACE_4,
68
postfixServices = 'Service',
69
postfixModels = '',
@@ -91,6 +94,7 @@ export const generate = async ({
91
94
exportServices,
92
95
exportModels,
93
96
exportSchemas,
97
+ exportOptions,
98
indent,
99
postfixServices,
100
postfixModels,
@@ -115,6 +119,7 @@ export const generate = async ({
115
119
116
120
117
121
122
118
123
124
125
src/openApi/v2/parser/getOperation.ts
@@ -1,3 +1,5 @@
1
+import camelCase from 'camelcase';
2
+
3
import type { Operation } from '../../../client/interfaces/Operation';
4
import type { OperationParameters } from '../../../client/interfaces/OperationParameters';
import type { OpenApi } from '../interfaces/OpenApi';
@@ -26,6 +28,7 @@ export const getOperation = (
const operation: Operation = {
service: serviceName,
30
name: operationName,
31
+ optionsTypeName: camelCase([operationName, 'Options'], { pascalCase: true }),
summary: op.summary || null,
description: op.description || null,
deprecated: op.deprecated === true,
src/openApi/v3/parser/getOperation.ts
@@ -29,6 +31,7 @@ export const getOperation = (
src/templates/exportService.hbs
@@ -31,6 +31,30 @@ import { OpenAPI } from '../core/OpenAPI';
import { request as __request } from '../core/request';
{{/if}}
+{{#if @root.useOptions }}
+{{#if @root.exportOptions }}
+{{#each operations}}
+{{#if parameters}}
+export type {{{optionsTypeName}}} = {
+{{#each parameters}}
40
+{{#ifdef description deprecated}}
+ /**
+{{#if description}}
+ * {{{escapeComment description}}}
+{{/if}}
+{{#if deprecated}}
+ * @deprecated
+ */
+{{/ifdef}}
+ {{{name}}}{{>isRequired}}: {{>type}},
+{{/each}}
52
+};
53
54
55
56
57
58
{{#equals @root.httpClient 'angular'}}
59
@Injectable({
60
providedIn: 'root',
src/templates/index.hbs
@@ -41,7 +41,7 @@ export { ${{{name}}} } from './schemas/${{{name}}}';
{{#if services}}
{{#each services}}
-export { {{{name}}}{{{@root.postfixServices}}} } from './services/{{{name}}}{{{@root.postfixServices}}}';
+export { {{{name}}}{{{@root.postfixServices}}}{{#if @root.useOptions}}{{#if @root.exportOptions}}{{#each operations}}{{#if parameters}}, {{{ optionsTypeName }}}{{/if}}{{/each}}{{/if}}{{/if}} } from './services/{{{name}}}{{{@root.postfixServices}}}';
{{/each}}
src/templates/partials/parameters.hbs
@@ -4,7 +4,7 @@
{{#each parameters}}
{{{name}}}{{#if default}} = {{{default}}}{{/if}},
-}: {
+}: {{#if @root.exportOptions~}}{{{ optionsTypeName }}}{{~else}}{
{{#ifdef description deprecated}}
/**
@@ -19,6 +19,7 @@
19
{{{name}}}{{>isRequired}}: {{>type}},
}
{{~else}}
src/utils/writeClient.spec.ts
@@ -47,6 +47,7 @@ describe('writeClient', () => {
true,
+ false,
Indent.SPACE_4,
'Service',
'AppClient'
0 commit comments