From 41e97e6d2bd817c39e0ce6593acea8b9b290ddd6 Mon Sep 17 00:00:00 2001 From: "Sebastien Rosset (serosset)" Date: Tue, 12 May 2020 18:57:25 -0700 Subject: [PATCH 1/5] Mustache template should use invokerPackage tag to generate import --- .../Java/libraries/jersey2/AbstractOpenApiSchema.mustache | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/openapi-generator/src/main/resources/Java/libraries/jersey2/AbstractOpenApiSchema.mustache b/modules/openapi-generator/src/main/resources/Java/libraries/jersey2/AbstractOpenApiSchema.mustache index cdba3be84552..c924650e6c0a 100644 --- a/modules/openapi-generator/src/main/resources/Java/libraries/jersey2/AbstractOpenApiSchema.mustache +++ b/modules/openapi-generator/src/main/resources/Java/libraries/jersey2/AbstractOpenApiSchema.mustache @@ -2,7 +2,7 @@ package {{invokerPackage}}.model; -import org.openapitools.client.ApiException; +import {{invokerPackage}}.ApiException; import java.lang.reflect.Type; import java.util.Map; import javax.ws.rs.core.GenericType; From da6744ad3f3211ce1d65844db140a59187965373 Mon Sep 17 00:00:00 2001 From: "Sebastien Rosset (serosset)" Date: Sat, 23 May 2020 11:57:24 -0700 Subject: [PATCH 2/5] Conditionally include HttpSignatureAuth.mustache template --- .../org/openapitools/codegen/languages/JavaClientCodegen.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/JavaClientCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/JavaClientCodegen.java index 0968056492ab..6e47119db0ef 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/JavaClientCodegen.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/JavaClientCodegen.java @@ -380,7 +380,9 @@ public void processOpts() { } else if (JERSEY2.equals(getLibrary())) { supportingFiles.add(new SupportingFile("JSON.mustache", invokerFolder, "JSON.java")); supportingFiles.add(new SupportingFile("ApiResponse.mustache", invokerFolder, "ApiResponse.java")); - supportingFiles.add(new SupportingFile("auth/HttpSignatureAuth.mustache", authFolder, "HttpSignatureAuth.java")); + if (ProcessUtils.hasHttpSignatureMethods(authMethods)) { + supportingFiles.add(new SupportingFile("auth/HttpSignatureAuth.mustache", authFolder, "HttpSignatureAuth.java")); + } supportingFiles.add(new SupportingFile("AbstractOpenApiSchema.mustache", (sourceFolder + File.separator + modelPackage().replace('.', File.separatorChar)).replace('/', File.separatorChar), "AbstractOpenApiSchema.java")); forceSerializationLibrary(SERIALIZATION_LIBRARY_JACKSON); } else if (NATIVE.equals(getLibrary())) { From c5e6f2d3d8a61c029a688592317921a187f8a7cc Mon Sep 17 00:00:00 2001 From: "Sebastien Rosset (serosset)" Date: Sat, 23 May 2020 12:11:48 -0700 Subject: [PATCH 3/5] Conditionally include HttpSignatureAuth.mustache template --- .../codegen/languages/JavaClientCodegen.java | 4 + .../jersey2-java7/.openapi-generator/FILES | 1 - .../client/auth/HttpSignatureAuth.java | 262 ------------------ .../jersey2-java8/.openapi-generator/FILES | 1 - .../client/auth/HttpSignatureAuth.java | 262 ------------------ 5 files changed, 4 insertions(+), 526 deletions(-) delete mode 100644 samples/client/petstore/java/jersey2-java7/src/main/java/org/openapitools/client/auth/HttpSignatureAuth.java delete mode 100644 samples/client/petstore/java/jersey2-java8/src/main/java/org/openapitools/client/auth/HttpSignatureAuth.java diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/JavaClientCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/JavaClientCodegen.java index 6e47119db0ef..858885958e97 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/JavaClientCodegen.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/JavaClientCodegen.java @@ -19,6 +19,7 @@ import io.swagger.v3.oas.models.Operation; import io.swagger.v3.oas.models.media.Schema; +import io.swagger.v3.oas.models.security.SecurityScheme; import org.apache.commons.lang3.BooleanUtils; import org.apache.commons.lang3.StringUtils; import org.openapitools.codegen.*; @@ -380,6 +381,9 @@ public void processOpts() { } else if (JERSEY2.equals(getLibrary())) { supportingFiles.add(new SupportingFile("JSON.mustache", invokerFolder, "JSON.java")); supportingFiles.add(new SupportingFile("ApiResponse.mustache", invokerFolder, "ApiResponse.java")); + Map securitySchemeMap = openAPI != null ? + (openAPI.getComponents() != null ? openAPI.getComponents().getSecuritySchemes() : null) : null; + List authMethods = fromSecurity(securitySchemeMap); if (ProcessUtils.hasHttpSignatureMethods(authMethods)) { supportingFiles.add(new SupportingFile("auth/HttpSignatureAuth.mustache", authFolder, "HttpSignatureAuth.java")); } diff --git a/samples/client/petstore/java/jersey2-java7/.openapi-generator/FILES b/samples/client/petstore/java/jersey2-java7/.openapi-generator/FILES index 3cd9918bb90e..7c98cddde480 100644 --- a/samples/client/petstore/java/jersey2-java7/.openapi-generator/FILES +++ b/samples/client/petstore/java/jersey2-java7/.openapi-generator/FILES @@ -86,7 +86,6 @@ src/main/java/org/openapitools/client/auth/ApiKeyAuth.java src/main/java/org/openapitools/client/auth/Authentication.java src/main/java/org/openapitools/client/auth/HttpBasicAuth.java src/main/java/org/openapitools/client/auth/HttpBearerAuth.java -src/main/java/org/openapitools/client/auth/HttpSignatureAuth.java src/main/java/org/openapitools/client/auth/OAuth.java src/main/java/org/openapitools/client/auth/OAuthFlow.java src/main/java/org/openapitools/client/model/AbstractOpenApiSchema.java diff --git a/samples/client/petstore/java/jersey2-java7/src/main/java/org/openapitools/client/auth/HttpSignatureAuth.java b/samples/client/petstore/java/jersey2-java7/src/main/java/org/openapitools/client/auth/HttpSignatureAuth.java deleted file mode 100644 index 628ba5c18df5..000000000000 --- a/samples/client/petstore/java/jersey2-java7/src/main/java/org/openapitools/client/auth/HttpSignatureAuth.java +++ /dev/null @@ -1,262 +0,0 @@ -/* - * OpenAPI Petstore - * This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\ - * - * The version of the OpenAPI document: 1.0.0 - * - * - * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). - * https://openapi-generator.tech - * Do not edit the class manually. - */ - - -package org.openapitools.client.auth; - -import org.openapitools.client.Pair; -import org.openapitools.client.ApiException; - -import java.net.URI; -import java.net.URLEncoder; -import java.security.MessageDigest; -import java.security.Key; -import java.text.SimpleDateFormat; -import java.util.ArrayList; -import java.util.Base64; -import java.util.Date; -import java.util.Locale; -import java.util.Map; -import java.util.List; -import java.security.spec.AlgorithmParameterSpec; - -import org.tomitribe.auth.signatures.Algorithm; -import org.tomitribe.auth.signatures.Signer; -import org.tomitribe.auth.signatures.Signature; -import org.tomitribe.auth.signatures.SigningAlgorithm; - -/** - * A Configuration object for the HTTP message signature security scheme. - */ -public class HttpSignatureAuth implements Authentication { - - private Signer signer; - - // An opaque string that the server can use to look up the component they need to validate the signature. - private String keyId; - - // The HTTP signature algorithm. - private SigningAlgorithm signingAlgorithm; - - // The HTTP cryptographic algorithm. - private Algorithm algorithm; - - // The cryptographic parameters. - private AlgorithmParameterSpec parameterSpec; - - // The list of HTTP headers that should be included in the HTTP signature. - private List headers; - - // The digest algorithm which is used to calculate a cryptographic digest of the HTTP request body. - private String digestAlgorithm; - - /** - * Construct a new HTTP signature auth configuration object. - * - * @param keyId An opaque string that the server can use to look up the component they need to validate the signature. - * @param signingAlgorithm The signature algorithm. - * @param algorithm The cryptographic algorithm. - * @param digestAlgorithm The digest algorithm. - * @param headers The list of HTTP headers that should be included in the HTTP signature. - */ - public HttpSignatureAuth(String keyId, - SigningAlgorithm signingAlgorithm, - Algorithm algorithm, - String digestAlgorithm, - AlgorithmParameterSpec parameterSpec, - List headers) { - this.keyId = keyId; - this.signingAlgorithm = signingAlgorithm; - this.algorithm = algorithm; - this.parameterSpec = parameterSpec; - this.digestAlgorithm = digestAlgorithm; - this.headers = headers; - } - - /** - * Returns the opaque string that the server can use to look up the component they need to validate the signature. - * - * @return The keyId. - */ - public String getKeyId() { - return keyId; - } - - /** - * Set the HTTP signature key id. - * - * @param keyId An opaque string that the server can use to look up the component they need to validate the signature. - */ - public void setKeyId(String keyId) { - this.keyId = keyId; - } - - /** - * Returns the HTTP signature algorithm which is used to sign HTTP requests. - */ - public SigningAlgorithm getSigningAlgorithm() { - return signingAlgorithm; - } - - /** - * Sets the HTTP signature algorithm which is used to sign HTTP requests. - * - * @param signingAlgorithm The HTTP signature algorithm. - */ - public void setSigningAlgorithm(SigningAlgorithm signingAlgorithm) { - this.signingAlgorithm = signingAlgorithm; - } - - /** - * Returns the HTTP cryptographic algorithm which is used to sign HTTP requests. - */ - public Algorithm getAlgorithm() { - return algorithm; - } - - /** - * Sets the HTTP cryptographic algorithm which is used to sign HTTP requests. - * - * @param algorithm The HTTP signature algorithm. - */ - public void setAlgorithm(Algorithm algorithm) { - this.algorithm = algorithm; - } - - /** - * Returns the cryptographic parameters which are used to sign HTTP requests. - */ - public AlgorithmParameterSpec getAlgorithmParameterSpec() { - return parameterSpec; - } - - /** - * Sets the cryptographic parameters which are used to sign HTTP requests. - * - * @param parameterSpec The cryptographic parameters. - */ - public void setAlgorithmParameterSpec(AlgorithmParameterSpec parameterSpec) { - this.parameterSpec = parameterSpec; - } - - /** - * Returns the digest algorithm which is used to calculate a cryptographic digest of the HTTP request body. - * - * @see java.security.MessageDigest - */ - public String getDigestAlgorithm() { - return digestAlgorithm; - } - - /** - * Sets the digest algorithm which is used to calculate a cryptographic digest of the HTTP request body. - * - * The exact list of supported digest algorithms depends on the installed security providers. - * Every implementation of the Java platform is required to support "MD5", "SHA-1" and "SHA-256". - * Do not use "MD5" and "SHA-1", they are vulnerable to multiple known attacks. - * By default, "SHA-256" is used. - * - * @param digestAlgorithm The digest algorithm. - * - * @see java.security.MessageDigest - */ - public void setDigestAlgorithm(String digestAlgorithm) { - this.digestAlgorithm = digestAlgorithm; - } - - /** - * Returns the list of HTTP headers that should be included in the HTTP signature. - */ - public List getHeaders() { - return headers; - } - - /** - * Sets the list of HTTP headers that should be included in the HTTP signature. - * - * @param headers The HTTP headers. - */ - public void setHeaders(List headers) { - this.headers = headers; - } - - /** - * Returns the signer instance used to sign HTTP messages. - * - * @returrn the signer instance. - */ - public Signer getSigner() { - return signer; - } - - /** - * Sets the signer instance used to sign HTTP messages. - * - * @param signer The signer instance to set. - */ - public void setSigner(Signer signer) { - this.signer = signer; - } - - /** - * Set the private key used to sign HTTP requests using the HTTP signature scheme. - * - * @param key The private key. - */ - public void setPrivateKey(Key key) throws ApiException { - if (key == null) { - throw new ApiException("Private key (java.security.Key) cannot be null"); - } - - signer = new Signer(key, new Signature(keyId, signingAlgorithm, algorithm, parameterSpec, null, headers)); - } - - @Override - public void applyToParams(List queryParams, Map headerParams, Map cookieParams, - String payload, String method, URI uri) throws ApiException { - try { - if (headers.contains("host")) { - headerParams.put("host", uri.getHost()); - } - - if (headers.contains("date")) { - headerParams.put("date", new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss zzz", Locale.US).format(new Date())); - } - - if (headers.contains("digest")) { - headerParams.put("digest", - this.digestAlgorithm + "=" + - new String(Base64.getEncoder().encode(MessageDigest.getInstance(this.digestAlgorithm).digest(payload.getBytes())))); - } - - if (signer == null) { - throw new ApiException("Signer cannot be null. Please call the method `setPrivateKey` to set it up correctly"); - } - - // construct the path with the URL query string - String path = uri.getPath(); - - List urlQueries = new ArrayList(); - for (Pair queryParam : queryParams) { - urlQueries.add(queryParam.getName() + "=" + URLEncoder.encode(queryParam.getValue(), "utf8").replaceAll("\\+", "%20")); - } - - if (!urlQueries.isEmpty()) { - path = path + "?" + String.join("&", urlQueries); - } - - headerParams.put("Authorization", signer.sign(method, path, headerParams).toString()); - } catch (Exception ex) { - throw new ApiException("Failed to create signature in the HTTP request header: " + ex.toString()); - } - } -} diff --git a/samples/client/petstore/java/jersey2-java8/.openapi-generator/FILES b/samples/client/petstore/java/jersey2-java8/.openapi-generator/FILES index 5f13bc879b4d..ec3057e7863d 100644 --- a/samples/client/petstore/java/jersey2-java8/.openapi-generator/FILES +++ b/samples/client/petstore/java/jersey2-java8/.openapi-generator/FILES @@ -86,7 +86,6 @@ src/main/java/org/openapitools/client/auth/ApiKeyAuth.java src/main/java/org/openapitools/client/auth/Authentication.java src/main/java/org/openapitools/client/auth/HttpBasicAuth.java src/main/java/org/openapitools/client/auth/HttpBearerAuth.java -src/main/java/org/openapitools/client/auth/HttpSignatureAuth.java src/main/java/org/openapitools/client/auth/OAuth.java src/main/java/org/openapitools/client/auth/OAuthFlow.java src/main/java/org/openapitools/client/model/AbstractOpenApiSchema.java diff --git a/samples/client/petstore/java/jersey2-java8/src/main/java/org/openapitools/client/auth/HttpSignatureAuth.java b/samples/client/petstore/java/jersey2-java8/src/main/java/org/openapitools/client/auth/HttpSignatureAuth.java deleted file mode 100644 index 628ba5c18df5..000000000000 --- a/samples/client/petstore/java/jersey2-java8/src/main/java/org/openapitools/client/auth/HttpSignatureAuth.java +++ /dev/null @@ -1,262 +0,0 @@ -/* - * OpenAPI Petstore - * This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\ - * - * The version of the OpenAPI document: 1.0.0 - * - * - * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). - * https://openapi-generator.tech - * Do not edit the class manually. - */ - - -package org.openapitools.client.auth; - -import org.openapitools.client.Pair; -import org.openapitools.client.ApiException; - -import java.net.URI; -import java.net.URLEncoder; -import java.security.MessageDigest; -import java.security.Key; -import java.text.SimpleDateFormat; -import java.util.ArrayList; -import java.util.Base64; -import java.util.Date; -import java.util.Locale; -import java.util.Map; -import java.util.List; -import java.security.spec.AlgorithmParameterSpec; - -import org.tomitribe.auth.signatures.Algorithm; -import org.tomitribe.auth.signatures.Signer; -import org.tomitribe.auth.signatures.Signature; -import org.tomitribe.auth.signatures.SigningAlgorithm; - -/** - * A Configuration object for the HTTP message signature security scheme. - */ -public class HttpSignatureAuth implements Authentication { - - private Signer signer; - - // An opaque string that the server can use to look up the component they need to validate the signature. - private String keyId; - - // The HTTP signature algorithm. - private SigningAlgorithm signingAlgorithm; - - // The HTTP cryptographic algorithm. - private Algorithm algorithm; - - // The cryptographic parameters. - private AlgorithmParameterSpec parameterSpec; - - // The list of HTTP headers that should be included in the HTTP signature. - private List headers; - - // The digest algorithm which is used to calculate a cryptographic digest of the HTTP request body. - private String digestAlgorithm; - - /** - * Construct a new HTTP signature auth configuration object. - * - * @param keyId An opaque string that the server can use to look up the component they need to validate the signature. - * @param signingAlgorithm The signature algorithm. - * @param algorithm The cryptographic algorithm. - * @param digestAlgorithm The digest algorithm. - * @param headers The list of HTTP headers that should be included in the HTTP signature. - */ - public HttpSignatureAuth(String keyId, - SigningAlgorithm signingAlgorithm, - Algorithm algorithm, - String digestAlgorithm, - AlgorithmParameterSpec parameterSpec, - List headers) { - this.keyId = keyId; - this.signingAlgorithm = signingAlgorithm; - this.algorithm = algorithm; - this.parameterSpec = parameterSpec; - this.digestAlgorithm = digestAlgorithm; - this.headers = headers; - } - - /** - * Returns the opaque string that the server can use to look up the component they need to validate the signature. - * - * @return The keyId. - */ - public String getKeyId() { - return keyId; - } - - /** - * Set the HTTP signature key id. - * - * @param keyId An opaque string that the server can use to look up the component they need to validate the signature. - */ - public void setKeyId(String keyId) { - this.keyId = keyId; - } - - /** - * Returns the HTTP signature algorithm which is used to sign HTTP requests. - */ - public SigningAlgorithm getSigningAlgorithm() { - return signingAlgorithm; - } - - /** - * Sets the HTTP signature algorithm which is used to sign HTTP requests. - * - * @param signingAlgorithm The HTTP signature algorithm. - */ - public void setSigningAlgorithm(SigningAlgorithm signingAlgorithm) { - this.signingAlgorithm = signingAlgorithm; - } - - /** - * Returns the HTTP cryptographic algorithm which is used to sign HTTP requests. - */ - public Algorithm getAlgorithm() { - return algorithm; - } - - /** - * Sets the HTTP cryptographic algorithm which is used to sign HTTP requests. - * - * @param algorithm The HTTP signature algorithm. - */ - public void setAlgorithm(Algorithm algorithm) { - this.algorithm = algorithm; - } - - /** - * Returns the cryptographic parameters which are used to sign HTTP requests. - */ - public AlgorithmParameterSpec getAlgorithmParameterSpec() { - return parameterSpec; - } - - /** - * Sets the cryptographic parameters which are used to sign HTTP requests. - * - * @param parameterSpec The cryptographic parameters. - */ - public void setAlgorithmParameterSpec(AlgorithmParameterSpec parameterSpec) { - this.parameterSpec = parameterSpec; - } - - /** - * Returns the digest algorithm which is used to calculate a cryptographic digest of the HTTP request body. - * - * @see java.security.MessageDigest - */ - public String getDigestAlgorithm() { - return digestAlgorithm; - } - - /** - * Sets the digest algorithm which is used to calculate a cryptographic digest of the HTTP request body. - * - * The exact list of supported digest algorithms depends on the installed security providers. - * Every implementation of the Java platform is required to support "MD5", "SHA-1" and "SHA-256". - * Do not use "MD5" and "SHA-1", they are vulnerable to multiple known attacks. - * By default, "SHA-256" is used. - * - * @param digestAlgorithm The digest algorithm. - * - * @see java.security.MessageDigest - */ - public void setDigestAlgorithm(String digestAlgorithm) { - this.digestAlgorithm = digestAlgorithm; - } - - /** - * Returns the list of HTTP headers that should be included in the HTTP signature. - */ - public List getHeaders() { - return headers; - } - - /** - * Sets the list of HTTP headers that should be included in the HTTP signature. - * - * @param headers The HTTP headers. - */ - public void setHeaders(List headers) { - this.headers = headers; - } - - /** - * Returns the signer instance used to sign HTTP messages. - * - * @returrn the signer instance. - */ - public Signer getSigner() { - return signer; - } - - /** - * Sets the signer instance used to sign HTTP messages. - * - * @param signer The signer instance to set. - */ - public void setSigner(Signer signer) { - this.signer = signer; - } - - /** - * Set the private key used to sign HTTP requests using the HTTP signature scheme. - * - * @param key The private key. - */ - public void setPrivateKey(Key key) throws ApiException { - if (key == null) { - throw new ApiException("Private key (java.security.Key) cannot be null"); - } - - signer = new Signer(key, new Signature(keyId, signingAlgorithm, algorithm, parameterSpec, null, headers)); - } - - @Override - public void applyToParams(List queryParams, Map headerParams, Map cookieParams, - String payload, String method, URI uri) throws ApiException { - try { - if (headers.contains("host")) { - headerParams.put("host", uri.getHost()); - } - - if (headers.contains("date")) { - headerParams.put("date", new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss zzz", Locale.US).format(new Date())); - } - - if (headers.contains("digest")) { - headerParams.put("digest", - this.digestAlgorithm + "=" + - new String(Base64.getEncoder().encode(MessageDigest.getInstance(this.digestAlgorithm).digest(payload.getBytes())))); - } - - if (signer == null) { - throw new ApiException("Signer cannot be null. Please call the method `setPrivateKey` to set it up correctly"); - } - - // construct the path with the URL query string - String path = uri.getPath(); - - List urlQueries = new ArrayList(); - for (Pair queryParam : queryParams) { - urlQueries.add(queryParam.getName() + "=" + URLEncoder.encode(queryParam.getValue(), "utf8").replaceAll("\\+", "%20")); - } - - if (!urlQueries.isEmpty()) { - path = path + "?" + String.join("&", urlQueries); - } - - headerParams.put("Authorization", signer.sign(method, path, headerParams).toString()); - } catch (Exception ex) { - throw new ApiException("Failed to create signature in the HTTP request header: " + ex.toString()); - } - } -} From 9c8f970ec6616f435d9dd86b329150935a534c03 Mon Sep 17 00:00:00 2001 From: "Sebastien Rosset (serosset)" Date: Sat, 23 May 2020 13:21:36 -0700 Subject: [PATCH 4/5] Conditionally include HttpSignatureAuth.mustache template --- .../main/resources/Java/libraries/jersey2/ApiClient.mustache | 2 ++ .../src/main/java/org/openapitools/client/ApiClient.java | 1 - .../src/main/java/org/openapitools/client/ApiClient.java | 1 - 3 files changed, 2 insertions(+), 2 deletions(-) diff --git a/modules/openapi-generator/src/main/resources/Java/libraries/jersey2/ApiClient.mustache b/modules/openapi-generator/src/main/resources/Java/libraries/jersey2/ApiClient.mustache index 66fe2735584a..362aee07d75d 100644 --- a/modules/openapi-generator/src/main/resources/Java/libraries/jersey2/ApiClient.mustache +++ b/modules/openapi-generator/src/main/resources/Java/libraries/jersey2/ApiClient.mustache @@ -59,7 +59,9 @@ import java.util.regex.Pattern; import {{invokerPackage}}.auth.Authentication; import {{invokerPackage}}.auth.HttpBasicAuth; import {{invokerPackage}}.auth.HttpBearerAuth; +{{#hasHttpSignatureMethods}} import {{invokerPackage}}.auth.HttpSignatureAuth; +{{/hasHttpSignatureMethods}} import {{invokerPackage}}.auth.ApiKeyAuth; {{#hasOAuthMethods}} import {{invokerPackage}}.auth.OAuth; diff --git a/samples/client/petstore/java/jersey2-java7/src/main/java/org/openapitools/client/ApiClient.java b/samples/client/petstore/java/jersey2-java7/src/main/java/org/openapitools/client/ApiClient.java index d2137b8d0882..a6405acc7842 100644 --- a/samples/client/petstore/java/jersey2-java7/src/main/java/org/openapitools/client/ApiClient.java +++ b/samples/client/petstore/java/jersey2-java7/src/main/java/org/openapitools/client/ApiClient.java @@ -51,7 +51,6 @@ import org.openapitools.client.auth.Authentication; import org.openapitools.client.auth.HttpBasicAuth; import org.openapitools.client.auth.HttpBearerAuth; -import org.openapitools.client.auth.HttpSignatureAuth; import org.openapitools.client.auth.ApiKeyAuth; import org.openapitools.client.auth.OAuth; import org.openapitools.client.model.AbstractOpenApiSchema; diff --git a/samples/client/petstore/java/jersey2-java8/src/main/java/org/openapitools/client/ApiClient.java b/samples/client/petstore/java/jersey2-java8/src/main/java/org/openapitools/client/ApiClient.java index d2137b8d0882..a6405acc7842 100644 --- a/samples/client/petstore/java/jersey2-java8/src/main/java/org/openapitools/client/ApiClient.java +++ b/samples/client/petstore/java/jersey2-java8/src/main/java/org/openapitools/client/ApiClient.java @@ -51,7 +51,6 @@ import org.openapitools.client.auth.Authentication; import org.openapitools.client.auth.HttpBasicAuth; import org.openapitools.client.auth.HttpBearerAuth; -import org.openapitools.client.auth.HttpSignatureAuth; import org.openapitools.client.auth.ApiKeyAuth; import org.openapitools.client.auth.OAuth; import org.openapitools.client.model.AbstractOpenApiSchema; From 80fcf07e2f1c99b90efc3019eeb750c990c99ed1 Mon Sep 17 00:00:00 2001 From: "Sebastien Rosset (serosset)" Date: Sat, 23 May 2020 13:27:16 -0700 Subject: [PATCH 5/5] Conditionally include HttpSignatureAuth.mustache template --- .../openapitools/codegen/languages/JavaClientCodegen.java | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/JavaClientCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/JavaClientCodegen.java index 858885958e97..b7d84d434665 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/JavaClientCodegen.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/JavaClientCodegen.java @@ -19,7 +19,6 @@ import io.swagger.v3.oas.models.Operation; import io.swagger.v3.oas.models.media.Schema; -import io.swagger.v3.oas.models.security.SecurityScheme; import org.apache.commons.lang3.BooleanUtils; import org.apache.commons.lang3.StringUtils; import org.openapitools.codegen.*; @@ -381,10 +380,7 @@ public void processOpts() { } else if (JERSEY2.equals(getLibrary())) { supportingFiles.add(new SupportingFile("JSON.mustache", invokerFolder, "JSON.java")); supportingFiles.add(new SupportingFile("ApiResponse.mustache", invokerFolder, "ApiResponse.java")); - Map securitySchemeMap = openAPI != null ? - (openAPI.getComponents() != null ? openAPI.getComponents().getSecuritySchemes() : null) : null; - List authMethods = fromSecurity(securitySchemeMap); - if (ProcessUtils.hasHttpSignatureMethods(authMethods)) { + if (ProcessUtils.hasHttpSignatureMethods(openAPI)) { supportingFiles.add(new SupportingFile("auth/HttpSignatureAuth.mustache", authFolder, "HttpSignatureAuth.java")); } supportingFiles.add(new SupportingFile("AbstractOpenApiSchema.mustache", (sourceFolder + File.separator + modelPackage().replace('.', File.separatorChar)).replace('/', File.separatorChar), "AbstractOpenApiSchema.java"));