Swagger: `extends` broken for DTOs

Created on 9 May 2018  路  5Comments  路  Source: nestjs/swagger

using extends in DTO classes appears to be broken between 1.2.2 and 1.3.0.

minimal example:

class foo {
    @ApiModelPropertyOptional()
    public prop?: string;
};

class bar extends foo {
    @ApiModelPropertyOptional()
    public otherProp?: string;
}

@Controller("leads")
@ApiProduces("application/json; charset=utf-8")
export class LeadsController {
    constructor() {}

    @Get()
    @ApiResponse({ status: 200, type: bar })
    public find(): bar {
        return {
            prop: "asdf",
            otherProp: "asdf"
        }
    }
}

using this controller, I get an error in swagger-ui: Uncaught ReferenceError: foo is not defined.

The generated swagger actually looks correct:

   "paths": {
        "/leads": {
            "get": {
                "responses": {
                    "200": {
                        "description": "",
                        "schema": {
                            "$ref": "#/definitions/bar"
                        }
                    }
                },
                "produces": [
                    "application/json"
                ],
                "consumes": [
                    "application/json"
                ]
            }
        }
    },
    "definitions": {
        "bar": {
            "type": "object",
            "properties": {
                "prop": {
                    "type": "string"
                },
                "otherProp": {
                    "type": "string"
                }
            }
        }
    }

but when swagger ui tries to consume it, it looks like this:
image

None of the recent changes look immediately obvious as the problem - any ideas?

potential issue

Most helpful comment

Got the exact same problem with v2.0.0

All 5 comments

Got the exact same problem with v2.0.0

馃憤

Fixed in 2.0.1

@kamilmysliwiec I get the same problem with the version @nestjs/swagger 4.2.3. I get error when I extend dtos

@dancespiele please, create a separate issue and share a minimal repository that reproduces your issue.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

alisherks picture alisherks  路  4Comments

otroboe picture otroboe  路  3Comments

ericzon picture ericzon  路  4Comments

kalaivanan-muthusamy picture kalaivanan-muthusamy  路  4Comments

vh13294 picture vh13294  路  4Comments