Last active
March 22, 2024 17:01
-
-
Save stand-sure/7533ca6b401f2a0ae0950bd1f8aa081c to your computer and use it in GitHub Desktop.
Revisions
-
stand-sure revised this gist
Mar 22, 2024 . 1 changed file with 6 additions and 3 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -6,12 +6,13 @@ 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` ### Replace, as needed - `Service_openapi.json`, which is the name of the file to output - `openapi`, at the end of the command, which is the name of the document. This is set via the `SwaggerDoc` method on `SwaggerGenOptions`, often invoked via calling the `AddSwaggerGen` extension method on an `IServiceCollection` instance. @@ -20,7 +21,9 @@ often invoked via calling the `AddSwaggerGen` extension method on an `IServiceCo *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` -
stand-sure created this gist
Mar 22, 2024 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,40 @@ <Project Sdk="Microsoft.NET.Sdk"> <PropertyGroup> <TargetFramework>netstandard2.0</TargetFramework> <RootNamespace>Demos.OAS.Client</RootNamespace> <GenerateAssemblyInfo>true</GenerateAssemblyInfo> <FileVersion>0.1.0.0</FileVersion> <LangVersion>latest</LangVersion> <GeneratePackageOnBuild>true</GeneratePackageOnBuild> <Version>0.1.0</Version> <Title>Demo OpenAPI Client</Title> <Authors>stand__sure</Authors> <RepositoryUrl>__NUGET_PACKAGE_REPO_URL__</RepositoryUrl> <PackageId>Demos.OAS.Client</PackageId> <Description>Kiota-generated SDK Client</Description> <Copyright>Copyright 2024 stand__sure</Copyright> <PackageProjectUrl>__NUGET_PACKAGE_PROJECT_URL__</PackageProjectUrl> <PackageTags>openapi;dotnet;</PackageTags> <AssemblyName>Demos.OAS.Client</AssemblyName> <RuntimeIdentifiers>win-x64|osx-x64|osx-arm64|linux-x64;</RuntimeIdentifiers> <CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies> <IsPackable>true</IsPackable> <PackageReadMeFile>README.md</PackageReadMeFile> </PropertyGroup> <ItemGroup> <PackageReference Include="Microsoft.Kiota.Abstractions" Version="1.8.0"/> <PackageReference Include="Microsoft.Kiota.Authentication.Azure" Version="1.1.4"/> <PackageReference Include="Microsoft.Kiota.Http.HttpClientLibrary" Version="1.3.7"/> <PackageReference Include="Microsoft.Kiota.Serialization.Form" Version="1.1.5"/> <PackageReference Include="Microsoft.Kiota.Serialization.Json" Version="1.2.0"/> <PackageReference Include="Microsoft.Kiota.Serialization.Multipart" Version="1.1.3"/> <PackageReference Include="Microsoft.Kiota.Serialization.Text" Version="1.1.4"/> </ItemGroup> <ItemGroup> <None Include="README.md" Pack="true" PackagePath="\"/> </ItemGroup> </Project> This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,26 @@ ## Tools to install - [dotnet swagger](https://github.com/domaindrivendev/Swashbuckle.AspNetCore) - [kiota](https://github.com/microsoft/kiota) ## Generating the OpenAPI file 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` ### Replace, as needed `Service_openapi.json`, which is the name of the file to output `openapi`, at the end of the command, which is the name of the document. This is set via the `SwaggerDoc` method on `SwaggerGenOptions`, often invoked via calling the `AddSwaggerGen` extension method on an `IServiceCollection` instance. ## Generating the client *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` This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,11 @@ <Project Sdk="Microsoft.NET.Sdk.Web"> <!-- ... elided ... --> <!-- Generate openapi and client --> <Target Name="OpenAPI" AfterTargets="Build" Condition="$(Configuration)=='Debug'"> <Exec Command="dotnet swagger tofile --output $(ProjectDir)/Service_openapi.json $(TargetPath) openapi" WorkingDirectory="$(TargetDir)" /> <Exec Command="kiota generate --language CSharp --class-name MyClassName --namespace-name MyNamespace --openapi $(SolutionDir)/src/Service/Service_openapi.json --output $(SolutionDir)/src/Client" WorkingDirectory="$(TargetDir)" /> </Target> </Project>