@povio/openapi-codegen-cli 0.13.11 → 0.14.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/brands.const.d.ts +8 -0
- package/dist/generators/const/deps.const.d.ts +6 -5
- package/dist/generators/generate/generateZodUtils.d.ts +2 -0
- package/dist/generators/types/generate.d.ts +1 -0
- package/dist/generators/utils/brand.utils.d.ts +7 -0
- package/dist/generators/utils/generate/generate.utils.d.ts +1 -1
- package/dist/generators/utils/generate-files.utils.d.ts +1 -1
- package/dist/index.js +47 -47
- package/dist/sh.js +66 -66
- package/package.json +1 -1
- package/src/generators/templates/endpoints.hbs +3 -3
- package/src/generators/templates/models.hbs +4 -0
- package/src/generators/templates/partials/endpoint-param-parse.hbs +1 -1
- package/src/generators/templates/partials/query-js-docs.hbs +3 -3
- package/src/generators/templates/zod-utils.hbs +80 -0
- package/dist/generators/generate/generateZod.d.ts +0 -2
- package/src/generators/templates/zod.hbs +0 -48
package/package.json
CHANGED
|
@@ -8,9 +8,9 @@
|
|
|
8
8
|
{{#if hasZodImport}}
|
|
9
9
|
{{{genImport zodImport}}}
|
|
10
10
|
{{/if}}
|
|
11
|
-
{{! Zod
|
|
12
|
-
{{#if
|
|
13
|
-
{{{genImport
|
|
11
|
+
{{! Zod utils import }}
|
|
12
|
+
{{#if hasZodUtilsImport}}
|
|
13
|
+
{{{genImport zodUtilsImport}}}
|
|
14
14
|
{{/if}}
|
|
15
15
|
{{! Models import }}
|
|
16
16
|
{{#each modelsImports as | modelsImport |}}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{{
|
|
1
|
+
{{zodUtilsNamespace}}.{{parse}}({{#if param.parameterSortingEnumSchemaName}}{{zodUtilsNamespace}}.{{sortExp}}({{{importedZodSchemaName param.parameterSortingEnumSchemaName}}}){{#if addOptional}}.optional(){{/if}}{{else}}{{{importedZodSchemaName param.zodSchema}}}{{#if addOptional}}.optional(){{/if}}{{/if}}, {{paramName}}{{#if isQuery}}, { type: "query", name: "{{paramName}}" }{{/if}})
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
* @summary {{addAsteriskAfterNewLine endpoint.summary}}{{/if}}{{#if endpoint.description}}
|
|
5
5
|
* @description {{addAsteriskAfterNewLine endpoint.description}}{{/if}}{{#if endpoint.acl}}
|
|
6
6
|
* @permission Requires `{{abilityFunctionName endpoint}}` ability {{/if}}
|
|
7
|
-
{{#if (endpointParams endpoint)}}{{#each (endpointParams endpoint infiniteQuery excludePageParam=true) as | endpointParam |}} * @param { {{endpointParam.type}} } object.{{endpointParam.name}} {{{endpointParamDescription endpointParam}}}
|
|
7
|
+
{{#if (endpointParams endpoint)}}{{#each (endpointParams endpoint infiniteQuery excludePageParam=true) as | endpointParam |}} * @param { {{{endpointParam.type}}} } object.{{endpointParam.name}} {{{endpointParamDescription endpointParam}}}
|
|
8
8
|
{{/each}}{{/if}} * @param { AppInfiniteQueryOptions } options Infinite query options
|
|
9
9
|
* @returns { UseInfiniteQueryResult<{{{importedZodSchemaInferedType endpoint.response}}}> } {{endpoint.responseDescription}}
|
|
10
10
|
* @statusCodes [{{commaSeparated endpoint.responseStatusCodes}}]
|
|
@@ -14,7 +14,7 @@
|
|
|
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
|
-
{{#if (endpointParams endpoint includeFileParam=true)}}{{#each (endpointParams endpoint includeFileParam=true) as | endpointParam |}} * @param { {{endpointParam.type}} } object.{{endpointParam.name}} {{{endpointParamDescription endpointParam}}}
|
|
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
19
|
* @returns { UseQueryResult<{{#if endpoint.mediaDownload}}AxiosResponse<{{/if}}{{{importedZodSchemaInferedType endpoint.response}}}{{#if endpoint.mediaDownload}}>{{/if}}> } {{endpoint.responseDescription}}
|
|
20
20
|
* @statusCodes [{{commaSeparated endpoint.responseStatusCodes}}]
|
|
@@ -24,7 +24,7 @@
|
|
|
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
|
-
{{#if (endpointParams endpoint includeFileParam=true)}}{{#each (endpointParams endpoint includeFileParam=true) as | endpointParam |}} * @param { {{endpointParam.type}} } mutation.{{endpointParam.name}} {{{endpointParamDescription endpointParam}}}
|
|
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 hasMutationEffects}} & {{mutationEffectsType}}{{/if}} } options Mutation options
|
|
29
29
|
* @returns { UseMutationResult<{{#if endpoint.mediaDownload}}AxiosResponse<{{/if}}{{{importedZodSchemaInferedType endpoint.response}}}{{#if endpoint.mediaDownload}}>{{/if}}> } {{endpoint.responseDescription}}
|
|
30
30
|
* @statusCodes [{{commaSeparated endpoint.responseStatusCodes}}]
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
/* eslint-disable no-underscore-dangle, no-useless-escape */
|
|
2
|
+
{{! Zod import }}
|
|
3
|
+
{{{genImport zodImport}}}
|
|
4
|
+
{{! Error handling import }}
|
|
5
|
+
{{{genImport errorHandlingImport}}}
|
|
6
|
+
|
|
7
|
+
interface ParseOptions {
|
|
8
|
+
type: "body" | "query";
|
|
9
|
+
name?: string;
|
|
10
|
+
errorHandler?: ErrorHandler<never>;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
function is{{capitalize sortExp}}Valid(enumSchema: z.ZodEnum<[string, ...string[]]>, data?: string) {
|
|
14
|
+
if (data === undefined || data === "" || enumSchema.options.length === 0) {
|
|
15
|
+
return true;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
const prefixedEnumOptions = `([+-]?(${enumSchema.options.join("|")}))`;
|
|
19
|
+
const commaSeparatedOptions = `(${prefixedEnumOptions})(\s*,\s*${prefixedEnumOptions})*`;
|
|
20
|
+
return new RegExp(`^${commaSeparatedOptions}$`).test(data);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
const ZOD_UTILS_BRAND: unique symbol = Symbol("__zod_utils_brand");
|
|
24
|
+
|
|
25
|
+
export namespace {{zodUtilsNamespace}} {
|
|
26
|
+
export function {{parse}}<T>(schema: z.ZodSchema<T>, data: unknown, { type, name, errorHandler }: ParseOptions = { type: "body" }) {
|
|
27
|
+
try {
|
|
28
|
+
return schema.parse(data);
|
|
29
|
+
} catch (e) {
|
|
30
|
+
if (e instanceof z.ZodError) {
|
|
31
|
+
e.name = `FE Request ${type === "body" ? "body" : "query param"}${name ? ` ("${name}")` : ""} schema mismatch - ZodError`;
|
|
32
|
+
}
|
|
33
|
+
(errorHandler ?? {{sharedErrorHandler}}).rethrowError(e);
|
|
34
|
+
throw e;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export const {{sortExp}} = (enumSchema: z.ZodEnum<[string, ...string[]]>) =>
|
|
39
|
+
z.string().superRefine((arg, ctx) => {
|
|
40
|
+
if (!is{{capitalize sortExp}}Valid(enumSchema, arg)) {
|
|
41
|
+
ctx.addIssue({
|
|
42
|
+
code: z.ZodIssueCode.custom,
|
|
43
|
+
message: "Invalid sorting string.",
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
export interface ZodBrand<T extends string | number | symbol> {
|
|
49
|
+
readonly [ZOD_UTILS_BRAND]: T;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
export class ZodBranded<T extends z.ZodTypeAny, B extends string | number | symbol> extends z.ZodType<
|
|
53
|
+
T["_output"] | (T["_output"] & ZodBrand<B>),
|
|
54
|
+
z.ZodTypeDef,
|
|
55
|
+
T["_input"]
|
|
56
|
+
> {
|
|
57
|
+
readonly _schema: T;
|
|
58
|
+
|
|
59
|
+
readonly _brand: B;
|
|
60
|
+
|
|
61
|
+
constructor(_schema: T, _brand: B) {
|
|
62
|
+
super(_schema._def);
|
|
63
|
+
this._schema = _schema;
|
|
64
|
+
this._brand = _brand;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
_parse(input: z.ParseInput) {
|
|
68
|
+
return this._schema._parse(input);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
export type ExtractZodBrand<T> = T extends ZodBrand<infer B> ? B : never;
|
|
73
|
+
|
|
74
|
+
export function {{brand}}<T extends z.ZodTypeAny, B extends string | number | symbol>(
|
|
75
|
+
schema: T,
|
|
76
|
+
_brand: B,
|
|
77
|
+
): ZodBranded<T, B> {
|
|
78
|
+
return new ZodBranded(schema, _brand);
|
|
79
|
+
}
|
|
80
|
+
}
|
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
/* eslint-disable no-useless-escape */
|
|
2
|
-
{{! Zod import }}
|
|
3
|
-
{{{genImport zodImport}}}
|
|
4
|
-
{{! Error handling import }}
|
|
5
|
-
{{{genImport errorHandlingImport}}}
|
|
6
|
-
|
|
7
|
-
export const {{zodExtension}} = {
|
|
8
|
-
{{sortingString}}: (enumSchema: z.ZodEnum<[string, ...string[]]>) =>
|
|
9
|
-
z
|
|
10
|
-
.string()
|
|
11
|
-
.superRefine((arg, ctx) => {
|
|
12
|
-
if (!isSortingStringValid(enumSchema, arg)) {
|
|
13
|
-
ctx.addIssue({
|
|
14
|
-
code: z.ZodIssueCode.custom,
|
|
15
|
-
message: "Invalid sorting string.",
|
|
16
|
-
});
|
|
17
|
-
}
|
|
18
|
-
}),
|
|
19
|
-
{{parse}},
|
|
20
|
-
};
|
|
21
|
-
|
|
22
|
-
function isSortingStringValid(enumSchema: z.ZodEnum<[string, ...string[]]>, data?: string) {
|
|
23
|
-
if (data === undefined || data === "" || enumSchema.options.length === 0) {
|
|
24
|
-
return true;
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
const prefixedEnumOptions = `([+-]?(${enumSchema.options.join("|")}))`;
|
|
28
|
-
const commaSeparatedOptions = `(${prefixedEnumOptions})(\s*,\s*${prefixedEnumOptions})*`;
|
|
29
|
-
return new RegExp(`^${commaSeparatedOptions}$`).test(data);
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
interface ParseOptions {
|
|
33
|
-
type: "body" | "query";
|
|
34
|
-
name?: string;
|
|
35
|
-
errorHandler?: {{errorHandler}}<never>;
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
function {{parse}}<T>(schema: z.ZodSchema<T>, data: unknown, { type, name, errorHandler }: ParseOptions = { type: "body" }) {
|
|
39
|
-
try {
|
|
40
|
-
return schema.parse(data);
|
|
41
|
-
} catch (e) {
|
|
42
|
-
if (e instanceof z.ZodError) {
|
|
43
|
-
e.name = `FE Request ${type === "body" ? "body" : "query param"}${name ? ` ("${name}")` : ""} schema mismatch - ZodError`;
|
|
44
|
-
}
|
|
45
|
-
(errorHandler ?? {{sharedErrorHandler}}).rethrowError(e);
|
|
46
|
-
throw e;
|
|
47
|
-
}
|
|
48
|
-
}
|