Skip to content

Commit

Permalink
Merge pull request #810 from nartc/bugfix/fix-array-enum-on-model
Browse files Browse the repository at this point in the history
fix(lib): fix enum array on model properties
  • Loading branch information
kamilmysliwiec committed Jun 18, 2020
2 parents 67f9c2f + e417a7a commit 7a208fd
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
7 changes: 6 additions & 1 deletion lib/services/schema-object-factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -317,8 +317,13 @@ export class SchemaObjectFactory {

const refHost = metadata.isArray ? { items: { $ref } } : { $ref };
const paramObject = { ..._schemaObject, ...refHost };
const pathsToOmit = ['enum', 'enumName'];

return omit(paramObject, ['enum', 'type']);
if (!metadata.isArray) {
pathsToOmit.push('type');
}

return omit(paramObject, pathsToOmit);
}

createNotBuiltInTypeReference(
Expand Down
10 changes: 9 additions & 1 deletion test/services/schema-object-factory.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ describe('SchemaObjectFactory', () => {
class Person {
@ApiProperty({ enum: Role, enumName: 'Role' })
role: Role;
@ApiProperty({ enum: Role, enumName: 'Role', isArray: true })
roles: Role[];
}

it('should explore enum', () => {
Expand All @@ -53,9 +55,15 @@ describe('SchemaObjectFactory', () => {
properties: {
role: {
$ref: '#/components/schemas/Role'
},
roles: {
type: 'array',
items: {
$ref: '#/components/schemas/Role'
}
}
},
required: ['role']
required: ['role', 'roles']
});

schemaObjectFactory.exploreModelSchema(CreatePersonDto, schemas, [
Expand Down

0 comments on commit 7a208fd

Please sign in to comment.