Skip to content

Commit

Permalink
TS weirdness, continuing to error but ignore ts-expect-error
Browse files Browse the repository at this point in the history
Currently, ThomasAribart/json-schema-to-ts#96 and microsoft/TypeScript#55638 point to the fact that this can't easily be completed at runtime. I'm going to explore moving more to the generated types.

Signed-off-by: Aramis <sennyeyaramis@gmail.com>
  • Loading branch information
sennyeya committed Jan 17, 2024
1 parent 0b079d3 commit 4054c96
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 23 deletions.
16 changes: 8 additions & 8 deletions plugins/permission-backend/src/schema/openapi.generated.ts
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ export const spec = {
},
},
required: ['resourceType', 'rule'],
additionalProperties: true,
additionalProperties: false,
},
PermissionCriteria: {
oneOf: [
Expand All @@ -279,38 +279,38 @@ export const spec = {
allOf: {
type: 'array',
items: {
$ref: '#/components/schemas/PermissionCondition',
$ref: '#/components/schemas/PermissionCriteria',
},
minItems: 1,
},
},
additionalProperties: true,
additionalProperties: false,
},
{
type: 'object',
properties: {
anyOf: {
type: 'array',
items: {
$ref: '#/components/schemas/PermissionCondition',
$ref: '#/components/schemas/PermissionCriteria',
},
minItems: 1,
},
},
additionalProperties: true,
additionalProperties: false,
},
{
type: 'object',
properties: {
not: {
type: 'array',
items: {
$ref: '#/components/schemas/PermissionCondition',
$ref: '#/components/schemas/PermissionCriteria',
},
minItems: 1,
},
},
additionalProperties: true,
additionalProperties: false,
},
{
$ref: '#/components/schemas/PermissionCondition',
Expand Down Expand Up @@ -352,7 +352,7 @@ export const spec = {
},
},
required: ['result', 'id', 'pluginId', 'resourceType', 'conditions'],
additionalProperties: true,
additionalProperties: false,
},
EvaluatePermissionResponse: {
oneOf: [
Expand Down
26 changes: 11 additions & 15 deletions plugins/permission-backend/src/schema/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@ paths:
items:
type: array
items:
$ref: '#/components/schemas/EvaluatePermissionResponse'
oneOf:
- $ref: '#/components/schemas/ConditionalPolicyDecision'
- $ref: '#/components/schemas/DefinitivePolicyDecision'
required:
- items
additionalProperties: false
Expand Down Expand Up @@ -185,36 +187,35 @@ components:
required:
- resourceType
- rule
additionalProperties: true
additionalProperties: false


PermissionCriteria:
# Restricting this to depth of 1, TS doesn't love recursive
oneOf:
- type: object
properties:
allOf:
type: array
items:
$ref: '#/components/schemas/PermissionCondition'
$ref: '#/components/schemas/PermissionCriteria'
minItems: 1
additionalProperties: true
additionalProperties: false
- type: object
properties:
anyOf:
type: array
items:
$ref: '#/components/schemas/PermissionCondition'
$ref: '#/components/schemas/PermissionCriteria'
minItems: 1
additionalProperties: true
additionalProperties: false
- type: object
properties:
not:
type: array
items:
$ref: '#/components/schemas/PermissionCondition'
$ref: '#/components/schemas/PermissionCriteria'
minItems: 1
additionalProperties: true
additionalProperties: false
- $ref: '#/components/schemas/PermissionCondition'


Expand Down Expand Up @@ -254,12 +255,7 @@ components:
- pluginId
- resourceType
- conditions
additionalProperties: true

EvaluatePermissionResponse:
oneOf:
- $ref: '#/components/schemas/ConditionalPolicyDecision'
- $ref: '#/components/schemas/DefinitivePolicyDecision'
additionalProperties: false

PostAuthorize400ResponseBody:
type: object
Expand Down
1 change: 1 addition & 0 deletions plugins/permission-backend/src/service/router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ export async function createRouter(
response.json({ status: 'ok' });
});

// @ts-expect-error - https://github.com/ThomasAribart/json-schema-to-ts/issues/96
router.post('/authorize', async (req, res) => {
const user = await identity.getIdentity({ request: req });

Expand Down

0 comments on commit 4054c96

Please sign in to comment.