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.

How to provide JSON response schema?

See original GitHub issue
@ApiResponse({ status: 201, description: 'Creates new player object.' })

Only (I think) allows for the status and description (plus some other fields). How can I implicitly or explicitly (^^) force SwaggerModule to show the JSON that will be returned?

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:7 (2 by maintainers)

github_iconTop GitHub Comments

4reactions
galkowskitcommented, Nov 27, 2017

But that’s the input? For POST I use @ApiModelProperty in the .dto files. I mean the output from the API. My API is connected via TypeORM to PostgreSQL.

  @Post()
  @UsePipes(new ValidationPipe())
  @ApiResponse({ status: 201, type: User, description: 'Creates new user object.' })
  async create (@Body() createUserDto: CreateUserDto): Promise<User> {
    const user = await this.userService.create(createUserDto)
    return this.userService.findOne(user.id)
  }

In Swagger UI I can see that CreateUserDto is used as a request body, that’s great. Should I create a similar class for output? Or is it somehow possible to derive the output from the User (TypeORM) object?

4reactions
kamilmysliwieccommented, Nov 27, 2017

Hi @galkowskit, Use type property. Pass there a class with properties annotated with @ApiModelProperty()

Read more comments on GitHub >

github_iconTop Results From Across the Web

Testing and validating API responses with JSON Schema
In this post, I'll walk-through an example of using Assertible to create a test that validates an API response against a JSON Schema....
Read more >
Getting Started Step-By-Step - JSON Schema
To start a schema definition, let's begin with a basic JSON schema. We start with four properties called keywords which are expressed as...
Read more >
JSON - Schema - Tutorialspoint
JSON - Schema, JSON Schema is a specification for JSON based format for defining the structure of JSON data. It was written under...
Read more >
How to Validate Your JSON Using JSON Schema
JSON Schema is a JSON-based format for defining the structure of JSON data. It provides a contract for what JSON data is required...
Read more >
JSON Schema Examples Tutorial - MongoDB
To add an object inside an object in JSON format, we use nested data structure. Creating subschemas for Nested objects work quite similarly...
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 Hashnode Post

No results found