-
Hello! I have ASP.NET API (.NET 8) with controller methods like this: [ProducesResponseType(typeof(PersonResponse), StatusCodes.Status201Created)]
[ProducesResponseType(typeof(ValidationProblemDetails), StatusCodes.Status400BadRequest)]
[ProducesResponseType(typeof(ProblemDetails), StatusCodes.Status409Conflict)]
[HttpPost("{id:guid}", Name = "CreatePerson")]
public async Task<IActionResult> Create([FromRoute] Guid id, [FromBody] PersonRequest request)
{
//...
} I also have ClientGenerator project with the following .csproj: <Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>
</PropertyGroup>
<Target Name="NSwag" AfterTargets="AfterBuild" Condition=" '$(Configuration)' == 'Debug' ">
<Exec Command="$(NSwagExe_Net80) run nswag.json /variables:Configuration=$(Configuration)"
EnvironmentVariables="SkipMigration=True"
ConsoleToMSBuild="true" />
</Target>
<ItemGroup>
<PackageReference Include="NSwag.MSBuild" >
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Api\Api.csproj" />
</ItemGroup>
<ItemGroup>
<None Include="nswag.json" />
</ItemGroup>
</Project> Here is an example of my nswag.json: {
"runtime": "Net80",
"defaultVariables": null,
"documentGenerator": {
"aspNetCoreToOpenApi": {
"project": "../Api/Api.csproj",
"documentName": "v1",
"msBuildProjectExtensionsPath": null,
"configuration": null,
"runtime": null,
"targetFramework": null,
"noBuild": true,
"msBuildOutputPath": null,
"useHttpAttributeNameAsOperationId": true,
"verbose": true,
"workingDirectory": null,
"aspNetCoreEnvironment": null,
"output": "../Client/swagger.json",
"newLineBehavior": "Auto"
}
},
"codeGenerators": {
//...
}
}
} My goal is to get a generated client with the method CreatePerson instead of NSwag's default Person_Create. Now, every time I build a ClientGenerator project it automatically rewrites nswag.json and deletes many (written by me) settings from there. Okay, I tried different nswag.json samples from this repo by adding useHttpAttributeNameAsOperationId: In both cases, there was no success and I still got method names like {controllerName}_{controllerMethodName} instead of the expected ones. Is this behaviour expected or is it a bug? Thank you in advance for your help. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
This occurs as I guess there is no property in command anymore. SImilar to eq. services.AddOpenApiDocument(document =>
{
document.UseHttpAttributeNameAsOperationId = true;
}); |
Beta Was this translation helpful? Give feedback.
This occurs as I guess there is no property in command anymore.
https://github.com/RicoSuter/NSwag/blob/master/src/NSwag.Commands/Commands/Generation/AspNetCore/AspNetCoreToOpenApiCommand.cs
SImilar to eq.
ApiGroupNames
- you can define it in your code#4524