From 17886b65c620ff63cebf2570c79e0f2fdffc7b03 Mon Sep 17 00:00:00 2001 From: Sergey Tihon Date: Sat, 20 Aug 2016 23:44:56 +0300 Subject: [PATCH] Allow to configure protocol together with host name --- src/SwaggerProvider.DesignTime/OperationCompiler.fs | 6 +----- .../SwaggerProviderConfig.fs | 7 ++++++- .../Swagger.PetStore.Tests.fs | 10 +++++----- 3 files changed, 12 insertions(+), 11 deletions(-) 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`` () =