Skip to content

Commit

Permalink
Allow to configure protocol together with host name
Browse files Browse the repository at this point in the history
  • Loading branch information
sergey-tihon committed Aug 20, 2016
1 parent c7fea05 commit 17886b6
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 11 deletions.
6 changes: 1 addition & 5 deletions src/SwaggerProvider.DesignTime/OperationCompiler.fs
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,8 @@ type OperationCompiler (schema:SwaggerObject, defCompiler:DefinitionCompiler) =
let customizeHttpRequest = Expr.PropertyGet(this, thisTy.GetProperty("CustomizeHttpRequest"))

let basePath =
let scheme =
match schema.Schemes with
| [||] -> "http" // Should use the scheme used to access the Swagger definition itself.
| array -> array.[0]
let basePath = schema.BasePath
<@ scheme + "://" + (%%host : string) + basePath @>
<@ (%%host : string) + basePath @>

// Fit headers into quotation
let headers =
Expand Down
7 changes: 6 additions & 1 deletion src/SwaggerProvider.DesignTime/SwaggerProviderConfig.fs
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,14 @@ module private SwaggerProviderConfig =
ty.AddXmlDoc ("Swagger.io Provider for " + schema.Host)
ty.HideObjectMethods <- true

let protocol =
match schema.Schemes with
| [||] -> "http" // Should use the scheme used to access the Swagger definition itself.
| array -> array.[0]
let ctor =
ProvidedConstructor(
[ProvidedParameter("host", typeof<string>, optionalValue = schema.Host)],
[ProvidedParameter("host", typeof<string>,
optionalValue = sprintf "%s://%s" protocol schema.Host)],
InvokeCode = fun args ->
match args with
| [] -> failwith "Generated constructors should always pass the instance as the first argument!"
Expand Down
10 changes: 5 additions & 5 deletions tests/SwaggerProvider.ProviderTests/Swagger.PetStore.Tests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ let apiKey = "special-key"

[<Test>]
let ``Test provided Host property`` () =
store.Host |> shouldEqual "petstore.swagger.io"
store.Host <- "test"
store.Host |> shouldEqual "test"
store.Host <- "petstore.swagger.io"
store.Host |> shouldEqual "petstore.swagger.io"
store.Host |> shouldEqual "http://petstore.swagger.io"
store.Host <- "https://petstore.swagger.io"
store.Host |> shouldEqual "https://petstore.swagger.io"
store.Host <- "http://petstore.swagger.io"
store.Host |> shouldEqual "http://petstore.swagger.io"

[<Test>]
let ``instantiate provided objects`` () =
Expand Down

0 comments on commit 17886b6

Please sign in to comment.