Skip to content

Commit

Permalink
FEAT: more valid json
Browse files Browse the repository at this point in the history
  • Loading branch information
rflechner committed Jul 24, 2017
1 parent 9f230bc commit 8b364bf
Show file tree
Hide file tree
Showing 21 changed files with 3,253 additions and 1,058 deletions.
6 changes: 6 additions & 0 deletions .idea/.idea.Suave.Swagger/.idea/contentModel.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions .idea/.idea.Suave.Swagger/.idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/.idea.Suave.Swagger/.idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

338 changes: 338 additions & 0 deletions .idea/.idea.Suave.Swagger/.idea/workspace.xml

Large diffs are not rendered by default.

35 changes: 35 additions & 0 deletions .idea/.idea.Suave.Swagger/riderModule.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion examples/Suave.Swagger.PetStoreAPi/App.config
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@
<dependentAssembly>
<Paket>True</Paket>
<assemblyIdentity name="FSharp.Core" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-65535.65535.65535.65535" newVersion="4.4.0.0" />
<bindingRedirect oldVersion="0.0.0.0-65535.65535.65535.65535" newVersion="4.4.1.0" />
</dependentAssembly>
</assemblyBinding></runtime></configuration>
103 changes: 52 additions & 51 deletions examples/Suave.Swagger.PetStoreAPi/Program.fs
Original file line number Diff line number Diff line change
Expand Up @@ -79,74 +79,74 @@ let bye3 = GET >=> path "/bye3" >=> XML "bye. @++"

let api =
swagger {
// syntax 1
//// syntax 1
for route in getting (simpleUrl "/time" |> thenReturns now) do
yield description Of route is "What time is it ?"
yield route |> tag "time"

for route in getting (urlFormat "/bonjour/%s" (fun x -> OK (sprintf "Bonjour %s" x))) do
yield description Of route is "Say hello in french"

// another syntax
for route in getOf (path "/time2" >=> now) do
yield description Of route is "What time is it 2?"
yield urlTemplate Of route is "/time2"
yield route |> tag "time"
//// another syntax
//for route in getOf (path "/time2" >=> now) do
// yield description Of route is "What time is it 2?"
// yield urlTemplate Of route is "/time2"
// yield route |> tag "time"

for route in getting <| urlFormat "/subtract/%d/%d" subtract do
yield description Of route is "Subtracts two numbers"
yield route |> tag "maths"
//for route in getting <| urlFormat "/subtract/%d/%d" subtract do
// yield description Of route is "Subtracts two numbers"
// yield route |> tag "maths"

for route in posting <| simpleUrl "/subtract" |> thenReturns subtractObj do
yield description Of route is "Subtracts two numbers"
yield route |> addResponse 200 "Subtraction result" (Some typeof<SubtractionResult>)
yield parameter "subtraction request" Of route (fun p -> { p with Type = (Some typeof<SubtractionRequest>); In=Body })
yield route |> tag "maths"
//for route in posting <| simpleUrl "/subtract" |> thenReturns subtractObj do
// yield description Of route is "Subtracts two numbers"
// yield route |> addResponse 200 "Subtraction result" (Some typeof<SubtractionResult>)
// yield parameter "subtraction request" Of route (fun p -> { p with Type = (Some typeof<SubtractionRequest>); In=Body })
// yield route |> tag "maths"

for route in posting <| urlFormat "/subtract/%d/%d" subtract do
yield description Of route is "Subtracts two numbers"
yield route |> tag "maths"
//for route in posting <| urlFormat "/subtract/%d/%d" subtract do
// yield description Of route is "Subtracts two numbers"
// yield route |> tag "maths"

for route in getting <| urlFormat "/pet/%d" findPetById do
yield description Of route is "Search a pet by id"
yield route |> addResponse 200 "The found pet" (Some typeof<Pet>)
yield route |> supportsJsonAndXml
yield route |> tag "pets"

for route in getOf (pathScan "/pet/byuuid/%s" findPetByUuid) do
yield description Of route is "Search a pet by uuid"
yield urlTemplate Of route is "/pet/byuuid/{uuid}"
yield parameter "UUID" Of route (fun p -> { p with Type = (Some typeof<Guid>); In=Path })
yield route |> addResponse 200 "The found pet" (Some typeof<Pet>)
yield route |> supportsJsonAndXml
yield route |> tag "pets"
// for route in getOf (pathScan "/pet/byuuid/%s" findPetByUuid) do
// yield description Of route is "Search a pet by uuid"
// yield urlTemplate Of route is "/pet/byuuid/{uuid}"
// yield parameter "UUID" Of route (fun p -> { p with Type = (Some typeof<Guid>); In=Path })
// yield route |> addResponse 200 "The found pet" (Some typeof<Pet>)
// yield route |> supportsJsonAndXml
// yield route |> tag "pets"

for route in getting <| urlFormat "/category/%d" findCategoryById do
yield description Of route is "Search a category by id"
yield route |> addResponse 200 "The found category" (Some typeof<PetCategory>)
yield route |> tag "pets"
// for route in getting <| urlFormat "/category/%d" findCategoryById do
// yield description Of route is "Search a category by id"
// yield route |> addResponse 200 "The found category" (Some typeof<PetCategory>)
// yield route |> tag "pets"

for route in posting <| simpleUrl "/category" |> thenReturns createCategory do
yield description Of route is "Create a category"
yield route |> addResponse 200 "returns the create model with assigned Id" (Some typeof<PetCategory>)
yield parameter "category model" Of route (fun p -> { p with Type = (Some typeof<PetCategory>); In=Body })
yield route |> tag "pets"

// Classic routes with manual documentation

for route in bye do
yield route.Documents(fun doc -> { doc with Description = "Say good bye." })
yield route.Documents(fun doc -> { doc with Template = "/bye"; Verb=Get })

for route in getOf (pathScan "/add/%d/%d" (fun (a,b) -> OK((a + b).ToString()))) do
yield description Of route is "Compute a simple addition"
yield urlTemplate Of route is "/add/{number1}/{number2}"
yield parameter "number1" Of route (fun p -> { p with Type = (Some typeof<int>); In=Path })
yield parameter "number2" Of route (fun p -> { p with Type = (Some typeof<int>); In=Path })

for route in getOf (path "/hello" >=> OK "coucou") do
yield description Of route is "Say hello"
yield urlTemplate Of route is "/hello"
// for route in posting <| simpleUrl "/category" |> thenReturns createCategory do
// yield description Of route is "Create a category"
// yield route |> addResponse 200 "returns the create model with assigned Id" (Some typeof<PetCategory>)
// yield parameter "category model" Of route (fun p -> { p with Type = (Some typeof<PetCategory>); In=Body })
// yield route |> tag "pets"

//// Classic routes with manual documentation

// for route in bye do
// yield route.Documents(fun doc -> { doc with Description = "Say good bye." })
// yield route.Documents(fun doc -> { doc with Template = "/bye"; Verb=Get })

// for route in getOf (pathScan "/add/%d/%d" (fun (a,b) -> OK((a + b).ToString()))) do
// yield description Of route is "Compute a simple addition"
// yield urlTemplate Of route is "/add/{number1}/{number2}"
// yield parameter "number1" Of route (fun p -> { p with Type = (Some typeof<int>); In=Path })
// yield parameter "number2" Of route (fun p -> { p with Type = (Some typeof<int>); In=Path })

// for route in getOf (path "/hello" >=> OK "coucou") do
// yield description Of route is "Say hello"
// yield urlTemplate Of route is "/hello"
}
|> fun a ->
a.Describes(
Expand All @@ -161,8 +161,9 @@ let api =
let main argv =
async {
do! Async.Sleep 2000
System.Diagnostics.Process.Start "http://localhost:8080/swagger/v2/ui/index.html" |> ignore
System.Diagnostics.Process.Start "http://localhost:8082/swagger/v2/ui/index.html" |> ignore
} |> Async.Start
startWebServer defaultConfig api.App

startWebServer { defaultConfig with bindings = [ HttpBinding.createSimple HTTP "127.0.0.1" 8082 ] } api.App
0 // return an integer exit code

Loading

0 comments on commit 8b364bf

Please sign in to comment.