nswag (OpenApi) typescript get error type
Hey, I'm generating an api client using nswag, here is an example route:
However, in the client itself the response is not a union type, but simply the 200 default type... How am I supposed to get the error in the frontend (typescript)?
11 Replies
Unknown User•3d ago
Message Not Public
Sign In & Join Server To View
400 is not a success code, so AppError will be signal as exception
right but 201 is also a generated exception
looked more at it and nswag merges 2xx responses if they are the same type, others throw
well it didn't seem to merge them together
I tried with multiple types on 200
right but that is inheritance
I was talking about unrelated types
also for some reason I can't instantiate request dtos using like
<BeginLoginRequest>{ email: "[email protected]" }
;
I can live with single response types for 200that's just how nswag generate code https://github.com/RicoSuter/NSwag/blob/3246c7b9be7a822ac62f51fb095d77fe747c8aab/src/NSwag.CodeGeneration/Models/ResponseModelBase.cs#L103
GitHub
NSwag/src/NSwag.CodeGeneration/Models/ResponseModelBase.cs at 3246c...
The Swagger/OpenAPI toolchain for .NET, ASP.NET Core and TypeScript. - RicoSuter/NSwag
first 2xx is primary success response type, another other 2xx can only use same type. other types will be thrown as exception
@Sehra , do you know how to instantiate the type using
<BeginLoginRequest>{ email: "[email protected]" }
it just shows me an error when i do this and svelte gives 500 error
I also need to generate a base class to inject headers in the request
nvm I found it
If you have no further questions, please use /close to mark the forum thread as answered