Client method name change when using OpenAPI 3 instead of 2
See original GitHub issueI wanted to use OpenAPI 3 to generate the axios typescript client I use for my project, mainly to use the same enum by reference, rather than having multiple instances being generated (this works fine).
For this, I’ve changed following references. Before:
<PackageReference Include="Swashbuckle.AspNetCore" Version="4.0.1" />
<PackageReference Include="Swashbuckle.AspNetCore.Filters" Version="4.5.5" />
After:
<PackageReference Include="Swashbuckle.AspNetCore" Version="5.0.0-rc4" />
<PackageReference Include="Swashbuckle.AspNetCore.Filters" Version="5.0.0-rc8" />
I use cake for the generation, but the generation is the same when using NswagStudio.
With: #addin nuget:?package=Cake.CodeGen.NSwag&version=1.2.0&loaddependencies=true
Before:
Task ("Frontend-Generate-API-Client")
.Does (() => {
var settings = new TypeScriptClientGeneratorSettings {
ClassName = "{controller}Client",
Template = TypeScriptTemplate.Axios,
OperationNameGenerator = new MultipleClientsFromFirstTagAndOperationIdGenerator (),
ExceptionClass = "ApiException",
GenerateDtoTypes = true
};
NSwag.FromJsonSpecification (new Uri (localApiUri))
.GenerateTypeScriptClient (apiClientFilePath, settings);
Information ($"The client API has been updated in '{apiClientFilePath}'");
});
After:
Task ("Frontend-Generate-API-Client")
.Does (() => {
var settings = new TypeScriptClientGeneratorSettings {
ClassName = "{controller}Client",
Template = TypeScriptTemplate.Axios,
OperationNameGenerator = new MultipleClientsFromFirstTagAndOperationIdGenerator(),
ExceptionClass = "ApiException",
GenerateDtoTypes = true,
CodeGeneratorSettings = {
SchemaType = NJsonSchema.SchemaType.OpenApi3
}
};
NSwag.FromJsonSpecification (new Uri (localApiUri))
.GenerateTypeScriptClient (apiClientFilePath, settings);
Information ($"The client API has been updated in '{apiClientFilePath}'");
});
Now the method names in the client aren’t being generate as before. Here’s an example:
Before: getUserByUserId(id: string): Promise<UserResponseDto> {...}
After: users4(id: string): Promise<UserResponseDto> {...}
Here’s the commit including all relevant changes. It can easily be tested and reproduced with it, if needed.
What do I have to change in order to have nice method names again?
Issue Analytics
- State:
- Created 4 years ago
- Comments:6 (2 by maintainers)
I have the same problem. After updating to dotnet core 3 and updating Swashbuckle.AspNetCore the client generated files are different. @taconaut did you find a solution for this?
Are you sure you are still using nswag in the v3 case? Can you also provide the generated specs?