Skip to content

Commit

Permalink
opa: generate using updated OpenAPI spec (#198)
Browse files Browse the repository at this point in the history
* opa: adapt porcelain code to generated changes
* ci: regenerated with OpenAPI Doc , Speakeasy CLI 1.376.0

Co-authored-by: speakeasybot <[email protected]>
  • Loading branch information
srenatus and speakeasybot authored Aug 20, 2024
1 parent 6ef5d1d commit 9604a4c
Show file tree
Hide file tree
Showing 18 changed files with 144 additions and 128 deletions.
2 changes: 1 addition & 1 deletion .speakeasy/gen.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ generation:
auth:
oAuth2ClientCredentialsEnabled: false
typescript:
version: 1.4.1
version: 1.5.0
additionalDependencies:
dependencies: {}
devDependencies:
Expand Down
12 changes: 6 additions & 6 deletions .speakeasy/workflow.lock
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
speakeasyVersion: 1.369.0
speakeasyVersion: 1.376.0
sources:
openapi:
sourceNamespace: openapi
sourceRevisionDigest: sha256:9b23164c63cb86b765915fb16fe576a049193d891ad7187b8b07933709cce52d
sourceBlobDigest: sha256:7a77d65d39072fc44b01f8f6d61e871955a17efd6f9ea7b21114566ae9199507
sourceRevisionDigest: sha256:3e6d52e3f6893aa962869edcca40f482a24867be190e6a4469914dfe62d872ff
sourceBlobDigest: sha256:f76f9d1e8be466eef2d0e9612845ce19f9a5f507682e92d7a4355b3b13eaa921
tags:
- latest
- main
- push-suoktzlvrumw
targets:
first-target:
source: openapi
sourceNamespace: openapi
sourceRevisionDigest: sha256:9b23164c63cb86b765915fb16fe576a049193d891ad7187b8b07933709cce52d
sourceBlobDigest: sha256:7a77d65d39072fc44b01f8f6d61e871955a17efd6f9ea7b21114566ae9199507
sourceRevisionDigest: sha256:3e6d52e3f6893aa962869edcca40f482a24867be190e6a4469914dfe62d872ff
sourceBlobDigest: sha256:f76f9d1e8be466eef2d0e9612845ce19f9a5f507682e92d7a4355b3b13eaa921
outLocation: packages/opa
workflow:
workflowVersion: 1.0.0
Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

28 changes: 14 additions & 14 deletions packages/opa-react/src/authz-provider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import {
type RequestOptions,
type BatchRequestOptions,
} from "@styra/opa";
import { type ServerError } from "@styra/opa/sdk/models/components";
import { type ServerErrorWithStatusCode } from "@styra/opa/sdk/models/components";
import { create, windowScheduler } from "@yornaath/batshit";

type EvalQuery = {
Expand Down Expand Up @@ -59,13 +59,13 @@ const evals = (sdk: OPAClient) =>
Object.entries(res).map(([k, res]) => [
k,
fromRs[k] ? fromRs[k](res) : res,
]),
),
])
)
);
}),
})
).then((all: object[]) =>
// combine result arrays of objects (if there's more than one)
all.length == 1 ? all[0] : Object.assign({}, ...all),
all.length == 1 ? all[0] : Object.assign({}, ...all)
);
},
resolver: (results, query) => results[key(query)] ?? null,
Expand All @@ -79,21 +79,21 @@ export interface OPAClient {
evaluate<In extends Input | ToInput, Res>(
path: string,
input?: In,
opts?: RequestOptions<Res>,
opts?: RequestOptions<Res>
): Promise<Res>;

/** Evaluate the server's default policy, with optional `input` and `RequestOptions`. */
evaluateDefault<In extends Input | ToInput, Res>(
input?: In,
opts?: RequestOptions<Res>,
opts?: RequestOptions<Res>
): Promise<Res>;

/** Evaluate a policy against a batch of inputs. */
evaluateBatch<In extends Input | ToInput, Res>(
path: string,
inputs: { [k: string]: In },
opts?: BatchRequestOptions<Res>,
): Promise<{ [k: string]: Res | ServerError }>;
opts?: BatchRequestOptions<Res>
): Promise<{ [k: string]: Res | ServerErrorWithStatusCode }>;
}

export type AuthzProviderContext = {
Expand All @@ -115,7 +115,7 @@ export type AuthzProviderContext = {

// Reference: https://reacttraining.com/blog/react-context-with-typescript
export const AuthzContext = createContext<AuthzProviderContext | undefined>(
undefined,
undefined
);

export interface AuthzProviderProps
Expand Down Expand Up @@ -151,7 +151,7 @@ export default function AuthzProvider({
}: AuthzProviderProps) {
const batcher = useMemo(
() => batch && opaClient && evals(opaClient),
[opaClient, batch],
[opaClient, batch]
);
const defaultQueryFn = useCallback(
async ({
Expand Down Expand Up @@ -182,7 +182,7 @@ export default function AuthzProvider({

return batcher.fetch({ path, input, fromResult });
},
[batcher, batch],
[batcher, batch]
);
const queryClient = useMemo(
() =>
Expand All @@ -194,7 +194,7 @@ export default function AuthzProvider({
},
},
}),
[defaultQueryFn, retry],
[defaultQueryFn, retry]
);

const context = useMemo<AuthzProviderContext>(
Expand All @@ -205,7 +205,7 @@ export default function AuthzProvider({
defaultFromResult,
queryClient: queryClient!,
}),
[opaClient, defaultPath, defaultInput, defaultFromResult, queryClient],
[opaClient, defaultPath, defaultInput, defaultFromResult, queryClient]
);

if (!queryClient) return null;
Expand Down
18 changes: 9 additions & 9 deletions packages/opa/.speakeasy/gen.lock
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
lockVersion: 2.0.0
id: 078615ff-ff96-44f8-8aca-2f4d3e687bf0
management:
docChecksum: 899b27d9399190d5ff40fc3e7c07c252
docChecksum: 54d33facef3aa19f358d15ab44e34141
docVersion: 0.2.0
speakeasyVersion: 1.369.0
generationVersion: 2.399.0
releaseVersion: 1.4.1
configChecksum: c714d6cd61c0b03af384266ab1d93b6b
speakeasyVersion: 1.376.0
generationVersion: 2.402.5
releaseVersion: 1.5.0
configChecksum: dc4ad85128f07abee67816f11d9d50e5
repoURL: https://github.com/StyraInc/opa-typescript.git
repoSubDirectory: packages/opa
installationURL: https://gitpkg.now.sh/StyraInc/opa-typescript/packages/opa
features:
typescript:
additionalDependencies: 0.1.0
constsAndDefaults: 0.1.8
core: 3.13.2
constsAndDefaults: 0.1.10
core: 3.14.1
defaultEnabledRetries: 0.1.0
envVarSecurityUsage: 0.1.1
examples: 2.81.4
Expand Down Expand Up @@ -113,8 +113,8 @@ generatedFiles:
- docs/sdk/models/components/gzipcontentencoding.md
- docs/sdk/models/components/location.md
- docs/sdk/models/components/errors.md
- docs/sdk/models/components/servererror.md
- docs/sdk/models/components/responsessuccessfulpolicyresponse.md
- docs/sdk/models/components/servererrorwithstatuscode.md
- docs/sdk/models/components/successfulpolicyresponsewithstatuscode.md
- docs/sdk/models/components/responses.md
- docs/sdk/models/components/batchmixedresults.md
- docs/sdk/models/components/batchsuccessfulpolicyevaluation.md
Expand Down
4 changes: 3 additions & 1 deletion packages/opa/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -389,7 +389,9 @@ run();
<!-- Start Debugging [debug] -->
## Debugging

To log HTTP requests and responses, you can pass a logger that matches `console`'s interface as an SDK option.
You can setup your SDK to emit debug logs for SDK requests and responses.

You can pass a logger that matches `console`'s interface as an SDK option.

> [!WARNING]
> Beware that debug logging will reveal secrets, like API tokens in headers, in log messages printed to a console or files. It's recommended to use this feature only during local development and not in production.
Expand Down
10 changes: 9 additions & 1 deletion packages/opa/RELEASES.md
Original file line number Diff line number Diff line change
Expand Up @@ -413,4 +413,12 @@ Based on:
- OpenAPI Doc
- Speakeasy CLI 1.369.0 (2.399.0) https://github.com/speakeasy-api/speakeasy
### Generated
- [typescript v1.4.1] packages/opa
- [typescript v1.4.1] packages/opa

## 2024-08-20 07:54:42
### Changes
Based on:
- OpenAPI Doc
- Speakeasy CLI 1.376.0 (2.402.5) https://github.com/speakeasy-api/speakeasy
### Generated
- [typescript v1.5.0] packages/opa
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ import { BatchMixedResults } from "@styra/opa/sdk/models/components";
let value: BatchMixedResults = {
responses: {
key: {
result: 3927.85,
httpStatusCode: "200",
result: 3927.85,
},
},
};
Expand Down
10 changes: 5 additions & 5 deletions packages/opa/docs/sdk/models/components/responses.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,24 +6,24 @@
import { Responses } from "@styra/opa/sdk/models/components";

let value: Responses = {
httpStatusCode: "200",
code: "<value>",
message: "<value>",
decisionId: "b84cf736-213c-4932-a8e4-bb5c648f1b4d",
httpStatusCode: "200",
};
```

## Supported Types

### `components.ResponsesSuccessfulPolicyResponse`
### `components.SuccessfulPolicyResponseWithStatusCode`

```typescript
const value: components.ResponsesSuccessfulPolicyResponse = /* values here */
const value: components.SuccessfulPolicyResponseWithStatusCode = /* values here */
```

### `components.ServerError`
### `components.ServerErrorWithStatusCode`

```typescript
const value: components.ServerError = /* values here */
const value: components.ServerErrorWithStatusCode = /* values here */
```

Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
# ServerError
# ServerErrorWithStatusCode

## Example Usage

```typescript
import { ServerError } from "@styra/opa/sdk/models/components";
import { ServerErrorWithStatusCode } from "@styra/opa/sdk/models/components";

let value: ServerError = {
let value: ServerErrorWithStatusCode = {
httpStatusCode: "200",
code: "<value>",
message: "<value>",
decisionId: "b84cf736-213c-4932-a8e4-bb5c648f1b4d",
httpStatusCode: "200",
};
```

## Fields

| Field | Type | Required | Description | Example |
| --------------------------------------------------------------- | --------------------------------------------------------------- | --------------------------------------------------------------- | --------------------------------------------------------------- | --------------------------------------------------------------- |
| `httpStatusCode` | *string* | :heavy_minus_sign: | N/A | 200 |
| `code` | *string* | :heavy_check_mark: | N/A | |
| `message` | *string* | :heavy_check_mark: | N/A | |
| `errors` | [components.Errors](../../../sdk/models/components/errors.md)[] | :heavy_minus_sign: | N/A | |
| `decisionId` | *string* | :heavy_minus_sign: | N/A | b84cf736-213c-4932-a8e4-bb5c648f1b4d |
| `httpStatusCode` | *string* | :heavy_minus_sign: | N/A | 200 |
| `decisionId` | *string* | :heavy_minus_sign: | N/A | b84cf736-213c-4932-a8e4-bb5c648f1b4d |
Loading

0 comments on commit 9604a4c

Please sign in to comment.