kiota-samples/petstore/README.md

2.5 KiB

Swagger Petstore samples

The following section showcases client SDK generated using the OpenApi 'Swagger Petstore' using Kiota.

NOTE: Kiota version 1.0.1 was used to generate these SDK's.

Table of content

Language Command line
dotnet kiota generate --openapi https://petstore.swagger.io/v2/swagger.json --additional-data false --language csharp -o PetstoreClient -c PetstoreApiClient --log-level information --clean-output true --namespace-name KiotaSamples.PetStoreSdk
java kiota generate --openapi https://petstore.swagger.io/v2/swagger.json --language java -o utilities/src/main/java/petstore/utilities -n petstore.utilities
typescript kiota generate --openapi https://petstore.swagger.io/v2/swagger.json --language typescript -o src -n petstore.utilities
go

Example of data retrieved

This is a dotnet example that shows how the data looks, after generation AND the target api is called:

image

How to generate an SDK against the Swagger Petstore

These steps are all based on the official docs for generating dotnet Kiota SDK's:

  • Create a new project or solution.
    e.g.
    dotnet new console -o petstore
    cd petstore
    
  • Add the nuget dependencies, which we will need for the SDK generated code to work:
    e.g.
    dotnet add package Microsoft.Kiota.Abstractions
    dotnet add package Microsoft.Kiota.Http.HttpClientLibrary
    dotnet add package Microsoft.Kiota.Serialization.Json
    dotnet add package Microsoft.Kiota.Serialization.Text
    dotnet add package Microsoft.Kiota.Serialization.Form
    
  • Create the Petstore SDK using Kiota and the custom params:
    e.g.
    kiota generate \
        --openapi https://petstore.swagger.io/v2/swagger.json \
        --additional-data false \
        --language csharp \
        --output src\PetstoreClient \ 
        --class-name PetstoreApiClient \
        --log-level information \ 
        --clean-output true \
        --namespace-name KiotaSamples.PetStoreSdk
    
  • And that's it! you're ready to go! So, lets grab some pets:
    var pet = await client.Pet["69"].GetAsync();
    

-- end of readme --