Skip to content

Latest commit

 

History

History
executable file
·
102 lines (90 loc) · 2.48 KB

configuration.md

File metadata and controls

executable file
·
102 lines (90 loc) · 2.48 KB

Configuration

.express(options: ISwaggerExpressOptions)

Example with default configuration:

app.use( swagger.express({
    definition : {
        info : {
            title : "My api" ,
            version : "1.0"
        } ,
        models : {
            Version : {
                properties : {
                    id : {
                        type : SwaggerDefinitionConstant.Model.Property.Type.STRING ,
                        required : true
                    } ,
                    name : {
                        type : SwaggerDefinitionConstant.Model.Property.Type.STRING ,
                        required : true
                    } ,
                    description : {
                        type : SwaggerDefinitionConstant.Model.Property.Type.STRING
                    } ,
                    version : {
                        type : SwaggerDefinitionConstant.Model.Property.Type.STRING
                    }
                }
            }
        } ,
        externalDocs : {
            url : "My url"
        }
    }
}) );

ISwaggerExpressOptions

path: string

Define path to serve swagger.json

  • Optional.
  • Default is "/api-docs/swagger.json".

Define swagger definition.

  • Required

Authentication

Configuration

Example:

    app.use( swagger.express(
        {
            definition : {
                ...
                securityDefinitions : {
                    basicAuth : {
                        type : SwaggerDefinitionConstant.Security.Type.BASIC_AUTHENTICATION
                    },
                    apiKeyHeader : {
                        type: SwaggerDefinitionConstant.Security.Type.API_KEY,
                        in: SwaggerDefinitionConstant.Security.In.HEADER,
                        name: "apiHeader"
                    }
                }
            }
        }
    ) );

Secure controller

Example:

    ...
    @ApiPath( {
        path : "/version",
        name : "Version",
        security : {
            basicAuth : []
        }
    } )
    ...
    @ApiOperationGet( {
        description : "Get version object",
        summary : "Get version",
        responses : {
            200 : { description : "Success", isArray : true, model : "Version" }
        },
        security : {
            basicAuth : []
        }
    } )
    ...