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

MIME based responses in OpenAPI/Swagger #1511

Closed
2 of 4 tasks
js-lowes opened this issue Nov 10, 2023 · 2 comments
Closed
2 of 4 tasks

MIME based responses in OpenAPI/Swagger #1511

js-lowes opened this issue Nov 10, 2023 · 2 comments
Labels

Comments

@js-lowes
Copy link

Sorting

Expected Behavior

Wish (but unable to generate b/c of error):

{
    ...
    "/base-path/{id}": {
        "get": {
            "tags": [],
            "summary": "Get Detailed Data",
            "operationId": "Foo_bar_v1",
            "parameters": [],
            "responses": {
                "200": {
                    "description": "Successfully retrieved list",
                    "content": {
                        "application/vnd.foo.bar.v1+json": {
                            "schema": {
                                "type": "#/components/schemas/Something1"
                            }
                        },
                        "application/vnd.moo.boo.v1+json": {
                            "schema": {
                                "$ref": "#/components/schemas/Something2"
                            }
                        }
                    }
                },
            }
        }
    }
    ...
}

Current Behavior

My code looks like the following:

import { Consumes, Controller, Get, Path, Produces, Route } from 'tsoa';

@Route('base-path')
class FooBarController extends Controller {
    @Get('{id}')
    @Consumes('application/vnd.foo.bar.v1+json')
    @Produces('application/vnd.foo.bar.v1+json')
    public getFooBar(@Path() id: string): object {
        this.setStatus(200);
        this.setHeader('Content-Type', 'application/vnd.foo.bar.v1+json');
        return { fooBar: id };
    }
    @Get('{id}')
    @Consumes('application/vnd.moo.boo.v1+json')
    @Produces('application/vnd.moo.boo.v1+json')
    public getMooBoo(@Path() id: string): object {
        this.setStatus(200);
        this.setHeader('Content-Type', 'application/vnd.moo.boo.v1+json');
        return { mooBoo: id };
    }
}
export { FooBarController };

And I get the following error:

$ tsoa -c tsoaConfig.json spec-and-routes
Generate routes error.
 GenerateMetadataError: Duplicate method signature @get(base-path/{id}) found in controllers: FooBarController#getFooBar, FooBarController#getMooBoo

Possible Solution

I am not sure if this is already supported and I cannot find the example or if this type of swagger response is not supported. @mrl5 was the original author, so maybe they can provide some more insight?

Steps to Reproduce

Copy the code, it should work fine on your machine.

Context (Environment)

Version of the library: 5.1.1
Version of NodeJS: v18.15.0

  • Confirm you were using yarn not npm: [X]

Detailed Description

At this moment, I am unsure if a change is required.

Breaking change?

At this moment, I am unsure if a change is required.

Copy link

Hello there js-lowes 👋

Thank you for opening your very first issue in this project.

We will try to get back to you as soon as we can.👀

Copy link

This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 5 days

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant