Skip to content

Commit 17886b6

Browse files
committed
Allow to configure protocol together with host name
1 parent c7fea05 commit 17886b6

File tree

3 files changed

+12
-11
lines changed

3 files changed

+12
-11
lines changed

src/SwaggerProvider.DesignTime/OperationCompiler.fs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -49,12 +49,8 @@ type OperationCompiler (schema:SwaggerObject, defCompiler:DefinitionCompiler) =
4949
let customizeHttpRequest = Expr.PropertyGet(this, thisTy.GetProperty("CustomizeHttpRequest"))
5050

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

5955
// Fit headers into quotation
6056
let headers =

src/SwaggerProvider.DesignTime/SwaggerProviderConfig.fs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,9 +70,14 @@ module private SwaggerProviderConfig =
7070
ty.AddXmlDoc ("Swagger.io Provider for " + schema.Host)
7171
ty.HideObjectMethods <- true
7272

73+
let protocol =
74+
match schema.Schemes with
75+
| [||] -> "http" // Should use the scheme used to access the Swagger definition itself.
76+
| array -> array.[0]
7377
let ctor =
7478
ProvidedConstructor(
75-
[ProvidedParameter("host", typeof<string>, optionalValue = schema.Host)],
79+
[ProvidedParameter("host", typeof<string>,
80+
optionalValue = sprintf "%s://%s" protocol schema.Host)],
7681
InvokeCode = fun args ->
7782
match args with
7883
| [] -> failwith "Generated constructors should always pass the instance as the first argument!"

tests/SwaggerProvider.ProviderTests/Swagger.PetStore.Tests.fs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,11 @@ let apiKey = "special-key"
1212

1313
[<Test>]
1414
let ``Test provided Host property`` () =
15-
store.Host |> shouldEqual "petstore.swagger.io"
16-
store.Host <- "test"
17-
store.Host |> shouldEqual "test"
18-
store.Host <- "petstore.swagger.io"
19-
store.Host |> shouldEqual "petstore.swagger.io"
15+
store.Host |> shouldEqual "http://petstore.swagger.io"
16+
store.Host <- "https://petstore.swagger.io"
17+
store.Host |> shouldEqual "https://petstore.swagger.io"
18+
store.Host <- "http://petstore.swagger.io"
19+
store.Host |> shouldEqual "http://petstore.swagger.io"
2020

2121
[<Test>]
2222
let ``instantiate provided objects`` () =

0 commit comments

Comments
 (0)