Skip to content

Commit

Permalink
Merge branch 'jessemyers-array-format-placement'
Browse files Browse the repository at this point in the history
  • Loading branch information
kamilmysliwiec committed Mar 19, 2021
2 parents 7703755 + 263a7b3 commit 86ee0a0
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 8 deletions.
3 changes: 2 additions & 1 deletion e2e/api-spec.json
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,8 @@
"tags": {
"type": "array",
"items": {
"type": "string"
"type": "string",
"format": "uri"
}
},
"createdAt": {
Expand Down
1 change: 1 addition & 0 deletions e2e/src/cats/dto/create-cat.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export class CreateCatDto {
readonly breed: string;

@ApiProperty({
format: 'uri',
type: [String]
})
readonly tags?: string[];
Expand Down
20 changes: 14 additions & 6 deletions lib/services/schema-object-factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ import {
keyBy,
mapValues,
omit,
omitBy
omitBy,
pick
} from 'lodash';
import { DECORATORS } from '../constants';
import { getTypeIsArrayTuple } from '../decorators/helpers';
Expand Down Expand Up @@ -424,15 +425,22 @@ export class SchemaObjectFactory {
type: string | Record<string, any>
): SchemaObjectMetadata {
const keysToRemove = ['type', 'enum'];
const keysToMove = [
'format',
'maximum',
'maxLength',
'minimum',
'minLength',
'pattern'
];
const movedProperties = pick(metadata, keysToMove);
const schemaHost = {
...omit(metadata, keysToRemove),
...omit(metadata, [...keysToRemove, ...keysToMove]),
name: metadata.name || key,
type: 'array',
items: isString(type)
? {
type
}
: { ...type }
? { type, ...movedProperties }
: { ...type, ...movedProperties }
};
schemaHost.items = omitBy(schemaHost.items, isUndefined);
return schemaHost as unknown;
Expand Down
3 changes: 2 additions & 1 deletion test/services/fixtures/create-user.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@ export class CreateUserDto {

@ApiProperty({
type: String,
isArray: true
isArray: true,
format: 'uri'
})
urls: string[];

Expand Down
1 change: 1 addition & 0 deletions test/services/schema-object-factory.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ describe('SchemaObjectFactory', () => {
},
urls: {
items: {
format: 'uri',
type: 'string'
},
type: 'array'
Expand Down

0 comments on commit 86ee0a0

Please sign in to comment.