Skip to content

Commit 737b270

Browse files
committed
fix: add replace in getRefTypeName()
1 parent 910ab16 commit 737b270

File tree

4 files changed

+15
-1
lines changed

4 files changed

+15
-1
lines changed

src/metadataGeneration/typeResolver.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -515,7 +515,8 @@ export class TypeResolver {
515515
.replace(/\[\]/g, 'Array')
516516
.replace(/{|}/g, '_') // SuccessResponse_{indexesCreated-number}_ -> SuccessResponse__indexesCreated-number__
517517
.replace(/([a-z]+):([a-z]+)/gi, '$1-$2') // SuccessResponse_indexesCreated:number_ -> SuccessResponse_indexesCreated-number_
518-
.replace(/;/g, '--'),
518+
.replace(/;/g, '--')
519+
.replace(/([a-z]+)\[([a-z]+)\]/gi, '$1~$2~'), // Partial_SerializedDatasourceWithVersion[format]_ -> Partial_SerializedDatasourceWithVersion~format~_,
519520
);
520521
}
521522

tests/fixtures/testModel.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ export interface TestModel extends Model {
6161
anyType?: any;
6262
unknownType?: unknown;
6363
genericTypeObject?: Generic<{ foo: string; bar: boolean }>;
64+
indexed?: Partial<Indexed['foo']>;
6465
// modelsObjectDirect?: {[key: string]: TestSubModel2;};
6566
modelsObjectIndirect?: TestSubModelContainer;
6667
modelsObjectIndirectNS?: TestSubModelContainerNamespace.TestSubModelContainer;
@@ -151,6 +152,12 @@ interface Generic<T> {
151152
foo: T;
152153
}
153154

155+
interface Indexed {
156+
foo: {
157+
bar: string;
158+
};
159+
}
160+
154161
type Maybe<T> = T | null;
155162

156163
export interface TypeAliasModel1 {

tests/unit/swagger/definitionsGeneration/definitions.spec.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -402,6 +402,9 @@ describe('Definition generation', () => {
402402
genericTypeObject: (propertyName, propertySchema) => {
403403
expect(propertySchema.$ref).to.eq('#/definitions/Generic__foo-string--bar-boolean__');
404404
},
405+
indexed: (propertyName, propertySchema) => {
406+
expect(propertySchema.$ref).to.eq('#/definitions/Partial_Indexed~foo~_');
407+
},
405408
modelsObjectIndirect: (propertyName, propertySchema) => {
406409
expect(propertySchema.$ref).to.eq('#/definitions/TestSubModelContainer', `for property ${propertyName}.$ref`);
407410
expect(propertySchema).to.not.haveOwnProperty('additionalProperties', `for property ${propertyName}`);

tests/unit/swagger/schemaDetails3.spec.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -589,6 +589,9 @@ describe('Definition generation for OpenAPI 3.0.0', () => {
589589
genericTypeObject: (propertyName, propertySchema) => {
590590
expect(propertySchema.$ref).to.eq('#/components/schemas/Generic__foo-string--bar-boolean__');
591591
},
592+
indexed: (propertyName, propertySchema) => {
593+
expect(propertySchema.$ref).to.eq('#/components/schemas/Partial_Indexed~foo~_');
594+
},
592595
modelsObjectIndirect: (propertyName, propertySchema) => {
593596
expect(propertySchema.$ref).to.eq('#/components/schemas/TestSubModelContainer', `for property ${propertyName}.$ref`);
594597
expect(propertySchema).to.not.haveOwnProperty('additionalProperties', `for property ${propertyName}`);

0 commit comments

Comments
 (0)