Skip to content

Commit

Permalink
Generics: Definition tests
Browse files Browse the repository at this point in the history
  • Loading branch information
WoH committed Sep 5, 2019
1 parent ea46476 commit 3b67358
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
2 changes: 2 additions & 0 deletions tests/fixtures/testModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -438,6 +438,8 @@ export class TestClassModel extends TestClassBaseModel {

export interface GenericModel<T> {
result: T;
union?: T | string;
nested?: GenericRequest<T>;
}

export interface GenericRequest<T> {
Expand Down
11 changes: 11 additions & 0 deletions tests/unit/swagger/definitionsGeneration/definitions.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -750,6 +750,17 @@ describe('Definition generation', () => {
}
expect((property.items as Swagger.Schema).type).to.equal('string');
});
it('should propagate generics', () => {
const definition = getValidatedDefinition('GenericModelTestModelArray', currentSpec).properties;

expect(definition!.result).to.deep.equal({ items: { $ref: '#/definitions/TestModel' }, type: 'array', description: undefined, format: undefined, default: undefined });
expect(definition!.union).to.deep.equal({ type: 'object', description: undefined, format: undefined, default: undefined, 'x-nullable': true });
expect(definition!.nested).to.deep.equal({ $ref: '#/definitions/GenericRequestTestModelArray', description: undefined, format: undefined, 'x-nullable': true });

const ref = getValidatedDefinition('GenericRequestTestModelArray', currentSpec).properties;
expect(ref!.name).to.deep.equal({ type: 'string', description: undefined, format: undefined, default: undefined });
expect(ref!.value).to.deep.equal({ items: { $ref: '#/definitions/TestModel' }, type: 'array', description: undefined, format: undefined, default: undefined });
});
});
});
});
Expand Down

0 comments on commit 3b67358

Please sign in to comment.