@povio/openapi-codegen-cli 0.8.3 → 0.9.1

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@povio/openapi-codegen-cli",
3
- "version": "0.8.3",
3
+ "version": "0.9.1",
4
4
  "main": "./dist/index.js",
5
5
  "bin": {
6
6
  "openapi-codegen": "./dist/sh.js"
@@ -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 sorting 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}})