Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 28 additions & 1 deletion lib/interfaces/open-api-spec.interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,33 @@ export type ParameterStyle =
| 'pipeDelimited'
| 'deepObject';

/**
* OpenAPI-defined standard format values and commonly used formats.
*
* The `format` property in OpenAPI is an "open value", allowing custom formats.
* This type provides IDE autocomplete for standard formats while still permitting custom values.
*
* @issue https://github.com/nestjs/swagger/issues/3508
* @see https://swagger.io/docs/specification/data-models/data-types/
*/
export type SchemaObjectFormat =
| 'int32'
| 'int64'
| 'float'
| 'double'
| 'byte'
| 'binary'
| 'date'
| 'date-time'
| 'password'
| 'email'
| 'uuid'
| 'uri'
| 'hostname'
| 'ipv4'
| 'ipv6'
| (string & {});

export interface BaseParameterObject {
description?: string;
required?: boolean;
Expand Down Expand Up @@ -214,7 +241,7 @@ export interface SchemaObject {
additionalProperties?: SchemaObject | ReferenceObject | boolean;
patternProperties?: SchemaObject | ReferenceObject | any;
description?: string;
format?: string;
format?: SchemaObjectFormat;
default?: any;
title?: string;
multipleOf?: number;
Expand Down
3 changes: 3 additions & 0 deletions test/services/fixtures/create-user.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,9 @@ export class CreateUserDto {
@ApiProperty({ type: [String], format: 'uuid' })
formatArray: string[];

@ApiProperty({ type: String, format: 'custom-format' })
customFormat: string;

static _OPENAPI_METADATA_FACTORY() {
return {
tags: { type: () => [String] },
Expand Down
7 changes: 6 additions & 1 deletion test/services/schema-object-factory.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -359,6 +359,10 @@ describe('SchemaObjectFactory', () => {
type: 'string',
format: 'uuid'
}
},
customFormat: {
type: 'string',
format: 'custom-format'
}
},
required: [
Expand All @@ -375,7 +379,8 @@ describe('SchemaObjectFactory', () => {
'houses',
'createdAt',
'amount',
'formatArray'
'formatArray',
'customFormat'
]
});
expect(schemas['CreateProfileDto']).toEqual({
Expand Down