Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow partial schema override for ApiResponses #1723

Closed
1 task done
tmtron opened this issue Dec 13, 2021 · 1 comment
Closed
1 task done

Allow partial schema override for ApiResponses #1723

tmtron opened this issue Dec 13, 2021 · 1 comment
Labels

Comments

@tmtron
Copy link
Contributor

tmtron commented Dec 13, 2021

Is there an existing issue that is already proposing this?

  • I have searched the existing issues

Is your feature request related to a problem? Please describe it

When using the @ApiResponse decorators, we need to use the type and override some schema properties: e.g. the example.

This is currently not possible.

Describe the solution you'd like

The @ApiResponse decorators, should "merge" an explicit schema to the schema generated from the type.

Stackblitz example

In the following decorator, the schema example is ignored and instead the default example (generated from the DTO properties is used):

  @ApiCreatedResponse({
    description: 'new cat created',
    type: Cat,
    schema: {
      example: {
        name: 'this is ingoed!',
        age: 11,
        breed: 'mixed',
      },
    },
  })

Teachability, documentation, adoption, migration strategy

I think toRefObject could be changed to not override the whole schema, but only $ref, e.g.

Index: lib/services/response-object-mapper.ts
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
diff --git a/lib/services/response-object-mapper.ts b/lib/services/response-object-mapper.ts
--- a/lib/services/response-object-mapper.ts	(revision 40106817a268820cdc5c46536048bc3c8887e38e)
+++ b/lib/services/response-object-mapper.ts	(date 1639386662284)
@@ -29,6 +29,7 @@
       ...response,
       ...this.mimetypeContentWrapper.wrap(produces, {
         schema: {
+          ...response.schema,
           $ref: getSchemaPath(name)
         }
       })

What is the motivation / use case for changing the behavior?

The motivation is to be able to mix type and explicit schema

@tmtron tmtron added the feature label Dec 13, 2021
@kamilmysliwiec
Copy link
Member

Thanks for your suggestion!

This has been discussed in the past and we decided to not implement it in the foreseeable future.

If you think your request could live outside Nest's scope, we'd encourage you to collaborate with the community on publishing it as an open source package.

@nestjs nestjs locked and limited conversation to collaborators Dec 13, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

2 participants