8000 SwaggerProvider/docs at master · fsprojects/SwaggerProvider · GitHub
[go: up one dir, main page]

Skip to content

Latest commit

 

History

History

README.md

NuGet Badge

SwaggerProvider is an umbrella project for two F# generative Type Providers that generate object models and HTTP clients for APIs described by OpenApi 3.0 and Swagger 2.0 schemas

Type Providers support schemas in JSON & YAML formats and run on netcoreapp3.1 and net46.

Getting started

F# Interactive

Create new F# script file (for example openapi.fsx) and copy following code

#r "nuget: SwaggerProvider"

open SwaggerProvider

let [<Literal>] Schema = "https://petstore.swagger.io/v2/swagger.json"
type PetStore = OpenApiClientProvider<Schema>

let client = PetStore.Client()

client.GetInventory()
|> Async.AwaitTask
|> Async.RunSynchronously

New project

Create new F# netcoreapp3.1 project and add reference to latest SwaggerProvider NuGet package

dotnet new console --name apiclient --language F#
cd apiclient
dotnet add package SwaggerProvider --version 0.10.0

replace content of Program.fs file by

open SwaggerProvider

let [<Literal>] Schema = "https://petstore.swagger.io/v2/swagger.json"
type PetStore = OpenApiClientProvider<Schema>

[<EntryPoint>]
let main argv =
    let client = PetStore.Client()
    client.GetInventory()
    |> Async.AwaitTask
    |> Async.RunSynchronously
    |> printfn "%O"
    0

build and run the project

dotnet run

in the console, you should see printed inventory from the server.

Intellisense

Intellisense works in your favorite IDE.

Visual Studio Code + Ionide Rider
Visual Studio for Mac Visual Studio
0