Skip to content

Commit

Permalink
(closes Szer#10) Unignore spec validation
Browse files Browse the repository at this point in the history
  • Loading branch information
bessgeor committed Oct 24, 2020
1 parent c323581 commit ec85264
Show file tree
Hide file tree
Showing 7 changed files with 60 additions and 12 deletions.
7 changes: 6 additions & 1 deletion src/GiraffeGenerator/Program.fs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,12 @@ let main argv =
let inputFile = getArg argv "--inputfile"
let outputFile = getArg argv "--outputfile"

let doc,_ = read inputFile
let doc, errors = read inputFile
if errors <> null && errors.Errors <> null && errors.Errors.Count > 0 then
errors.Errors
|> Seq.map (fun err -> sprintf "%s (at %s)" err.Message err.Pointer)
|> String.concat "\n"
|> failwith
let api = parse doc

let resultSource =
Expand Down
13 changes: 7 additions & 6 deletions tests/GiraffeGenerator.IntegrationTests/SpecSimpleTests.fs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
namespace GiraffeGenerator.IntegrationTests

open System.Net
open System.Threading.Tasks
open FSharp.Control.Tasks.V2.ContextInsensitive
open System
open Giraffe
Expand All @@ -16,9 +17,9 @@ type SpecSimpleTests() =

let simpleSpecService =
{ new SpecSimpleAPI.Service() with
member _.ListVersionsv2 = text "123"
member _.GetVersionDetailsv2 = text "234"
member _.PostVersionDetailsv2 = text "345" }
member _.ListVersionsv2Input _ = Task.FromResult "123"
member _.GetVersionDetailsv2Input _ = Task.FromResult "234"
member _.PostVersionDetailsv2Input _ = Task.FromResult "345" }

let configureApp (app : IApplicationBuilder) =
app.UseGiraffe SpecSimpleAPI.webApp
Expand Down Expand Up @@ -47,23 +48,23 @@ type SpecSimpleTests() =
let ``GET / -> OK "123"``() = task {
let! response = client.GetAsync("/")
let! text = response.Content.ReadAsStringAsync()
Assert.Equal("123",text)
Assert.Equal("\"123\"",text)
Assert.Equal(HttpStatusCode.OK ,response.StatusCode)
}

[<Fact>]
let ``GET /v2 -> OK "234"``() = task {
let! response = client.GetAsync("/v2")
let! text = response.Content.ReadAsStringAsync()
Assert.Equal("234",text)
Assert.Equal("\"234\"",text)
Assert.Equal(HttpStatusCode.OK ,response.StatusCode)
}

[<Fact>]
let ``POST /v2 -> OK "345"``() = task {
let! response = client.PostAsync("/v2", null)
let! text = response.Content.ReadAsStringAsync()
Assert.Equal("345",text)
Assert.Equal("\"345\"",text)
Assert.Equal(HttpStatusCode.OK ,response.StatusCode)
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
namespace GiraffeGenerator.IntegrationTests

open System.Net
open System.Threading.Tasks
open FSharp.Control.Tasks.V2.ContextInsensitive
open System
open Giraffe
Expand All @@ -17,12 +18,12 @@ type SpecWithSchemasTests() =
let specWithSchemasService=
{ new SpecwithschemasAPI.Service() with

member _.ListVersionsv2 = text "123"
member _.ListVersionsv2Input _ = Task.FromResult "123"

member _.GetVersionDetailsv2Input ctx = task {
return { SpecwithschemasAPI.dataSetList.apis = [||]; total = 123 }
}
member _.PostVersionDetailsv2 = text "345"}
member _.PostVersionDetailsv2Input _ = Task.FromResult "345"}

let configureApp (app : IApplicationBuilder) =
app.UseGiraffe SpecwithschemasAPI.webApp
Expand Down Expand Up @@ -51,7 +52,7 @@ type SpecWithSchemasTests() =
let ``GET / -> OK "123"``() = task {
let! response = client.GetAsync("/")
let! text = response.Content.ReadAsStringAsync()
Assert.Equal("123",text)
Assert.Equal("\"123\"",text)
Assert.Equal(HttpStatusCode.OK ,response.StatusCode)
}

Expand All @@ -67,7 +68,7 @@ type SpecWithSchemasTests() =
let ``POST /v2 -> OK "345"``() = task {
let! response = client.PostAsync("/v2", null)
let! text = response.Content.ReadAsStringAsync()
Assert.Equal("345",text)
Assert.Equal("\"345\"",text)
Assert.Equal(HttpStatusCode.OK ,response.StatusCode)
}

Expand Down
24 changes: 23 additions & 1 deletion tests/GiraffeGenerator.IntegrationTests/specs/specSimple.yaml
Original file line number Diff line number Diff line change
@@ -1,12 +1,34 @@
openapi: "3.0.0"
info:
title: Spec Simple API
version: 1
paths:
/:
get:
operationId: listVersionsv2
responses:
'200':
description: returns string
content:
application/json:
schema:
type: string
/v2:
get:
operationId: getVersionDetailsv2
responses:
'200':
description: returns string
content:
application/json:
schema:
type: string
post:
operationId: postVersionDetailsv2
operationId: postVersionDetailsv2
responses:
'200':
description: returns string
content:
application/json:
schema:
type: string
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
openapi: "3.0.0"
info:
title: Spec with arguments API
version: 1
paths:
/{dataset}/{version}/fields:
get:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
openapi: "3.0.0"
info:
title: Spec with parameters and request body API
version: 1
paths:
/id/{param}:
parameters:
Expand All @@ -24,6 +25,7 @@ paths:
$ref: '#/components/schemas/dataSetListInput'
responses:
'200':
description: returns all input parameters in one object
content:
application/json:
schema:
Expand Down
16 changes: 16 additions & 0 deletions tests/GiraffeGenerator.IntegrationTests/specs/specWithSchemas.yaml
Original file line number Diff line number Diff line change
@@ -1,21 +1,37 @@
openapi: "3.0.0"
info:
title: Spec with schemas API
version: 1
paths:
/:
get:
operationId: listVersionsv2
responses:
'200':
description: returns string
content:
application/json:
schema:
type: string
/v2:
get:
operationId: getVersionDetailsv2
responses:
'200':
description: returns dataset
content:
application/json:
schema:
$ref: '#/components/schemas/dataSetList'
post:
operationId: postVersionDetailsv2
responses:
'200':
description: returns string
content:
application/json:
schema:
type: string
components:
schemas:
dataSetList:
Expand Down

0 comments on commit ec85264

Please sign in to comment.