|
1 | 1 | import { ApiExtension, ApiProperty } from '../../lib/decorators';
|
2 |
| -import { SchemasObject } from '../../lib/interfaces/open-api-spec.interface'; |
| 2 | +import { BaseParameterObject, SchemasObject } from '../../lib/interfaces/open-api-spec.interface'; |
3 | 3 | import { ModelPropertiesAccessor } from '../../lib/services/model-properties-accessor';
|
4 | 4 | import { SchemaObjectFactory } from '../../lib/services/schema-object-factory';
|
5 | 5 | import { SwaggerTypesMapper } from '../../lib/services/swagger-types-mapper';
|
6 | 6 | import { CreateUserDto } from './fixtures/create-user.dto';
|
| 7 | +import { ParamWithTypeMetadata } from '../../lib/services/parameter-metadata-accessor'; |
7 | 8 |
|
8 | 9 | describe('SchemaObjectFactory', () => {
|
9 | 10 | let modelPropertiesAccessor: ModelPropertiesAccessor;
|
@@ -328,4 +329,44 @@ describe('SchemaObjectFactory', () => {
|
328 | 329 | expect(schemas).toEqual({ MyEnum: { enum: [1, 2, 3], type: 'number' } });
|
329 | 330 | });
|
330 | 331 | });
|
| 332 | + |
| 333 | + describe('createEnumParam', () => { |
| 334 | + it('should create an enum schema definition', () => { |
| 335 | + const params: ParamWithTypeMetadata & BaseParameterObject = { |
| 336 | + required: true, |
| 337 | + isArray: false, |
| 338 | + enumName: 'MyEnum', |
| 339 | + enum: ['a', 'b', 'c'] |
| 340 | + } |
| 341 | + const schemas = {}; |
| 342 | + schemaObjectFactory.createEnumParam(params, schemas) |
| 343 | + |
| 344 | + expect(schemas['MyEnum']).toEqual({ |
| 345 | + enum: ['a', 'b', 'c'], |
| 346 | + type: 'string' |
| 347 | + }) |
| 348 | + }) |
| 349 | + |
| 350 | + it('should create an enum schema definition for an array', () => { |
| 351 | + const params: ParamWithTypeMetadata & BaseParameterObject = { |
| 352 | + required: true, |
| 353 | + isArray: true, |
| 354 | + enumName: 'MyEnum', |
| 355 | + schema: { |
| 356 | + type: 'array', |
| 357 | + items: { |
| 358 | + type: 'string', |
| 359 | + enum: ['a', 'b', 'c'] |
| 360 | + } |
| 361 | + } |
| 362 | + } |
| 363 | + const schemas = {}; |
| 364 | + schemaObjectFactory.createEnumParam(params, schemas) |
| 365 | + |
| 366 | + expect(schemas['MyEnum']).toEqual({ |
| 367 | + enum: ['a', 'b', 'c'], |
| 368 | + type: 'string' |
| 369 | + }) |
| 370 | + }) |
| 371 | + }) |
331 | 372 | });
|
0 commit comments