complex type in API [FromBody] signature incorrectly handled in generated TypeScript as string
See original GitHub issueHi, I’m using:
- Swashbuckle package (version 5.6.0) in WebApi 2 .NET project to generate json representation of API -
- nswag npm package (version 11.11.3) with swagger2tsclient command to generate TS based on API json representation
nswag swagger2tsclient /Input:swagger.json /Output:src/api.ts /ClassName:{controller}Service /WrapDtoExceptions:true /TypeScriptVersion:2.0 /Template:Angular DateTimeType:Date /GenerateClientClasses:true /GenerateClientInterfaces:true /ImportRequiredTypes:true /BaseUrlTokenName:API_BASE_URL /HttpClass:HttpClient /injectionTokenType:InjectionToken
WebApi controller:
public async Task<IHttpActionResult> Patch(int id, [FromBody] ComplexType complexType)
{
return this.StatusCode(HttpStatusCode.NoContent);
}
public class ComplexType
{
public int Id { get; set; }
public string Name { get; set; }
}
swagger json for this request params is:
"parameters": [
{
"name": "id",
"in": "path",
"description": "Id",
"required": true,
"type": "integer",
"format": "int32"
},
{
"name": "complexType",
"in": "body",
"description": "ComplexType model",
"required": true,
"schema": { "$ref": "#/definitions/ComplexType" }
}
],
the problem is that generated typescript code expects complex type as string which isn’t right:
patch(id: number, complexType: string): Observable<any> {
generated code also includes TS class definition for ComplexType but as you can see, string type is used instead of ComplexType in TS function parameter
Am I missing something in my setup? do I need to apply some attribute/command switch to ensure generated typescript is using complex type as parameter instead of string?
Issue Analytics
- State:
- Created 5 years ago
- Comments:6 (4 by maintainers)
Yep, but it’s just a temporary patch until this is fixed…
If I switch the consumes/produces, it works:
have to check whether we have to fix this in the generator or if this is expected (probably not 😃)