diff --git a/src/main/kotlin/com/cjbooms/fabrikt/generators/client/OpenFeignInterfaceGenerator.kt b/src/main/kotlin/com/cjbooms/fabrikt/generators/client/OpenFeignInterfaceGenerator.kt index 9a5a66ff..eedf4298 100644 --- a/src/main/kotlin/com/cjbooms/fabrikt/generators/client/OpenFeignInterfaceGenerator.kt +++ b/src/main/kotlin/com/cjbooms/fabrikt/generators/client/OpenFeignInterfaceGenerator.kt @@ -211,10 +211,9 @@ class OpenFeignInterfaceGenerator( } return if (headersValueParts.isNotEmpty()) { - val format = if (headersValueParts.size == 1) "%L" else "value = [%L]" - OpenFeignAnnotations.headersBuilder() - .addMember(format, headersValueParts.joinToString(", ")) - .build() + val headersBuilder = OpenFeignAnnotations.headersBuilder() + headersValueParts.forEach { headersBuilder.addMember("%S", it) } + return headersBuilder.build() } else { null } @@ -241,7 +240,7 @@ class OpenFeignInterfaceGenerator( "{${parameter.name}}" } return buildCodeBlock { - add("%S", "${parameter.originalName}: $parameterValue") + add("%L", "${parameter.originalName}: $parameterValue") }.toString() } @@ -249,7 +248,7 @@ class OpenFeignInterfaceGenerator( return operation.getPrimaryContentMediaType()?.key?.let { mediaType -> buildCodeBlock { add( - "%S", + "%L", "${ClientGeneratorUtils.ACCEPT_HEADER_NAME}: $mediaType", ) }.toString() diff --git a/src/test/resources/examples/multiMediaType/client/OpenFeignClient.kt b/src/test/resources/examples/multiMediaType/client/OpenFeignClient.kt index eafcd534..910f19a1 100644 --- a/src/test/resources/examples/multiMediaType/client/OpenFeignClient.kt +++ b/src/test/resources/examples/multiMediaType/client/OpenFeignClient.kt @@ -24,7 +24,10 @@ interface ExamplePath1Client { * @param acceptHeader */ @RequestLine("GET /example-path-1?explode_list_query_param={explodeListQueryParam}&query_param2={queryParam2}") - @Headers(value = ["Accept: {acceptHeader}", "Accept: application/vnd.custom.media+xml"]) + @Headers( + "Accept: {acceptHeader}", + "Accept: application/vnd.custom.media+xml" + ) fun getExamplePath1( @Param("explodeListQueryParam") explodeListQueryParam: List? = null, @Param("queryParam2") queryParam2: Int? = null, @@ -43,7 +46,10 @@ interface ExamplePath2Client { * @param accept the content type accepted by the client */ @RequestLine("GET /example-path-2?explode_list_query_param={explodeListQueryParam}&query_param2={queryParam2}") - @Headers(value = ["Accept: {accept}", "Accept: application/vnd.custom.media+xml"]) + @Headers( + "Accept: {accept}", + "Accept: application/vnd.custom.media+xml" + ) fun getExamplePath2( @Param("explodeListQueryParam") explodeListQueryParam: List? = null, @Param("queryParam2") queryParam2: Int? = null, @@ -60,7 +66,10 @@ interface MultipleResponseSchemasClient { * @param accept the content type accepted by the client */ @RequestLine("GET /multiple-response-schemas") - @Headers(value = ["Accept: {accept}", "Accept: application/json"]) + @Headers( + "Accept: {accept}", + "Accept: application/json" + ) fun getMultipleResponseSchemas( @Param("accept") accept: ContentType? = null, @HeaderMap diff --git a/src/test/resources/examples/openFeignClient/api.yaml b/src/test/resources/examples/openFeignClient/api.yaml index cb3bff0a..d02ebe42 100644 --- a/src/test/resources/examples/openFeignClient/api.yaml +++ b/src/test/resources/examples/openFeignClient/api.yaml @@ -9,6 +9,8 @@ paths: parameters: - $ref: "#/components/parameters/ListQueryParamExploded" - $ref: "#/components/parameters/QueryParam2" + - $ref: "#/components/parameters/HeaderParam1" + - $ref: "#/components/parameters/HeaderParam2" responses: 200: description: "successful operation" @@ -169,6 +171,19 @@ components: schema: type: boolean required: false + HeaderParam1: + name: "header_param1" + in: "header" + schema: + type: string + required: false + HeaderParam2: + name: "header_param2" + in: "header" + schema: + type: string + required: false + headers: Location: diff --git a/src/test/resources/examples/openFeignClient/client/OpenFeignClient.kt b/src/test/resources/examples/openFeignClient/client/OpenFeignClient.kt index 583b93ce..7c0b3b66 100644 --- a/src/test/resources/examples/openFeignClient/client/OpenFeignClient.kt +++ b/src/test/resources/examples/openFeignClient/client/OpenFeignClient.kt @@ -21,12 +21,20 @@ interface ExamplePath1Client { * * @param explodeListQueryParam * @param queryParam2 + * @param headerParam1 + * @param headerParam2 */ @RequestLine("GET /example-path-1?explode_list_query_param={explodeListQueryParam}&query_param2={queryParam2}") - @Headers("Accept: application/vnd.custom.media+json") + @Headers( + "header_param1: {headerParam1}", + "header_param2: {headerParam2}", + "Accept: application/vnd.custom.media+json" + ) fun getExamplePath1( @Param("explodeListQueryParam") explodeListQueryParam: List? = null, @Param("queryParam2") queryParam2: Int? = null, + @Param("headerParam1") headerParam1: String? = null, + @Param("headerParam2") headerParam2: String? = null, @HeaderMap additionalHeaders: Map = emptyMap() ): QueryResult @@ -55,7 +63,10 @@ interface ExamplePath2Client { * @param ifNoneMatch The RFC7232 If-None-Match header field */ @RequestLine("GET /example-path-2/{pathParam}?limit={limit}&query_param2={queryParam2}") - @Headers(value = ["If-None-Match: {ifNoneMatch}", "Accept: application/json"]) + @Headers( + "If-None-Match: {ifNoneMatch}", + "Accept: application/json" + ) fun getExamplePath2PathParam( @Param("pathParam") pathParam: String, @Param("limit") limit: Int = 500, diff --git a/src/test/resources/examples/openFeignClient/client/SuspendableOpenFeignClient.kt b/src/test/resources/examples/openFeignClient/client/SuspendableOpenFeignClient.kt index f4146ccc..99d70c67 100644 --- a/src/test/resources/examples/openFeignClient/client/SuspendableOpenFeignClient.kt +++ b/src/test/resources/examples/openFeignClient/client/SuspendableOpenFeignClient.kt @@ -21,12 +21,20 @@ interface ExamplePath1Client { * * @param explodeListQueryParam * @param queryParam2 + * @param headerParam1 + * @param headerParam2 */ @RequestLine("GET /example-path-1?explode_list_query_param={explodeListQueryParam}&query_param2={queryParam2}") - @Headers("Accept: application/vnd.custom.media+json") + @Headers( + "header_param1: {headerParam1}", + "header_param2: {headerParam2}", + "Accept: application/vnd.custom.media+json" + ) suspend fun getExamplePath1( @Param("explodeListQueryParam") explodeListQueryParam: List? = null, @Param("queryParam2") queryParam2: Int? = null, + @Param("headerParam1") headerParam1: String? = null, + @Param("headerParam2") headerParam2: String? = null, @HeaderMap additionalHeaders: Map = emptyMap() ): QueryResult @@ -55,7 +63,10 @@ interface ExamplePath2Client { * @param ifNoneMatch The RFC7232 If-None-Match header field */ @RequestLine("GET /example-path-2/{pathParam}?limit={limit}&query_param2={queryParam2}") - @Headers(value = ["If-None-Match: {ifNoneMatch}", "Accept: application/json"]) + @Headers( + "If-None-Match: {ifNoneMatch}", + "Accept: application/json" + ) suspend fun getExamplePath2PathParam( @Param("pathParam") pathParam: String, @Param("limit") limit: Int = 500,