@povio/openapi-codegen-cli 0.8.2 → 0.9.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/generators/const/deps.const.d.ts +7 -0
- package/dist/generators/const/zod.const.d.ts +1 -0
- package/dist/generators/core/SchemaResolver.class.d.ts +3 -10
- package/dist/generators/core/endpoints/getEndpointParameter.d.ts +2 -1
- package/dist/generators/core/zod/getZodSchema.d.ts +1 -0
- package/dist/generators/utils/generate/generate.endpoints.utils.d.ts +3 -2
- package/dist/generators/utils/generate/generate.utils.d.ts +1 -0
- package/dist/generators/utils/generate/generate.zod.utils.d.ts +1 -1
- package/dist/generators/utils/openapi-schema.utils.d.ts +1 -0
- package/dist/generators/utils/openapi.utils.d.ts +2 -2
- package/dist/generators/utils/string.utils.d.ts +1 -0
- package/dist/index.js +42 -42
- package/dist/sh.js +61 -61
- package/package.json +1 -1
- package/src/assets/zodExtended.ts +24 -0
- package/src/generators/templates/endpoints.hbs +4 -0
- package/src/generators/templates/partials/endpoint-config.hbs +2 -2
- package/src/generators/templates/partials/endpoint-param-sorting.hbs +1 -0
- package/src/generators/templates/partials/query-js-docs.hbs +4 -4
- package/src/generators/templates/partials/query-use-mutation.hbs +2 -2
package/package.json
CHANGED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/* eslint-disable no-useless-escape */
|
|
2
|
+
import { z } from "zod";
|
|
3
|
+
|
|
4
|
+
export const zodExtended = {
|
|
5
|
+
sortingString: (enumSchema: z.ZodEnum<[string, ...string[]]>) =>
|
|
6
|
+
z.string().superRefine((val, ctx) => {
|
|
7
|
+
if (!isSortingStringValid(val, enumSchema)) {
|
|
8
|
+
ctx.addIssue({
|
|
9
|
+
code: z.ZodIssueCode.custom,
|
|
10
|
+
message: "Invalid order string.",
|
|
11
|
+
});
|
|
12
|
+
}
|
|
13
|
+
}),
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
function isSortingStringValid(val: string, enumSchema: z.ZodEnum<[string, ...string[]]>) {
|
|
17
|
+
if (val === "" || enumSchema.options.length === 0) {
|
|
18
|
+
return true;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
const prefixedEnumOptions = `([+-]?(${enumSchema.options.join("|")}))`;
|
|
22
|
+
const commaSeparatedOptions = `(${prefixedEnumOptions})(\s*,\s*${prefixedEnumOptions})*`;
|
|
23
|
+
return new RegExp(`^${commaSeparatedOptions}$`).test(val);
|
|
24
|
+
}
|
|
@@ -8,6 +8,10 @@
|
|
|
8
8
|
{{#if hasZodImport}}
|
|
9
9
|
{{{genImport zodImport}}}
|
|
10
10
|
{{/if}}
|
|
11
|
+
{{! Zod extended import }}
|
|
12
|
+
{{#if hasZodExtendedImport}}
|
|
13
|
+
{{{genImport zodExtendedImport}}}
|
|
14
|
+
{{/if}}
|
|
11
15
|
{{! Models import }}
|
|
12
16
|
{{#each modelsImports as | modelsImport |}}
|
|
13
17
|
{{{genImport modelsImport}}}
|
|
@@ -7,9 +7,9 @@
|
|
|
7
7
|
params: {
|
|
8
8
|
{{#each endpointConfig.params as | param |}}
|
|
9
9
|
{{#if (isEqual param.name param.value) }}
|
|
10
|
-
{{{param.name}}},
|
|
10
|
+
{{{param.name}}}{{#if param.parameterSortingEnumSchemaName}}: {{{genEndpointParamSorting param.parameterSortingEnumSchemaName param.name}}}{{/if}},
|
|
11
11
|
{{else}}
|
|
12
|
-
{{{param.name}}}: {{param.value}},
|
|
12
|
+
{{{param.name}}}: {{#if param.parameterSortingEnumSchemaName}}{{{genEndpointParamSorting param.parameterSortingEnumSchemaName param.value}}}{{else}}{{param.value}}{{/if}},
|
|
13
13
|
{{/if}}
|
|
14
14
|
{{/each}}
|
|
15
15
|
},
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{{zodExtended}}.{{sortingString}}({{importedZodSchemaName enumSchemaName}}).parse({{paramName}})
|
|
@@ -10,22 +10,22 @@
|
|
|
10
10
|
* @statusCodes [{{commaSeparated endpoint.responseStatusCodes}}]
|
|
11
11
|
*/{{else if query}}
|
|
12
12
|
/**
|
|
13
|
-
* Query `{{queryName endpoint}}`{{#if endpoint.summary}}{{#if endpoint.
|
|
13
|
+
* Query `{{queryName endpoint}}`{{#if endpoint.summary}}{{#if endpoint.mediaDownload}} - recommended when file should be cached{{/if}}
|
|
14
14
|
* @summary {{addAsteriskAfterNewLine endpoint.summary}}{{/if}}{{#if endpoint.description}}
|
|
15
15
|
* @description {{addAsteriskAfterNewLine endpoint.description}}{{/if}}{{#if endpoint.acl}}
|
|
16
16
|
* @permission Requires `{{abilityFunctionName endpoint}}` ability {{/if}}
|
|
17
17
|
{{#if (endpointParams endpoint includeFileParam=true)}}{{#each (endpointParams endpoint includeFileParam=true) as | endpointParam |}} * @param { {{endpointParam.type}} } object.{{endpointParam.name}} {{{endpointParamDescription endpointParam}}}
|
|
18
18
|
{{/each}}{{/if}} * @param { AppQueryOptions } options Query options
|
|
19
|
-
* @returns { UseQueryResult<{{#if endpoint.
|
|
19
|
+
* @returns { UseQueryResult<{{#if endpoint.mediaDownload}}AxiosResponse<{{/if}}{{{importedZodSchemaInferedType endpoint.response}}}{{#if endpoint.mediaDownload}}>{{/if}}> } {{endpoint.responseDescription}}
|
|
20
20
|
* @statusCodes [{{commaSeparated endpoint.responseStatusCodes}}]
|
|
21
21
|
*/{{else if mutation}}
|
|
22
22
|
/**
|
|
23
|
-
* Mutation `{{queryName endpoint mutation=true}}`{{#if endpoint.summary}}{{#if endpoint.
|
|
23
|
+
* Mutation `{{queryName endpoint mutation=true}}`{{#if endpoint.summary}}{{#if endpoint.mediaDownload}} - recommended when file should not be cached{{/if}}
|
|
24
24
|
* @summary {{addAsteriskAfterNewLine endpoint.summary}}{{/if}}{{#if endpoint.description}}
|
|
25
25
|
* @description {{addAsteriskAfterNewLine endpoint.description}}{{/if}}{{#if endpoint.acl}}
|
|
26
26
|
* @permission Requires `{{abilityFunctionName endpoint}}` ability {{/if}}
|
|
27
27
|
{{#if (endpointParams endpoint includeFileParam=true)}}{{#each (endpointParams endpoint includeFileParam=true) as | endpointParam |}} * @param { {{endpointParam.type}} } mutation.{{endpointParam.name}} {{{endpointParamDescription endpointParam}}}
|
|
28
28
|
{{/each}}{{/if}} * @param { AppMutationOptions{{#if hasInvalidateQueryOptions}} & {{invalidateQueryOptionsType}}{{/if}} } options Mutation options
|
|
29
|
-
* @returns { UseMutationResult<{{#if endpoint.
|
|
29
|
+
* @returns { UseMutationResult<{{#if endpoint.mediaDownload}}AxiosResponse<{{/if}}{{{importedZodSchemaInferedType endpoint.response}}}{{#if endpoint.mediaDownload}}>{{/if}}> } {{endpoint.responseDescription}}
|
|
30
30
|
* @statusCodes [{{commaSeparated endpoint.responseStatusCodes}}]
|
|
31
31
|
*/{{/if}}
|
|
@@ -5,8 +5,8 @@ export const {{queryName endpoint mutation=true}} = (options?: AppMutationOption
|
|
|
5
5
|
{{#if hasInvalidateQueryOptions}} const queryClient = useQueryClient();{{/if}}
|
|
6
6
|
|
|
7
7
|
return {{queryHook}}({
|
|
8
|
-
mutationFn: {{#if endpoint.
|
|
9
|
-
const uploadInstructions = await{{/if}} {{importedEndpointName endpoint}}({{{endpointArgs endpoint}}}{{#if hasAxiosRequestConfig}}{{#if (endpointArgs endpoint)}}, {{/if}}{{axiosRequestConfigName}}{{/if}}){{#if endpoint.
|
|
8
|
+
mutationFn: {{#if endpoint.mediaUpload}}async {{/if}}({{#if (endpointParams endpoint includeFileParam=true)}} { {{{endpointArgs endpoint includeFileParam=true}}} } {{/if}}) => {{#if endpoint.mediaUpload}} {
|
|
9
|
+
const uploadInstructions = await{{/if}} {{importedEndpointName endpoint}}({{{endpointArgs endpoint}}}{{#if hasAxiosRequestConfig}}{{#if (endpointArgs endpoint)}}, {{/if}}{{axiosRequestConfigName}}{{/if}}){{#if endpoint.mediaUpload}};
|
|
10
10
|
|
|
11
11
|
if (file && uploadInstructions.url) {
|
|
12
12
|
await axios.put(uploadInstructions.url, file, {
|