RicoSuter/NSwag

Angular TS client Accept header is "text/plain" when using OAS3

Open

#2.672 geöffnet am 4. Feb. 2020

Auf GitHub ansehen
 (3 Kommentare) (0 Reaktionen) (0 zugewiesene Personen)C# (1.189 Forks)batch import
help wantedtype: bugtype: enhancement

Repository-Metriken

Stars
 (6.291 Stars)
PR-Merge-Metriken
 (Keine gemergten PRs in 30 T)

Beschreibung

We use NSwag Studio to generate TypeScript clients for our Angular applications. When we switch from Swagger2 to OAS3 the generated Angular client uses a different Accept header.

Output from Swagger2 definition ("Accept": "application/json"):

let options_ : any = {
  observe: "response",
  responseType: "blob",
  headers: new HttpHeaders({
    "Accept": "application/json"
  })
};

Output from OAS3 definition ("Accept": "text/plain"):

let options_ : any = {
  observe: "response",
  responseType: "blob",
  headers: new HttpHeaders({
    "Accept": "text/plain"
  })
};

The related part of the definition looks of course a bit different, but I don't see a reason why it results in different output. Swagger2:

  "produces": [
      "text/plain",
      "application/json",
      "text/json"
  ],

OAS3:

  "content": {
    "text/plain": {
      "schema": {
        "type": "array",
        "items": {
          "$ref": "#/components/schemas/Supplier"
        }
      }
    },
    "application/json": {
      "schema": {
        "type": "array",
        "items": {
          "$ref": "#/components/schemas/Supplier"
        }
      }
    },
    "text/json": {
      "schema": {
        "type": "array",
        "items": {
          "$ref": "#/components/schemas/Supplier"
        }
      }
    }
  }

As far as I understand the ASP.NET Core documentation, the Accept header is ignored if the request comes from a browser. Are there any other side-effects? Is there a way to configure which Accept header should be used?

Contributor Guide