Swagger: Support "format" in ApiModelProperty and correct default Date format

Created on 7 Jan 2018  路  7Comments  路  Source: nestjs/swagger

See specification for Data Types

Primitives have an optional modifier property: format

This would be very usefull for Date as it will be transported as "string".
So please add format property to ApiModelProperty.

Example class:

class Event {
    @ApiModelProperty({ format: 'password' })
    mySecret: string;

    @ApiModelProperty()
    myDate: Date;
}

should generate:

"definitions": {
  "Event": { 
    "type": "object",
    "properties": {
      "mySecret": { "type": "string", "format": "password" },
      "myDate": { "type": "string", "format": "date-time" } // Date schould get this format by default
    }
  }
}

Most helpful comment

@xmlking try to use

@ApiModelProperty({type: 'string', format: 'date-time'}) dateField: Date;

All 7 comments

This would indeed be very useful to bring to the project.

@kamilmysliwiec By the way, thank you so much for your efforts and keep up the good work !!

Format property will be available in the incoming release 馃憤

@ApiModelProperty({ type: Date, format: 'date-time'}) still generate Object !

@xmlking try to use

@ApiModelProperty({type: 'string', format: 'date-time'}) dateField: Date;

this works for me.

@ApiModelProperty({ type: 'string', format: 'date-time', example: '2018-11-21T06:20:32.232Z' })
@CreateDateColumn({ type: 'timestamptz' })
createdAt?: Date;

How can I apply this to query string parameters? Here I have the same problem:

image

... so how can I change this to type=string, format=date?

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

malbertSC picture malbertSC  路  5Comments

itslenny picture itslenny  路  3Comments

dennisameling picture dennisameling  路  4Comments

mogusbi picture mogusbi  路  3Comments

djedlajn picture djedlajn  路  4Comments