Generators "scala-sttp" and "scala-sttp4" produce valid code when using APIKeyQuery, APIKeyHeader and APIKeyCookie #13474 (#21551)

* fix: using APIKeyQuery and APIKeyHeader generates invalid code (#13474)

* fix: include test

* fix: also fix auth generation for sttp4

* fix: maintain prev whitespaces & update generated APIs
This commit is contained in:
Diego Casella 2025-07-16 09:41:01 +02:00 committed by GitHub
parent 8862b960f8
commit 7f2ee8520e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
16 changed files with 199 additions and 56 deletions

View File

@ -22,13 +22,13 @@ class {{classname}}(baseUrl: String) {
{{/javadocRenderer}}
def {{operationId}}({{>methodParameters}}): Request[{{#separateErrorChannel}}Either[ResponseException[String, Exception], {{>operationReturnType}}]{{/separateErrorChannel}}{{^separateErrorChannel}}{{>operationReturnType}}{{/separateErrorChannel}}, Any] =
basicRequest
.method(Method.{{httpMethod.toUpperCase}}, uri"$baseUrl{{{path}}}{{#queryParams.0}}?{{#queryParams}}{{baseName}}=${ {{{paramName}}} }{{^-last}}&{{/-last}}{{/queryParams}}{{/queryParams.0}}{{#isApiKey}}{{#isKeyInQuery}}{{^queryParams.0}}?{{/queryParams.0}}{{#queryParams.0}}&{{/queryParams.0}}{{keyParamName}}=${apiKey.value}&{{/isKeyInQuery}}{{/isApiKey}}")
.method(Method.{{httpMethod.toUpperCase}}, uri"$baseUrl{{{path}}}{{#queryParams.0}}?{{/queryParams.0}}{{#queryParams}}{{baseName}}=${ {{paramName}} }{{^-last}}&{{/-last}}{{/queryParams}}{{#authMethods}}{{#isApiKey}}{{#isKeyInQuery}}{{#queryParams.0}}&{{/queryParams.0}}{{^queryParams.0}}?{{/queryParams.0}}{{keyParamName}}=${apiKeyQuery}{{/isKeyInQuery}}{{/isApiKey}}{{/authMethods}}")
.contentType({{#consumes.0}}"{{{mediaType}}}"{{/consumes.0}}{{^consumes}}"application/json"{{/consumes}}){{#headerParams}}
.header({{>paramCreation}}){{/headerParams}}{{#authMethods}}{{#isBasic}}{{#isBasicBasic}}
.auth.basic(username, password){{/isBasicBasic}}{{#isBasicBearer}}
.auth.bearer(bearerToken){{/isBasicBearer}}{{/isBasic}}{{#isApiKey}}{{#isKeyInHeader}}
.header("{{keyParamName}}", apiKey){{/isKeyInHeader}}{{#isKeyInCookie}}
.cookie("{{keyParamName}}", apiKey){{/isKeyInCookie}}{{/isApiKey}}{{/authMethods}}{{#formParams.0}}{{^isMultipart}}
.header("{{keyParamName}}", apiKeyHeader){{/isKeyInHeader}}{{#isKeyInCookie}}
.cookie("{{keyParamName}}", apiKeyCookie){{/isKeyInCookie}}{{/isApiKey}}{{/authMethods}}{{#formParams.0}}{{^isMultipart}}
.body(Map({{#formParams}}
{{>paramFormCreation}}{{^-last}},{{/-last}}{{/formParams}}
)){{/isMultipart}}{{#isMultipart}}

View File

@ -1 +1 @@
{{#authMethods.0}}{{#authMethods}}{{#isApiKey}}apiKey: String{{/isApiKey}}{{#isBasic}}{{#isBasicBasic}}username: String, password: String{{/isBasicBasic}}{{#isBasicBearer}}bearerToken: String{{/isBasicBearer}}{{/isBasic}}{{^-last}}, {{/-last}}{{/authMethods}})({{/authMethods.0}}{{#allParams}}{{paramName}}: {{#required}}{{dataType}}{{/required}}{{^required}}{{#isContainer}}{{dataType}}{{/isContainer}}{{^isContainer}}Option[{{dataType}}]{{/isContainer}}{{/required}}{{^defaultValue}}{{^required}}{{^isContainer}} = None{{/isContainer}}{{/required}}{{/defaultValue}}{{^-last}}, {{/-last}}{{/allParams}}
{{#authMethods.0}}{{#authMethods}}{{#isApiKey}}{{#isKeyInHeader}}apiKeyHeader: String{{/isKeyInHeader}}{{#isKeyInQuery}}apiKeyQuery: String{{/isKeyInQuery}}{{#isKeyInCookie}}apiKeyCookie: String{{/isKeyInCookie}}{{/isApiKey}}{{#isBasic}}{{#isBasicBasic}}username: String, password: String{{/isBasicBasic}}{{#isBasicBearer}}bearerToken: String{{/isBasicBearer}}{{/isBasic}}{{^-last}}, {{/-last}}{{/authMethods}})({{/authMethods.0}}{{#allParams}}{{paramName}}: {{#required}}{{dataType}}{{/required}}{{^required}}{{#isContainer}}{{dataType}}{{/isContainer}}{{^isContainer}}Option[{{dataType}}]{{/isContainer}}{{/required}}{{^defaultValue}}{{^required}}{{^isContainer}} = None{{/isContainer}}{{/required}}{{/defaultValue}}{{^-last}}, {{/-last}}{{/allParams}}

View File

@ -22,13 +22,13 @@ class {{classname}}(baseUrl: String) {
{{/javadocRenderer}}
def {{operationId}}({{>methodParameters}}): Request[{{#separateErrorChannel}}Either[ResponseException[String, Exception], {{>operationReturnType}}]{{/separateErrorChannel}}{{^separateErrorChannel}}{{>operationReturnType}}{{/separateErrorChannel}}] =
basicRequest
.method(Method.{{httpMethod.toUpperCase}}, uri"$baseUrl{{{path}}}{{#queryParams.0}}?{{#queryParams}}{{baseName}}=${ {{{paramName}}} }{{^-last}}&{{/-last}}{{/queryParams}}{{/queryParams.0}}{{#isApiKey}}{{#isKeyInQuery}}{{^queryParams.0}}?{{/queryParams.0}}{{#queryParams.0}}&{{/queryParams.0}}{{keyParamName}}=${apiKey.value}&{{/isKeyInQuery}}{{/isApiKey}}")
.method(Method.{{httpMethod.toUpperCase}}, uri"$baseUrl{{{path}}}{{#queryParams.0}}?{{/queryParams.0}}{{#queryParams}}{{baseName}}=${ {{paramName}} }{{^-last}}&{{/-last}}{{/queryParams}}{{#authMethods}}{{#isApiKey}}{{#isKeyInQuery}}{{#queryParams.0}}&{{/queryParams.0}}{{^queryParams.0}}?{{/queryParams.0}}{{keyParamName}}=${apiKeyQuery}{{/isKeyInQuery}}{{/isApiKey}}{{/authMethods}}")
.contentType({{#consumes.0}}"{{{mediaType}}}"{{/consumes.0}}{{^consumes}}"application/json"{{/consumes}}){{#headerParams}}
.header({{>paramCreation}}){{/headerParams}}{{#authMethods}}{{#isBasic}}{{#isBasicBasic}}
.auth.basic(username, password){{/isBasicBasic}}{{#isBasicBearer}}
.auth.bearer(bearerToken){{/isBasicBearer}}{{/isBasic}}{{#isApiKey}}{{#isKeyInHeader}}
.header("{{keyParamName}}", apiKey){{/isKeyInHeader}}{{#isKeyInCookie}}
.cookie("{{keyParamName}}", apiKey){{/isKeyInCookie}}{{/isApiKey}}{{/authMethods}}{{#formParams.0}}{{^isMultipart}}
.header("{{keyParamName}}", apiKeyHeader){{/isKeyInHeader}}{{#isKeyInCookie}}
.cookie("{{keyParamName}}", apiKeyCookie){{/isKeyInCookie}}{{/isApiKey}}{{/authMethods}}{{#formParams.0}}{{^isMultipart}}
.body(Map({{#formParams}}
{{>paramFormCreation}}{{^-last}},{{/-last}}{{/formParams}}
)){{/isMultipart}}{{#isMultipart}}

View File

@ -1 +1 @@
{{#authMethods.0}}{{#authMethods}}{{#isApiKey}}apiKey: String{{/isApiKey}}{{#isBasic}}{{#isBasicBasic}}username: String, password: String{{/isBasicBasic}}{{#isBasicBearer}}bearerToken: String{{/isBasicBearer}}{{/isBasic}}{{^-last}}, {{/-last}}{{/authMethods}})({{/authMethods.0}}{{#allParams}}{{paramName}}: {{#required}}{{dataType}}{{/required}}{{^required}}{{#isContainer}}{{dataType}}{{/isContainer}}{{^isContainer}}Option[{{dataType}}]{{/isContainer}}{{/required}}{{^defaultValue}}{{^required}}{{^isContainer}} = None{{/isContainer}}{{/required}}{{/defaultValue}}{{^-last}}, {{/-last}}{{/allParams}}
{{#authMethods.0}}{{#authMethods}}{{#isApiKey}}{{#isKeyInHeader}}apiKeyHeader: String{{/isKeyInHeader}}{{#isKeyInQuery}}apiKeyQuery: String{{/isKeyInQuery}}{{#isKeyInCookie}}apiKeyCookie: String{{/isKeyInCookie}}{{/isApiKey}}{{#isBasic}}{{#isBasicBasic}}username: String, password: String{{/isBasicBasic}}{{#isBasicBearer}}bearerToken: String{{/isBasicBearer}}{{/isBasic}}{{^-last}}, {{/-last}}{{/authMethods}})({{/authMethods.0}}{{#allParams}}{{paramName}}: {{#required}}{{dataType}}{{/required}}{{^required}}{{#isContainer}}{{dataType}}{{/isContainer}}{{^isContainer}}Option[{{dataType}}]{{/isContainer}}{{/required}}{{^defaultValue}}{{^required}}{{^isContainer}} = None{{/isContainer}}{{/required}}{{/defaultValue}}{{^-last}}, {{/-last}}{{/allParams}}

View File

@ -0,0 +1,56 @@
package org.openapitools.codegen.scala;
import io.swagger.parser.OpenAPIParser;
import io.swagger.v3.oas.models.OpenAPI;
import io.swagger.v3.oas.models.media.Schema;
import io.swagger.v3.parser.core.models.ParseOptions;
import org.openapitools.codegen.ClientOptInput;
import org.openapitools.codegen.CodegenConstants;
import org.openapitools.codegen.DefaultGenerator;
import org.openapitools.codegen.languages.ScalaSttp4ClientCodegen;
import org.openapitools.codegen.languages.features.CXFServerFeatures;
import org.testng.Assert;
import org.testng.annotations.Test;
import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import static org.openapitools.codegen.TestUtils.assertFileContains;
public class Sttp4CodegenTest {
@Test
public void verifyApiKeyLocations() throws IOException {
File output = Files.createTempDirectory("test").toFile().getCanonicalFile();
output.deleteOnExit();
String outputPath = output.getAbsolutePath().replace('\\', '/');
OpenAPI openAPI = new OpenAPIParser()
.readLocation("src/test/resources/bugs/issue_13474.json", null, new ParseOptions()).getOpenAPI();
ScalaSttp4ClientCodegen codegen = new ScalaSttp4ClientCodegen();
codegen.setOutputDir(output.getAbsolutePath());
codegen.additionalProperties().put(CXFServerFeatures.LOAD_TEST_DATA_FROM_FILE, "true");
ClientOptInput input = new ClientOptInput();
input.openAPI(openAPI);
input.config(codegen);
DefaultGenerator generator = new DefaultGenerator();
generator.setGeneratorPropertyDefault(CodegenConstants.MODELS, "true");
generator.setGeneratorPropertyDefault(CodegenConstants.MODEL_TESTS, "false");
generator.setGeneratorPropertyDefault(CodegenConstants.MODEL_DOCS, "false");
generator.setGeneratorPropertyDefault(CodegenConstants.APIS, "true");
generator.setGeneratorPropertyDefault(CodegenConstants.SUPPORTING_FILES, "false");
generator.opts(input).generate();
Path path = Paths.get(outputPath + "/src/main/scala/org/openapitools/client/api/DefaultApi.scala");
assertFileContains(path, ".method(Method.GET, uri\"$baseUrl/entities/?api_key=${apiKeyQuery}\")\n");
assertFileContains(path, ".header(\"X-Api-Key\", apiKeyHeader)");
assertFileContains(path, ".cookie(\"apikey\", apiKeyCookie)");
}
}

View File

@ -78,4 +78,36 @@ public class SttpCodegenTest {
assertFileNotContains(path, "val X3D = Value(\"!=\")");
}
@Test
public void verifyApiKeyLocations() throws IOException {
File output = Files.createTempDirectory("test").toFile().getCanonicalFile();
output.deleteOnExit();
String outputPath = output.getAbsolutePath().replace('\\', '/');
OpenAPI openAPI = new OpenAPIParser()
.readLocation("src/test/resources/bugs/issue_13474.json", null, new ParseOptions()).getOpenAPI();
ScalaSttpClientCodegen codegen = new ScalaSttpClientCodegen();
codegen.setOutputDir(output.getAbsolutePath());
codegen.additionalProperties().put(CXFServerFeatures.LOAD_TEST_DATA_FROM_FILE, "true");
ClientOptInput input = new ClientOptInput();
input.openAPI(openAPI);
input.config(codegen);
DefaultGenerator generator = new DefaultGenerator();
generator.setGeneratorPropertyDefault(CodegenConstants.MODELS, "true");
generator.setGeneratorPropertyDefault(CodegenConstants.MODEL_TESTS, "false");
generator.setGeneratorPropertyDefault(CodegenConstants.MODEL_DOCS, "false");
generator.setGeneratorPropertyDefault(CodegenConstants.APIS, "true");
generator.setGeneratorPropertyDefault(CodegenConstants.SUPPORTING_FILES, "false");
generator.opts(input).generate();
Path path = Paths.get(outputPath + "/src/main/scala/org/openapitools/client/api/DefaultApi.scala");
assertFileContains(path, ".method(Method.GET, uri\"$baseUrl/entities/?api_key=${apiKeyQuery}\")\n");
assertFileContains(path, ".header(\"X-Api-Key\", apiKeyHeader)");
assertFileContains(path, ".cookie(\"apikey\", apiKeyCookie)");
}
}

View File

@ -0,0 +1,55 @@
{
"openapi": "3.0.2",
"info": {
"title": "Sample ApPI",
"version": "0.1.0"
},
"paths": {
"/entities/": {
"get": {
"responses": {
"200": {
"description": "Successful Response",
"content": {
"text/plain" : {
"schema": {
"type": "string"
}
}
}
}
},
"security": [
{
"APIKeyHeader": []
},
{
"APIKeyQuery": []
},
{
"APIKeyCookie": []
}
]
}
}
},
"components": {
"securitySchemes": {
"APIKeyHeader": {
"type": "apiKey",
"in": "header",
"name": "X-Api-Key"
},
"APIKeyQuery": {
"type": "apiKey",
"in": "query",
"name": "api_key"
},
"APIKeyCookie": {
"type": "apiKey",
"in": "cookie",
"name": "apikey"
}
}
}
}

View File

@ -103,12 +103,12 @@ class PetApi(baseUrl: String) {
*
* @param petId ID of pet to return
*/
def getPetById(apiKey: String)(petId: Long
def getPetById(apiKeyHeader: String)(petId: Long
): Request[Either[ResponseException[String, Exception], Pet], Any] =
basicRequest
.method(Method.GET, uri"$baseUrl/pet/${petId}")
.contentType("application/json")
.header("api_key", apiKey)
.header("api_key", apiKeyHeader)
.response(asJson[Pet])
/**

View File

@ -47,12 +47,12 @@ class StoreApi(baseUrl: String) {
* Available security schemes:
* api_key (apiKey)
*/
def getInventory(apiKey: String)(
def getInventory(apiKeyHeader: String)(
): Request[Either[ResponseException[String, Exception], Map[String, Int]], Any] =
basicRequest
.method(Method.GET, uri"$baseUrl/store/inventory")
.contentType("application/json")
.header("api_key", apiKey)
.header("api_key", apiKeyHeader)
.response(asJson[Map[String, Int]])
/**

View File

@ -34,12 +34,12 @@ class UserApi(baseUrl: String) {
*
* @param user Created user object
*/
def createUser(apiKey: String)(user: User
def createUser(apiKeyHeader: String)(user: User
): Request[Either[ResponseException[String, Exception], Unit], Any] =
basicRequest
.method(Method.POST, uri"$baseUrl/user")
.contentType("application/json")
.header("api_key", apiKey)
.header("api_key", apiKeyHeader)
.body(user)
.response(asString.mapWithMetadata(ResponseAs.deserializeRightWithError(_ => Right(()))))
@ -54,12 +54,12 @@ class UserApi(baseUrl: String) {
*
* @param user List of user object
*/
def createUsersWithArrayInput(apiKey: String)(user: Seq[User]
def createUsersWithArrayInput(apiKeyHeader: String)(user: Seq[User]
): Request[Either[ResponseException[String, Exception], Unit], Any] =
basicRequest
.method(Method.POST, uri"$baseUrl/user/createWithArray")
.contentType("application/json")
.header("api_key", apiKey)
.header("api_key", apiKeyHeader)
.body(user)
.response(asString.mapWithMetadata(ResponseAs.deserializeRightWithError(_ => Right(()))))
@ -74,12 +74,12 @@ class UserApi(baseUrl: String) {
*
* @param user List of user object
*/
def createUsersWithListInput(apiKey: String)(user: Seq[User]
def createUsersWithListInput(apiKeyHeader: String)(user: Seq[User]
): Request[Either[ResponseException[String, Exception], Unit], Any] =
basicRequest
.method(Method.POST, uri"$baseUrl/user/createWithList")
.contentType("application/json")
.header("api_key", apiKey)
.header("api_key", apiKeyHeader)
.body(user)
.response(asString.mapWithMetadata(ResponseAs.deserializeRightWithError(_ => Right(()))))
@ -95,12 +95,12 @@ class UserApi(baseUrl: String) {
*
* @param username The name that needs to be deleted
*/
def deleteUser(apiKey: String)(username: String
def deleteUser(apiKeyHeader: String)(username: String
): Request[Either[ResponseException[String, Exception], Unit], Any] =
basicRequest
.method(Method.DELETE, uri"$baseUrl/user/${username}")
.contentType("application/json")
.header("api_key", apiKey)
.header("api_key", apiKeyHeader)
.response(asString.mapWithMetadata(ResponseAs.deserializeRightWithError(_ => Right(()))))
/**
@ -150,12 +150,12 @@ class UserApi(baseUrl: String) {
* Available security schemes:
* api_key (apiKey)
*/
def logoutUser(apiKey: String)(
def logoutUser(apiKeyHeader: String)(
): Request[Either[ResponseException[String, Exception], Unit], Any] =
basicRequest
.method(Method.GET, uri"$baseUrl/user/logout")
.contentType("application/json")
.header("api_key", apiKey)
.header("api_key", apiKeyHeader)
.response(asString.mapWithMetadata(ResponseAs.deserializeRightWithError(_ => Right(()))))
/**
@ -171,12 +171,12 @@ class UserApi(baseUrl: String) {
* @param username name that need to be deleted
* @param user Updated user object
*/
def updateUser(apiKey: String)(username: String, user: User
def updateUser(apiKeyHeader: String)(username: String, user: User
): Request[Either[ResponseException[String, Exception], Unit], Any] =
basicRequest
.method(Method.PUT, uri"$baseUrl/user/${username}")
.contentType("application/json")
.header("api_key", apiKey)
.header("api_key", apiKeyHeader)
.body(user)
.response(asString.mapWithMetadata(ResponseAs.deserializeRightWithError(_ => Right(()))))

View File

@ -103,12 +103,12 @@ class PetApi(baseUrl: String) {
*
* @param petId ID of pet to return
*/
def getPetById(apiKey: String)(petId: Long
def getPetById(apiKeyHeader: String)(petId: Long
): Request[Either[ResponseException[String, Exception], Pet], Any] =
basicRequest
.method(Method.GET, uri"$baseUrl/pet/${petId}")
.contentType("application/json")
.header("api_key", apiKey)
.header("api_key", apiKeyHeader)
.response(asJson[Pet])
/**

View File

@ -47,12 +47,12 @@ class StoreApi(baseUrl: String) {
* Available security schemes:
* api_key (apiKey)
*/
def getInventory(apiKey: String)(
def getInventory(apiKeyHeader: String)(
): Request[Either[ResponseException[String, Exception], Map[String, Int]], Any] =
basicRequest
.method(Method.GET, uri"$baseUrl/store/inventory")
.contentType("application/json")
.header("api_key", apiKey)
.header("api_key", apiKeyHeader)
.response(asJson[Map[String, Int]])
/**

View File

@ -34,12 +34,12 @@ class UserApi(baseUrl: String) {
*
* @param user Created user object
*/
def createUser(apiKey: String)(user: User
def createUser(apiKeyHeader: String)(user: User
): Request[Either[ResponseException[String, Exception], Unit], Any] =
basicRequest
.method(Method.POST, uri"$baseUrl/user")
.contentType("application/json")
.header("api_key", apiKey)
.header("api_key", apiKeyHeader)
.body(user)
.response(asString.mapWithMetadata(ResponseAs.deserializeRightWithError(_ => Right(()))))
@ -54,12 +54,12 @@ class UserApi(baseUrl: String) {
*
* @param user List of user object
*/
def createUsersWithArrayInput(apiKey: String)(user: Seq[User]
def createUsersWithArrayInput(apiKeyHeader: String)(user: Seq[User]
): Request[Either[ResponseException[String, Exception], Unit], Any] =
basicRequest
.method(Method.POST, uri"$baseUrl/user/createWithArray")
.contentType("application/json")
.header("api_key", apiKey)
.header("api_key", apiKeyHeader)
.body(user)
.response(asString.mapWithMetadata(ResponseAs.deserializeRightWithError(_ => Right(()))))
@ -74,12 +74,12 @@ class UserApi(baseUrl: String) {
*
* @param user List of user object
*/
def createUsersWithListInput(apiKey: String)(user: Seq[User]
def createUsersWithListInput(apiKeyHeader: String)(user: Seq[User]
): Request[Either[ResponseException[String, Exception], Unit], Any] =
basicRequest
.method(Method.POST, uri"$baseUrl/user/createWithList")
.contentType("application/json")
.header("api_key", apiKey)
.header("api_key", apiKeyHeader)
.body(user)
.response(asString.mapWithMetadata(ResponseAs.deserializeRightWithError(_ => Right(()))))
@ -95,12 +95,12 @@ class UserApi(baseUrl: String) {
*
* @param username The name that needs to be deleted
*/
def deleteUser(apiKey: String)(username: String
def deleteUser(apiKeyHeader: String)(username: String
): Request[Either[ResponseException[String, Exception], Unit], Any] =
basicRequest
.method(Method.DELETE, uri"$baseUrl/user/${username}")
.contentType("application/json")
.header("api_key", apiKey)
.header("api_key", apiKeyHeader)
.response(asString.mapWithMetadata(ResponseAs.deserializeRightWithError(_ => Right(()))))
/**
@ -150,12 +150,12 @@ class UserApi(baseUrl: String) {
* Available security schemes:
* api_key (apiKey)
*/
def logoutUser(apiKey: String)(
def logoutUser(apiKeyHeader: String)(
): Request[Either[ResponseException[String, Exception], Unit], Any] =
basicRequest
.method(Method.GET, uri"$baseUrl/user/logout")
.contentType("application/json")
.header("api_key", apiKey)
.header("api_key", apiKeyHeader)
.response(asString.mapWithMetadata(ResponseAs.deserializeRightWithError(_ => Right(()))))
/**
@ -171,12 +171,12 @@ class UserApi(baseUrl: String) {
* @param username name that need to be deleted
* @param user Updated user object
*/
def updateUser(apiKey: String)(username: String, user: User
def updateUser(apiKeyHeader: String)(username: String, user: User
): Request[Either[ResponseException[String, Exception], Unit], Any] =
basicRequest
.method(Method.PUT, uri"$baseUrl/user/${username}")
.contentType("application/json")
.header("api_key", apiKey)
.header("api_key", apiKeyHeader)
.body(user)
.response(asString.mapWithMetadata(ResponseAs.deserializeRightWithError(_ => Right(()))))

View File

@ -99,11 +99,11 @@ class PetApi(baseUrl: String) {
*
* @param petId ID of pet to return
*/
def getPetById(apiKey: String)(petId: Long): Request[Either[ResponseException[String, Exception], Pet]] =
def getPetById(apiKeyHeader: String)(petId: Long): Request[Either[ResponseException[String, Exception], Pet]] =
basicRequest
.method(Method.GET, uri"$baseUrl/pet/${petId}")
.contentType("application/json")
.header("api_key", apiKey)
.header("api_key", apiKeyHeader)
.response(asJson[Pet])
/**

View File

@ -46,11 +46,11 @@ class StoreApi(baseUrl: String) {
* Available security schemes:
* api_key (apiKey)
*/
def getInventory(apiKey: String)(): Request[Either[ResponseException[String, Exception], Map[String, Int]]] =
def getInventory(apiKeyHeader: String)(): Request[Either[ResponseException[String, Exception], Map[String, Int]]] =
basicRequest
.method(Method.GET, uri"$baseUrl/store/inventory")
.contentType("application/json")
.header("api_key", apiKey)
.header("api_key", apiKeyHeader)
.response(asJson[Map[String, Int]])
/**

View File

@ -34,11 +34,11 @@ class UserApi(baseUrl: String) {
*
* @param user Created user object
*/
def createUser(apiKey: String)(user: User): Request[Either[ResponseException[String, Exception], Unit]] =
def createUser(apiKeyHeader: String)(user: User): Request[Either[ResponseException[String, Exception], Unit]] =
basicRequest
.method(Method.POST, uri"$baseUrl/user")
.contentType("application/json")
.header("api_key", apiKey)
.header("api_key", apiKeyHeader)
.body(user)
.response(asString.mapWithMetadata(ResponseAs.deserializeRightWithError(_ => Right(()))))
@ -53,11 +53,11 @@ class UserApi(baseUrl: String) {
*
* @param user List of user object
*/
def createUsersWithArrayInput(apiKey: String)(user: Seq[User]): Request[Either[ResponseException[String, Exception], Unit]] =
def createUsersWithArrayInput(apiKeyHeader: String)(user: Seq[User]): Request[Either[ResponseException[String, Exception], Unit]] =
basicRequest
.method(Method.POST, uri"$baseUrl/user/createWithArray")
.contentType("application/json")
.header("api_key", apiKey)
.header("api_key", apiKeyHeader)
.body(user)
.response(asString.mapWithMetadata(ResponseAs.deserializeRightWithError(_ => Right(()))))
@ -72,11 +72,11 @@ class UserApi(baseUrl: String) {
*
* @param user List of user object
*/
def createUsersWithListInput(apiKey: String)(user: Seq[User]): Request[Either[ResponseException[String, Exception], Unit]] =
def createUsersWithListInput(apiKeyHeader: String)(user: Seq[User]): Request[Either[ResponseException[String, Exception], Unit]] =
basicRequest
.method(Method.POST, uri"$baseUrl/user/createWithList")
.contentType("application/json")
.header("api_key", apiKey)
.header("api_key", apiKeyHeader)
.body(user)
.response(asString.mapWithMetadata(ResponseAs.deserializeRightWithError(_ => Right(()))))
@ -92,11 +92,11 @@ class UserApi(baseUrl: String) {
*
* @param username The name that needs to be deleted
*/
def deleteUser(apiKey: String)(username: String): Request[Either[ResponseException[String, Exception], Unit]] =
def deleteUser(apiKeyHeader: String)(username: String): Request[Either[ResponseException[String, Exception], Unit]] =
basicRequest
.method(Method.DELETE, uri"$baseUrl/user/${username}")
.contentType("application/json")
.header("api_key", apiKey)
.header("api_key", apiKeyHeader)
.response(asString.mapWithMetadata(ResponseAs.deserializeRightWithError(_ => Right(()))))
/**
@ -144,11 +144,11 @@ class UserApi(baseUrl: String) {
* Available security schemes:
* api_key (apiKey)
*/
def logoutUser(apiKey: String)(): Request[Either[ResponseException[String, Exception], Unit]] =
def logoutUser(apiKeyHeader: String)(): Request[Either[ResponseException[String, Exception], Unit]] =
basicRequest
.method(Method.GET, uri"$baseUrl/user/logout")
.contentType("application/json")
.header("api_key", apiKey)
.header("api_key", apiKeyHeader)
.response(asString.mapWithMetadata(ResponseAs.deserializeRightWithError(_ => Right(()))))
/**
@ -164,11 +164,11 @@ class UserApi(baseUrl: String) {
* @param username name that need to be deleted
* @param user Updated user object
*/
def updateUser(apiKey: String)(username: String, user: User): Request[Either[ResponseException[String, Exception], Unit]] =
def updateUser(apiKeyHeader: String)(username: String, user: User): Request[Either[ResponseException[String, Exception], Unit]] =
basicRequest
.method(Method.PUT, uri"$baseUrl/user/${username}")
.contentType("application/json")
.header("api_key", apiKey)
.header("api_key", apiKeyHeader)
.body(user)
.response(asString.mapWithMetadata(ResponseAs.deserializeRightWithError(_ => Right(()))))