lukeautry / tsoa

Build OpenAPI-compliant REST APIs using TypeScript and Node
MIT License
3.42k stars 489 forks source link

MIME based responses in OpenAPI/Swagger #1511

Closed js-lowes closed 8 months ago

js-lowes commented 9 months ago

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

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.

github-actions[bot] commented 9 months ago

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.👀

github-actions[bot] commented 8 months ago

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