diff --git a/src/SwaggerProvider.DesignTime/OperationCompiler.fs b/src/SwaggerProvider.DesignTime/OperationCompiler.fs index d5a5c0bd..6eef7fe0 100644 --- a/src/SwaggerProvider.DesignTime/OperationCompiler.fs +++ b/src/SwaggerProvider.DesignTime/OperationCompiler.fs @@ -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 = diff --git a/src/SwaggerProvider.DesignTime/SwaggerProviderConfig.fs b/src/SwaggerProvider.DesignTime/SwaggerProviderConfig.fs index 33517e06..289f18b8 100644 --- a/src/SwaggerProvider.DesignTime/SwaggerProviderConfig.fs +++ b/src/SwaggerProvider.DesignTime/SwaggerProviderConfig.fs @@ -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, optionalValue = schema.Host)], + [ProvidedParameter("host", typeof, + 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!" diff --git a/tests/SwaggerProvider.ProviderTests/Swagger.PetStore.Tests.fs b/tests/SwaggerProvider.ProviderTests/Swagger.PetStore.Tests.fs index d5adf6df..17053c01 100644 --- a/tests/SwaggerProvider.ProviderTests/Swagger.PetStore.Tests.fs +++ b/tests/SwaggerProvider.ProviderTests/Swagger.PetStore.Tests.fs @@ -12,11 +12,11 @@ let apiKey = "special-key" [] 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" [] let ``instantiate provided objects`` () =