Open ascott18 opened 6 years ago
we're on the same issue. Using a generator to create types for a npm angular library with a conf like this:
{
"runtime": "NetCore20",
"swaggerGenerator": {
"typesToSwagger": {
"output": "swagger.json",
"assemblyPaths": [ "$(OutDir)my.dll" ],
"classNames": [
"myclass"
]
}
},
"codeGenerators": {
"swaggerToTypeScriptClient": {
"wrapDtoExceptions": false,
"input": "swagger.json",
"output": "servertypes.ts"
}
}
}
generates this:
/* tslint:disable */
//----------------------
// <auto-generated>
// Generated using the NSwag toolchain v11.17.6.0 (NJsonSchema v9.10.46.0 (Newtonsoft.Json v9.0.0.0)) (http://NSwag.org)
// </auto-generated>
//----------------------
// ReSharper disable InconsistentNaming
export class myclass implements Imyclass {
...
}
export interface Imyclass {
...
}
function throwException(message: string, status: number, response: string, headers: { [key: string]: any; }, result?: any): any {
if(result !== null && result !== undefined)
throw result;
else
throw new SwaggerException(message, status, response, headers, null);
}
the output works fine, as soon as we manually remove throwException from the file.
I think this is already fixed with this PR: https://github.com/RSuter/NSwag/pull/1705
A bit of an edge case - in a project I'm working on, we integrated automatic generation of clients via some MSBuild targets that are automatically pulled in via a shared nuget package. This is all working great, except at the very beginning of a new project where we haven't written any endpoints yet, and are still working on the data/business layer of the app. At this stage, our swagger.json has no endpoints defined.
The TypeScript that gets generated doesn't compile because
SwaggerException
isn't created unless there is at least one client.For a swagger.json:
and spec:
We get the following output:
See that
throwException
is being generated, butSwaggerException
is not, so the TypeScript can't compile.