Skip to content

Commit 91394c2

Browse files
committed
Skip root types generation for enum and still trim Schema prefix if needed
1 parent 31054dc commit 91394c2

File tree

3 files changed

+9
-7
lines changed

3 files changed

+9
-7
lines changed

Diff for: .gitignore

-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
dist
44
node_modules
55
coverage
6-
mise.toml
76

87
packages/openapi-typescript/test/fixtures/cli-outputs/out
98

Diff for: packages/openapi-typescript/src/transform/components-object.ts

+6-3
Original file line numberDiff line numberDiff line change
@@ -80,9 +80,12 @@ export default function transformComponentsObject(componentsObject: ComponentsOb
8080
}
8181

8282
const ref = ts.factory.createTypeReferenceNode(`components['${key}']['${name}']`);
83-
// We skip schema prefix replacement when --enum flag is present
84-
if (ctx.rootTypesNoSchemaPrefix && key === "schemas" && !ctx.enum) {
85-
aliasName = aliasName.replace(componentKey, "");
83+
if (ctx.rootTypesNoSchemaPrefix && key === "schemas") {
84+
// Skipping --root-types generation only for enums if --enum is set
85+
// while still applying --root-types-no-schema-prefix to other types.
86+
if (!(ctx.enum && item.enum !== undefined)) {
87+
aliasName = aliasName.replace(componentKey, "");
88+
}
8689
}
8790
const typeAlias = ts.factory.createTypeAliasDeclaration(
8891
/* modifiers */ tsModifiers({ export: true }),

Diff for: packages/openapi-typescript/test/transform/components-object.test.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -820,9 +820,9 @@ export type Error = components['schemas']['Error'];
820820
headers: never;
821821
pathItems: never;
822822
}
823-
export type SchemaItem = components['schemas']['Item'];
824-
export type SchemaDocument = components['schemas']['Document'];
825-
export type SchemaError = components['schemas']['Error'];
823+
export type Item = components['schemas']['Item'];
824+
export type Document = components['schemas']['Document'];
825+
export type Error = components['schemas']['Error'];
826826
export type SchemaMyEnum = components['schemas']['MyEnum'];
827827
`,
828828
options: { ...DEFAULT_OPTIONS, rootTypes: true, rootTypesNoSchemaPrefix: true, enum: true },

0 commit comments

Comments
 (0)