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.

support: how to set correct content type in generated oas3

See original GitHub issue

Endpoint returning text/plain has a corresponding tsoa generated oas3 content set as application/json.

Is there any way to have a accurate content in generated swagger.json?

Sorting

  • I’m submitting a …

    • bug report
    • feature request
    • support request
  • I confirm that I

    • used the search to make sure that a similar issue hasn’t already been submit

Expected Behavior

                                        "200": {
                                                "description": "Ok",
                                                "content": {
-                                                       "application/json": {
+                                                       "text/plain": {
                                                                "schema": {
-                                                                       "type": "number",
-                                                                       "enum": [
-                                                                               null
-                                                                       ],
-                                                                       "nullable": true
+                                                                       "type": "string"
                                                                }
                                                        }
                                                }

Current Behavior

                        }
+               },
+               "/.well-known/security.txt": {
+                       "get": {
+                               "operationId": "GetSecurityTxt",
+                               "responses": {
+                                       "200": {
+                                               "description": "Ok",
+                                               "content": {
+                                                       "application/json": {
+                                                               "schema": {
+                                                                       "type": "number",
+                                                                       "enum": [
+                                                                               null
+                                                                       ],
+                                                                       "nullable": true
+                                                               }
+                                                       }
+                                               }
+                                       }
+                               },
+                               "security": [],
+                               "parameters": []
+                       }
                }

Possible Solution

No idea

Steps to Reproduce

--- /dev/null
+++ b/src/well-known/wellKnownController.ts
@@ -0,0 +1,16 @@
+import { Response as ExResponse, Request as ExRequest } from 'express';
+import { Controller, Get, Request, Route } from 'tsoa';
+import { WellKnownService } from './wellKnownService';
+
+@Route('/.well-known')
+export class WellKnownController extends Controller {
+    @Get('/security.txt')
+    async getSecurityTxt(@Request() request: ExRequest): Promise<null> {
+        const securityTxt = await new WellKnownService().getSecurityTxt();
+        // eslint-disable-next-line @typescript-eslint/no-explicit-any
+        const res = (<any>request).res as ExResponse;
+        res.type('.txt');
+        res.send(securityTxt);
+        return null;
+    }
+}

Context (Environment)

Version of the library: 3.14.0 Version of NodeJS: v14.17.6

  • Confirm you were using yarn not npm:
    • I confirm

Detailed Description

use case 1 As a security researcher I must know how to securely disclose security vulnerabilities

use case 2 as a developer that’s creating JSON REST API I wan’t to serve security.txt as specified in https://securitytxt.org/ and mentioned in https://cheatsheetseries.owasp.org/cheatsheets/Vulnerability_Disclosure_Cheat_Sheet.html#finding-contact-details

specification of security.txt says this:

The security.txt file should have an Internet Media Type of text/plain and must be served over HTTPS.

Issue Analytics

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

github_iconTop GitHub Comments

2reactions
mrl5commented, Nov 8, 2021

reopened since I’m preparing a PR that solves this

0reactions
mrl5commented, Nov 7, 2021

thanks @WoH - closing this one to avoid duplicates

Read more comments on GitHub >

github_iconTop Results From Across the Web

OpenAPI Specification - Version 3.0.3 - Swagger
OAS uses several known formats to define in fine detail the data type being used. However, to support documentation needs, the format property...
Read more >
OpenAPI Specification v3.0.3 | Introduction, Definitions, & More
The OpenAPI Specification (OAS) defines a standard, programming language-agnostic interface description for HTTP APIs.
Read more >
Designing an API OpenAPI 3.0 - header parameter Content ...
The implementation will take care of processing it correctly and validate the right Content-Type header is used at execution time.
Read more >
OpenAPI 3.0 Tutorial | SwaggerHub Documentation
In this tutorial, we will write a simple API definition in the OpenAPI ... a list of artists content: application/json: schema: type: array ......
Read more >
java: Content-Type: application/json on GET requests ... - GitHub
I think changing the code as you have proposed is a good idea. In ApiClient (to be changed in ApiClient.mustache ). /** *...
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 Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found