I want to generate a TypeScript client from an OpenApi specification. I'm using NSwagStudio to create the config file. I leave the default {controller}Client value, but the placeholder has no effect, as the class name is generated as just Client.
What could be the problem?
"codeGenerators": {
"openApiToTypeScriptClient": {
"className": "{controller}Client",
"operationGenerationMode": "MultipleClientsFromOperationId",
...
[ApiController]
public class WorkoutsController : ControllerBase
{
private readonly IWorkoutService _workoutService;
public WorkoutsController(IWorkoutService workoutService)
{
_workoutService = workoutService;
}
[ProducesResponseType(StatusCodes.Status404NotFound)]
[ProducesResponseType(typeof(WorkoutResponse), StatusCodes.Status200OK)]
[HttpGet(ApiEndpoints.Workouts.Get)]
public async Task<IActionResult> Get([FromRoute] Guid id, CancellationToken token)
{
var workout = await _workoutService.GetByIdAsync(id, token);
if (workout is null)
return NotFound();
var workoutResponse = workout.ToWorkoutResponse();
return Ok(workoutResponse);
}
...
{
"openapi": "3.0.1",
"info": {
"title": "fitflow.RestApi",
"version": "1.0"
},
"paths": {
"/api/workouts/{id}": {
"get": {
"tags": [
"Workouts"
],
"parameters": [
{
"name": "id",
"in": "path",
"required": true,
"style": "simple",
"schema": {
"type": "string",
"format": "uuid"
}
}
],
"responses": {
"200": {
"description": "Success",
"content": {
"text/plain": {
"schema": {
"$ref": "#/components/schemas/WorkoutResponse"
}
},
"application/json": {
"schema": {
"$ref": "#/components/schemas/WorkoutResponse"
}
},
"text/json": {
"schema": {
"$ref": "#/components/schemas/WorkoutResponse"
}
}
}
},
"404": {
"description": "Not Found",
"content": {
"text/plain": {
"schema": {
"$ref": "#/components/schemas/ProblemDetails"
}
},
"application/json": {
"schema": {
"$ref": "#/components/schemas/ProblemDetails"
}
},
"text/json": {
"schema": {
"$ref": "#/components/schemas/ProblemDetails"
}
}
}
}
}
}
},
"/api/workouts": {
...
Make sure you have the
NSwag.AspNetCorepackage installed from NuGet. Otherwise if you have the defaultSwashbuckle.AspNetCoreinstalled, it will use that, which would be undesirable in this case and would cause the issue you are experiencing.In addition, ensure you have the following in your
Program.cs. This is required for OpenAPI 3.0 generation through NSwag:And these are the NSwag extensions for serving Swagger docs: