Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow to configure protocol together with host name #49

Merged
merged 1 commit into from
Aug 20, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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