question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

`extends` broken for DTOs

See original GitHub issue

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?

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:3
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

3reactions
hendrichbenjamincommented, May 16, 2018

Got the exact same problem with v2.0.0

1reaction
kamilmysliwieccommented, May 28, 2018

Fixed in 2.0.1

Read more comments on GitHub >

github_iconTop Results From Across the Web

Domain Object extends Data Transfer Object
Main purpose of using DTO is to pass it to View. I've extended it in Customer class not to have duplication of properties....
Read more >
DTO Inheritance not working properly Nestjs · Issue #1067 ...
I am trying to Implement inheritance in my DTOs and validate the derived classes. The inheritance is fully working with a factory class, ......
Read more >
Use composition and inheritance for DTOs
I use inheritance with DTOs inside the same layer or same context. A DTO will never inherit from a POCO, a BLL DTO...
Read more >
Rethinking the Java DTO
A DTO is a server-side value object which stores data using the presentation layer representation. We separate DTOs into those received by the ......
Read more >
Complexity, Services and Role of DTOs | Documentation
I'd typically use discrete DTOs for Service Responses as it allows freely extending existing Services to return extra data or metadata without breaking...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found