From dfa99fd0939c5a01e63a0dd0a4b8f2e1b14863bb Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Thu, 3 Oct 2024 15:49:23 -0400 Subject: [PATCH] =?UTF-8?q?chore:=20=F0=9F=90=9D=20Update=20SDK=20-=2002?= =?UTF-8?q?=20-=20Generate=201.8.0=20(#72)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * ci: regenerated with OpenAPI Doc , Speakeasy CLI 1.406.0 * fix compile error relating to error list type This also includes a workaround to fix the path separator regression in the new SDK generation. * manually run post-generate hook --------- Co-authored-by: speakeasybot Co-authored-by: Charles Daniels --- .speakeasy/gen.lock | 292 ++++++++++++------ .speakeasy/gen.yaml | 2 +- .speakeasy/workflow.lock | 11 +- README.md | 273 ++++++---------- RELEASES.md | 11 + USAGE.md | 109 +++---- build.gradle | 4 +- docs/models/errors/BatchServerError.md | 11 +- docs/models/errors/ClientError1.md | 12 + docs/models/errors/UnhealthyServer.md | 2 + docs/models/shared/BatchMixedResults.md | 2 + .../shared/BatchSuccessfulPolicyEvaluation.md | 4 + docs/models/shared/HealthyServer.md | 2 + docs/models/shared/ResponsesErrors.md | 10 + docs/models/shared/ResponsesLocation.md | 10 + docs/models/shared/ServerError.md | 11 + .../shared/ServerErrorWithStatusCode.md | 14 +- .../models/shared/SuccessfulPolicyResponse.md | 4 + docs/sdks/opaapiclient/README.md | 227 +++++--------- src/main/java/com/styra/opa/OPAClient.java | 14 +- .../com/styra/opa/openapi/OpaApiClient.java | 25 +- .../styra/opa/openapi/SDKConfiguration.java | 13 +- .../models/errors/BatchServerError.java | 5 + .../openapi/models/errors/ClientError1.java | 168 ++++++++++ .../models/errors/UnhealthyServer.java | 3 + .../ExecuteBatchPolicyWithInputRequest.java | 3 +- ...uteBatchPolicyWithInputRequestBuilder.java | 2 +- ...eDefaultPolicyWithInputRequestBuilder.java | 8 +- .../operations/ExecutePolicyRequest.java | 3 +- .../ExecutePolicyRequestBuilder.java | 2 +- .../ExecutePolicyWithInputRequest.java | 3 +- .../ExecutePolicyWithInputRequestBuilder.java | 2 +- .../models/operations/HealthRequest.java | 3 +- .../operations/HealthRequestBuilder.java | 9 +- .../operations/SDKMethodInterfaces.java | 11 +- .../models/shared/BatchMixedResults.java | 3 + .../BatchSuccessfulPolicyEvaluation.java | 5 + .../openapi/models/shared/HealthyServer.java | 3 + .../opa/openapi/models/shared/Input.java | 12 +- .../models/shared/ResponsesErrors.java | 171 ++++++++++ .../models/shared/ResponsesLocation.java | 148 +++++++++ .../opa/openapi/models/shared/Result.java | 12 +- .../openapi/models/shared/ServerError.java | 214 +++++++++++++ .../shared/ServerErrorWithStatusCode.java | 18 +- .../shared/SuccessfulPolicyResponse.java | 5 + .../opa/openapi/utils/OneOfDeserializer.java | 2 +- .../com/styra/opa/openapi/utils/Options.java | 12 +- .../opa/openapi/utils/QueryParameters.java | 7 +- .../com/styra/opa/openapi/utils/Security.java | 10 +- .../styra/opa/openapi/utils/TypedObject.java | 7 +- .../com/styra/opa/openapi/utils/Utils.java | 207 ++++++++++--- .../com/styra/opa/utils/OPAHTTPClient.java | 20 +- 52 files changed, 1514 insertions(+), 627 deletions(-) create mode 100644 docs/models/errors/ClientError1.md create mode 100644 docs/models/shared/ResponsesErrors.md create mode 100644 docs/models/shared/ResponsesLocation.md create mode 100644 docs/models/shared/ServerError.md create mode 100644 src/main/java/com/styra/opa/openapi/models/errors/ClientError1.java create mode 100644 src/main/java/com/styra/opa/openapi/models/shared/ResponsesErrors.java create mode 100644 src/main/java/com/styra/opa/openapi/models/shared/ResponsesLocation.java create mode 100644 src/main/java/com/styra/opa/openapi/models/shared/ServerError.java diff --git a/.speakeasy/gen.lock b/.speakeasy/gen.lock index 8755b9fd..051e3dbf 100755 --- a/.speakeasy/gen.lock +++ b/.speakeasy/gen.lock @@ -3,17 +3,17 @@ id: 47e8e950-a454-4ebb-9f78-86fda7dfa0c2 management: docChecksum: 54d33facef3aa19f358d15ab44e34141 docVersion: 0.2.0 - speakeasyVersion: 1.376.0 - generationVersion: 2.402.5 - releaseVersion: 1.7.0 - configChecksum: 1e364b7503baf8ad2a9aca5d31bbc6b5 + speakeasyVersion: 1.406.0 + generationVersion: 2.429.0 + releaseVersion: 1.8.0 + configChecksum: 39fc35b210cab57386c8f5c0d40d9dcb repoURL: https://github.com/StyraInc/opa-java.git published: true features: java: additionalDependencies: 0.1.0 constsAndDefaults: 0.1.1 - core: 3.29.4 + core: 3.30.4 examples: 2.81.3 flattening: 2.81.1 globalSecurity: 2.82.7 @@ -22,22 +22,109 @@ features: sdkHooks: 0.1.0 unions: 0.0.5 generatedFiles: - - src/main/java/com/styra/opa/openapi/SecuritySource.java - - src/main/java/com/styra/opa/openapi/SDKConfiguration.java - - src/main/java/com/styra/opa/openapi/models/operations/ExecuteDefaultPolicyWithInputRequestBuilder.java - - src/main/java/com/styra/opa/openapi/models/operations/ExecutePolicyRequestBuilder.java - - src/main/java/com/styra/opa/openapi/models/operations/ExecutePolicyWithInputRequestBuilder.java - - src/main/java/com/styra/opa/openapi/models/operations/ExecuteBatchPolicyWithInputRequestBuilder.java - - src/main/java/com/styra/opa/openapi/models/operations/HealthRequestBuilder.java - - src/main/java/com/styra/opa/openapi/models/operations/SDKMethodInterfaces.java - - src/main/java/com/styra/opa/openapi/OpaApiClient.java - .gitattributes + - CONTRIBUTING.md + - USAGE.md - build.gradle + - docs/models/errors/BatchServerError.md + - docs/models/errors/ClientError.md + - docs/models/errors/ClientError1.md + - docs/models/errors/Errors.md + - docs/models/errors/Location.md + - docs/models/errors/ServerError.md + - docs/models/errors/ServerErrorErrors.md + - docs/models/errors/ServerErrorLocation.md + - docs/models/errors/UnhealthyServer.md + - docs/models/operations/ExecuteBatchPolicyWithInputRequest.md + - docs/models/operations/ExecuteBatchPolicyWithInputRequestBody.md + - docs/models/operations/ExecuteBatchPolicyWithInputResponse.md + - docs/models/operations/ExecuteDefaultPolicyWithInputRequest.md + - docs/models/operations/ExecuteDefaultPolicyWithInputResponse.md + - docs/models/operations/ExecutePolicyRequest.md + - docs/models/operations/ExecutePolicyResponse.md + - docs/models/operations/ExecutePolicyWithInputRequest.md + - docs/models/operations/ExecutePolicyWithInputRequestBody.md + - docs/models/operations/ExecutePolicyWithInputResponse.md + - docs/models/operations/HealthRequest.md + - docs/models/operations/HealthResponse.md + - docs/models/shared/BatchMixedResults.md + - docs/models/shared/BatchSuccessfulPolicyEvaluation.md + - docs/models/shared/Errors.md + - docs/models/shared/Explain.md + - docs/models/shared/GzipAcceptEncoding.md + - docs/models/shared/GzipContentEncoding.md + - docs/models/shared/HealthyServer.md + - docs/models/shared/Input.md + - docs/models/shared/Location.md + - docs/models/shared/Provenance.md + - docs/models/shared/Responses.md + - docs/models/shared/ResponsesErrors.md + - docs/models/shared/ResponsesLocation.md + - docs/models/shared/Result.md + - docs/models/shared/Revision.md + - docs/models/shared/Security.md + - docs/models/shared/ServerError.md + - docs/models/shared/ServerErrorWithStatusCode.md + - docs/models/shared/SuccessfulPolicyResponse.md + - docs/models/shared/SuccessfulPolicyResponseWithStatusCode.md + - docs/sdks/opaapiclient/README.md - gradle/wrapper/gradle-wrapper.jar - gradle/wrapper/gradle-wrapper.properties - gradlew - gradlew.bat - settings.gradle + - src/main/java/com/styra/opa/openapi/OpaApiClient.java + - src/main/java/com/styra/opa/openapi/SDKConfiguration.java + - src/main/java/com/styra/opa/openapi/SecuritySource.java + - src/main/java/com/styra/opa/openapi/models/errors/AuthException.java + - src/main/java/com/styra/opa/openapi/models/errors/BatchServerError.java + - src/main/java/com/styra/opa/openapi/models/errors/ClientError.java + - src/main/java/com/styra/opa/openapi/models/errors/ClientError1.java + - src/main/java/com/styra/opa/openapi/models/errors/Errors.java + - src/main/java/com/styra/opa/openapi/models/errors/Location.java + - src/main/java/com/styra/opa/openapi/models/errors/SDKError.java + - src/main/java/com/styra/opa/openapi/models/errors/ServerError.java + - src/main/java/com/styra/opa/openapi/models/errors/ServerErrorErrors.java + - src/main/java/com/styra/opa/openapi/models/errors/ServerErrorLocation.java + - src/main/java/com/styra/opa/openapi/models/errors/UnhealthyServer.java + - src/main/java/com/styra/opa/openapi/models/operations/ExecuteBatchPolicyWithInputRequest.java + - src/main/java/com/styra/opa/openapi/models/operations/ExecuteBatchPolicyWithInputRequestBody.java + - src/main/java/com/styra/opa/openapi/models/operations/ExecuteBatchPolicyWithInputRequestBuilder.java + - src/main/java/com/styra/opa/openapi/models/operations/ExecuteBatchPolicyWithInputResponse.java + - src/main/java/com/styra/opa/openapi/models/operations/ExecuteDefaultPolicyWithInputRequest.java + - src/main/java/com/styra/opa/openapi/models/operations/ExecuteDefaultPolicyWithInputRequestBuilder.java + - src/main/java/com/styra/opa/openapi/models/operations/ExecuteDefaultPolicyWithInputResponse.java + - src/main/java/com/styra/opa/openapi/models/operations/ExecutePolicyRequest.java + - src/main/java/com/styra/opa/openapi/models/operations/ExecutePolicyRequestBuilder.java + - src/main/java/com/styra/opa/openapi/models/operations/ExecutePolicyResponse.java + - src/main/java/com/styra/opa/openapi/models/operations/ExecutePolicyWithInputRequest.java + - src/main/java/com/styra/opa/openapi/models/operations/ExecutePolicyWithInputRequestBody.java + - src/main/java/com/styra/opa/openapi/models/operations/ExecutePolicyWithInputRequestBuilder.java + - src/main/java/com/styra/opa/openapi/models/operations/ExecutePolicyWithInputResponse.java + - src/main/java/com/styra/opa/openapi/models/operations/HealthRequest.java + - src/main/java/com/styra/opa/openapi/models/operations/HealthRequestBuilder.java + - src/main/java/com/styra/opa/openapi/models/operations/HealthResponse.java + - src/main/java/com/styra/opa/openapi/models/operations/SDKMethodInterfaces.java + - src/main/java/com/styra/opa/openapi/models/shared/BatchMixedResults.java + - src/main/java/com/styra/opa/openapi/models/shared/BatchSuccessfulPolicyEvaluation.java + - src/main/java/com/styra/opa/openapi/models/shared/Errors.java + - src/main/java/com/styra/opa/openapi/models/shared/Explain.java + - src/main/java/com/styra/opa/openapi/models/shared/GzipAcceptEncoding.java + - src/main/java/com/styra/opa/openapi/models/shared/GzipContentEncoding.java + - src/main/java/com/styra/opa/openapi/models/shared/HealthyServer.java + - src/main/java/com/styra/opa/openapi/models/shared/Input.java + - src/main/java/com/styra/opa/openapi/models/shared/Location.java + - src/main/java/com/styra/opa/openapi/models/shared/Provenance.java + - src/main/java/com/styra/opa/openapi/models/shared/Responses.java + - src/main/java/com/styra/opa/openapi/models/shared/ResponsesErrors.java + - src/main/java/com/styra/opa/openapi/models/shared/ResponsesLocation.java + - src/main/java/com/styra/opa/openapi/models/shared/Result.java + - src/main/java/com/styra/opa/openapi/models/shared/Revision.java + - src/main/java/com/styra/opa/openapi/models/shared/Security.java + - src/main/java/com/styra/opa/openapi/models/shared/ServerError.java + - src/main/java/com/styra/opa/openapi/models/shared/ServerErrorWithStatusCode.java + - src/main/java/com/styra/opa/openapi/models/shared/SuccessfulPolicyResponse.java + - src/main/java/com/styra/opa/openapi/models/shared/SuccessfulPolicyResponseWithStatusCode.java - src/main/java/com/styra/opa/openapi/utils/BackoffStrategy.java - src/main/java/com/styra/opa/openapi/utils/BigDecimalString.java - src/main/java/com/styra/opa/openapi/utils/BigIntegerString.java @@ -75,82 +162,101 @@ generatedFiles: - src/main/java/com/styra/opa/openapi/utils/TypedObject.java - src/main/java/com/styra/opa/openapi/utils/Types.java - src/main/java/com/styra/opa/openapi/utils/Utils.java - - src/main/java/com/styra/opa/openapi/models/errors/AuthException.java - - src/main/java/com/styra/opa/openapi/models/errors/SDKError.java - - src/main/java/com/styra/opa/openapi/models/operations/ExecuteDefaultPolicyWithInputRequest.java - - src/main/java/com/styra/opa/openapi/models/operations/ExecuteDefaultPolicyWithInputResponse.java - - src/main/java/com/styra/opa/openapi/models/operations/ExecutePolicyRequest.java - - src/main/java/com/styra/opa/openapi/models/operations/ExecutePolicyResponse.java - - src/main/java/com/styra/opa/openapi/models/operations/ExecutePolicyWithInputRequestBody.java - - src/main/java/com/styra/opa/openapi/models/operations/ExecutePolicyWithInputRequest.java - - src/main/java/com/styra/opa/openapi/models/operations/ExecutePolicyWithInputResponse.java - - src/main/java/com/styra/opa/openapi/models/operations/ExecuteBatchPolicyWithInputRequestBody.java - - src/main/java/com/styra/opa/openapi/models/operations/ExecuteBatchPolicyWithInputRequest.java - - src/main/java/com/styra/opa/openapi/models/operations/ExecuteBatchPolicyWithInputResponse.java - - src/main/java/com/styra/opa/openapi/models/operations/HealthRequest.java - - src/main/java/com/styra/opa/openapi/models/operations/HealthResponse.java - - src/main/java/com/styra/opa/openapi/models/shared/Result.java - - src/main/java/com/styra/opa/openapi/models/shared/Input.java - - src/main/java/com/styra/opa/openapi/models/shared/GzipAcceptEncoding.java - - src/main/java/com/styra/opa/openapi/models/shared/SuccessfulPolicyResponse.java - - src/main/java/com/styra/opa/openapi/models/shared/Revision.java - - src/main/java/com/styra/opa/openapi/models/shared/Provenance.java - - src/main/java/com/styra/opa/openapi/models/shared/Explain.java - - src/main/java/com/styra/opa/openapi/models/shared/GzipContentEncoding.java - - src/main/java/com/styra/opa/openapi/models/shared/Location.java - - src/main/java/com/styra/opa/openapi/models/shared/Errors.java - - src/main/java/com/styra/opa/openapi/models/shared/ServerErrorWithStatusCode.java - - src/main/java/com/styra/opa/openapi/models/shared/SuccessfulPolicyResponseWithStatusCode.java - - src/main/java/com/styra/opa/openapi/models/shared/Responses.java - - src/main/java/com/styra/opa/openapi/models/shared/BatchMixedResults.java - - src/main/java/com/styra/opa/openapi/models/shared/BatchSuccessfulPolicyEvaluation.java - - src/main/java/com/styra/opa/openapi/models/shared/HealthyServer.java - - src/main/java/com/styra/opa/openapi/models/shared/Security.java - - src/main/java/com/styra/opa/openapi/models/errors/Location.java - - src/main/java/com/styra/opa/openapi/models/errors/Errors.java - - src/main/java/com/styra/opa/openapi/models/errors/ClientError.java - - src/main/java/com/styra/opa/openapi/models/errors/ServerErrorLocation.java - - src/main/java/com/styra/opa/openapi/models/errors/ServerErrorErrors.java - - src/main/java/com/styra/opa/openapi/models/errors/ServerError.java - - src/main/java/com/styra/opa/openapi/models/errors/BatchServerError.java - - src/main/java/com/styra/opa/openapi/models/errors/UnhealthyServer.java - - docs/models/operations/ExecuteDefaultPolicyWithInputRequest.md - - docs/models/operations/ExecuteDefaultPolicyWithInputResponse.md - - docs/models/operations/ExecutePolicyRequest.md - - docs/models/operations/ExecutePolicyResponse.md - - docs/models/operations/ExecutePolicyWithInputRequestBody.md - - docs/models/operations/ExecutePolicyWithInputRequest.md - - docs/models/operations/ExecutePolicyWithInputResponse.md - - docs/models/operations/ExecuteBatchPolicyWithInputRequestBody.md - - docs/models/operations/ExecuteBatchPolicyWithInputRequest.md - - docs/models/operations/ExecuteBatchPolicyWithInputResponse.md - - docs/models/operations/HealthRequest.md - - docs/models/operations/HealthResponse.md - - docs/models/shared/Result.md - - docs/models/shared/Input.md - - docs/models/shared/GzipAcceptEncoding.md - - docs/models/shared/SuccessfulPolicyResponse.md - - docs/models/shared/Revision.md - - docs/models/shared/Provenance.md - - docs/models/shared/Explain.md - - docs/models/shared/GzipContentEncoding.md - - docs/models/shared/Location.md - - docs/models/shared/Errors.md - - docs/models/shared/ServerErrorWithStatusCode.md - - docs/models/shared/SuccessfulPolicyResponseWithStatusCode.md - - docs/models/shared/Responses.md - - docs/models/shared/BatchMixedResults.md - - docs/models/shared/BatchSuccessfulPolicyEvaluation.md - - docs/models/shared/HealthyServer.md - - docs/models/shared/Security.md - - docs/models/errors/Location.md - - docs/models/errors/Errors.md - - docs/models/errors/ClientError.md - - docs/models/errors/ServerErrorLocation.md - - docs/models/errors/ServerErrorErrors.md - - docs/models/errors/ServerError.md - - docs/models/errors/BatchServerError.md - - docs/models/errors/UnhealthyServer.md - - docs/sdks/opaapiclient/README.md - - USAGE.md - - CONTRIBUTING.md +examples: + executeBatchPolicyWithInput: + speakeasy-default-execute-batch-policy-with-input: + parameters: + header: {} + path: + path: app/rbac + query: {} + requestBody: + application/json: + inputs: + key: "6919.52" + responses: + "200": + application/json: + batch_decision_id: 1bef6b7d-cd13-4890-bfe1-fd2e8de32189 + responses: + key: + result: + "207": + application/json: + responses: + key: + code: + decision_id: b84cf736-213c-4932-a8e4-bb5c648f1b4d + http_status_code: "200" + message: + "400": + application/json: + code: + message: + "500": + application/json: + responses: + key: + code: + decision_id: b84cf736-213c-4932-a8e4-bb5c648f1b4d + message: + executeDefaultPolicyWithInput: + speakeasy-default-execute-default-policy-with-input: + requestBody: + application/json: "4963.69" + responses: + "200": + application/json: + "400": + application/json: + code: + message: + "500": + application/json: + code: + decision_id: b84cf736-213c-4932-a8e4-bb5c648f1b4d + message: + executePolicy: + speakeasy-default-execute-policy: + parameters: + header: {} + path: + path: app/rbac + query: {} + responses: + "200": + application/json: + result: false + "400": + application/json: + code: + message: + "500": + application/json: + code: + decision_id: b84cf736-213c-4932-a8e4-bb5c648f1b4d + message: + executePolicyWithInput: + speakeasy-default-execute-policy-with-input: + parameters: + header: {} + path: + path: app/rbac + query: {} + requestBody: + application/json: + input: true + responses: + "200": + application/json: + result: false + "400": + application/json: + code: + message: + "500": + application/json: + code: + decision_id: b84cf736-213c-4932-a8e4-bb5c648f1b4d + message: + health: {} diff --git a/.speakeasy/gen.yaml b/.speakeasy/gen.yaml index f15f3f96..a700c83e 100755 --- a/.speakeasy/gen.yaml +++ b/.speakeasy/gen.yaml @@ -12,7 +12,7 @@ generation: auth: oAuth2ClientCredentialsEnabled: false java: - version: 1.7.0 + version: 1.8.0 additionalDependencies: - testImplementation:org.junit.jupiter:junit-jupiter-api:5.8.2 - runtimeOnly:org.junit.jupiter:junit-jupiter-engine:5.8.2 diff --git a/.speakeasy/workflow.lock b/.speakeasy/workflow.lock index d161d638..b4552c8d 100644 --- a/.speakeasy/workflow.lock +++ b/.speakeasy/workflow.lock @@ -2,17 +2,18 @@ speakeasyVersion: 1.376.0 sources: openapi: sourceNamespace: openapi - sourceRevisionDigest: sha256:1ee32a806cc62fb2ea0359d3e3bd0a7bfd85e739abe15af4c81944953da8a4a2 - sourceBlobDigest: sha256:ba34b5e8162fb661727f5fc9878a8a8862a31609f96a6d73abf9d2c12076d872 + sourceRevisionDigest: sha256:89b83eaab457a2ec77f662a88b35e45c6f4f67507c2daf85e486a9dfb847ec1e + sourceBlobDigest: sha256:f76f9d1e8be466eef2d0e9612845ce19f9a5f507682e92d7a4355b3b13eaa921 tags: - latest + - main targets: opa: source: openapi sourceNamespace: openapi - sourceRevisionDigest: sha256:1ee32a806cc62fb2ea0359d3e3bd0a7bfd85e739abe15af4c81944953da8a4a2 - sourceBlobDigest: sha256:ba34b5e8162fb661727f5fc9878a8a8862a31609f96a6d73abf9d2c12076d872 - outLocation: /Users/cad/f/src/opa-java + sourceRevisionDigest: sha256:89b83eaab457a2ec77f662a88b35e45c6f4f67507c2daf85e486a9dfb847ec1e + sourceBlobDigest: sha256:f76f9d1e8be466eef2d0e9612845ce19f9a5f507682e92d7a4355b3b13eaa921 + outLocation: /github/workspace/repo workflow: workflowVersion: 1.0.0 speakeasyVersion: latest diff --git a/README.md b/README.md index 1f985e49..54db4ebb 100644 --- a/README.md +++ b/README.md @@ -82,6 +82,23 @@ public class App { # OPA OpenApi SDK (low-level) + +## Summary + +For more information about the API: [Enterprise OPA documentation](https://docs.styra.com/enterprise-opa) + + + +## Table of Contents + +* [SDK Installation](#sdk-installation) +* [SDK Example Usage](#sdk-example-usage) +* [Available Resources and Operations](#available-resources-and-operations) +* [Error Handling](#error-handling) +* [Server Selection](#server-selection) +* [Authentication](#authentication) + + ## SDK Example Usage @@ -91,7 +108,8 @@ public class App { package hello.world; import com.styra.opa.openapi.OpaApiClient; -import com.styra.opa.openapi.models.errors.SDKError; +import com.styra.opa.openapi.models.errors.ClientError; +import com.styra.opa.openapi.models.errors.ServerError; import com.styra.opa.openapi.models.operations.ExecuteDefaultPolicyWithInputResponse; import com.styra.opa.openapi.models.shared.GzipAcceptEncoding; import com.styra.opa.openapi.models.shared.Input; @@ -100,37 +118,23 @@ import java.lang.Exception; public class Application { - public static void main(String[] args) throws Exception { - try { - OpaApiClient sdk = OpaApiClient.builder() + public static void main(String[] args) throws ClientError, ServerError, Exception { + + OpaApiClient sdk = OpaApiClient.builder() .security(Security.builder() .bearerAuth("") .build()) - .build(); + .build(); - ExecuteDefaultPolicyWithInputResponse res = sdk.executeDefaultPolicyWithInput() + ExecuteDefaultPolicyWithInputResponse res = sdk.executeDefaultPolicyWithInput() .pretty(false) .acceptEncoding(GzipAcceptEncoding.GZIP) - .input(Input.of(8203.11d)) + .input(Input.of(4963.69d)) .call(); - if (res.result().isPresent()) { - // handle response - } - } catch (com.styra.opa.openapi.models.errors.ClientError e) { - // handle exception - throw e; - } catch (com.styra.opa.openapi.models.errors.ServerError e) { - // handle exception - throw e; - } catch (SDKError e) { - // handle exception - throw e; - } catch (Exception e) { - // handle exception - throw e; + if (res.result().isPresent()) { + // handle response } - } } ``` @@ -141,7 +145,8 @@ public class Application { package hello.world; import com.styra.opa.openapi.OpaApiClient; -import com.styra.opa.openapi.models.errors.SDKError; +import com.styra.opa.openapi.models.errors.ClientError1; +import com.styra.opa.openapi.models.errors.ServerError; import com.styra.opa.openapi.models.operations.ExecutePolicyWithInputRequest; import com.styra.opa.openapi.models.operations.ExecutePolicyWithInputRequestBody; import com.styra.opa.openapi.models.operations.ExecutePolicyWithInputResponse; @@ -151,42 +156,28 @@ import java.lang.Exception; public class Application { - public static void main(String[] args) throws Exception { - try { - OpaApiClient sdk = OpaApiClient.builder() + public static void main(String[] args) throws ClientError1, ServerError, Exception { + + OpaApiClient sdk = OpaApiClient.builder() .security(Security.builder() .bearerAuth("") .build()) - .build(); + .build(); - ExecutePolicyWithInputRequest req = ExecutePolicyWithInputRequest.builder() + ExecutePolicyWithInputRequest req = ExecutePolicyWithInputRequest.builder() .path("app/rbac") .requestBody(ExecutePolicyWithInputRequestBody.builder() - .input(Input.of(false)) - .build()) + .input(Input.of(false)) + .build()) .build(); - ExecutePolicyWithInputResponse res = sdk.executePolicyWithInput() + ExecutePolicyWithInputResponse res = sdk.executePolicyWithInput() .request(req) .call(); - if (res.successfulPolicyResponse().isPresent()) { - // handle response - } - } catch (com.styra.opa.openapi.models.errors.ClientError e) { - // handle exception - throw e; - } catch (com.styra.opa.openapi.models.errors.ServerError e) { - // handle exception - throw e; - } catch (SDKError e) { - // handle exception - throw e; - } catch (Exception e) { - // handle exception - throw e; + if (res.successfulPolicyResponse().isPresent()) { + // handle response } - } } ``` @@ -197,7 +188,8 @@ public class Application { package hello.world; import com.styra.opa.openapi.OpaApiClient; -import com.styra.opa.openapi.models.errors.SDKError; +import com.styra.opa.openapi.models.errors.BatchServerError; +import com.styra.opa.openapi.models.errors.ClientError1; import com.styra.opa.openapi.models.operations.ExecuteBatchPolicyWithInputRequest; import com.styra.opa.openapi.models.operations.ExecuteBatchPolicyWithInputRequestBody; import com.styra.opa.openapi.models.operations.ExecuteBatchPolicyWithInputResponse; @@ -208,43 +200,29 @@ import java.util.Map; public class Application { - public static void main(String[] args) throws Exception { - try { - OpaApiClient sdk = OpaApiClient.builder() + public static void main(String[] args) throws ClientError1, BatchServerError, Exception { + + OpaApiClient sdk = OpaApiClient.builder() .security(Security.builder() .bearerAuth("") .build()) - .build(); + .build(); - ExecuteBatchPolicyWithInputRequest req = ExecuteBatchPolicyWithInputRequest.builder() + ExecuteBatchPolicyWithInputRequest req = ExecuteBatchPolicyWithInputRequest.builder() .path("app/rbac") .requestBody(ExecuteBatchPolicyWithInputRequestBody.builder() - .inputs(Map.ofEntries( - Map.entry("key", Input.of("")))) - .build()) + .inputs(Map.ofEntries( + Map.entry("key", Input.of("")))) + .build()) .build(); - ExecuteBatchPolicyWithInputResponse res = sdk.executeBatchPolicyWithInput() + ExecuteBatchPolicyWithInputResponse res = sdk.executeBatchPolicyWithInput() .request(req) .call(); - if (res.batchSuccessfulPolicyEvaluation().isPresent()) { - // handle response - } - } catch (com.styra.opa.openapi.models.errors.ClientError e) { - // handle exception - throw e; - } catch (com.styra.opa.openapi.models.errors.BatchServerError e) { - // handle exception - throw e; - } catch (SDKError e) { - // handle exception - throw e; - } catch (Exception e) { - // handle exception - throw e; + if (res.batchSuccessfulPolicyEvaluation().isPresent()) { + // handle response } - } } ``` @@ -253,6 +231,9 @@ public class Application { ## Available Resources and Operations +
+Available methods + ### [OpaApiClient SDK](docs/sdks/opaapiclient/README.md) * [executeDefaultPolicyWithInput](docs/sdks/opaapiclient/README.md#executedefaultpolicywithinput) - Execute the default decision given an input @@ -260,6 +241,8 @@ public class Application { * [executePolicyWithInput](docs/sdks/opaapiclient/README.md#executepolicywithinput) - Execute a policy given an input * [executeBatchPolicyWithInput](docs/sdks/opaapiclient/README.md#executebatchpolicywithinput) - Execute a policy given a batch of inputs * [health](docs/sdks/opaapiclient/README.md#health) - Verify the server is operational + +
@@ -279,7 +262,8 @@ You can override the default server globally by passing a server index to the `s package hello.world; import com.styra.opa.openapi.OpaApiClient; -import com.styra.opa.openapi.models.errors.SDKError; +import com.styra.opa.openapi.models.errors.ClientError; +import com.styra.opa.openapi.models.errors.ServerError; import com.styra.opa.openapi.models.operations.ExecuteDefaultPolicyWithInputResponse; import com.styra.opa.openapi.models.shared.GzipAcceptEncoding; import com.styra.opa.openapi.models.shared.Input; @@ -288,38 +272,24 @@ import java.lang.Exception; public class Application { - public static void main(String[] args) throws Exception { - try { - OpaApiClient sdk = OpaApiClient.builder() + public static void main(String[] args) throws ClientError, ServerError, Exception { + + OpaApiClient sdk = OpaApiClient.builder() .serverIndex(0) .security(Security.builder() .bearerAuth("") .build()) - .build(); + .build(); - ExecuteDefaultPolicyWithInputResponse res = sdk.executeDefaultPolicyWithInput() + ExecuteDefaultPolicyWithInputResponse res = sdk.executeDefaultPolicyWithInput() .pretty(false) .acceptEncoding(GzipAcceptEncoding.GZIP) - .input(Input.of(8203.11d)) + .input(Input.of(4963.69d)) .call(); - if (res.result().isPresent()) { - // handle response - } - } catch (com.styra.opa.openapi.models.errors.ClientError e) { - // handle exception - throw e; - } catch (com.styra.opa.openapi.models.errors.ServerError e) { - // handle exception - throw e; - } catch (SDKError e) { - // handle exception - throw e; - } catch (Exception e) { - // handle exception - throw e; + if (res.result().isPresent()) { + // handle response } - } } ``` @@ -332,7 +302,8 @@ The default server can also be overridden globally by passing a URL to the `serv package hello.world; import com.styra.opa.openapi.OpaApiClient; -import com.styra.opa.openapi.models.errors.SDKError; +import com.styra.opa.openapi.models.errors.ClientError; +import com.styra.opa.openapi.models.errors.ServerError; import com.styra.opa.openapi.models.operations.ExecuteDefaultPolicyWithInputResponse; import com.styra.opa.openapi.models.shared.GzipAcceptEncoding; import com.styra.opa.openapi.models.shared.Input; @@ -341,38 +312,24 @@ import java.lang.Exception; public class Application { - public static void main(String[] args) throws Exception { - try { - OpaApiClient sdk = OpaApiClient.builder() + public static void main(String[] args) throws ClientError, ServerError, Exception { + + OpaApiClient sdk = OpaApiClient.builder() .serverURL("http://localhost:8181") .security(Security.builder() .bearerAuth("") .build()) - .build(); + .build(); - ExecuteDefaultPolicyWithInputResponse res = sdk.executeDefaultPolicyWithInput() + ExecuteDefaultPolicyWithInputResponse res = sdk.executeDefaultPolicyWithInput() .pretty(false) .acceptEncoding(GzipAcceptEncoding.GZIP) - .input(Input.of(8203.11d)) + .input(Input.of(4963.69d)) .call(); - if (res.result().isPresent()) { - // handle response - } - } catch (com.styra.opa.openapi.models.errors.ClientError e) { - // handle exception - throw e; - } catch (com.styra.opa.openapi.models.errors.ServerError e) { - // handle exception - throw e; - } catch (SDKError e) { - // handle exception - throw e; - } catch (Exception e) { - // handle exception - throw e; + if (res.result().isPresent()) { + // handle response } - } } ``` @@ -381,13 +338,15 @@ public class Application { ## Error Handling -Handling errors in this SDK should largely match your expectations. All operations return a response object or raise an error. If Error objects are specified in your OpenAPI Spec, the SDK will throw the appropriate Exception type. +Handling errors in this SDK should largely match your expectations. All operations return a response object or raise an exception. -| Error Object | Status Code | Content Type | +By default, an API error will throw a `models/errors/SDKError` exception. When custom error responses are specified for an operation, the SDK may also throw their associated exception. You can refer to respective *Errors* tables in SDK docs for more details on possible exception types for each operation. For example, the `executeDefaultPolicyWithInput` method throws the following exceptions: + +| Error Type | Status Code | Content Type | | ------------------------- | ------------------------- | ------------------------- | -| models/errors/ClientError | 400,404 | application/json | +| models/errors/ClientError | 400, 404 | application/json | | models/errors/ServerError | 500 | application/json | -| models/errors/SDKError | 4xx-5xx | \*\/* | +| models/errors/SDKError | 4XX, 5XX | \*/\* | ### Example @@ -395,7 +354,8 @@ Handling errors in this SDK should largely match your expectations. All operati package hello.world; import com.styra.opa.openapi.OpaApiClient; -import com.styra.opa.openapi.models.errors.SDKError; +import com.styra.opa.openapi.models.errors.ClientError; +import com.styra.opa.openapi.models.errors.ServerError; import com.styra.opa.openapi.models.operations.ExecuteDefaultPolicyWithInputResponse; import com.styra.opa.openapi.models.shared.GzipAcceptEncoding; import com.styra.opa.openapi.models.shared.Input; @@ -404,37 +364,23 @@ import java.lang.Exception; public class Application { - public static void main(String[] args) throws Exception { - try { - OpaApiClient sdk = OpaApiClient.builder() + public static void main(String[] args) throws ClientError, ServerError, Exception { + + OpaApiClient sdk = OpaApiClient.builder() .security(Security.builder() .bearerAuth("") .build()) - .build(); + .build(); - ExecuteDefaultPolicyWithInputResponse res = sdk.executeDefaultPolicyWithInput() + ExecuteDefaultPolicyWithInputResponse res = sdk.executeDefaultPolicyWithInput() .pretty(false) .acceptEncoding(GzipAcceptEncoding.GZIP) - .input(Input.of(8203.11d)) + .input(Input.of(4963.69d)) .call(); - if (res.result().isPresent()) { - // handle response - } - } catch (com.styra.opa.openapi.models.errors.ClientError e) { - // handle exception - throw e; - } catch (com.styra.opa.openapi.models.errors.ServerError e) { - // handle exception - throw e; - } catch (SDKError e) { - // handle exception - throw e; - } catch (Exception e) { - // handle exception - throw e; + if (res.result().isPresent()) { + // handle response } - } } ``` @@ -456,7 +402,8 @@ You can set the security parameters through the `security` builder method when i package hello.world; import com.styra.opa.openapi.OpaApiClient; -import com.styra.opa.openapi.models.errors.SDKError; +import com.styra.opa.openapi.models.errors.ClientError; +import com.styra.opa.openapi.models.errors.ServerError; import com.styra.opa.openapi.models.operations.ExecuteDefaultPolicyWithInputResponse; import com.styra.opa.openapi.models.shared.GzipAcceptEncoding; import com.styra.opa.openapi.models.shared.Input; @@ -465,37 +412,23 @@ import java.lang.Exception; public class Application { - public static void main(String[] args) throws Exception { - try { - OpaApiClient sdk = OpaApiClient.builder() + public static void main(String[] args) throws ClientError, ServerError, Exception { + + OpaApiClient sdk = OpaApiClient.builder() .security(Security.builder() .bearerAuth("") .build()) - .build(); + .build(); - ExecuteDefaultPolicyWithInputResponse res = sdk.executeDefaultPolicyWithInput() + ExecuteDefaultPolicyWithInputResponse res = sdk.executeDefaultPolicyWithInput() .pretty(false) .acceptEncoding(GzipAcceptEncoding.GZIP) - .input(Input.of(8203.11d)) + .input(Input.of(4963.69d)) .call(); - if (res.result().isPresent()) { - // handle response - } - } catch (com.styra.opa.openapi.models.errors.ClientError e) { - // handle exception - throw e; - } catch (com.styra.opa.openapi.models.errors.ServerError e) { - // handle exception - throw e; - } catch (SDKError e) { - // handle exception - throw e; - } catch (Exception e) { - // handle exception - throw e; + if (res.result().isPresent()) { + // handle response } - } } ``` diff --git a/RELEASES.md b/RELEASES.md index 6e5b56b8..9d8477e2 100644 --- a/RELEASES.md +++ b/RELEASES.md @@ -348,3 +348,14 @@ Based on: - [java v1.7.0] . ### Releases - [Maven Central v1.7.0] https://central.sonatype.com/artifact/com.styra.opa/openapi/1.7.0 - . + + +## 2024-10-03 00:23:42 +### Changes +Based on: +- OpenAPI Doc +- Speakeasy CLI 1.406.0 (2.429.0) https://github.com/speakeasy-api/speakeasy +### Generated +- [java v1.8.0] . +### Releases +- [Maven Central v1.8.0] https://central.sonatype.com/artifact/com.styra.opa/openapi/1.8.0 - . \ No newline at end of file diff --git a/USAGE.md b/USAGE.md index 0bd6317a..23a3bb96 100644 --- a/USAGE.md +++ b/USAGE.md @@ -3,7 +3,8 @@ package hello.world; import com.styra.opa.openapi.OpaApiClient; -import com.styra.opa.openapi.models.errors.SDKError; +import com.styra.opa.openapi.models.errors.ClientError; +import com.styra.opa.openapi.models.errors.ServerError; import com.styra.opa.openapi.models.operations.ExecuteDefaultPolicyWithInputResponse; import com.styra.opa.openapi.models.shared.GzipAcceptEncoding; import com.styra.opa.openapi.models.shared.Input; @@ -12,37 +13,23 @@ import java.lang.Exception; public class Application { - public static void main(String[] args) throws Exception { - try { - OpaApiClient sdk = OpaApiClient.builder() + public static void main(String[] args) throws ClientError, ServerError, Exception { + + OpaApiClient sdk = OpaApiClient.builder() .security(Security.builder() .bearerAuth("") .build()) - .build(); + .build(); - ExecuteDefaultPolicyWithInputResponse res = sdk.executeDefaultPolicyWithInput() + ExecuteDefaultPolicyWithInputResponse res = sdk.executeDefaultPolicyWithInput() .pretty(false) .acceptEncoding(GzipAcceptEncoding.GZIP) - .input(Input.of(8203.11d)) + .input(Input.of(4963.69d)) .call(); - if (res.result().isPresent()) { - // handle response - } - } catch (com.styra.opa.openapi.models.errors.ClientError e) { - // handle exception - throw e; - } catch (com.styra.opa.openapi.models.errors.ServerError e) { - // handle exception - throw e; - } catch (SDKError e) { - // handle exception - throw e; - } catch (Exception e) { - // handle exception - throw e; + if (res.result().isPresent()) { + // handle response } - } } ``` @@ -51,7 +38,8 @@ public class Application { package hello.world; import com.styra.opa.openapi.OpaApiClient; -import com.styra.opa.openapi.models.errors.SDKError; +import com.styra.opa.openapi.models.errors.ClientError1; +import com.styra.opa.openapi.models.errors.ServerError; import com.styra.opa.openapi.models.operations.ExecutePolicyWithInputRequest; import com.styra.opa.openapi.models.operations.ExecutePolicyWithInputRequestBody; import com.styra.opa.openapi.models.operations.ExecutePolicyWithInputResponse; @@ -61,42 +49,28 @@ import java.lang.Exception; public class Application { - public static void main(String[] args) throws Exception { - try { - OpaApiClient sdk = OpaApiClient.builder() + public static void main(String[] args) throws ClientError1, ServerError, Exception { + + OpaApiClient sdk = OpaApiClient.builder() .security(Security.builder() .bearerAuth("") .build()) - .build(); + .build(); - ExecutePolicyWithInputRequest req = ExecutePolicyWithInputRequest.builder() + ExecutePolicyWithInputRequest req = ExecutePolicyWithInputRequest.builder() .path("app/rbac") .requestBody(ExecutePolicyWithInputRequestBody.builder() - .input(Input.of(false)) - .build()) + .input(Input.of(false)) + .build()) .build(); - ExecutePolicyWithInputResponse res = sdk.executePolicyWithInput() + ExecutePolicyWithInputResponse res = sdk.executePolicyWithInput() .request(req) .call(); - if (res.successfulPolicyResponse().isPresent()) { - // handle response - } - } catch (com.styra.opa.openapi.models.errors.ClientError e) { - // handle exception - throw e; - } catch (com.styra.opa.openapi.models.errors.ServerError e) { - // handle exception - throw e; - } catch (SDKError e) { - // handle exception - throw e; - } catch (Exception e) { - // handle exception - throw e; + if (res.successfulPolicyResponse().isPresent()) { + // handle response } - } } ``` @@ -105,7 +79,8 @@ public class Application { package hello.world; import com.styra.opa.openapi.OpaApiClient; -import com.styra.opa.openapi.models.errors.SDKError; +import com.styra.opa.openapi.models.errors.BatchServerError; +import com.styra.opa.openapi.models.errors.ClientError1; import com.styra.opa.openapi.models.operations.ExecuteBatchPolicyWithInputRequest; import com.styra.opa.openapi.models.operations.ExecuteBatchPolicyWithInputRequestBody; import com.styra.opa.openapi.models.operations.ExecuteBatchPolicyWithInputResponse; @@ -116,43 +91,29 @@ import java.util.Map; public class Application { - public static void main(String[] args) throws Exception { - try { - OpaApiClient sdk = OpaApiClient.builder() + public static void main(String[] args) throws ClientError1, BatchServerError, Exception { + + OpaApiClient sdk = OpaApiClient.builder() .security(Security.builder() .bearerAuth("") .build()) - .build(); + .build(); - ExecuteBatchPolicyWithInputRequest req = ExecuteBatchPolicyWithInputRequest.builder() + ExecuteBatchPolicyWithInputRequest req = ExecuteBatchPolicyWithInputRequest.builder() .path("app/rbac") .requestBody(ExecuteBatchPolicyWithInputRequestBody.builder() - .inputs(Map.ofEntries( - Map.entry("key", Input.of("")))) - .build()) + .inputs(Map.ofEntries( + Map.entry("key", Input.of("")))) + .build()) .build(); - ExecuteBatchPolicyWithInputResponse res = sdk.executeBatchPolicyWithInput() + ExecuteBatchPolicyWithInputResponse res = sdk.executeBatchPolicyWithInput() .request(req) .call(); - if (res.batchSuccessfulPolicyEvaluation().isPresent()) { - // handle response - } - } catch (com.styra.opa.openapi.models.errors.ClientError e) { - // handle exception - throw e; - } catch (com.styra.opa.openapi.models.errors.BatchServerError e) { - // handle exception - throw e; - } catch (SDKError e) { - // handle exception - throw e; - } catch (Exception e) { - // handle exception - throw e; + if (res.batchSuccessfulPolicyEvaluation().isPresent()) { + // handle response } - } } ``` diff --git a/build.gradle b/build.gradle index 7a9ed696..12356640 100644 --- a/build.gradle +++ b/build.gradle @@ -64,7 +64,7 @@ tasks.withType(Javadoc) { } group = "com.styra" -version = "1.7.0" +version = "1.8.0" sourcesJar { archiveBaseName = "opa" @@ -91,7 +91,7 @@ publishing { maven(MavenPublication) { groupId = 'com.styra' artifactId = 'opa' - version = '1.7.0' + version = '1.8.0' from components.java diff --git a/docs/models/errors/BatchServerError.md b/docs/models/errors/BatchServerError.md index f54948aa..73a07f0b 100644 --- a/docs/models/errors/BatchServerError.md +++ b/docs/models/errors/BatchServerError.md @@ -1,9 +1,12 @@ # BatchServerError +Server Error. All requests returned a 500 error. + + ## Fields -| Field | Type | Required | Description | -| -------------------------- | -------------------------- | -------------------------- | -------------------------- | -| `batchDecisionId` | *Optional* | :heavy_minus_sign: | N/A | -| `responses` | Map | :heavy_minus_sign: | N/A | \ No newline at end of file +| Field | Type | Required | Description | +| -------------------------------------------------------------- | -------------------------------------------------------------- | -------------------------------------------------------------- | -------------------------------------------------------------- | +| `batchDecisionId` | *Optional* | :heavy_minus_sign: | N/A | +| `responses` | Map | :heavy_minus_sign: | N/A | \ No newline at end of file diff --git a/docs/models/errors/ClientError1.md b/docs/models/errors/ClientError1.md new file mode 100644 index 00000000..01633c9d --- /dev/null +++ b/docs/models/errors/ClientError1.md @@ -0,0 +1,12 @@ +# ClientError1 + +Bad Request + + +## Fields + +| Field | Type | Required | Description | +| --------------------------------------------- | --------------------------------------------- | --------------------------------------------- | --------------------------------------------- | +| `code` | *String* | :heavy_check_mark: | N/A | +| `message` | *String* | :heavy_check_mark: | N/A | +| `errors` | List<[Errors](../../models/errors/Errors.md)> | :heavy_minus_sign: | N/A | \ No newline at end of file diff --git a/docs/models/errors/UnhealthyServer.md b/docs/models/errors/UnhealthyServer.md index 95b6189b..727d73cd 100644 --- a/docs/models/errors/UnhealthyServer.md +++ b/docs/models/errors/UnhealthyServer.md @@ -1,5 +1,7 @@ # UnhealthyServer +OPA service is not healthy. If the bundles option is specified this can mean any of the configured bundles have not yet been activated. If the plugins option is specified then at least one plugin is in a non-OK state. + ## Fields diff --git a/docs/models/shared/BatchMixedResults.md b/docs/models/shared/BatchMixedResults.md index da2477d3..f4942e8f 100644 --- a/docs/models/shared/BatchMixedResults.md +++ b/docs/models/shared/BatchMixedResults.md @@ -1,5 +1,7 @@ # BatchMixedResults +Mixed success and failures. + ## Fields diff --git a/docs/models/shared/BatchSuccessfulPolicyEvaluation.md b/docs/models/shared/BatchSuccessfulPolicyEvaluation.md index b000b372..1030a6e9 100644 --- a/docs/models/shared/BatchSuccessfulPolicyEvaluation.md +++ b/docs/models/shared/BatchSuccessfulPolicyEvaluation.md @@ -1,5 +1,9 @@ # BatchSuccessfulPolicyEvaluation +All batched policy executions succeeded. +The server also returns 200 if the path refers to an undefined document. In this case, responses will be empty. + + ## Fields diff --git a/docs/models/shared/HealthyServer.md b/docs/models/shared/HealthyServer.md index 1579a46e..f1bf5b5c 100644 --- a/docs/models/shared/HealthyServer.md +++ b/docs/models/shared/HealthyServer.md @@ -1,5 +1,7 @@ # HealthyServer +OPA service is healthy. If the bundles option is specified then all configured bundles have been activated. If the plugins option is specified then all plugins are in an OK state. + ## Fields diff --git a/docs/models/shared/ResponsesErrors.md b/docs/models/shared/ResponsesErrors.md new file mode 100644 index 00000000..62879336 --- /dev/null +++ b/docs/models/shared/ResponsesErrors.md @@ -0,0 +1,10 @@ +# ResponsesErrors + + +## Fields + +| Field | Type | Required | Description | +| ----------------------------------------------------------------------- | ----------------------------------------------------------------------- | ----------------------------------------------------------------------- | ----------------------------------------------------------------------- | +| `code` | *String* | :heavy_check_mark: | N/A | +| `message` | *String* | :heavy_check_mark: | N/A | +| `location` | [Optional](../../models/shared/ResponsesLocation.md) | :heavy_minus_sign: | N/A | \ No newline at end of file diff --git a/docs/models/shared/ResponsesLocation.md b/docs/models/shared/ResponsesLocation.md new file mode 100644 index 00000000..1b04dfc0 --- /dev/null +++ b/docs/models/shared/ResponsesLocation.md @@ -0,0 +1,10 @@ +# ResponsesLocation + + +## Fields + +| Field | Type | Required | Description | +| ------------------ | ------------------ | ------------------ | ------------------ | +| `file` | *String* | :heavy_check_mark: | N/A | +| `row` | *long* | :heavy_check_mark: | N/A | +| `col` | *long* | :heavy_check_mark: | N/A | \ No newline at end of file diff --git a/docs/models/shared/ServerError.md b/docs/models/shared/ServerError.md new file mode 100644 index 00000000..e7fde472 --- /dev/null +++ b/docs/models/shared/ServerError.md @@ -0,0 +1,11 @@ +# ServerError + + +## Fields + +| Field | Type | Required | Description | Example | +| --------------------------------------------- | --------------------------------------------- | --------------------------------------------- | --------------------------------------------- | --------------------------------------------- | +| `code` | *String* | :heavy_check_mark: | N/A | | +| `message` | *String* | :heavy_check_mark: | N/A | | +| `errors` | List<[Errors](../../models/shared/Errors.md)> | :heavy_minus_sign: | N/A | | +| `decisionId` | *Optional* | :heavy_minus_sign: | N/A | b84cf736-213c-4932-a8e4-bb5c648f1b4d | \ No newline at end of file diff --git a/docs/models/shared/ServerErrorWithStatusCode.md b/docs/models/shared/ServerErrorWithStatusCode.md index aaa5812d..6a4623cc 100644 --- a/docs/models/shared/ServerErrorWithStatusCode.md +++ b/docs/models/shared/ServerErrorWithStatusCode.md @@ -3,10 +3,10 @@ ## Fields -| Field | Type | Required | Description | Example | -| --------------------------------------------- | --------------------------------------------- | --------------------------------------------- | --------------------------------------------- | --------------------------------------------- | -| `httpStatusCode` | *Optional* | :heavy_minus_sign: | N/A | 200 | -| `code` | *String* | :heavy_check_mark: | N/A | | -| `message` | *String* | :heavy_check_mark: | N/A | | -| `errors` | List<[Errors](../../models/shared/Errors.md)> | :heavy_minus_sign: | N/A | | -| `decisionId` | *Optional* | :heavy_minus_sign: | N/A | b84cf736-213c-4932-a8e4-bb5c648f1b4d | \ No newline at end of file +| Field | Type | Required | Description | Example | +| --------------------------------------------------------------- | --------------------------------------------------------------- | --------------------------------------------------------------- | --------------------------------------------------------------- | --------------------------------------------------------------- | +| `httpStatusCode` | *Optional* | :heavy_minus_sign: | N/A | 200 | +| `code` | *String* | :heavy_check_mark: | N/A | | +| `message` | *String* | :heavy_check_mark: | N/A | | +| `errors` | List<[ResponsesErrors](../../models/shared/ResponsesErrors.md)> | :heavy_minus_sign: | N/A | | +| `decisionId` | *Optional* | :heavy_minus_sign: | N/A | b84cf736-213c-4932-a8e4-bb5c648f1b4d | \ No newline at end of file diff --git a/docs/models/shared/SuccessfulPolicyResponse.md b/docs/models/shared/SuccessfulPolicyResponse.md index a53bf399..29f799dd 100644 --- a/docs/models/shared/SuccessfulPolicyResponse.md +++ b/docs/models/shared/SuccessfulPolicyResponse.md @@ -1,5 +1,9 @@ # SuccessfulPolicyResponse +Success. +The server also returns 200 if the path refers to an undefined document. In this case, the response will not contain a result property. + + ## Fields diff --git a/docs/sdks/opaapiclient/README.md b/docs/sdks/opaapiclient/README.md index 69c61159..393edfd2 100644 --- a/docs/sdks/opaapiclient/README.md +++ b/docs/sdks/opaapiclient/README.md @@ -1,10 +1,10 @@ # OpaApiClient SDK - ## Overview Enterprise OPA documentation + ### Available Operations * [executeDefaultPolicyWithInput](#executedefaultpolicywithinput) - Execute the default decision given an input @@ -23,7 +23,8 @@ Execute the default decision given an input package hello.world; import com.styra.opa.openapi.OpaApiClient; -import com.styra.opa.openapi.models.errors.SDKError; +import com.styra.opa.openapi.models.errors.ClientError; +import com.styra.opa.openapi.models.errors.ServerError; import com.styra.opa.openapi.models.operations.ExecuteDefaultPolicyWithInputResponse; import com.styra.opa.openapi.models.shared.GzipAcceptEncoding; import com.styra.opa.openapi.models.shared.Input; @@ -32,43 +33,27 @@ import java.lang.Exception; public class Application { - public static void main(String[] args) throws Exception { - try { - OpaApiClient sdk = OpaApiClient.builder() + public static void main(String[] args) throws ClientError, ServerError, Exception { + + OpaApiClient sdk = OpaApiClient.builder() .security(Security.builder() .bearerAuth("") .build()) - .build(); + .build(); - ExecuteDefaultPolicyWithInputResponse res = sdk.executeDefaultPolicyWithInput() + ExecuteDefaultPolicyWithInputResponse res = sdk.executeDefaultPolicyWithInput() .pretty(false) .acceptEncoding(GzipAcceptEncoding.GZIP) - .input(Input.of(8203.11d)) + .input(Input.of(4963.69d)) .call(); - if (res.result().isPresent()) { - // handle response - } - } catch (com.styra.opa.openapi.models.errors.ClientError e) { - // handle exception - throw e; - } catch (com.styra.opa.openapi.models.errors.ServerError e) { - // handle exception - throw e; - } catch (SDKError e) { - // handle exception - throw e; - } catch (Exception e) { - // handle exception - throw e; + if (res.result().isPresent()) { + // handle response } - } } ``` - - ### Parameters | Parameter | Type | Required | Description | @@ -77,17 +62,17 @@ public class Application { | `acceptEncoding` | [Optional](../../models/shared/GzipAcceptEncoding.md) | :heavy_minus_sign: | Indicates the server should respond with a gzip encoded body. The server will send the compressed response only if its length is above `server.encoding.gzip.min_length` value. See the configuration section | | `input` | [Input](../../models/shared/Input.md) | :heavy_check_mark: | The input document | - ### Response **[ExecuteDefaultPolicyWithInputResponse](../../models/operations/ExecuteDefaultPolicyWithInputResponse.md)** + ### Errors -| Error Object | Status Code | Content Type | +| Error Type | Status Code | Content Type | | ------------------------- | ------------------------- | ------------------------- | -| models/errors/ClientError | 400,404 | application/json | +| models/errors/ClientError | 400, 404 | application/json | | models/errors/ServerError | 500 | application/json | -| models/errors/SDKError | 4xx-5xx | \*\/* | +| models/errors/SDKError | 4XX, 5XX | \*/\* | ## executePolicy @@ -99,7 +84,8 @@ Execute a policy package hello.world; import com.styra.opa.openapi.OpaApiClient; -import com.styra.opa.openapi.models.errors.SDKError; +import com.styra.opa.openapi.models.errors.ClientError1; +import com.styra.opa.openapi.models.errors.ServerError; import com.styra.opa.openapi.models.operations.ExecutePolicyRequest; import com.styra.opa.openapi.models.operations.ExecutePolicyResponse; import com.styra.opa.openapi.models.shared.Security; @@ -107,62 +93,46 @@ import java.lang.Exception; public class Application { - public static void main(String[] args) throws Exception { - try { - OpaApiClient sdk = OpaApiClient.builder() + public static void main(String[] args) throws ClientError1, ServerError, Exception { + + OpaApiClient sdk = OpaApiClient.builder() .security(Security.builder() .bearerAuth("") .build()) - .build(); + .build(); - ExecutePolicyRequest req = ExecutePolicyRequest.builder() + ExecutePolicyRequest req = ExecutePolicyRequest.builder() .path("app/rbac") .build(); - ExecutePolicyResponse res = sdk.executePolicy() + ExecutePolicyResponse res = sdk.executePolicy() .request(req) .call(); - if (res.successfulPolicyResponse().isPresent()) { - // handle response - } - } catch (com.styra.opa.openapi.models.errors.ClientError e) { - // handle exception - throw e; - } catch (com.styra.opa.openapi.models.errors.ServerError e) { - // handle exception - throw e; - } catch (SDKError e) { - // handle exception - throw e; - } catch (Exception e) { - // handle exception - throw e; + if (res.successfulPolicyResponse().isPresent()) { + // handle response } - } } ``` - - ### Parameters | Parameter | Type | Required | Description | | ----------------------------------------------------------------------- | ----------------------------------------------------------------------- | ----------------------------------------------------------------------- | ----------------------------------------------------------------------- | | `request` | [ExecutePolicyRequest](../../models/operations/ExecutePolicyRequest.md) | :heavy_check_mark: | The request object to use for the request. | - ### Response **[ExecutePolicyResponse](../../models/operations/ExecutePolicyResponse.md)** + ### Errors -| Error Object | Status Code | Content Type | -| ------------------------- | ------------------------- | ------------------------- | -| models/errors/ClientError | 400 | application/json | -| models/errors/ServerError | 500 | application/json | -| models/errors/SDKError | 4xx-5xx | \*\/* | +| Error Type | Status Code | Content Type | +| -------------------------- | -------------------------- | -------------------------- | +| models/errors/ClientError1 | 400 | application/json | +| models/errors/ServerError | 500 | application/json | +| models/errors/SDKError | 4XX, 5XX | \*/\* | ## executePolicyWithInput @@ -174,7 +144,8 @@ Execute a policy given an input package hello.world; import com.styra.opa.openapi.OpaApiClient; -import com.styra.opa.openapi.models.errors.SDKError; +import com.styra.opa.openapi.models.errors.ClientError1; +import com.styra.opa.openapi.models.errors.ServerError; import com.styra.opa.openapi.models.operations.ExecutePolicyWithInputRequest; import com.styra.opa.openapi.models.operations.ExecutePolicyWithInputRequestBody; import com.styra.opa.openapi.models.operations.ExecutePolicyWithInputResponse; @@ -184,65 +155,49 @@ import java.lang.Exception; public class Application { - public static void main(String[] args) throws Exception { - try { - OpaApiClient sdk = OpaApiClient.builder() + public static void main(String[] args) throws ClientError1, ServerError, Exception { + + OpaApiClient sdk = OpaApiClient.builder() .security(Security.builder() .bearerAuth("") .build()) - .build(); + .build(); - ExecutePolicyWithInputRequest req = ExecutePolicyWithInputRequest.builder() + ExecutePolicyWithInputRequest req = ExecutePolicyWithInputRequest.builder() .path("app/rbac") .requestBody(ExecutePolicyWithInputRequestBody.builder() - .input(Input.of(false)) - .build()) + .input(Input.of(false)) + .build()) .build(); - ExecutePolicyWithInputResponse res = sdk.executePolicyWithInput() + ExecutePolicyWithInputResponse res = sdk.executePolicyWithInput() .request(req) .call(); - if (res.successfulPolicyResponse().isPresent()) { - // handle response - } - } catch (com.styra.opa.openapi.models.errors.ClientError e) { - // handle exception - throw e; - } catch (com.styra.opa.openapi.models.errors.ServerError e) { - // handle exception - throw e; - } catch (SDKError e) { - // handle exception - throw e; - } catch (Exception e) { - // handle exception - throw e; + if (res.successfulPolicyResponse().isPresent()) { + // handle response } - } } ``` - - ### Parameters | Parameter | Type | Required | Description | | ----------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------- | | `request` | [ExecutePolicyWithInputRequest](../../models/operations/ExecutePolicyWithInputRequest.md) | :heavy_check_mark: | The request object to use for the request. | - ### Response **[ExecutePolicyWithInputResponse](../../models/operations/ExecutePolicyWithInputResponse.md)** + ### Errors -| Error Object | Status Code | Content Type | -| ------------------------- | ------------------------- | ------------------------- | -| models/errors/ClientError | 400 | application/json | -| models/errors/ServerError | 500 | application/json | -| models/errors/SDKError | 4xx-5xx | \*\/* | +| Error Type | Status Code | Content Type | +| -------------------------- | -------------------------- | -------------------------- | +| models/errors/ClientError1 | 400 | application/json | +| models/errors/ServerError | 500 | application/json | +| models/errors/SDKError | 4XX, 5XX | \*/\* | ## executeBatchPolicyWithInput @@ -254,7 +209,8 @@ Execute a policy given a batch of inputs package hello.world; import com.styra.opa.openapi.OpaApiClient; -import com.styra.opa.openapi.models.errors.SDKError; +import com.styra.opa.openapi.models.errors.BatchServerError; +import com.styra.opa.openapi.models.errors.ClientError1; import com.styra.opa.openapi.models.operations.ExecuteBatchPolicyWithInputRequest; import com.styra.opa.openapi.models.operations.ExecuteBatchPolicyWithInputRequestBody; import com.styra.opa.openapi.models.operations.ExecuteBatchPolicyWithInputResponse; @@ -265,66 +221,50 @@ import java.util.Map; public class Application { - public static void main(String[] args) throws Exception { - try { - OpaApiClient sdk = OpaApiClient.builder() + public static void main(String[] args) throws ClientError1, BatchServerError, Exception { + + OpaApiClient sdk = OpaApiClient.builder() .security(Security.builder() .bearerAuth("") .build()) - .build(); + .build(); - ExecuteBatchPolicyWithInputRequest req = ExecuteBatchPolicyWithInputRequest.builder() + ExecuteBatchPolicyWithInputRequest req = ExecuteBatchPolicyWithInputRequest.builder() .path("app/rbac") .requestBody(ExecuteBatchPolicyWithInputRequestBody.builder() - .inputs(Map.ofEntries( - Map.entry("key", Input.of("")))) - .build()) + .inputs(Map.ofEntries( + Map.entry("key", Input.of("")))) + .build()) .build(); - ExecuteBatchPolicyWithInputResponse res = sdk.executeBatchPolicyWithInput() + ExecuteBatchPolicyWithInputResponse res = sdk.executeBatchPolicyWithInput() .request(req) .call(); - if (res.batchSuccessfulPolicyEvaluation().isPresent()) { - // handle response - } - } catch (com.styra.opa.openapi.models.errors.ClientError e) { - // handle exception - throw e; - } catch (com.styra.opa.openapi.models.errors.BatchServerError e) { - // handle exception - throw e; - } catch (SDKError e) { - // handle exception - throw e; - } catch (Exception e) { - // handle exception - throw e; + if (res.batchSuccessfulPolicyEvaluation().isPresent()) { + // handle response } - } } ``` - - ### Parameters | Parameter | Type | Required | Description | | --------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------- | | `request` | [ExecuteBatchPolicyWithInputRequest](../../models/operations/ExecuteBatchPolicyWithInputRequest.md) | :heavy_check_mark: | The request object to use for the request. | - ### Response **[ExecuteBatchPolicyWithInputResponse](../../models/operations/ExecuteBatchPolicyWithInputResponse.md)** + ### Errors -| Error Object | Status Code | Content Type | +| Error Type | Status Code | Content Type | | ------------------------------ | ------------------------------ | ------------------------------ | -| models/errors/ClientError | 400 | application/json | +| models/errors/ClientError1 | 400 | application/json | | models/errors/BatchServerError | 500 | application/json | -| models/errors/SDKError | 4xx-5xx | \*\/* | +| models/errors/SDKError | 4XX, 5XX | \*/\* | ## health @@ -336,7 +276,7 @@ The health API endpoint executes a simple built-in policy query to verify that t package hello.world; import com.styra.opa.openapi.OpaApiClient; -import com.styra.opa.openapi.models.errors.SDKError; +import com.styra.opa.openapi.models.errors.UnhealthyServer; import com.styra.opa.openapi.models.operations.HealthResponse; import com.styra.opa.openapi.models.shared.Security; import java.lang.Exception; @@ -344,41 +284,28 @@ import java.util.List; public class Application { - public static void main(String[] args) throws Exception { - try { - OpaApiClient sdk = OpaApiClient.builder() + public static void main(String[] args) throws UnhealthyServer, Exception { + + OpaApiClient sdk = OpaApiClient.builder() .security(Security.builder() .bearerAuth("") .build()) - .build(); + .build(); - HealthResponse res = sdk.health() + HealthResponse res = sdk.health() .bundles(false) .plugins(false) .excludePlugin(List.of( "")) .call(); - if (res.healthyServer().isPresent()) { - // handle response - } - } catch (com.styra.opa.openapi.models.errors.UnhealthyServer e) { - // handle exception - throw e; - } catch (SDKError e) { - // handle exception - throw e; - } catch (Exception e) { - // handle exception - throw e; + if (res.healthyServer().isPresent()) { + // handle response } - } } ``` - - ### Parameters | Parameter | Type | Required | Description | @@ -387,13 +314,13 @@ public class Application { | `plugins` | *Optional* | :heavy_minus_sign: | Boolean parameter to account for plugin status in response. | | `excludePlugin` | List<*String*> | :heavy_minus_sign: | String parameter to exclude a plugin from status checks. Can be added multiple times. Does nothing if plugins is not true. This parameter is useful for special use cases where a plugin depends on the server being fully initialized before it can fully initialize itself. | - ### Response **[HealthResponse](../../models/operations/HealthResponse.md)** + ### Errors -| Error Object | Status Code | Content Type | +| Error Type | Status Code | Content Type | | ----------------------------- | ----------------------------- | ----------------------------- | | models/errors/UnhealthyServer | 500 | application/json | -| models/errors/SDKError | 4xx-5xx | \*\/* | +| models/errors/SDKError | 4XX, 5XX | \*/\* | \ No newline at end of file diff --git a/src/main/java/com/styra/opa/OPAClient.java b/src/main/java/com/styra/opa/OPAClient.java index ce55ac5e..fd0c157f 100644 --- a/src/main/java/com/styra/opa/OPAClient.java +++ b/src/main/java/com/styra/opa/OPAClient.java @@ -20,11 +20,11 @@ import com.styra.opa.openapi.models.operations.ExecutePolicyWithInputResponse; import com.styra.opa.openapi.models.shared.BatchMixedResults; import com.styra.opa.openapi.models.shared.BatchSuccessfulPolicyEvaluation; -import com.styra.opa.openapi.models.shared.Errors; import com.styra.opa.openapi.models.shared.Explain; import com.styra.opa.openapi.models.shared.Input; -import com.styra.opa.openapi.models.shared.Location; import com.styra.opa.openapi.models.shared.Responses; +import com.styra.opa.openapi.models.shared.ResponsesErrors; +import com.styra.opa.openapi.models.shared.ResponsesLocation; import com.styra.opa.openapi.models.shared.Result; import com.styra.opa.openapi.models.shared.ServerErrorWithStatusCode; import com.styra.opa.openapi.models.shared.SuccessfulPolicyResponse; @@ -80,7 +80,7 @@ public class OPAClient { * suitable value for most sidecar style deployments of OPA. */ public OPAClient() { - this.sdk = OpaApiClient.builder().serverURL(sdkServerURL).build(); + this.sdk = OpaApiClient.builder().client(new OPAHTTPClient()).serverURL(sdkServerURL).build(); } /** @@ -90,7 +90,7 @@ public OPAClient() { */ public OPAClient(String opaURL) { this.sdkServerURL = opaURL; - this.sdk = OpaApiClient.builder().serverURL(opaURL).build(); + this.sdk = OpaApiClient.builder().client(new OPAHTTPClient()).serverURL(opaURL).build(); } /** @@ -961,7 +961,7 @@ private Map executePolicyBatchFallback( return out; } - private static Optional convertErrorLocation(Optional loc) { + private static Optional convertErrorLocation(Optional loc) { if (loc.isPresent()) { return Optional.of(new ServerErrorLocation(loc.get().file(), loc.get().row(), loc.get().col())); } else { @@ -969,10 +969,10 @@ private static Optional convertErrorLocation(Optional> convertErrorList(Optional> errs) { + private static Optional> convertErrorList(Optional> errs) { if (errs.isPresent()) { ArrayList out = new ArrayList(); - for (Errors e : errs.get()) { + for (ResponsesErrors e : errs.get()) { out.add(new ServerErrorErrors(e.code(), e.message(), convertErrorLocation(e.location()))); } return Optional.of(out); diff --git a/src/main/java/com/styra/opa/openapi/OpaApiClient.java b/src/main/java/com/styra/opa/openapi/OpaApiClient.java index 7b8fa69c..7b31a77b 100644 --- a/src/main/java/com/styra/opa/openapi/OpaApiClient.java +++ b/src/main/java/com/styra/opa/openapi/OpaApiClient.java @@ -6,6 +6,7 @@ import com.fasterxml.jackson.core.type.TypeReference; import com.styra.opa.openapi.models.errors.BatchServerError; +import com.styra.opa.openapi.models.errors.ClientError1; import com.styra.opa.openapi.models.errors.ClientError; import com.styra.opa.openapi.models.errors.SDKError; import com.styra.opa.openapi.models.errors.ServerError; @@ -138,7 +139,7 @@ public Builder serverURL(String serverUrl) { * @return The builder instance. */ public Builder serverURL(String serverUrl, Map params) { - this.sdkConfiguration.serverUrl = com.styra.opa.openapi.utils.Utils.templateUrl(serverUrl, params); + this.sdkConfiguration.serverUrl = Utils.templateUrl(serverUrl, params); return this; } @@ -264,7 +265,7 @@ public ExecuteDefaultPolicyWithInputResponse executeDefaultPolicyWithInput( _req.setBody(Optional.ofNullable(_serializedRequestBody)); _req.addHeader("Accept", "application/json") .addHeader("user-agent", - this.sdkConfiguration.userAgent); + SDKConfiguration.USER_AGENT); _req.addQueryParams(Utils.getQueryParams( ExecuteDefaultPolicyWithInputRequest.class, @@ -414,7 +415,7 @@ public ExecutePolicyResponse executePolicy( HTTPRequest _req = new HTTPRequest(_url, "GET"); _req.addHeader("Accept", "application/json") .addHeader("user-agent", - this.sdkConfiguration.userAgent); + SDKConfiguration.USER_AGENT); _req.addQueryParams(Utils.getQueryParams( ExecutePolicyRequest.class, @@ -496,9 +497,9 @@ public ExecutePolicyResponse executePolicy( } if (Utils.statusCodeMatches(_httpRes.statusCode(), "400")) { if (Utils.contentTypeMatches(_contentType, "application/json")) { - ClientError _out = Utils.mapper().readValue( + ClientError1 _out = Utils.mapper().readValue( Utils.toUtf8AndClose(_httpRes.body()), - new TypeReference() {}); + new TypeReference() {}); throw _out; } else { throw new SDKError( @@ -577,7 +578,7 @@ public ExecutePolicyWithInputResponse executePolicyWithInput( _req.setBody(Optional.ofNullable(_serializedRequestBody)); _req.addHeader("Accept", "application/json") .addHeader("user-agent", - this.sdkConfiguration.userAgent); + SDKConfiguration.USER_AGENT); _req.addQueryParams(Utils.getQueryParams( ExecutePolicyWithInputRequest.class, @@ -659,9 +660,9 @@ public ExecutePolicyWithInputResponse executePolicyWithInput( } if (Utils.statusCodeMatches(_httpRes.statusCode(), "400")) { if (Utils.contentTypeMatches(_contentType, "application/json")) { - ClientError _out = Utils.mapper().readValue( + ClientError1 _out = Utils.mapper().readValue( Utils.toUtf8AndClose(_httpRes.body()), - new TypeReference() {}); + new TypeReference() {}); throw _out; } else { throw new SDKError( @@ -740,7 +741,7 @@ public ExecuteBatchPolicyWithInputResponse executeBatchPolicyWithInput( _req.setBody(Optional.ofNullable(_serializedRequestBody)); _req.addHeader("Accept", "application/json") .addHeader("user-agent", - this.sdkConfiguration.userAgent); + SDKConfiguration.USER_AGENT); _req.addQueryParams(Utils.getQueryParams( ExecuteBatchPolicyWithInputRequest.class, @@ -838,9 +839,9 @@ public ExecuteBatchPolicyWithInputResponse executeBatchPolicyWithInput( } if (Utils.statusCodeMatches(_httpRes.statusCode(), "400")) { if (Utils.contentTypeMatches(_contentType, "application/json")) { - ClientError _out = Utils.mapper().readValue( + ClientError1 _out = Utils.mapper().readValue( Utils.toUtf8AndClose(_httpRes.body()), - new TypeReference() {}); + new TypeReference() {}); throw _out; } else { throw new SDKError( @@ -928,7 +929,7 @@ public HealthResponse health( HTTPRequest _req = new HTTPRequest(_url, "GET"); _req.addHeader("Accept", "application/json") .addHeader("user-agent", - this.sdkConfiguration.userAgent); + SDKConfiguration.USER_AGENT); _req.addQueryParams(Utils.getQueryParams( HealthRequest.class, diff --git a/src/main/java/com/styra/opa/openapi/SDKConfiguration.java b/src/main/java/com/styra/opa/openapi/SDKConfiguration.java index af23035b..6cf3ea29 100644 --- a/src/main/java/com/styra/opa/openapi/SDKConfiguration.java +++ b/src/main/java/com/styra/opa/openapi/SDKConfiguration.java @@ -21,11 +21,14 @@ public Optional securitySource() { public HTTPClient defaultClient; public String serverUrl; public int serverIdx = 0; - public String language = "java"; - public String openapiDocVersion = "0.2.0"; - public String sdkVersion = "1.7.0"; - public String genVersion = "2.402.5"; - public String userAgent = "speakeasy-sdk/java 1.7.0 2.402.5 0.2.0 com.styra.opa.openapi"; + private static final String LANGUAGE = "java"; + public static final String OPENAPI_DOC_VERSION = "0.2.0"; + public static final String SDK_VERSION = "1.8.0"; + public static final String GEN_VERSION = "2.429.0"; + private static final String BASE_PACKAGE = "com.styra.opa.openapi"; + public static final String USER_AGENT = + String.format("speakeasy-sdk/%s %s %s %s %s", + LANGUAGE, SDK_VERSION, GEN_VERSION, OPENAPI_DOC_VERSION, BASE_PACKAGE); private Hooks _hooks = createHooks(); diff --git a/src/main/java/com/styra/opa/openapi/models/errors/BatchServerError.java b/src/main/java/com/styra/opa/openapi/models/errors/BatchServerError.java index 27ea3992..78564bc5 100644 --- a/src/main/java/com/styra/opa/openapi/models/errors/BatchServerError.java +++ b/src/main/java/com/styra/opa/openapi/models/errors/BatchServerError.java @@ -8,6 +8,7 @@ import com.fasterxml.jackson.annotation.JsonInclude.Include; import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.annotation.JsonProperty; +import com.styra.opa.openapi.models.shared.ServerError; import com.styra.opa.openapi.utils.Utils; import java.lang.Override; import java.lang.String; @@ -16,6 +17,10 @@ import java.util.Objects; import java.util.Optional; +/** + * BatchServerError - Server Error. All requests returned a 500 error. + * + */ public class BatchServerError extends RuntimeException { @JsonInclude(Include.NON_ABSENT) diff --git a/src/main/java/com/styra/opa/openapi/models/errors/ClientError1.java b/src/main/java/com/styra/opa/openapi/models/errors/ClientError1.java new file mode 100644 index 00000000..867116f9 --- /dev/null +++ b/src/main/java/com/styra/opa/openapi/models/errors/ClientError1.java @@ -0,0 +1,168 @@ +/* + * Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT. + */ + +package com.styra.opa.openapi.models.errors; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonInclude.Include; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.styra.opa.openapi.utils.Utils; +import java.lang.Override; +import java.lang.String; +import java.lang.SuppressWarnings; +import java.util.List; +import java.util.Objects; +import java.util.Optional; + +/** + * ClientError1 - Bad Request + */ +public class ClientError1 extends RuntimeException { + + @JsonProperty("code") + private String code; + + @JsonProperty("message") + private String message; + + @JsonInclude(Include.NON_ABSENT) + @JsonProperty("errors") + private Optional> errors; + + @JsonCreator + public ClientError1( + @JsonProperty("code") String code, + @JsonProperty("message") String message, + @JsonProperty("errors") Optional> errors) { + Utils.checkNotNull(code, "code"); + Utils.checkNotNull(message, "message"); + Utils.checkNotNull(errors, "errors"); + this.code = code; + this.message = message; + this.errors = errors; + } + + public ClientError1( + String code, + String message) { + this(code, message, Optional.empty()); + } + + public String code(){ + return code; + } + + public String message(){ + return message; + } + + @SuppressWarnings("unchecked") + public Optional> errors(){ + return (Optional>) errors; + } + + public final static Builder builder() { + return new Builder(); + } + + public ClientError1 withCode(String code) { + Utils.checkNotNull(code, "code"); + this.code = code; + return this; + } + + public ClientError1 withMessage(String message) { + Utils.checkNotNull(message, "message"); + this.message = message; + return this; + } + + public ClientError1 withErrors(List errors) { + Utils.checkNotNull(errors, "errors"); + this.errors = Optional.ofNullable(errors); + return this; + } + + public ClientError1 withErrors(Optional> errors) { + Utils.checkNotNull(errors, "errors"); + this.errors = errors; + return this; + } + + @Override + public boolean equals(java.lang.Object o) { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + ClientError1 other = (ClientError1) o; + return + Objects.deepEquals(this.code, other.code) && + Objects.deepEquals(this.message, other.message) && + Objects.deepEquals(this.errors, other.errors); + } + + @Override + public int hashCode() { + return java.util.Objects.hash( + code, + message, + errors); + } + + @Override + public String toString() { + return Utils.toString(ClientError1.class, + "code", code, + "message", message, + "errors", errors); + } + + public final static class Builder { + + private String code; + + private String message; + + private Optional> errors = Optional.empty(); + + private Builder() { + // force use of static builder() method + } + + public Builder code(String code) { + Utils.checkNotNull(code, "code"); + this.code = code; + return this; + } + + public Builder message(String message) { + Utils.checkNotNull(message, "message"); + this.message = message; + return this; + } + + public Builder errors(List errors) { + Utils.checkNotNull(errors, "errors"); + this.errors = Optional.ofNullable(errors); + return this; + } + + public Builder errors(Optional> errors) { + Utils.checkNotNull(errors, "errors"); + this.errors = errors; + return this; + } + + public ClientError1 build() { + return new ClientError1( + code, + message, + errors); + } + } +} diff --git a/src/main/java/com/styra/opa/openapi/models/errors/UnhealthyServer.java b/src/main/java/com/styra/opa/openapi/models/errors/UnhealthyServer.java index 9f7c3724..8cba2c94 100644 --- a/src/main/java/com/styra/opa/openapi/models/errors/UnhealthyServer.java +++ b/src/main/java/com/styra/opa/openapi/models/errors/UnhealthyServer.java @@ -14,6 +14,9 @@ import java.util.Objects; import java.util.Optional; +/** + * UnhealthyServer - OPA service is not healthy. If the bundles option is specified this can mean any of the configured bundles have not yet been activated. If the plugins option is specified then at least one plugin is in a non-OK state. + */ public class UnhealthyServer extends RuntimeException { @JsonInclude(Include.NON_ABSENT) diff --git a/src/main/java/com/styra/opa/openapi/models/operations/ExecuteBatchPolicyWithInputRequest.java b/src/main/java/com/styra/opa/openapi/models/operations/ExecuteBatchPolicyWithInputRequest.java index 5843ad18..dd1241c6 100644 --- a/src/main/java/com/styra/opa/openapi/models/operations/ExecuteBatchPolicyWithInputRequest.java +++ b/src/main/java/com/styra/opa/openapi/models/operations/ExecuteBatchPolicyWithInputRequest.java @@ -616,8 +616,7 @@ public Builder requestBody(ExecuteBatchPolicyWithInputRequestBody requestBody) { public ExecuteBatchPolicyWithInputRequest build() { if (path == null) { path = _SINGLETON_VALUE_Path.value(); - } - return new ExecuteBatchPolicyWithInputRequest( + } return new ExecuteBatchPolicyWithInputRequest( path, contentEncoding, acceptEncoding, diff --git a/src/main/java/com/styra/opa/openapi/models/operations/ExecuteBatchPolicyWithInputRequestBuilder.java b/src/main/java/com/styra/opa/openapi/models/operations/ExecuteBatchPolicyWithInputRequestBuilder.java index 71d08b38..249e052f 100644 --- a/src/main/java/com/styra/opa/openapi/models/operations/ExecuteBatchPolicyWithInputRequestBuilder.java +++ b/src/main/java/com/styra/opa/openapi/models/operations/ExecuteBatchPolicyWithInputRequestBuilder.java @@ -15,7 +15,7 @@ public ExecuteBatchPolicyWithInputRequestBuilder(SDKMethodInterfaces.MethodCallE this.sdk = sdk; } - public ExecuteBatchPolicyWithInputRequestBuilder request(com.styra.opa.openapi.models.operations.ExecuteBatchPolicyWithInputRequest request) { + public ExecuteBatchPolicyWithInputRequestBuilder request(ExecuteBatchPolicyWithInputRequest request) { Utils.checkNotNull(request, "request"); this.request = request; return this; diff --git a/src/main/java/com/styra/opa/openapi/models/operations/ExecuteDefaultPolicyWithInputRequestBuilder.java b/src/main/java/com/styra/opa/openapi/models/operations/ExecuteDefaultPolicyWithInputRequestBuilder.java index 46610cb6..eb7fa91c 100644 --- a/src/main/java/com/styra/opa/openapi/models/operations/ExecuteDefaultPolicyWithInputRequestBuilder.java +++ b/src/main/java/com/styra/opa/openapi/models/operations/ExecuteDefaultPolicyWithInputRequestBuilder.java @@ -27,25 +27,25 @@ public ExecuteDefaultPolicyWithInputRequestBuilder pretty(boolean pretty) { return this; } - public ExecuteDefaultPolicyWithInputRequestBuilder pretty(java.util.Optional pretty) { + public ExecuteDefaultPolicyWithInputRequestBuilder pretty(Optional pretty) { Utils.checkNotNull(pretty, "pretty"); this.pretty = pretty; return this; } - public ExecuteDefaultPolicyWithInputRequestBuilder acceptEncoding(com.styra.opa.openapi.models.shared.GzipAcceptEncoding acceptEncoding) { + public ExecuteDefaultPolicyWithInputRequestBuilder acceptEncoding(GzipAcceptEncoding acceptEncoding) { Utils.checkNotNull(acceptEncoding, "acceptEncoding"); this.acceptEncoding = Optional.of(acceptEncoding); return this; } - public ExecuteDefaultPolicyWithInputRequestBuilder acceptEncoding(java.util.Optional acceptEncoding) { + public ExecuteDefaultPolicyWithInputRequestBuilder acceptEncoding(Optional acceptEncoding) { Utils.checkNotNull(acceptEncoding, "acceptEncoding"); this.acceptEncoding = acceptEncoding; return this; } - public ExecuteDefaultPolicyWithInputRequestBuilder input(com.styra.opa.openapi.models.shared.Input input) { + public ExecuteDefaultPolicyWithInputRequestBuilder input(Input input) { Utils.checkNotNull(input, "input"); this.input = input; return this; diff --git a/src/main/java/com/styra/opa/openapi/models/operations/ExecutePolicyRequest.java b/src/main/java/com/styra/opa/openapi/models/operations/ExecutePolicyRequest.java index 2dc4ca70..2932ed20 100644 --- a/src/main/java/com/styra/opa/openapi/models/operations/ExecutePolicyRequest.java +++ b/src/main/java/com/styra/opa/openapi/models/operations/ExecutePolicyRequest.java @@ -515,8 +515,7 @@ public Builder strictBuiltinErrors(Optional strictBuiltinErrors) { public ExecutePolicyRequest build() { if (path == null) { path = _SINGLETON_VALUE_Path.value(); - } - return new ExecutePolicyRequest( + } return new ExecutePolicyRequest( path, acceptEncoding, pretty, diff --git a/src/main/java/com/styra/opa/openapi/models/operations/ExecutePolicyRequestBuilder.java b/src/main/java/com/styra/opa/openapi/models/operations/ExecutePolicyRequestBuilder.java index 4be7acfb..7c4ab6c9 100644 --- a/src/main/java/com/styra/opa/openapi/models/operations/ExecutePolicyRequestBuilder.java +++ b/src/main/java/com/styra/opa/openapi/models/operations/ExecutePolicyRequestBuilder.java @@ -15,7 +15,7 @@ public ExecutePolicyRequestBuilder(SDKMethodInterfaces.MethodCallExecutePolicy s this.sdk = sdk; } - public ExecutePolicyRequestBuilder request(com.styra.opa.openapi.models.operations.ExecutePolicyRequest request) { + public ExecutePolicyRequestBuilder request(ExecutePolicyRequest request) { Utils.checkNotNull(request, "request"); this.request = request; return this; diff --git a/src/main/java/com/styra/opa/openapi/models/operations/ExecutePolicyWithInputRequest.java b/src/main/java/com/styra/opa/openapi/models/operations/ExecutePolicyWithInputRequest.java index 0aa0f537..b84140cd 100644 --- a/src/main/java/com/styra/opa/openapi/models/operations/ExecutePolicyWithInputRequest.java +++ b/src/main/java/com/styra/opa/openapi/models/operations/ExecutePolicyWithInputRequest.java @@ -616,8 +616,7 @@ public Builder requestBody(ExecutePolicyWithInputRequestBody requestBody) { public ExecutePolicyWithInputRequest build() { if (path == null) { path = _SINGLETON_VALUE_Path.value(); - } - return new ExecutePolicyWithInputRequest( + } return new ExecutePolicyWithInputRequest( path, contentEncoding, acceptEncoding, diff --git a/src/main/java/com/styra/opa/openapi/models/operations/ExecutePolicyWithInputRequestBuilder.java b/src/main/java/com/styra/opa/openapi/models/operations/ExecutePolicyWithInputRequestBuilder.java index ca75e581..b8f77d94 100644 --- a/src/main/java/com/styra/opa/openapi/models/operations/ExecutePolicyWithInputRequestBuilder.java +++ b/src/main/java/com/styra/opa/openapi/models/operations/ExecutePolicyWithInputRequestBuilder.java @@ -15,7 +15,7 @@ public ExecutePolicyWithInputRequestBuilder(SDKMethodInterfaces.MethodCallExecut this.sdk = sdk; } - public ExecutePolicyWithInputRequestBuilder request(com.styra.opa.openapi.models.operations.ExecutePolicyWithInputRequest request) { + public ExecutePolicyWithInputRequestBuilder request(ExecutePolicyWithInputRequest request) { Utils.checkNotNull(request, "request"); this.request = request; return this; diff --git a/src/main/java/com/styra/opa/openapi/models/operations/HealthRequest.java b/src/main/java/com/styra/opa/openapi/models/operations/HealthRequest.java index 7fd9c4d1..9e43ea35 100644 --- a/src/main/java/com/styra/opa/openapi/models/operations/HealthRequest.java +++ b/src/main/java/com/styra/opa/openapi/models/operations/HealthRequest.java @@ -243,8 +243,7 @@ public HealthRequest build() { } if (plugins == null) { plugins = _SINGLETON_VALUE_Plugins.value(); - } - return new HealthRequest( + } return new HealthRequest( bundles, plugins, excludePlugin); diff --git a/src/main/java/com/styra/opa/openapi/models/operations/HealthRequestBuilder.java b/src/main/java/com/styra/opa/openapi/models/operations/HealthRequestBuilder.java index b7d87849..93ad5835 100644 --- a/src/main/java/com/styra/opa/openapi/models/operations/HealthRequestBuilder.java +++ b/src/main/java/com/styra/opa/openapi/models/operations/HealthRequestBuilder.java @@ -35,7 +35,7 @@ public HealthRequestBuilder bundles(boolean bundles) { return this; } - public HealthRequestBuilder bundles(java.util.Optional bundles) { + public HealthRequestBuilder bundles(Optional bundles) { Utils.checkNotNull(bundles, "bundles"); this.bundles = bundles; return this; @@ -47,19 +47,19 @@ public HealthRequestBuilder plugins(boolean plugins) { return this; } - public HealthRequestBuilder plugins(java.util.Optional plugins) { + public HealthRequestBuilder plugins(Optional plugins) { Utils.checkNotNull(plugins, "plugins"); this.plugins = plugins; return this; } - public HealthRequestBuilder excludePlugin(java.util.List excludePlugin) { + public HealthRequestBuilder excludePlugin(List excludePlugin) { Utils.checkNotNull(excludePlugin, "excludePlugin"); this.excludePlugin = Optional.of(excludePlugin); return this; } - public HealthRequestBuilder excludePlugin(java.util.Optional> excludePlugin) { + public HealthRequestBuilder excludePlugin(Optional> excludePlugin) { Utils.checkNotNull(excludePlugin, "excludePlugin"); this.excludePlugin = excludePlugin; return this; @@ -72,7 +72,6 @@ public HealthResponse call() throws Exception { if (plugins == null) { plugins = _SINGLETON_VALUE_Plugins.value(); } - return sdk.health( bundles, plugins, diff --git a/src/main/java/com/styra/opa/openapi/models/operations/SDKMethodInterfaces.java b/src/main/java/com/styra/opa/openapi/models/operations/SDKMethodInterfaces.java index a31035f0..bce06cd8 100644 --- a/src/main/java/com/styra/opa/openapi/models/operations/SDKMethodInterfaces.java +++ b/src/main/java/com/styra/opa/openapi/models/operations/SDKMethodInterfaces.java @@ -7,6 +7,7 @@ import com.styra.opa.openapi.models.shared.GzipAcceptEncoding; import com.styra.opa.openapi.models.shared.Input; import java.lang.Boolean; +import java.lang.Exception; import java.lang.String; import java.util.List; import java.util.Optional; @@ -15,7 +16,7 @@ public class SDKMethodInterfaces { public interface MethodCallExecuteDefaultPolicyWithInput { - com.styra.opa.openapi.models.operations.ExecuteDefaultPolicyWithInputResponse executeDefaultPolicyWithInput( + ExecuteDefaultPolicyWithInputResponse executeDefaultPolicyWithInput( Optional pretty, Optional acceptEncoding, Input input) throws Exception; @@ -23,25 +24,25 @@ com.styra.opa.openapi.models.operations.ExecuteDefaultPolicyWithInputResponse ex public interface MethodCallExecutePolicy { - com.styra.opa.openapi.models.operations.ExecutePolicyResponse executePolicy( + ExecutePolicyResponse executePolicy( ExecutePolicyRequest request) throws Exception; } public interface MethodCallExecutePolicyWithInput { - com.styra.opa.openapi.models.operations.ExecutePolicyWithInputResponse executePolicyWithInput( + ExecutePolicyWithInputResponse executePolicyWithInput( ExecutePolicyWithInputRequest request) throws Exception; } public interface MethodCallExecuteBatchPolicyWithInput { - com.styra.opa.openapi.models.operations.ExecuteBatchPolicyWithInputResponse executeBatchPolicyWithInput( + ExecuteBatchPolicyWithInputResponse executeBatchPolicyWithInput( ExecuteBatchPolicyWithInputRequest request) throws Exception; } public interface MethodCallHealth { - com.styra.opa.openapi.models.operations.HealthResponse health( + HealthResponse health( Optional bundles, Optional plugins, Optional> excludePlugin) throws Exception; diff --git a/src/main/java/com/styra/opa/openapi/models/shared/BatchMixedResults.java b/src/main/java/com/styra/opa/openapi/models/shared/BatchMixedResults.java index f9a082db..dac49913 100644 --- a/src/main/java/com/styra/opa/openapi/models/shared/BatchMixedResults.java +++ b/src/main/java/com/styra/opa/openapi/models/shared/BatchMixedResults.java @@ -19,6 +19,9 @@ import java.util.Objects; import java.util.Optional; +/** + * BatchMixedResults - Mixed success and failures. + */ public class BatchMixedResults { diff --git a/src/main/java/com/styra/opa/openapi/models/shared/BatchSuccessfulPolicyEvaluation.java b/src/main/java/com/styra/opa/openapi/models/shared/BatchSuccessfulPolicyEvaluation.java index d76f16d9..b841fc4e 100644 --- a/src/main/java/com/styra/opa/openapi/models/shared/BatchSuccessfulPolicyEvaluation.java +++ b/src/main/java/com/styra/opa/openapi/models/shared/BatchSuccessfulPolicyEvaluation.java @@ -19,6 +19,11 @@ import java.util.Objects; import java.util.Optional; +/** + * BatchSuccessfulPolicyEvaluation - All batched policy executions succeeded. + * The server also returns 200 if the path refers to an undefined document. In this case, responses will be empty. + * + */ public class BatchSuccessfulPolicyEvaluation { diff --git a/src/main/java/com/styra/opa/openapi/models/shared/HealthyServer.java b/src/main/java/com/styra/opa/openapi/models/shared/HealthyServer.java index fb5c8081..02f76a7d 100644 --- a/src/main/java/com/styra/opa/openapi/models/shared/HealthyServer.java +++ b/src/main/java/com/styra/opa/openapi/models/shared/HealthyServer.java @@ -11,6 +11,9 @@ import java.lang.String; import java.util.Objects; +/** + * HealthyServer - OPA service is healthy. If the bundles option is specified then all configured bundles have been activated. If the plugins option is specified then all plugins are in an OK state. + */ public class HealthyServer { diff --git a/src/main/java/com/styra/opa/openapi/models/shared/Input.java b/src/main/java/com/styra/opa/openapi/models/shared/Input.java index 9770b692..f05fc3bf 100644 --- a/src/main/java/com/styra/opa/openapi/models/shared/Input.java +++ b/src/main/java/com/styra/opa/openapi/models/shared/Input.java @@ -13,6 +13,8 @@ import com.styra.opa.openapi.utils.Utils.JsonShape; import com.styra.opa.openapi.utils.Utils.TypeReferenceWithShape; import com.styra.opa.openapi.utils.Utils; +import java.lang.Boolean; +import java.lang.Double; import java.lang.Object; import java.lang.Override; import java.lang.String; @@ -107,11 +109,11 @@ public static final class _Deserializer extends OneOfDeserializer { public _Deserializer() { super(Input.class, false, - TypeReferenceWithShape.of(new TypeReference>() {}, JsonShape.DEFAULT), - TypeReferenceWithShape.of(new TypeReference>() {}, JsonShape.DEFAULT), - TypeReferenceWithShape.of(new TypeReference() {}, JsonShape.DEFAULT), - TypeReferenceWithShape.of(new TypeReference() {}, JsonShape.DEFAULT), - TypeReferenceWithShape.of(new TypeReference() {}, JsonShape.DEFAULT)); + TypeReferenceWithShape.of(new TypeReference>() {}, JsonShape.DEFAULT), + TypeReferenceWithShape.of(new TypeReference>() {}, JsonShape.DEFAULT), + TypeReferenceWithShape.of(new TypeReference() {}, JsonShape.DEFAULT), + TypeReferenceWithShape.of(new TypeReference() {}, JsonShape.DEFAULT), + TypeReferenceWithShape.of(new TypeReference() {}, JsonShape.DEFAULT)); } } diff --git a/src/main/java/com/styra/opa/openapi/models/shared/ResponsesErrors.java b/src/main/java/com/styra/opa/openapi/models/shared/ResponsesErrors.java new file mode 100644 index 00000000..59314d5c --- /dev/null +++ b/src/main/java/com/styra/opa/openapi/models/shared/ResponsesErrors.java @@ -0,0 +1,171 @@ +/* + * Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT. + */ + +package com.styra.opa.openapi.models.shared; + + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonIgnore; +import com.fasterxml.jackson.annotation.JsonInclude.Include; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.styra.opa.openapi.utils.Utils; +import java.lang.Override; +import java.lang.String; +import java.lang.SuppressWarnings; +import java.util.Objects; +import java.util.Optional; + + +public class ResponsesErrors { + + @JsonProperty("code") + private String code; + + @JsonProperty("message") + private String message; + + @JsonInclude(Include.NON_ABSENT) + @JsonProperty("location") + private Optional location; + + @JsonCreator + public ResponsesErrors( + @JsonProperty("code") String code, + @JsonProperty("message") String message, + @JsonProperty("location") Optional location) { + Utils.checkNotNull(code, "code"); + Utils.checkNotNull(message, "message"); + Utils.checkNotNull(location, "location"); + this.code = code; + this.message = message; + this.location = location; + } + + public ResponsesErrors( + String code, + String message) { + this(code, message, Optional.empty()); + } + + @JsonIgnore + public String code() { + return code; + } + + @JsonIgnore + public String message() { + return message; + } + + @SuppressWarnings("unchecked") + @JsonIgnore + public Optional location() { + return (Optional) location; + } + + public final static Builder builder() { + return new Builder(); + } + + public ResponsesErrors withCode(String code) { + Utils.checkNotNull(code, "code"); + this.code = code; + return this; + } + + public ResponsesErrors withMessage(String message) { + Utils.checkNotNull(message, "message"); + this.message = message; + return this; + } + + public ResponsesErrors withLocation(ResponsesLocation location) { + Utils.checkNotNull(location, "location"); + this.location = Optional.ofNullable(location); + return this; + } + + public ResponsesErrors withLocation(Optional location) { + Utils.checkNotNull(location, "location"); + this.location = location; + return this; + } + + @Override + public boolean equals(java.lang.Object o) { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + ResponsesErrors other = (ResponsesErrors) o; + return + Objects.deepEquals(this.code, other.code) && + Objects.deepEquals(this.message, other.message) && + Objects.deepEquals(this.location, other.location); + } + + @Override + public int hashCode() { + return Objects.hash( + code, + message, + location); + } + + @Override + public String toString() { + return Utils.toString(ResponsesErrors.class, + "code", code, + "message", message, + "location", location); + } + + public final static class Builder { + + private String code; + + private String message; + + private Optional location = Optional.empty(); + + private Builder() { + // force use of static builder() method + } + + public Builder code(String code) { + Utils.checkNotNull(code, "code"); + this.code = code; + return this; + } + + public Builder message(String message) { + Utils.checkNotNull(message, "message"); + this.message = message; + return this; + } + + public Builder location(ResponsesLocation location) { + Utils.checkNotNull(location, "location"); + this.location = Optional.ofNullable(location); + return this; + } + + public Builder location(Optional location) { + Utils.checkNotNull(location, "location"); + this.location = location; + return this; + } + + public ResponsesErrors build() { + return new ResponsesErrors( + code, + message, + location); + } + } +} + diff --git a/src/main/java/com/styra/opa/openapi/models/shared/ResponsesLocation.java b/src/main/java/com/styra/opa/openapi/models/shared/ResponsesLocation.java new file mode 100644 index 00000000..7003e555 --- /dev/null +++ b/src/main/java/com/styra/opa/openapi/models/shared/ResponsesLocation.java @@ -0,0 +1,148 @@ +/* + * Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT. + */ + +package com.styra.opa.openapi.models.shared; + + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonIgnore; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.styra.opa.openapi.utils.Utils; +import java.lang.Long; +import java.lang.Override; +import java.lang.String; +import java.util.Objects; + + +public class ResponsesLocation { + + @JsonProperty("file") + private String file; + + @JsonProperty("row") + private long row; + + @JsonProperty("col") + private long col; + + @JsonCreator + public ResponsesLocation( + @JsonProperty("file") String file, + @JsonProperty("row") long row, + @JsonProperty("col") long col) { + Utils.checkNotNull(file, "file"); + Utils.checkNotNull(row, "row"); + Utils.checkNotNull(col, "col"); + this.file = file; + this.row = row; + this.col = col; + } + + @JsonIgnore + public String file() { + return file; + } + + @JsonIgnore + public long row() { + return row; + } + + @JsonIgnore + public long col() { + return col; + } + + public final static Builder builder() { + return new Builder(); + } + + public ResponsesLocation withFile(String file) { + Utils.checkNotNull(file, "file"); + this.file = file; + return this; + } + + public ResponsesLocation withRow(long row) { + Utils.checkNotNull(row, "row"); + this.row = row; + return this; + } + + public ResponsesLocation withCol(long col) { + Utils.checkNotNull(col, "col"); + this.col = col; + return this; + } + + @Override + public boolean equals(java.lang.Object o) { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + ResponsesLocation other = (ResponsesLocation) o; + return + Objects.deepEquals(this.file, other.file) && + Objects.deepEquals(this.row, other.row) && + Objects.deepEquals(this.col, other.col); + } + + @Override + public int hashCode() { + return Objects.hash( + file, + row, + col); + } + + @Override + public String toString() { + return Utils.toString(ResponsesLocation.class, + "file", file, + "row", row, + "col", col); + } + + public final static class Builder { + + private String file; + + private Long row; + + private Long col; + + private Builder() { + // force use of static builder() method + } + + public Builder file(String file) { + Utils.checkNotNull(file, "file"); + this.file = file; + return this; + } + + public Builder row(long row) { + Utils.checkNotNull(row, "row"); + this.row = row; + return this; + } + + public Builder col(long col) { + Utils.checkNotNull(col, "col"); + this.col = col; + return this; + } + + public ResponsesLocation build() { + return new ResponsesLocation( + file, + row, + col); + } + } +} + diff --git a/src/main/java/com/styra/opa/openapi/models/shared/Result.java b/src/main/java/com/styra/opa/openapi/models/shared/Result.java index ade1fdd8..955a0f2a 100644 --- a/src/main/java/com/styra/opa/openapi/models/shared/Result.java +++ b/src/main/java/com/styra/opa/openapi/models/shared/Result.java @@ -13,6 +13,8 @@ import com.styra.opa.openapi.utils.Utils.JsonShape; import com.styra.opa.openapi.utils.Utils.TypeReferenceWithShape; import com.styra.opa.openapi.utils.Utils; +import java.lang.Boolean; +import java.lang.Double; import java.lang.Object; import java.lang.Override; import java.lang.String; @@ -107,11 +109,11 @@ public static final class _Deserializer extends OneOfDeserializer { public _Deserializer() { super(Result.class, false, - TypeReferenceWithShape.of(new TypeReference>() {}, JsonShape.DEFAULT), - TypeReferenceWithShape.of(new TypeReference>() {}, JsonShape.DEFAULT), - TypeReferenceWithShape.of(new TypeReference() {}, JsonShape.DEFAULT), - TypeReferenceWithShape.of(new TypeReference() {}, JsonShape.DEFAULT), - TypeReferenceWithShape.of(new TypeReference() {}, JsonShape.DEFAULT)); + TypeReferenceWithShape.of(new TypeReference>() {}, JsonShape.DEFAULT), + TypeReferenceWithShape.of(new TypeReference>() {}, JsonShape.DEFAULT), + TypeReferenceWithShape.of(new TypeReference() {}, JsonShape.DEFAULT), + TypeReferenceWithShape.of(new TypeReference() {}, JsonShape.DEFAULT), + TypeReferenceWithShape.of(new TypeReference() {}, JsonShape.DEFAULT)); } } diff --git a/src/main/java/com/styra/opa/openapi/models/shared/ServerError.java b/src/main/java/com/styra/opa/openapi/models/shared/ServerError.java new file mode 100644 index 00000000..79c9138d --- /dev/null +++ b/src/main/java/com/styra/opa/openapi/models/shared/ServerError.java @@ -0,0 +1,214 @@ +/* + * Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT. + */ + +package com.styra.opa.openapi.models.shared; + + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonIgnore; +import com.fasterxml.jackson.annotation.JsonInclude.Include; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.styra.opa.openapi.utils.Utils; +import java.lang.Override; +import java.lang.String; +import java.lang.SuppressWarnings; +import java.util.List; +import java.util.Objects; +import java.util.Optional; + + +public class ServerError { + + @JsonProperty("code") + private String code; + + @JsonProperty("message") + private String message; + + @JsonInclude(Include.NON_ABSENT) + @JsonProperty("errors") + private Optional> errors; + + @JsonInclude(Include.NON_ABSENT) + @JsonProperty("decision_id") + private Optional decisionId; + + @JsonCreator + public ServerError( + @JsonProperty("code") String code, + @JsonProperty("message") String message, + @JsonProperty("errors") Optional> errors, + @JsonProperty("decision_id") Optional decisionId) { + Utils.checkNotNull(code, "code"); + Utils.checkNotNull(message, "message"); + Utils.checkNotNull(errors, "errors"); + Utils.checkNotNull(decisionId, "decisionId"); + this.code = code; + this.message = message; + this.errors = errors; + this.decisionId = decisionId; + } + + public ServerError( + String code, + String message) { + this(code, message, Optional.empty(), Optional.empty()); + } + + @JsonIgnore + public String code() { + return code; + } + + @JsonIgnore + public String message() { + return message; + } + + @SuppressWarnings("unchecked") + @JsonIgnore + public Optional> errors() { + return (Optional>) errors; + } + + @JsonIgnore + public Optional decisionId() { + return decisionId; + } + + public final static Builder builder() { + return new Builder(); + } + + public ServerError withCode(String code) { + Utils.checkNotNull(code, "code"); + this.code = code; + return this; + } + + public ServerError withMessage(String message) { + Utils.checkNotNull(message, "message"); + this.message = message; + return this; + } + + public ServerError withErrors(List errors) { + Utils.checkNotNull(errors, "errors"); + this.errors = Optional.ofNullable(errors); + return this; + } + + public ServerError withErrors(Optional> errors) { + Utils.checkNotNull(errors, "errors"); + this.errors = errors; + return this; + } + + public ServerError withDecisionId(String decisionId) { + Utils.checkNotNull(decisionId, "decisionId"); + this.decisionId = Optional.ofNullable(decisionId); + return this; + } + + public ServerError withDecisionId(Optional decisionId) { + Utils.checkNotNull(decisionId, "decisionId"); + this.decisionId = decisionId; + return this; + } + + @Override + public boolean equals(java.lang.Object o) { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + ServerError other = (ServerError) o; + return + Objects.deepEquals(this.code, other.code) && + Objects.deepEquals(this.message, other.message) && + Objects.deepEquals(this.errors, other.errors) && + Objects.deepEquals(this.decisionId, other.decisionId); + } + + @Override + public int hashCode() { + return Objects.hash( + code, + message, + errors, + decisionId); + } + + @Override + public String toString() { + return Utils.toString(ServerError.class, + "code", code, + "message", message, + "errors", errors, + "decisionId", decisionId); + } + + public final static class Builder { + + private String code; + + private String message; + + private Optional> errors = Optional.empty(); + + private Optional decisionId = Optional.empty(); + + private Builder() { + // force use of static builder() method + } + + public Builder code(String code) { + Utils.checkNotNull(code, "code"); + this.code = code; + return this; + } + + public Builder message(String message) { + Utils.checkNotNull(message, "message"); + this.message = message; + return this; + } + + public Builder errors(List errors) { + Utils.checkNotNull(errors, "errors"); + this.errors = Optional.ofNullable(errors); + return this; + } + + public Builder errors(Optional> errors) { + Utils.checkNotNull(errors, "errors"); + this.errors = errors; + return this; + } + + public Builder decisionId(String decisionId) { + Utils.checkNotNull(decisionId, "decisionId"); + this.decisionId = Optional.ofNullable(decisionId); + return this; + } + + public Builder decisionId(Optional decisionId) { + Utils.checkNotNull(decisionId, "decisionId"); + this.decisionId = decisionId; + return this; + } + + public ServerError build() { + return new ServerError( + code, + message, + errors, + decisionId); + } + } +} + diff --git a/src/main/java/com/styra/opa/openapi/models/shared/ServerErrorWithStatusCode.java b/src/main/java/com/styra/opa/openapi/models/shared/ServerErrorWithStatusCode.java index 0b284041..46a66bc7 100644 --- a/src/main/java/com/styra/opa/openapi/models/shared/ServerErrorWithStatusCode.java +++ b/src/main/java/com/styra/opa/openapi/models/shared/ServerErrorWithStatusCode.java @@ -33,7 +33,7 @@ public class ServerErrorWithStatusCode implements Responses { @JsonInclude(Include.NON_ABSENT) @JsonProperty("errors") - private Optional> errors; + private Optional> errors; @JsonInclude(Include.NON_ABSENT) @JsonProperty("decision_id") @@ -44,7 +44,7 @@ public ServerErrorWithStatusCode( @JsonProperty("http_status_code") Optional httpStatusCode, @JsonProperty("code") String code, @JsonProperty("message") String message, - @JsonProperty("errors") Optional> errors, + @JsonProperty("errors") Optional> errors, @JsonProperty("decision_id") Optional decisionId) { Utils.checkNotNull(httpStatusCode, "httpStatusCode"); Utils.checkNotNull(code, "code"); @@ -82,8 +82,8 @@ public String message() { @SuppressWarnings("unchecked") @JsonIgnore - public Optional> errors() { - return (Optional>) errors; + public Optional> errors() { + return (Optional>) errors; } @JsonIgnore @@ -119,13 +119,13 @@ public ServerErrorWithStatusCode withMessage(String message) { return this; } - public ServerErrorWithStatusCode withErrors(List errors) { + public ServerErrorWithStatusCode withErrors(List errors) { Utils.checkNotNull(errors, "errors"); this.errors = Optional.ofNullable(errors); return this; } - public ServerErrorWithStatusCode withErrors(Optional> errors) { + public ServerErrorWithStatusCode withErrors(Optional> errors) { Utils.checkNotNull(errors, "errors"); this.errors = errors; return this; @@ -188,7 +188,7 @@ public final static class Builder { private String message; - private Optional> errors = Optional.empty(); + private Optional> errors = Optional.empty(); private Optional decisionId = Optional.empty(); @@ -220,13 +220,13 @@ public Builder message(String message) { return this; } - public Builder errors(List errors) { + public Builder errors(List errors) { Utils.checkNotNull(errors, "errors"); this.errors = Optional.ofNullable(errors); return this; } - public Builder errors(Optional> errors) { + public Builder errors(Optional> errors) { Utils.checkNotNull(errors, "errors"); this.errors = errors; return this; diff --git a/src/main/java/com/styra/opa/openapi/models/shared/SuccessfulPolicyResponse.java b/src/main/java/com/styra/opa/openapi/models/shared/SuccessfulPolicyResponse.java index 6537dc26..bd9e4ba2 100644 --- a/src/main/java/com/styra/opa/openapi/models/shared/SuccessfulPolicyResponse.java +++ b/src/main/java/com/styra/opa/openapi/models/shared/SuccessfulPolicyResponse.java @@ -19,6 +19,11 @@ import java.util.Objects; import java.util.Optional; +/** + * SuccessfulPolicyResponse - Success. + * The server also returns 200 if the path refers to an undefined document. In this case, the response will not contain a result property. + * + */ public class SuccessfulPolicyResponse { diff --git a/src/main/java/com/styra/opa/openapi/utils/OneOfDeserializer.java b/src/main/java/com/styra/opa/openapi/utils/OneOfDeserializer.java index 50c439a2..2794515c 100644 --- a/src/main/java/com/styra/opa/openapi/utils/OneOfDeserializer.java +++ b/src/main/java/com/styra/opa/openapi/utils/OneOfDeserializer.java @@ -35,7 +35,7 @@ public class OneOfDeserializer extends StdDeserializer { private static final long serialVersionUID = -1; - private final List typeReferences; // oneOf subschemas + private final transient List typeReferences; // oneOf subschemas private final Class cls; private final boolean strict; private final ObjectMapper mapper; diff --git a/src/main/java/com/styra/opa/openapi/utils/Options.java b/src/main/java/com/styra/opa/openapi/utils/Options.java index 2ee3503b..e6489df7 100644 --- a/src/main/java/com/styra/opa/openapi/utils/Options.java +++ b/src/main/java/com/styra/opa/openapi/utils/Options.java @@ -13,14 +13,14 @@ public enum Option { RETRY_CONFIG; } - private Optional retryConfig = Optional.empty(); + private Optional retryConfig = Optional.empty(); - private Options(Optional retryConfig) { + private Options(Optional retryConfig) { Utils.checkNotNull(retryConfig, "retryConfig"); this.retryConfig = retryConfig; } - public Optional retryConfig() { + public Optional retryConfig() { return retryConfig; } @@ -36,17 +36,17 @@ public final static Builder builder() { public final static class Builder { - private Optional retryConfig = Optional.empty(); + private Optional retryConfig = Optional.empty(); private Builder() {} - public Builder retryConfig(com.styra.opa.openapi.utils.RetryConfig retryConfig) throws IllegalArgumentException { + public Builder retryConfig(RetryConfig retryConfig) throws IllegalArgumentException { Utils.checkNotNull(retryConfig, "retryConfig"); this.retryConfig = Optional.of(retryConfig); return this; } - public Builder retryConfig(Optional retryConfig) throws IllegalArgumentException { + public Builder retryConfig(Optional retryConfig) throws IllegalArgumentException { Utils.checkNotNull(retryConfig, "retryConfig"); this.retryConfig = retryConfig; return this; diff --git a/src/main/java/com/styra/opa/openapi/utils/QueryParameters.java b/src/main/java/com/styra/opa/openapi/utils/QueryParameters.java index 95751667..09d271b2 100644 --- a/src/main/java/com/styra/opa/openapi/utils/QueryParameters.java +++ b/src/main/java/com/styra/opa/openapi/utils/QueryParameters.java @@ -61,6 +61,8 @@ public static List parseQueryParams(Class t List pipeDelimitedParams = parseDelimitedParams(queryParamsMetadata, value, "|"); allParams.addAll(pipeDelimitedParams); break; + default: + break; } } } @@ -71,16 +73,15 @@ public static List parseQueryParams(Class t private static List parseSerializedParams(QueryParamsMetadata queryParamsMetadata, Object value) throws JsonProcessingException { List params = new ArrayList<>(); - switch (queryParamsMetadata.serialization) { case "json": ObjectMapper mapper = JSON.getMapper(); String json = mapper.writeValueAsString(value); - params.add(new BasicNameValuePair(queryParamsMetadata.name, json)); break; + default: + break; } - return params; } diff --git a/src/main/java/com/styra/opa/openapi/utils/Security.java b/src/main/java/com/styra/opa/openapi/utils/Security.java index f8171219..e61028fb 100644 --- a/src/main/java/com/styra/opa/openapi/utils/Security.java +++ b/src/main/java/com/styra/opa/openapi/utils/Security.java @@ -5,6 +5,7 @@ package com.styra.opa.openapi.utils; import java.lang.reflect.Field; +import java.nio.charset.StandardCharsets; import java.util.Base64; public final class Security { @@ -122,7 +123,9 @@ private static void parseSecuritySchemeValue(HTTPRequest request, SecurityMetada request.addHeader(securityMetadata.name, Utils.prefixBearer(Utils.valToString(value))); break; case "oauth2": - request.addHeader(securityMetadata.name, Utils.prefixBearer(Utils.valToString(value))); + if (!"client_credentials".equals(schemeMetadata.subtype)) { + request.addHeader(securityMetadata.name, Utils.prefixBearer(Utils.valToString(value))); + } break; case "http": switch (schemeMetadata.subtype) { @@ -171,6 +174,9 @@ private static void parseBasicAuthScheme(HTTPRequest requestBuilder, Object sche } requestBuilder.addHeader("Authorization", - "Basic " + Base64.getEncoder().encodeToString(String.format("%s:%s", username, password).getBytes())); + "Basic " + + Base64.getEncoder() + .encodeToString(String.format("%s:%s", username, password) + .getBytes(StandardCharsets.UTF_8))); } } \ No newline at end of file diff --git a/src/main/java/com/styra/opa/openapi/utils/TypedObject.java b/src/main/java/com/styra/opa/openapi/utils/TypedObject.java index f56061bd..b18a23dd 100644 --- a/src/main/java/com/styra/opa/openapi/utils/TypedObject.java +++ b/src/main/java/com/styra/opa/openapi/utils/TypedObject.java @@ -37,7 +37,12 @@ public TypeReference typeReference() { public JsonShape shape() { return shape; } - + + @Override + public String toString() { + return String.valueOf(value); + } + public static TypedObject of(T value, JsonShape shape, TypeReference typeReference) { return new TypedObject(value, shape, typeReference); } diff --git a/src/main/java/com/styra/opa/openapi/utils/Utils.java b/src/main/java/com/styra/opa/openapi/utils/Utils.java index a8cd34b9..1057804a 100644 --- a/src/main/java/com/styra/opa/openapi/utils/Utils.java +++ b/src/main/java/com/styra/opa/openapi/utils/Utils.java @@ -4,36 +4,44 @@ package com.styra.opa.openapi.utils; -import java.io.InputStream; import java.io.ByteArrayInputStream; +import java.io.File; import java.io.IOException; +import java.io.InputStream; +import java.io.UncheckedIOException; import java.lang.reflect.Field; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import java.math.BigDecimal; import java.math.BigInteger; import java.net.URI; +import java.net.URISyntaxException; import java.net.URLEncoder; import java.net.http.HttpClient.Version; import java.net.http.HttpHeaders; import java.net.http.HttpRequest; import java.net.http.HttpResponse; import java.nio.charset.StandardCharsets; +import java.nio.file.Files; +import java.nio.file.Paths; +import java.nio.file.StandardOpenOption; import java.time.LocalDate; import java.time.OffsetDateTime; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; -import java.util.concurrent.Callable; -import java.util.function.BiPredicate; import java.util.HashMap; import java.util.Iterator; +import java.util.LinkedHashMap; import java.util.List; import java.util.Locale; import java.util.Map; import java.util.Map.Entry; import java.util.NoSuchElementException; import java.util.Optional; +import java.util.UUID; +import java.util.concurrent.Callable; +import java.util.function.BiPredicate; import java.util.regex.Matcher; import java.util.regex.Pattern; import java.util.stream.Collectors; @@ -44,7 +52,6 @@ import org.apache.commons.io.IOUtils; import org.apache.http.NameValuePair; - import org.openapitools.jackson.nullable.JsonNullable; import com.fasterxml.jackson.core.JsonProcessingException; @@ -137,7 +144,7 @@ public static String generateURL(Class type, String baseURL, String path, pathParams.put(pathParamsMetadata.name, String.join(",", - array.stream().map(v -> Utils.valToString(v)) + array.stream().map(v -> valToString(v)) .collect(Collectors.toList()))); break; case MAP: @@ -149,17 +156,17 @@ public static String generateURL(Class type, String baseURL, String path, pathParams.put(pathParamsMetadata.name, String.join(",", map.entrySet().stream().map(e -> { if (pathParamsMetadata.explode) { - return String.format("%s=%s", Utils.valToString(e.getKey()), - Utils.valToString(e.getValue())); + return String.format("%s=%s", valToString(e.getKey()), + valToString(e.getValue())); } else { - return String.format("%s,%s", Utils.valToString(e.getKey()), - Utils.valToString(e.getValue())); + return String.format("%s,%s", valToString(e.getKey()), + valToString(e.getValue())); } }).collect(Collectors.toList()))); break; case OBJECT: if (!allowIntrospection(value.getClass())) { - pathParams.put(pathParamsMetadata.name, Utils.valToString(value)); + pathParams.put(pathParamsMetadata.name, valToString(value)); break; } List values = new ArrayList<>(); @@ -180,17 +187,17 @@ public static String generateURL(Class type, String baseURL, String path, if (pathParamsMetadata.explode) { values.add(String.format("%s=%s", valuePathParamsMetadata.name, - Utils.valToString(val))); + valToString(val))); } else { values.add(String.format("%s,%s", valuePathParamsMetadata.name, - Utils.valToString(val))); + valToString(val))); } } pathParams.put(pathParamsMetadata.name, String.join(",", values)); break; default: - pathParams.put(pathParamsMetadata.name, Utils.valToString(value)); + pathParams.put(pathParamsMetadata.name, valToString(value)); break; } } @@ -287,7 +294,7 @@ public static String templateUrl(String url, Map params) { String key = match.substring(1, match.length() - 1); String value = params.get(key); if (value != null) { - m.appendReplacement(sb, value); + m.appendReplacement(sb, URLEncoder.encode(value, StandardCharsets.UTF_8)); } } m.appendTail(sb); @@ -344,10 +351,10 @@ public static Map> getHeadersFromMetadata(Object headers, M if (headerMetadata.explode) { items.add( String.format("%s=%s", valueHeaderMetadata.name, - Utils.valToString(valueFieldValue))); + valToString(valueFieldValue))); } else { items.add(valueHeaderMetadata.name); - items.add(Utils.valToString(valueFieldValue)); + items.add(valToString(valueFieldValue)); } } @@ -370,11 +377,11 @@ public static Map> getHeadersFromMetadata(Object headers, M for (Map.Entry entry : map.entrySet()) { if (headerMetadata.explode) { - items.add(String.format("%s=%s", Utils.valToString(entry.getKey()), - Utils.valToString(entry.getValue()))); + items.add(String.format("%s=%s", valToString(entry.getKey()), + valToString(entry.getValue()))); } else { - items.add(Utils.valToString(entry.getKey())); - items.add(Utils.valToString(entry.getValue())); + items.add(valToString(entry.getKey())); + items.add(valToString(entry.getValue())); } } @@ -397,7 +404,7 @@ public static Map> getHeadersFromMetadata(Object headers, M List items = new ArrayList<>(); for (Object item : array) { - items.add(Utils.valToString(item)); + items.add(valToString(item)); } if (!result.containsKey(headerMetadata.name)) { @@ -415,7 +422,7 @@ public static Map> getHeadersFromMetadata(Object headers, M } List values = result.get(headerMetadata.name); - values.add(Utils.valToString(value)); + values.add(valToString(value)); break; } } @@ -425,17 +432,16 @@ public static Map> getHeadersFromMetadata(Object headers, M } public static String valToString(Object value) { - switch (Types.getType(value.getClass())) { - case ENUM: - try { - Field field = value.getClass().getDeclaredField("value"); - field.setAccessible(true); - return String.valueOf(field.get(value)); - } catch (Exception e) { - return "ERROR_UNKNOWN_VALUE"; - } - default: - return String.valueOf(resolveOptionals(value)); + if (value.getClass().isEnum()) { + try { + Field field = value.getClass().getDeclaredField("value"); + field.setAccessible(true); + return String.valueOf(field.get(value)); + } catch (IllegalArgumentException | IllegalAccessException | NoSuchFieldException | SecurityException e) { + return "ERROR_UNKNOWN_VALUE"; + } + } else { + return String.valueOf(resolveOptionals(value)); } } @@ -464,16 +470,15 @@ public static Object populateGlobal(Object value, String fieldName, String param private static Map parseSerializedParams(PathParamsMetadata pathParamsMetadata, Object value) throws JsonProcessingException { Map params = new HashMap<>(); - switch (pathParamsMetadata.serialization) { case "json": ObjectMapper mapper = JSON.getMapper(); String json = mapper.writeValueAsString(value); - - params.put(pathParamsMetadata.name, URLEncoder.encode(json, StandardCharsets.UTF_8)); + params.put(pathParamsMetadata.name, json); + break; + default: break; } - return params; } @@ -961,7 +966,7 @@ public static final class HttpResponseCached implements HttpResponse response) throws IOException { this.response = response; - this.bytes = Utils.toByteArrayAndClose(response.body()); + this.bytes = toByteArrayAndClose(response.body()); } public String bodyAsUtf8() { @@ -1050,4 +1055,130 @@ public static String discriminatorToString(Object o) { return (String) o; } } + + public static void recordTest(String id) { + try { + new File("build").mkdir(); + Files.writeString(Paths.get("build/test-javav2-record.txt"), id + "\n", StandardOpenOption.CREATE, + StandardOpenOption.APPEND); + } catch (IOException e) { + throw new UncheckedIOException(e); + } + } + + /** + * Returns an equivalent url with query parameters sorted by name. Sort is + * stable in that parameters with the same name will not be reordered. + * + * @param url input + * @return url with query parameters sorted by name + */ + public static String sortQueryParameters(String url) { + if (url == null || url.isBlank()) { + return ""; + } + String[] parts = url.split("\\?"); + if (parts.length == 1) { + return url; + } + String query = parts[1]; + String[] params = query.split("&"); + sortByDelimitedKey(params, "="); + return parts[0] + "?" + Arrays.stream(params).collect(Collectors.joining("&")); + } + + public static Object sortSerializedMaps(Object input, String regex, String delim) { + if (input == null) { + return input; + } else if (input instanceof String) { + return sortMapString((String) input, regex, delim); + } else if (input.getClass().isArray()) { + Object[] a = (Object[]) input; + String[] b = new String[a.length]; + for (int i = 0; i < a.length; i++) { + if (!(a[i] instanceof String)) { + throw new IllegalArgumentException("expected array item type of String, found " + a[i]); + } + b[i] = sortMapString((String) a[i], regex, delim); + } + return b; + } else if (input instanceof Map) { + @SuppressWarnings("unchecked") + Map a = (Map) input; + Map b = new LinkedHashMap<>(); + for (Entry entry: a.entrySet()) { + if (!(entry.getKey() instanceof String)) { + throw new IllegalArgumentException("expected map key type of String, found " + entry.getKey()); + } + if (!(entry.getValue() instanceof String)) { + throw new IllegalArgumentException("expected map value type of String, found " + entry.getValue()); + } + b.put((String) entry.getKey(), sortMapString((String) entry.getValue(), regex, delim)); + } + return b; + } else { + throw new IllegalArgumentException("unexpected type: " + input.getClass()); + } + } + + private static String sortMapString(String input, String regex, String delim) { + return Pattern.compile(regex).matcher(input).replaceAll(m -> { + String escapedDelim = Pattern.quote(delim); + String result = m.group(); + for (int i = 1; i <= m.groupCount(); i++) { + final String match = m.group(i); + String[] pairs; + if (match.contains("=")) { + pairs = match.split(escapedDelim); + sortByDelimitedKey(pairs, "="); + } else { + String[] values = match.split(escapedDelim); + if (values.length == 1) { + pairs = values; + } else { + pairs = new String[values.length / 2]; + for (int j = 0; j < values.length; j += 2) { + pairs[j / 2] = values[j] + delim + values[j + 1]; + } + } + sortByDelimitedKey(pairs, delim); + } + String joined = Arrays.stream(pairs).collect(Collectors.joining(delim)); + result = result.replace(m.group(i), joined); + } + return result; + }); + } + + private static void sortByDelimitedKey(String[] array, String delim) { + Arrays.sort(array, (a, b) -> { + String escapedDelim = Pattern.quote(delim); + String aKey = a.split(escapedDelim)[0]; + String bKey = b.split(escapedDelim)[0]; + return aKey.compareTo(bKey); + }); + } + + public static boolean isPresentAndNotNull(Optional x) { + return x.isPresent(); + } + + public static boolean isPresentAndNotNull(JsonNullable x) { + return x.isPresent() && x.get() != null; + } + + private static final String OPEN_BRACKET_MARKER = UUID.randomUUID().toString().replace("-", ""); + private static final String CLOSE_BRACKET_MARKER = UUID.randomUUID().toString().replace("-", ""); + + public static String urlEncode(String s) { + // Ensure that complies with RFC 2732 (URLEncoder does not and we don't want to + // encode [, ] chars) + return URLEncoder.encode( // + s.replace("[", OPEN_BRACKET_MARKER) // + .replace("]", CLOSE_BRACKET_MARKER), // + StandardCharsets.UTF_8) // + .replace(OPEN_BRACKET_MARKER, "[") // + .replace(CLOSE_BRACKET_MARKER, "]"); + } + } diff --git a/src/main/java/com/styra/opa/utils/OPAHTTPClient.java b/src/main/java/com/styra/opa/utils/OPAHTTPClient.java index 5494df08..e6501916 100644 --- a/src/main/java/com/styra/opa/utils/OPAHTTPClient.java +++ b/src/main/java/com/styra/opa/utils/OPAHTTPClient.java @@ -7,6 +7,7 @@ import java.io.IOException; import java.io.InputStream; +import java.net.URI; import java.net.URISyntaxException; import java.net.http.HttpClient; import java.net.http.HttpRequest; @@ -53,7 +54,6 @@ public OPAHTTPClient() { public HttpResponse send(HttpRequest request) throws IOException, InterruptedException, URISyntaxException { - // At this point, the HTTP request has already been built, so there // is no way to add a new header, see: // @@ -62,7 +62,23 @@ public HttpResponse send(HttpRequest request) // Consequentially, we need to make a new builder and copy all of the // existing request data into it. - Builder b = HttpRequest.newBuilder(request.uri()); + // Explicitly expand path separators in the URI, as the SE SDK + // sometimes escapes them as %2F. `/` is not a legal character to appear in + // a Rego package path or rule head, so we can simply re-expand those path + // elements. + + URI oldURI = request.uri(); + URI newURI = new URI( + oldURI.getScheme(), + oldURI.getUserInfo(), + oldURI.getHost(), + oldURI.getPort(), + oldURI.getPath().replaceAll("%2F", "/"), + oldURI.getQuery(), + oldURI.getFragment() + ); + + Builder b = HttpRequest.newBuilder(newURI); b.method( request.method(), request.bodyPublisher().orElse(HttpRequest.BodyPublishers.noBody()));