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

Annotating generic file response #143

Open
Johoseph opened this issue Dec 13, 2023 · 1 comment
Open

Annotating generic file response #143

Johoseph opened this issue Dec 13, 2023 · 1 comment

Comments

@Johoseph
Copy link

Hello! Is there an established way to annotate a generic file response? I am currently facilitating this using the OpenAPI decorator as below:

@Get("/file")
@OpenAPI({
  responses: {
    "200": {
      description: "File response",
      content: {
        "application/octet-stream": {
          schema: {
            type: "file",
          },
        },
      },
    },
  },
})

Which does render the response I am looking for, however since no @ResponseSchema decorator has been specified, swagger also includes a blank application/json response option (which is not correct).

image

I have tried using the ResponseSchema decorator, rather than my current implementation, but specifying a contentType of application/octet-stream produces the following error:

C:\Users\JosephMoroney\Documents\FR2\ex-api\node_modules\routing-controllers-openapi\src\decorators.ts:133
        source.responses[statusCode]?.content[contentType].schema
                                                           ^
TypeError: Cannot read properties of undefined (reading 'schema')

Any thoughts/ideas would be appreciated!

@Johoseph
Copy link
Author

Johoseph commented Dec 13, 2023

I have manually filtered out these 'empty' default responses in the interim:

const spec = routingControllersToSpec(...);

for (const path in spec.paths) {
  for (const route in spec.paths[path]) {
    const defaultResPath =
      spec.paths[path][route].responses["200"].content["application/json"];

    if (defaultResPath && Object.keys(defaultResPath).length === 0)
      delete spec.paths[path][route].responses["200"].content[
        "application/json"
      ];
  }
}

return spec;

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

No branches or pull requests

1 participant