Skip to content

Commit aaac821

Browse files
committed
Import path fix & Circular zod type todo comment
1 parent 498a614 commit aaac821

4 files changed

Lines changed: 5 additions & 5 deletions

File tree

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@povio/openapi-codegen-cli",
3-
"version": "0.3.6",
3+
"version": "0.3.7",
44
"main": "./dist/index.js",
55
"bin": {
66
"openapi-codegen": "./dist/sh.js"

src/generators/templates/models.hbs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ export namespace {{namespace}} {
1010
{{/if}}
1111
{{#each zodSchemasData as | zodSchema |}}
1212
{{! Zod schema export }}
13+
{{#if zodSchema.isCircular}}// TODO: Fix type inference {{/if}}
1314
export const {{@key}}{{#if zodSchema.isCircular}}: z.ZodType<unknown>{{/if}} = {{{zodSchema.code}}};
1415
{{! Zod schema infered type export }}
1516
export type {{zodInferedType @key}} = z.infer<typeof {{@key}}>;

src/generators/utils/generate/generate.imports.utils.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ describe("Utils: generate imports", () => {
1515
expect(getImportPath({ output: "src/data/auto-gen", importPath: "ts" })).toEqual("@/data/auto-gen/");
1616
expect(getImportPath({ output: "src/data/auto-gen", importPath: "relative" })).toEqual("../");
1717
expect(getImportPath({ output: "src/data/auto-gen", importPath: "absolute" })).toEqual("src/data/auto-gen/");
18-
expect(getImportPath({ output: "frontend/src/data/auto-gen", importPath: "ts" })).toEqual("@/data/");
18+
expect(getImportPath({ output: "frontend/src/data/auto-gen", importPath: "ts" })).toEqual("@/data/auto-gen/");
1919
expect(getImportPath({ output: "frontend/src/data/auto-gen", importPath: "relative" })).toEqual("../");
2020
expect(getImportPath({ output: "frontend/src/data/auto-gen", importPath: "absolute" })).toEqual(
2121
"frontend/src/data/auto-gen/",

src/generators/utils/generate/generate.imports.utils.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,13 +65,12 @@ export function getEndpointsImports({
6565

6666
export function getImportPath(options: Pick<GenerateOptions, "output" | "importPath">) {
6767
let importPath = DATA_TS_PATH;
68-
const regex = new RegExp(`^${DATA_FILE_PATH}`, "g");
6968
if (options.importPath === "relative") {
7069
importPath = "../";
7170
} else if (options.importPath === "absolute") {
7271
importPath = options.output;
73-
} else if (regex.test(options.output)) {
74-
importPath = options.output.replace(regex, DATA_TS_PATH);
72+
} else if (new RegExp(`${DATA_FILE_PATH}`, "g").test(options.output)) {
73+
importPath = options.output.replace(new RegExp(`.*${DATA_FILE_PATH}`, "g"), DATA_TS_PATH);
7574
}
7675
return `${importPath}/`.replace(/\/\//g, "/");
7776
}

0 commit comments

Comments
 (0)