Skip to content

Commit f07e518

Browse files
authored
Merge pull request #13 from moznion/replace_hyphen_in_schema_name
Replace hyphens in generated schema names
2 parents 0b42c5f + f10c0f2 commit f07e518

File tree

4 files changed

+14
-2
lines changed

4 files changed

+14
-2
lines changed

src/index.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,8 +92,9 @@ function generateSchemaTypes(
9292
for (const schema of schemasType.getProperties()) {
9393
const schemaType = schema.getValueDeclaration()?.getType();
9494
if (schemaType) {
95-
const schemaName =
96-
schema.getName() === "Client" ? "ClientSchema" : schema.getName();
95+
const schemaName = (
96+
schema.getName() === "Client" ? "ClientSchema" : schema.getName()
97+
).replaceAll(/-/g, "_");
9798
types.push(`export type ${schemaName} = ${schemaType.getText()};`);
9899
}
99100
}

src/test_resources/expected_client.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -335,3 +335,4 @@ export type BulkJobStatus = {
335335
total: number;
336336
};
337337
export type ClientSchema = { id?: string };
338+
export type schema_Something = { id?: string };

src/test_resources/schema.d.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -531,6 +531,9 @@ export interface components {
531531
Client: {
532532
id?: string;
533533
};
534+
"schema-Something": {
535+
id?: string;
536+
};
534537
};
535538
responses: {
536539
/** @description Bad request due to invalid input */

src/test_resources/schema.yaml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -530,3 +530,10 @@ components:
530530
id:
531531
type: string
532532

533+
# this is dummy schema to check hyphen replacement
534+
schema-Something:
535+
type: object
536+
properties:
537+
id:
538+
type: string
539+

0 commit comments

Comments
 (0)