diff --git a/.speakeasy/gen.lock b/.speakeasy/gen.lock index 333abfe..238fe4c 100755 --- a/.speakeasy/gen.lock +++ b/.speakeasy/gen.lock @@ -3,28 +3,29 @@ id: f1a8c321-72a7-41c5-8f5e-3d925aeafa1a management: docChecksum: 54d33facef3aa19f358d15ab44e34141 docVersion: 0.2.0 - speakeasyVersion: 1.397.2 - generationVersion: 2.415.8 - releaseVersion: 1.3.7 - configChecksum: 4b87e08fd57be3ea8915050d1a96f16b - repoURL: https://github.com/StyraInc/opa-csharp.git + speakeasyVersion: 1.441.0 + generationVersion: 2.460.1 + releaseVersion: 1.4.0 + configChecksum: 2e42be5c6bac9686dc03b50dfbc95bd0 + repoURL: https://github.com/StyraInc/opa-csharp repoSubDirectory: Styra/Opa/OpenApi/ published: true features: csharp: additionalDependencies: 0.1.0 constsAndDefaults: 0.0.1 - core: 3.9.19 + core: 3.10.5 examples: 2.81.3 - flattening: 2.81.2 + flattening: 2.81.3 globalSecurity: 2.83.6 globalSecurityCallbacks: 0.1.0 globalSecurityFlattening: 0.1.0 globalServerURLs: 2.82.3 intellisenseMarkdownSupport: 0.1.0 + methodArguments: 0.1.0 responseFormat: 0.0.4 sdkHooks: 0.1.0 - unions: 0.2.1 + unions: 0.2.2 generatedFiles: - .gitattributes - CONTRIBUTING.md @@ -42,9 +43,12 @@ generatedFiles: - Styra/Opa/OpenApi/Models/Components/Location.cs - Styra/Opa/OpenApi/Models/Components/Provenance.cs - Styra/Opa/OpenApi/Models/Components/Responses.cs + - Styra/Opa/OpenApi/Models/Components/ResponsesErrors.cs + - Styra/Opa/OpenApi/Models/Components/ResponsesLocation.cs - Styra/Opa/OpenApi/Models/Components/Result.cs - Styra/Opa/OpenApi/Models/Components/Revision.cs - Styra/Opa/OpenApi/Models/Components/Security.cs + - Styra/Opa/OpenApi/Models/Components/ServerError.cs - Styra/Opa/OpenApi/Models/Components/ServerErrorWithStatusCode.cs - Styra/Opa/OpenApi/Models/Components/SuccessfulPolicyResponse.cs - Styra/Opa/OpenApi/Models/Components/SuccessfulPolicyResponseWithStatusCode.cs @@ -90,6 +94,24 @@ generatedFiles: - USAGE.md - global.json examples: + executeBatchPolicyWithInput: + speakeasy-default-execute-batch-policy-with-input: + parameters: + path: + path: "app/rbac" + query: {} + header: {} + requestBody: + application/json: {"inputs": {"key": []}} + responses: + "200": + application/json: {"batch_decision_id": "1bef6b7d-cd13-4890-bfe1-fd2e8de32189", "responses": {"key": {"result": ""}, "key1": {"result": []}}} + "207": + application/json: {"responses": {"key": {"http_status_code": "200", "result": ""}}} + "400": + application/json: {"code": "", "message": ""} + "500": + application/json: {"responses": {}} executeDefaultPolicyWithInput: speakeasy-default-execute-default-policy-with-input: requestBody: @@ -123,7 +145,7 @@ examples: query: {} header: {} requestBody: - application/json: {"input": false} + application/json: {"input": true} responses: "200": application/json: {"result": ""} @@ -131,23 +153,5 @@ examples: application/json: {"code": "", "message": ""} "500": application/json: {"code": "", "message": "", "decision_id": "b84cf736-213c-4932-a8e4-bb5c648f1b4d"} - executeBatchPolicyWithInput: - speakeasy-default-execute-batch-policy-with-input: - parameters: - path: - path: "app/rbac" - query: {} - header: {} - requestBody: - application/json: {"inputs": {"key": []}} - responses: - "200": - application/json: {"batch_decision_id": "1bef6b7d-cd13-4890-bfe1-fd2e8de32189", "responses": {"key": {"result": {"allow": true, "user_is_admin": true, "user_is_granted": []}}, "key1": {"result": []}}} - "207": - application/json: {"responses": {"key": {"http_status_code": "200", "result": ""}}} - "400": - application/json: {"code": "", "message": ""} - "500": - application/json: {"responses": {}} health: speakeasy-default-health: {} diff --git a/.speakeasy/gen.yaml b/.speakeasy/gen.yaml index 4aa795b..8152fdf 100755 --- a/.speakeasy/gen.yaml +++ b/.speakeasy/gen.yaml @@ -11,16 +11,19 @@ generation: requestResponseComponentNamesFeb2024: true auth: oAuth2ClientCredentialsEnabled: false + oAuth2PasswordEnabled: false csharp: - version: 1.3.7 + version: 1.4.0 additionalDependencies: [] author: Styra clientServerStatusCodesAsErrors: true company: Styra + defaultErrorName: SDKException disableNamespacePascalCasingApr2024: true - dotnetVersion: net6.0 + dotnetVersion: net8.0 enableSourceLink: false flattenGlobalSecurity: true + flatteningOrder: "" imports: option: openapi paths: @@ -32,8 +35,10 @@ csharp: includeDebugSymbols: false inputModelSuffix: input maxMethodParams: 4 + methodArguments: infer-optional-args outputModelSuffix: output packageName: Styra.Opa.OpenApi packageTags: "" product: "" responseFormat: envelope + sourceDirectory: "" diff --git a/.speakeasy/workflow.yaml b/.speakeasy/workflow.yaml index 3eca8a7..757c63e 100644 --- a/.speakeasy/workflow.yaml +++ b/.speakeasy/workflow.yaml @@ -1,15 +1,19 @@ workflowVersion: 1.0.0 speakeasyVersion: latest sources: - openapi: - inputs: - - location: https://raw.githubusercontent.com/StyraInc/enterprise-opa/main/openapi/openapi.yaml - registry: - location: registry.speakeasyapi.dev/styra/styra/openapi + openapi: + inputs: + - location: https://raw.githubusercontent.com/StyraInc/enterprise-opa/main/openapi/openapi.yaml + registry: + location: registry.speakeasyapi.dev/styra/styra/openapi targets: - first-target: - target: csharp - source: openapi - publish: - nuget: - apiKey: $nuget_api_key + first-target: + target: csharp + source: openapi + publish: + nuget: + apiKey: $nuget_api_key + codeSamples: + registry: + location: registry.speakeasyapi.dev/styra/styra/openapi-code-samples + blocking: false diff --git a/NUGET.md b/NUGET.md index 868e683..59d3840 100644 --- a/NUGET.md +++ b/NUGET.md @@ -16,7 +16,7 @@ var sdk = new OpaApiClient(bearerAuth: ""); var res = await sdk.ExecuteDefaultPolicyWithInputAsync( input: Input.CreateNumber( - 8203.11D + 4963.69D ), pretty: false, acceptEncoding: Styra.Opa.OpenApi.Models.Components.GzipAcceptEncoding.Gzip @@ -79,13 +79,24 @@ var res = await sdk.ExecuteBatchPolicyWithInputAsync(req); ## Error Handling -Handling errors in this SDK should largely match your expectations. All operations return a response object or thow an exception. If Error objects are specified in your OpenAPI Spec, the SDK will raise the appropriate type. +Handling errors in this SDK should largely match your expectations. All operations return a response object or throw an exception. -| Error Object | Status Code | Content Type | -| -------------------------------------------- | -------------------------------------------- | -------------------------------------------- | -| Styra.Opa.OpenApi.Models.Errors.ClientError | 400,404 | application/json | -| Styra.Opa.OpenApi.Models.Errors.ServerError | 500 | application/json | -| Styra.Opa.OpenApi.Models.Errors.SDKException | 4xx-5xx | */* | +By default, an API error will raise a `Styra.Opa.OpenApi.Models.Errors.SDKException` exception, which has the following properties: + +| Property | Type | Description | +|---------------|-----------------------|-----------------------| +| `Message` | *string* | The error message | +| `StatusCode` | *int* | The HTTP status code | +| `RawResponse` | *HttpResponseMessage* | The raw HTTP response | +| `Body` | *string* | The response content | + +When custom error responses are specified for an operation, the SDK may also throw their associated exceptions. You can refer to respective *Errors* tables in SDK docs for more details on possible exception types for each operation. For example, the `ExecuteDefaultPolicyWithInputAsync` method throws the following exceptions: + +| Error Type | Status Code | Content Type | +| -------------------------------------------- | ----------- | ---------------- | +| Styra.Opa.OpenApi.Models.Errors.ClientError | 400, 404 | application/json | +| Styra.Opa.OpenApi.Models.Errors.ServerError | 500 | application/json | +| Styra.Opa.OpenApi.Models.Errors.SDKException | 4XX, 5XX | \*/\* | ### Example @@ -103,7 +114,7 @@ try { var res = await sdk.ExecuteDefaultPolicyWithInputAsync( input: Input.CreateNumber( - 8203.11D + 4963.69D ), pretty: false, acceptEncoding: Styra.Opa.OpenApi.Models.Components.GzipAcceptEncoding.Gzip @@ -115,15 +126,18 @@ catch (Exception ex) { if (ex is ClientError) { - // handle exception + // Handle exception data + throw; } - else if (ex is ServerError) + else if (ex is Models.Errors.ServerError) { - // handle exception + // Handle exception data + throw; } else if (ex is Styra.Opa.OpenApi.Models.Errors.SDKException) { - // handle exception + // Handle default exception + throw; } } ``` @@ -132,20 +146,30 @@ catch (Exception ex) ## Server Selection -### Select Server by Index - -You can override the default server globally by passing a server index to the `serverIndex: number` optional parameter when initializing the SDK client instance. The selected server will then be used as the default on the operations that use it. This table lists the indexes associated with the available servers: - -| # | Server | Variables | -| - | ------ | --------- | -| 0 | `http://localhost:8181` | None | - +### Override Server URL Per-Client +The default server can also be overridden globally by passing a URL to the `serverUrl: string` optional parameter when initializing the SDK client instance. For example: +```csharp +using Styra.Opa.OpenApi; +using Styra.Opa.OpenApi.Models.Requests; +using Styra.Opa.OpenApi.Models.Components; +using System.Collections.Generic; +var sdk = new OpaApiClient( + serverUrl: "http://localhost:8181", + bearerAuth: "" +); -### Override Server URL Per-Client +var res = await sdk.ExecuteDefaultPolicyWithInputAsync( + input: Input.CreateNumber( + 4963.69D + ), + pretty: false, + acceptEncoding: Styra.Opa.OpenApi.Models.Components.GzipAcceptEncoding.Gzip +); -The default server can also be overridden globally by passing a URL to the `serverUrl: str` optional parameter when initializing the SDK client instance. For example: +// handle response +``` @@ -155,9 +179,9 @@ The default server can also be overridden globally by passing a URL to the `serv This SDK supports the following security scheme globally: -| Name | Type | Scheme | -| ------------ | ------------ | ------------ | -| `BearerAuth` | http | HTTP Bearer | +| Name | Type | Scheme | +| ------------ | ---- | ----------- | +| `BearerAuth` | http | HTTP Bearer | To authenticate with the API the `BearerAuth` parameter must be set when initializing the SDK client instance. For example: ```csharp @@ -170,7 +194,7 @@ var sdk = new OpaApiClient(bearerAuth: ""); var res = await sdk.ExecuteDefaultPolicyWithInputAsync( input: Input.CreateNumber( - 8203.11D + 4963.69D ), pretty: false, acceptEncoding: Styra.Opa.OpenApi.Models.Components.GzipAcceptEncoding.Gzip diff --git a/README.md b/README.md index 6d329d6..88465fb 100644 --- a/README.md +++ b/README.md @@ -158,7 +158,7 @@ var sdk = new OpaApiClient(bearerAuth: ""); var res = await sdk.ExecuteDefaultPolicyWithInputAsync( input: Input.CreateNumber( - 8203.11D + 4963.69D ), pretty: false, acceptEncoding: Styra.Opa.OpenApi.Models.Components.GzipAcceptEncoding.Gzip @@ -238,32 +238,53 @@ var res = await sdk.ExecuteBatchPolicyWithInputAsync(req); ## Server Selection -### Select Server by Index - -You can override the default server globally by passing a server index to the `serverIndex: number` optional parameter when initializing the SDK client instance. The selected server will then be used as the default on the operations that use it. This table lists the indexes associated with the available servers: - -| # | Server | Variables | -| - | ------ | --------- | -| 0 | `http://localhost:8181` | None | - +### Override Server URL Per-Client +The default server can also be overridden globally by passing a URL to the `serverUrl: string` optional parameter when initializing the SDK client instance. For example: +```csharp +using Styra.Opa.OpenApi; +using Styra.Opa.OpenApi.Models.Requests; +using Styra.Opa.OpenApi.Models.Components; +using System.Collections.Generic; +var sdk = new OpaApiClient( + serverUrl: "http://localhost:8181", + bearerAuth: "" +); -### Override Server URL Per-Client +var res = await sdk.ExecuteDefaultPolicyWithInputAsync( + input: Input.CreateNumber( + 4963.69D + ), + pretty: false, + acceptEncoding: Styra.Opa.OpenApi.Models.Components.GzipAcceptEncoding.Gzip +); -The default server can also be overridden globally by passing a URL to the `serverUrl: str` optional parameter when initializing the SDK client instance. For example: +// handle response +``` ## Error Handling -Handling errors in this SDK should largely match your expectations. All operations return a response object or thow an exception. If Error objects are specified in your OpenAPI Spec, the SDK will raise the appropriate type. +Handling errors in this SDK should largely match your expectations. All operations return a response object or throw an exception. + +By default, an API error will raise a `Styra.Opa.OpenApi.Models.Errors.SDKException` exception, which has the following properties: + +| Property | Type | Description | +|---------------|-----------------------|-----------------------| +| `Message` | *string* | The error message | +| `StatusCode` | *int* | The HTTP status code | +| `RawResponse` | *HttpResponseMessage* | The raw HTTP response | +| `Body` | *string* | The response content | + +When custom error responses are specified for an operation, the SDK may also throw their associated exceptions. You can refer to respective *Errors* tables in SDK docs for more details on possible exception types for each operation. For example, the `ExecuteDefaultPolicyWithInputAsync` method throws the following exceptions: -| Error Object | Status Code | Content Type | -| -------------------------------------------- | -------------------------------------------- | -------------------------------------------- | -| Styra.Opa.OpenApi.Models.Errors.ClientError | 400,404 | application/json | -| Styra.Opa.OpenApi.Models.Errors.ServerError | 500 | application/json | -| Styra.Opa.OpenApi.Models.Errors.SDKException | 4xx-5xx | */* | +| Error Type | Status Code | Content Type | +| -------------------------------------------- | ----------- | ---------------- | +| Styra.Opa.OpenApi.Models.Errors.ClientError | 400, 404 | application/json | +| Styra.Opa.OpenApi.Models.Errors.ServerError | 500 | application/json | +| Styra.Opa.OpenApi.Models.Errors.SDKException | 4XX, 5XX | \*/\* | ### Example @@ -281,7 +302,7 @@ try { var res = await sdk.ExecuteDefaultPolicyWithInputAsync( input: Input.CreateNumber( - 8203.11D + 4963.69D ), pretty: false, acceptEncoding: Styra.Opa.OpenApi.Models.Components.GzipAcceptEncoding.Gzip @@ -293,15 +314,18 @@ catch (Exception ex) { if (ex is ClientError) { - // handle exception + // Handle exception data + throw; } - else if (ex is ServerError) + else if (ex is Models.Errors.ServerError) { - // handle exception + // Handle exception data + throw; } else if (ex is Styra.Opa.OpenApi.Models.Errors.SDKException) { - // handle exception + // Handle default exception + throw; } } ``` @@ -314,9 +338,9 @@ catch (Exception ex) This SDK supports the following security scheme globally: -| Name | Type | Scheme | -| ------------ | ------------ | ------------ | -| `BearerAuth` | http | HTTP Bearer | +| Name | Type | Scheme | +| ------------ | ---- | ----------- | +| `BearerAuth` | http | HTTP Bearer | To authenticate with the API the `BearerAuth` parameter must be set when initializing the SDK client instance. For example: ```csharp @@ -329,7 +353,7 @@ var sdk = new OpaApiClient(bearerAuth: ""); var res = await sdk.ExecuteDefaultPolicyWithInputAsync( input: Input.CreateNumber( - 8203.11D + 4963.69D ), pretty: false, acceptEncoding: Styra.Opa.OpenApi.Models.Components.GzipAcceptEncoding.Gzip diff --git a/Styra/Opa/OpaBatchTypes.cs b/Styra/Opa/OpaBatchTypes.cs index 9b10cc6..722fe8f 100644 --- a/Styra/Opa/OpaBatchTypes.cs +++ b/Styra/Opa/OpaBatchTypes.cs @@ -72,6 +72,16 @@ public static OpaBatchErrors ToOpaBatchErrors(this Dictionary errors) + { + var opaBatchErrors = new OpaBatchErrors(); + foreach (var kvp in errors) + { + opaBatchErrors[kvp.Key] = new OpaError(kvp.Value); + } + return opaBatchErrors; + } + public static OpaBatchResults ToOpaBatchResults(this Dictionary responses) { var opaBatchResults = new OpaBatchResults(); diff --git a/Styra/Opa/OpaError.cs b/Styra/Opa/OpaError.cs index e48ee46..2683caa 100644 --- a/Styra/Opa/OpaError.cs +++ b/Styra/Opa/OpaError.cs @@ -32,6 +32,7 @@ public OpaError() { } + public OpaError(Styra.Opa.OpenApi.Models.Components.ServerErrorWithStatusCode err) { Code = err.Code; @@ -39,6 +40,14 @@ public OpaError(Styra.Opa.OpenApi.Models.Components.ServerErrorWithStatusCode er Message = err.Message; HttpStatusCode = err.HttpStatusCode; } + + public OpaError(Styra.Opa.OpenApi.Models.Components.ServerError err) + { + Code = err.Code; + DecisionId = err.DecisionId; + Message = err.Message; + } + public OpaError(Styra.Opa.OpenApi.Models.Errors.ServerError err) { Code = err.Code; diff --git a/Styra/Opa/OpenApi/Models/Components/BatchMixedResults.cs b/Styra/Opa/OpenApi/Models/Components/BatchMixedResults.cs index 8bedef2..648cb98 100644 --- a/Styra/Opa/OpenApi/Models/Components/BatchMixedResults.cs +++ b/Styra/Opa/OpenApi/Models/Components/BatchMixedResults.cs @@ -14,6 +14,9 @@ namespace Styra.Opa.OpenApi.Models.Components using Styra.Opa.OpenApi.Utils; using System.Collections.Generic; + /// + /// Mixed success and failures. + /// public class BatchMixedResults { diff --git a/Styra/Opa/OpenApi/Models/Components/BatchSuccessfulPolicyEvaluation.cs b/Styra/Opa/OpenApi/Models/Components/BatchSuccessfulPolicyEvaluation.cs index da7ab6d..5f187ca 100644 --- a/Styra/Opa/OpenApi/Models/Components/BatchSuccessfulPolicyEvaluation.cs +++ b/Styra/Opa/OpenApi/Models/Components/BatchSuccessfulPolicyEvaluation.cs @@ -14,6 +14,14 @@ namespace Styra.Opa.OpenApi.Models.Components using Styra.Opa.OpenApi.Utils; using System.Collections.Generic; + /// + /// 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/Styra/Opa/OpenApi/Models/Components/HealthyServer.cs b/Styra/Opa/OpenApi/Models/Components/HealthyServer.cs index d2795d8..b1fa1e5 100644 --- a/Styra/Opa/OpenApi/Models/Components/HealthyServer.cs +++ b/Styra/Opa/OpenApi/Models/Components/HealthyServer.cs @@ -11,6 +11,9 @@ namespace Styra.Opa.OpenApi.Models.Components { using Styra.Opa.OpenApi.Utils; + /// + /// 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/Styra/Opa/OpenApi/Models/Components/ResponsesErrors.cs b/Styra/Opa/OpenApi/Models/Components/ResponsesErrors.cs new file mode 100644 index 0000000..59db1fa --- /dev/null +++ b/Styra/Opa/OpenApi/Models/Components/ResponsesErrors.cs @@ -0,0 +1,28 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by Speakeasy (https://speakeasy.com). DO NOT EDIT. +// +// Changes to this file may cause incorrect behavior and will be lost when +// the code is regenerated. +// +//------------------------------------------------------------------------------ +#nullable enable +namespace Styra.Opa.OpenApi.Models.Components +{ + using Newtonsoft.Json; + using Styra.Opa.OpenApi.Models.Components; + using Styra.Opa.OpenApi.Utils; + + public class ResponsesErrors + { + + [JsonProperty("code")] + public string Code { get; set; } = default!; + + [JsonProperty("message")] + public string Message { get; set; } = default!; + + [JsonProperty("location")] + public ResponsesLocation? Location { get; set; } + } +} \ No newline at end of file diff --git a/Styra/Opa/OpenApi/Models/Components/ResponsesLocation.cs b/Styra/Opa/OpenApi/Models/Components/ResponsesLocation.cs new file mode 100644 index 0000000..d5a9fa4 --- /dev/null +++ b/Styra/Opa/OpenApi/Models/Components/ResponsesLocation.cs @@ -0,0 +1,27 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by Speakeasy (https://speakeasy.com). DO NOT EDIT. +// +// Changes to this file may cause incorrect behavior and will be lost when +// the code is regenerated. +// +//------------------------------------------------------------------------------ +#nullable enable +namespace Styra.Opa.OpenApi.Models.Components +{ + using Newtonsoft.Json; + using Styra.Opa.OpenApi.Utils; + + public class ResponsesLocation + { + + [JsonProperty("file")] + public string File { get; set; } = default!; + + [JsonProperty("row")] + public long Row { get; set; } = default!; + + [JsonProperty("col")] + public long Col { get; set; } = default!; + } +} \ No newline at end of file diff --git a/Styra/Opa/OpenApi/Models/Components/ServerError.cs b/Styra/Opa/OpenApi/Models/Components/ServerError.cs new file mode 100644 index 0000000..049d265 --- /dev/null +++ b/Styra/Opa/OpenApi/Models/Components/ServerError.cs @@ -0,0 +1,32 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by Speakeasy (https://speakeasy.com). DO NOT EDIT. +// +// Changes to this file may cause incorrect behavior and will be lost when +// the code is regenerated. +// +//------------------------------------------------------------------------------ +#nullable enable +namespace Styra.Opa.OpenApi.Models.Components +{ + using Newtonsoft.Json; + using Styra.Opa.OpenApi.Models.Components; + using Styra.Opa.OpenApi.Utils; + using System.Collections.Generic; + + public class ServerError + { + + [JsonProperty("code")] + public string Code { get; set; } = default!; + + [JsonProperty("message")] + public string Message { get; set; } = default!; + + [JsonProperty("errors")] + public List? Errors { get; set; } + + [JsonProperty("decision_id")] + public string? DecisionId { get; set; } + } +} \ No newline at end of file diff --git a/Styra/Opa/OpenApi/Models/Components/ServerErrorWithStatusCode.cs b/Styra/Opa/OpenApi/Models/Components/ServerErrorWithStatusCode.cs index a2018e6..583824c 100644 --- a/Styra/Opa/OpenApi/Models/Components/ServerErrorWithStatusCode.cs +++ b/Styra/Opa/OpenApi/Models/Components/ServerErrorWithStatusCode.cs @@ -27,7 +27,7 @@ public class ServerErrorWithStatusCode public string Message { get; set; } = default!; [JsonProperty("errors")] - public List? Errors { get; set; } + public List? Errors { get; set; } [JsonProperty("decision_id")] public string? DecisionId { get; set; } diff --git a/Styra/Opa/OpenApi/Models/Components/SuccessfulPolicyResponse.cs b/Styra/Opa/OpenApi/Models/Components/SuccessfulPolicyResponse.cs index c705b12..816c98f 100644 --- a/Styra/Opa/OpenApi/Models/Components/SuccessfulPolicyResponse.cs +++ b/Styra/Opa/OpenApi/Models/Components/SuccessfulPolicyResponse.cs @@ -14,6 +14,14 @@ namespace Styra.Opa.OpenApi.Models.Components using Styra.Opa.OpenApi.Utils; using System.Collections.Generic; + /// + /// 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/Styra/Opa/OpenApi/Models/Errors/BatchServerError.cs b/Styra/Opa/OpenApi/Models/Errors/BatchServerError.cs index eb0578e..e3faaf0 100644 --- a/Styra/Opa/OpenApi/Models/Errors/BatchServerError.cs +++ b/Styra/Opa/OpenApi/Models/Errors/BatchServerError.cs @@ -10,11 +10,18 @@ namespace Styra.Opa.OpenApi.Models.Errors { using Newtonsoft.Json; - using Styra.Opa.OpenApi.Models.Errors; + using Styra.Opa.OpenApi.Models.Components; using Styra.Opa.OpenApi.Utils; using System.Collections.Generic; using System; + /// + /// Server Error. All requests returned a 500 error.
+ /// + /// + /// + /// + ///
public class BatchServerError : Exception { @@ -22,6 +29,6 @@ public class BatchServerError : Exception public string? BatchDecisionId { get; set; } [JsonProperty("responses")] - public Dictionary? Responses { get; set; } + public Dictionary? Responses { get; set; } } } \ No newline at end of file diff --git a/Styra/Opa/OpenApi/Models/Errors/UnhealthyServer.cs b/Styra/Opa/OpenApi/Models/Errors/UnhealthyServer.cs index e4181e9..31fe098 100644 --- a/Styra/Opa/OpenApi/Models/Errors/UnhealthyServer.cs +++ b/Styra/Opa/OpenApi/Models/Errors/UnhealthyServer.cs @@ -13,6 +13,9 @@ namespace Styra.Opa.OpenApi.Models.Errors using Styra.Opa.OpenApi.Utils; using System; + /// + /// 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 : Exception { diff --git a/Styra/Opa/OpenApi/OpaApiClient.cs b/Styra/Opa/OpenApi/OpaApiClient.cs index 2099b31..7112c41 100644 --- a/Styra/Opa/OpenApi/OpaApiClient.cs +++ b/Styra/Opa/OpenApi/OpaApiClient.cs @@ -103,10 +103,10 @@ public class OpaApiClient: IOpaApiClient public SDKConfig SDKConfiguration { get; private set; } private const string _language = "csharp"; - private const string _sdkVersion = "1.3.7"; - private const string _sdkGenVersion = "2.415.8"; + private const string _sdkVersion = "1.4.0"; + private const string _sdkGenVersion = "2.460.1"; private const string _openapiDocVersion = "0.2.0"; - private const string _userAgent = "speakeasy-sdk/csharp 1.3.7 2.415.8 0.2.0 Styra.Opa.OpenApi"; + private const string _userAgent = "speakeasy-sdk/csharp 1.4.0 2.460.1 0.2.0 Styra.Opa.OpenApi"; private string _serverUrl = ""; private int _serverIndex = 0; private ISpeakeasyHttpClient _client; @@ -229,10 +229,8 @@ public async Task ExecuteDefaultPolicyWit response.Result = obj; return response; } - else - { - throw new SDKException("Unknown content type received", responseStatusCode, await httpResponse.Content.ReadAsStringAsync(), httpResponse); - } + + throw new Models.Errors.SDKException("Unknown content type received", responseStatusCode, await httpResponse.Content.ReadAsStringAsync(), httpResponse); } else if(new List{400, 404}.Contains(responseStatusCode)) { @@ -241,31 +239,25 @@ public async Task ExecuteDefaultPolicyWit var obj = ResponseBodyDeserializer.Deserialize(await httpResponse.Content.ReadAsStringAsync(), NullValueHandling.Ignore); throw obj!; } - else - { - throw new SDKException("Unknown content type received", responseStatusCode, await httpResponse.Content.ReadAsStringAsync(), httpResponse); - } + + throw new Models.Errors.SDKException("Unknown content type received", responseStatusCode, await httpResponse.Content.ReadAsStringAsync(), httpResponse); } else if(responseStatusCode == 500) { if(Utilities.IsContentTypeMatch("application/json", contentType)) { - var obj = ResponseBodyDeserializer.Deserialize(await httpResponse.Content.ReadAsStringAsync(), NullValueHandling.Ignore); + var obj = ResponseBodyDeserializer.Deserialize(await httpResponse.Content.ReadAsStringAsync(), NullValueHandling.Ignore); throw obj!; } - else - { - throw new SDKException("Unknown content type received", responseStatusCode, await httpResponse.Content.ReadAsStringAsync(), httpResponse); - } + + throw new Models.Errors.SDKException("Unknown content type received", responseStatusCode, await httpResponse.Content.ReadAsStringAsync(), httpResponse); } else if(responseStatusCode >= 400 && responseStatusCode < 500 || responseStatusCode >= 500 && responseStatusCode < 600) { - throw new SDKException("API error occurred", responseStatusCode, await httpResponse.Content.ReadAsStringAsync(), httpResponse); - } - else - { - throw new SDKException("Unknown status code received", responseStatusCode, await httpResponse.Content.ReadAsStringAsync(), httpResponse); + throw new Models.Errors.SDKException("API error occurred", responseStatusCode, await httpResponse.Content.ReadAsStringAsync(), httpResponse); } + + throw new Models.Errors.SDKException("Unknown status code received", responseStatusCode, await httpResponse.Content.ReadAsStringAsync(), httpResponse); } public async Task ExecutePolicyAsync(ExecutePolicyRequest request) @@ -332,10 +324,8 @@ public async Task ExecutePolicyAsync(ExecutePolicyRequest response.SuccessfulPolicyResponse = obj; return response; } - else - { - throw new SDKException("Unknown content type received", responseStatusCode, await httpResponse.Content.ReadAsStringAsync(), httpResponse); - } + + throw new Models.Errors.SDKException("Unknown content type received", responseStatusCode, await httpResponse.Content.ReadAsStringAsync(), httpResponse); } else if(responseStatusCode == 400) { @@ -344,31 +334,25 @@ public async Task ExecutePolicyAsync(ExecutePolicyRequest var obj = ResponseBodyDeserializer.Deserialize(await httpResponse.Content.ReadAsStringAsync(), NullValueHandling.Ignore); throw obj!; } - else - { - throw new SDKException("Unknown content type received", responseStatusCode, await httpResponse.Content.ReadAsStringAsync(), httpResponse); - } + + throw new Models.Errors.SDKException("Unknown content type received", responseStatusCode, await httpResponse.Content.ReadAsStringAsync(), httpResponse); } else if(responseStatusCode == 500) { if(Utilities.IsContentTypeMatch("application/json", contentType)) { - var obj = ResponseBodyDeserializer.Deserialize(await httpResponse.Content.ReadAsStringAsync(), NullValueHandling.Ignore); + var obj = ResponseBodyDeserializer.Deserialize(await httpResponse.Content.ReadAsStringAsync(), NullValueHandling.Ignore); throw obj!; } - else - { - throw new SDKException("Unknown content type received", responseStatusCode, await httpResponse.Content.ReadAsStringAsync(), httpResponse); - } + + throw new Models.Errors.SDKException("Unknown content type received", responseStatusCode, await httpResponse.Content.ReadAsStringAsync(), httpResponse); } else if(responseStatusCode >= 400 && responseStatusCode < 500 || responseStatusCode >= 500 && responseStatusCode < 600) { - throw new SDKException("API error occurred", responseStatusCode, await httpResponse.Content.ReadAsStringAsync(), httpResponse); - } - else - { - throw new SDKException("Unknown status code received", responseStatusCode, await httpResponse.Content.ReadAsStringAsync(), httpResponse); + throw new Models.Errors.SDKException("API error occurred", responseStatusCode, await httpResponse.Content.ReadAsStringAsync(), httpResponse); } + + throw new Models.Errors.SDKException("Unknown status code received", responseStatusCode, await httpResponse.Content.ReadAsStringAsync(), httpResponse); } public async Task ExecutePolicyWithInputAsync(ExecutePolicyWithInputRequest request) @@ -441,10 +425,8 @@ public async Task ExecutePolicyWithInputAsync(Ex response.SuccessfulPolicyResponse = obj; return response; } - else - { - throw new SDKException("Unknown content type received", responseStatusCode, await httpResponse.Content.ReadAsStringAsync(), httpResponse); - } + + throw new Models.Errors.SDKException("Unknown content type received", responseStatusCode, await httpResponse.Content.ReadAsStringAsync(), httpResponse); } else if(responseStatusCode == 400) { @@ -453,31 +435,25 @@ public async Task ExecutePolicyWithInputAsync(Ex var obj = ResponseBodyDeserializer.Deserialize(await httpResponse.Content.ReadAsStringAsync(), NullValueHandling.Ignore); throw obj!; } - else - { - throw new SDKException("Unknown content type received", responseStatusCode, await httpResponse.Content.ReadAsStringAsync(), httpResponse); - } + + throw new Models.Errors.SDKException("Unknown content type received", responseStatusCode, await httpResponse.Content.ReadAsStringAsync(), httpResponse); } else if(responseStatusCode == 500) { if(Utilities.IsContentTypeMatch("application/json", contentType)) { - var obj = ResponseBodyDeserializer.Deserialize(await httpResponse.Content.ReadAsStringAsync(), NullValueHandling.Ignore); + var obj = ResponseBodyDeserializer.Deserialize(await httpResponse.Content.ReadAsStringAsync(), NullValueHandling.Ignore); throw obj!; } - else - { - throw new SDKException("Unknown content type received", responseStatusCode, await httpResponse.Content.ReadAsStringAsync(), httpResponse); - } + + throw new Models.Errors.SDKException("Unknown content type received", responseStatusCode, await httpResponse.Content.ReadAsStringAsync(), httpResponse); } else if(responseStatusCode >= 400 && responseStatusCode < 500 || responseStatusCode >= 500 && responseStatusCode < 600) { - throw new SDKException("API error occurred", responseStatusCode, await httpResponse.Content.ReadAsStringAsync(), httpResponse); - } - else - { - throw new SDKException("Unknown status code received", responseStatusCode, await httpResponse.Content.ReadAsStringAsync(), httpResponse); + throw new Models.Errors.SDKException("API error occurred", responseStatusCode, await httpResponse.Content.ReadAsStringAsync(), httpResponse); } + + throw new Models.Errors.SDKException("Unknown status code received", responseStatusCode, await httpResponse.Content.ReadAsStringAsync(), httpResponse); } public async Task ExecuteBatchPolicyWithInputAsync(ExecuteBatchPolicyWithInputRequest request) @@ -550,10 +526,8 @@ public async Task ExecuteBatchPolicyWithInp response.BatchSuccessfulPolicyEvaluation = obj; return response; } - else - { - throw new SDKException("Unknown content type received", responseStatusCode, await httpResponse.Content.ReadAsStringAsync(), httpResponse); - } + + throw new Models.Errors.SDKException("Unknown content type received", responseStatusCode, await httpResponse.Content.ReadAsStringAsync(), httpResponse); } else if(responseStatusCode == 207) { @@ -569,10 +543,8 @@ public async Task ExecuteBatchPolicyWithInp response.BatchMixedResults = obj; return response; } - else - { - throw new SDKException("Unknown content type received", responseStatusCode, await httpResponse.Content.ReadAsStringAsync(), httpResponse); - } + + throw new Models.Errors.SDKException("Unknown content type received", responseStatusCode, await httpResponse.Content.ReadAsStringAsync(), httpResponse); } else if(responseStatusCode == 400) { @@ -581,10 +553,8 @@ public async Task ExecuteBatchPolicyWithInp var obj = ResponseBodyDeserializer.Deserialize(await httpResponse.Content.ReadAsStringAsync(), NullValueHandling.Ignore); throw obj!; } - else - { - throw new SDKException("Unknown content type received", responseStatusCode, await httpResponse.Content.ReadAsStringAsync(), httpResponse); - } + + throw new Models.Errors.SDKException("Unknown content type received", responseStatusCode, await httpResponse.Content.ReadAsStringAsync(), httpResponse); } else if(responseStatusCode == 500) { @@ -593,19 +563,15 @@ public async Task ExecuteBatchPolicyWithInp var obj = ResponseBodyDeserializer.Deserialize(await httpResponse.Content.ReadAsStringAsync(), NullValueHandling.Ignore); throw obj!; } - else - { - throw new SDKException("Unknown content type received", responseStatusCode, await httpResponse.Content.ReadAsStringAsync(), httpResponse); - } + + throw new Models.Errors.SDKException("Unknown content type received", responseStatusCode, await httpResponse.Content.ReadAsStringAsync(), httpResponse); } else if(responseStatusCode >= 400 && responseStatusCode < 500 || responseStatusCode >= 500 && responseStatusCode < 600) { - throw new SDKException("API error occurred", responseStatusCode, await httpResponse.Content.ReadAsStringAsync(), httpResponse); - } - else - { - throw new SDKException("Unknown status code received", responseStatusCode, await httpResponse.Content.ReadAsStringAsync(), httpResponse); + throw new Models.Errors.SDKException("API error occurred", responseStatusCode, await httpResponse.Content.ReadAsStringAsync(), httpResponse); } + + throw new Models.Errors.SDKException("Unknown status code received", responseStatusCode, await httpResponse.Content.ReadAsStringAsync(), httpResponse); } public async Task HealthAsync(bool? bundles = null, bool? plugins = null, List? excludePlugin = null) @@ -667,7 +633,7 @@ public async Task HealthAsync(bool? bundles = null, bool? plugin { if(Utilities.IsContentTypeMatch("application/json", contentType)) { - var obj = ResponseBodyDeserializer.Deserialize(await httpResponse.Content.ReadAsStringAsync(), NullValueHandling.Ignore); + var obj = ResponseBodyDeserializer.Deserialize(await httpResponse.Content.ReadAsStringAsync(), NullValueHandling.Include); var response = new HealthResponse() { StatusCode = responseStatusCode, @@ -677,31 +643,25 @@ public async Task HealthAsync(bool? bundles = null, bool? plugin response.HealthyServer = obj; return response; } - else - { - throw new SDKException("Unknown content type received", responseStatusCode, await httpResponse.Content.ReadAsStringAsync(), httpResponse); - } + + throw new Models.Errors.SDKException("Unknown content type received", responseStatusCode, await httpResponse.Content.ReadAsStringAsync(), httpResponse); } else if(responseStatusCode == 500) { if(Utilities.IsContentTypeMatch("application/json", contentType)) { - var obj = ResponseBodyDeserializer.Deserialize(await httpResponse.Content.ReadAsStringAsync(), NullValueHandling.Ignore); + var obj = ResponseBodyDeserializer.Deserialize(await httpResponse.Content.ReadAsStringAsync(), NullValueHandling.Include); throw obj!; } - else - { - throw new SDKException("Unknown content type received", responseStatusCode, await httpResponse.Content.ReadAsStringAsync(), httpResponse); - } + + throw new Models.Errors.SDKException("Unknown content type received", responseStatusCode, await httpResponse.Content.ReadAsStringAsync(), httpResponse); } else if(responseStatusCode >= 400 && responseStatusCode < 500 || responseStatusCode >= 500 && responseStatusCode < 600) { - throw new SDKException("API error occurred", responseStatusCode, await httpResponse.Content.ReadAsStringAsync(), httpResponse); - } - else - { - throw new SDKException("Unknown status code received", responseStatusCode, await httpResponse.Content.ReadAsStringAsync(), httpResponse); + throw new Models.Errors.SDKException("API error occurred", responseStatusCode, await httpResponse.Content.ReadAsStringAsync(), httpResponse); } + + throw new Models.Errors.SDKException("Unknown status code received", responseStatusCode, await httpResponse.Content.ReadAsStringAsync(), httpResponse); } } } \ No newline at end of file diff --git a/Styra/Opa/OpenApi/Utils/SecurityMetadata.cs b/Styra/Opa/OpenApi/Utils/SecurityMetadata.cs index 9c8ab9b..8d3844b 100644 --- a/Styra/Opa/OpenApi/Utils/SecurityMetadata.cs +++ b/Styra/Opa/OpenApi/Utils/SecurityMetadata.cs @@ -186,7 +186,9 @@ object value headerParams.Add(key, Utilities.PrefixBearer(valStr)); break; case "oauth2": - headerParams.Add(key, Utilities.PrefixBearer(valStr)); + if (!"client_credentials".Equals(schemeMetadata.SubType)) { + headerParams.Add(key, Utilities.PrefixBearer(valStr)); + } break; case "http": switch (schemeMetadata.SubType) diff --git a/Styra/Opa/Styra.Opa.csproj b/Styra/Opa/Styra.Opa.csproj index 47f093c..371eaee 100644 --- a/Styra/Opa/Styra.Opa.csproj +++ b/Styra/Opa/Styra.Opa.csproj @@ -2,7 +2,7 @@ true Styra.Opa - 1.3.7 + 1.4.0 Styra net8.0 enable diff --git a/USAGE.md b/USAGE.md index 9d6736a..62d1440 100644 --- a/USAGE.md +++ b/USAGE.md @@ -9,7 +9,7 @@ var sdk = new OpaApiClient(bearerAuth: ""); var res = await sdk.ExecuteDefaultPolicyWithInputAsync( input: Input.CreateNumber( - 8203.11D + 4963.69D ), pretty: false, acceptEncoding: Styra.Opa.OpenApi.Models.Components.GzipAcceptEncoding.Gzip diff --git a/global.json b/global.json index 75a80e9..ef3195a 100644 --- a/global.json +++ b/global.json @@ -2,5 +2,5 @@ "sdk": { "version": "8.0.0", "rollForward": "latestMinor" - } + } } \ No newline at end of file diff --git a/test/SmokeTest.Tests/OpenApiTest.cs b/test/SmokeTest.Tests/OpenApiTest.cs index 1a04ca8..279733b 100644 --- a/test/SmokeTest.Tests/OpenApiTest.cs +++ b/test/SmokeTest.Tests/OpenApiTest.cs @@ -1,4 +1,5 @@ -using Styra.Opa.OpenApi; +using Styra.Opa; +using Styra.Opa.OpenApi; using Styra.Opa.OpenApi.Models.Components; using Styra.Opa.OpenApi.Models.Errors; using Styra.Opa.OpenApi.Models.Requests; @@ -274,7 +275,7 @@ public async Task OpenApiClientBatchPolicyAllFailureTest() // We populate this variable later in the catch block, otherwise this would // not be a terribly good idea. - Dictionary responsesMap = null!; + Dictionary responsesMap = null!; try { var res = await client.ExecuteBatchPolicyWithInputAsync(req); @@ -288,7 +289,7 @@ public async Task OpenApiClientBatchPolicyAllFailureTest() else if (ex is BatchServerError bse) { Assert.NotNull(bse.Responses); - responsesMap = bse.Responses; + responsesMap = bse.Responses.ToOpaBatchErrors(); } else if (ex is SDKException sdke) {