This is done in the csproj file for the service as a post build step. See Service.csproj
.
The following generates the file into the root of the project, which is desirable, since another project is going to use the file:
dotnet swagger tofile --output $(ProjectDir)/Service_openapi.json $(TargetPath) openapi
Service_openapi.json
, which is the name of the file to outputopenapi
, at the end of the command, which is the name of the document. This is set via theSwaggerDoc
method onSwaggerGenOptions
, often invoked via calling theAddSwaggerGen
extension method on anIServiceCollection
instance.
BEFORE generation it is wise to set up the folder location and add the project.
The following command will indicate what packages you will need to add:
kiota info -d "~/src/Service/Service_openapi.json" -l CSharp
The command to generate the client is as follows:
kiota generate --language CSharp --class-name MyClassName --namespace-name MyNamespace --openapi $(SolutionDir)/src/Service/Service_openapi.json --output $(SolutionDir)/src/Client