Skip to content

Commit

Permalink
fix(services): resolve enum type correctly if enumName is provided
Browse files Browse the repository at this point in the history
  • Loading branch information
quangtran88 committed Aug 28, 2023
1 parent ae47808 commit b517b7f
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/services/schema-object-factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@ export class SchemaObjectFactory {

if (!(enumName in schemas)) {
schemas[enumName] = {
type: 'string',
type: metadata.type as string,
enum:
metadata.isArray && metadata.items
? metadata.items['enum']
Expand Down
16 changes: 16 additions & 0 deletions test/services/schema-object-factory.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -266,4 +266,20 @@ describe('SchemaObjectFactory', () => {
});
});
});

describe('createEnumSchemaType', () => {
it('should assign schema type correctly if enumName is provided', () => {
const metadata = {
type: 'number',
enum: [1, 2, 3],
enumName: 'MyEnum',
isArray: false
};
const schemas = {};

schemaObjectFactory.createEnumSchemaType('field', metadata, schemas);

expect(schemas).toEqual({ MyEnum: { enum: [1, 2, 3], type: 'number' } });
});
});
});

0 comments on commit b517b7f

Please sign in to comment.