swagger-api/swagger-codegen

[typescript-fetch] response parser doesn't match the generated model

Open

#4.785 geöffnet am 13. Feb. 2017

Auf GitHub ansehen
 (3 Kommentare) (1 Reaktion) (0 zugewiesene Personen)HTML (5.474 Forks)batch import
Client: TypeScriptIssue: Bughelp wanted

Repository-Metriken

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

Beschreibung

Description

Running swagger-codegen with -l typescript-fetch produces code that can't properly parse the responses.

Swagger-codegen version

2.2.1

Swagger declaration file content or url

https://gist.github.com/farcaller/825c3aaae2a26f6883fb3554b4ccece9

Command line used for generation

swagger-codegen generate -i test.swagger.json -l typescript-fetch -o api/

Steps to reproduce

Generate the file, try to use it.

Based on the swagger config, the server will reply with an object that looks like:

{
"underscore_name": "qwe",
"a_string": "abc",
"a_number": 123
}

Which is processed as:

...
if (response.status >= 200 && response.status < 300) {
    return response.json();
} else {
...

i.e., taking the json as is and returning it as a typed MainTestMessage interface. But the defined model looks like:

export interface MainTestMessage {
    "underscoreName"?: string;
    "aString"?: string;
    "aNumber"?: number;
}

Producing incorrect result.

Related issues

Nothing relevant found.

Suggest a Fix

Unless {"modelPropertyNaming":"original"} is passed in the config, the generator must preform keys re-mapping.

Contributor Guide