Swagger projects and targets
As of v1.11.0, nx-dotnet supports generating code-generated projects from your .NET webapi projects.
How it works
Newly generated projects (@nx-dotnet/core:application/@nx-dotnet/core:library) can optionally create 2 swagger related libraries:
libs/generated/{project}-swaggerlibs/generated/{project}-types
- A
swaggertarget is added to the generated webapi project which leverages Swashbuckle.AspNetCore to extract aswagger.jsonspec file.- The swagger.json file is output to the
-swaggerproject.
- The swagger.json file is output to the
- The
-typesproject is created containing a typescript client for consuming the webapi- A
codegentarget is added to the webapi project to refresh this library - The typescript client can be produced in 2 flavors:
- Interfaces only - with
useNxPluginOpenApi = false - A full fetch based implementation - with
useNxPluginOpenApi = true. Note: Java 8 is a pre-requisite for running this plugin.
- Interfaces only - with
- A
- Nx dependencies ensure that the project targets are properly rebuilt whenever changes are made to the webapi
- To manually refresh the generated client, use
nx codegen {project}-types
How to use it
From your typescript projects, the generated library can be used via import '@MyWorkspace/MyTypesProject'. Invoke it as you would any other imported code.
Customizations
To change the generated client type (default is "typescript-fetch"), edit the options in the codegen target.
- For example, to use
typescript-angularto generate a complete angular service implementation"targets": { "codegen": { "executor": "@trumbitta/nx-plugin-openapi:generate-api-lib-sources", "options": { "generator": "typescript-angular", "sourceSpecPathOrUrl": "libs/generated/api-swagger/swagger.json" }, "dependsOn": ["^swagger"] } } - Many other generators exist, see openapi-generator-tools