Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/openapi/types/resource-role-create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,12 @@ export interface ResourceRoleCreate {
* @memberof ResourceRoleCreate
*/
attributes?: object;
/**
* list of role keys that define what roles this role extends. In other words: this role will automatically inherit all the permissions of the given roles in this list.
* @type {Array<string>}
* @memberof ResourceRoleCreate
*/
extends?: Array<string>;
/**
*
* @type {GrantedTo1}
Expand Down
6 changes: 6 additions & 0 deletions src/openapi/types/resource-role-read.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,12 @@ export interface ResourceRoleRead {
* @memberof ResourceRoleRead
*/
attributes?: object;
/**
* list of role keys that define what roles this role extends. In other words: this role will automatically inherit all the permissions of the given roles in this list.
* @type {Array<string>}
* @memberof ResourceRoleRead
*/
extends?: Array<string>;
/**
*
* @type {GrantedTo2}
Expand Down
6 changes: 6 additions & 0 deletions src/openapi/types/resource-role-update.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,12 @@ export interface ResourceRoleUpdate {
* @memberof ResourceRoleUpdate
*/
attributes?: object;
/**
* list of role keys that define what roles this role extends. In other words: this role will automatically inherit all the permissions of the given roles in this list.
* @type {Array<string>}
* @memberof ResourceRoleUpdate
*/
extends?: Array<string>;
/**
*
* @type {GrantedTo1}
Expand Down
6 changes: 6 additions & 0 deletions src/openapi/types/role-create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,12 @@ export interface RoleCreate {
* @memberof RoleCreate
*/
attributes?: object;
/**
* list of role keys that define what roles this role extends. In other words: this role will automatically inherit all the permissions of the given roles in this list.
* @type {Array<string>}
* @memberof RoleCreate
*/
extends?: Array<string>;
Comment on lines +55 to +60
/**
*
* @type {GrantedTo1}
Expand Down
6 changes: 6 additions & 0 deletions src/openapi/types/role-read.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,12 @@ export interface RoleRead {
* @memberof RoleRead
*/
attributes?: object;
/**
* list of role keys that define what roles this role extends. In other words: this role will automatically inherit all the permissions of the given roles in this list.
* @type {Array<string>}
* @memberof RoleRead
*/
extends?: Array<string>;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[MEDIUM] Hand-editing generated files will be clobbered on regen (applies to role-create/role-update too)

These files carry the 'auto generated by OpenAPI Generator — Do not edit the class manually' header and are produced by yarn generate-openapi-client from the live spec (package.json:54). Since extends is already in the backend/spec, a manual edit diverges from the generator and is overwritten on the next regeneration.

Suggestion: Run yarn generate-openapi-client and commit the regenerated output — it picks up extends (and any other drift) faithfully and survives regen.

Comment on lines +49 to +54
/**
*
* @type {GrantedTo}
Expand Down
6 changes: 6 additions & 0 deletions src/openapi/types/role-update.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,12 @@ export interface RoleUpdate {
* @memberof RoleUpdate
*/
attributes?: object;
/**
* list of role keys that define what roles this role extends. In other words: this role will automatically inherit all the permissions of the given roles in this list.
* @type {Array<string>}
* @memberof RoleUpdate
*/
extends?: Array<string>;
Comment on lines +49 to +54
/**
*
* @type {GrantedTo1}
Expand Down
36 changes: 36 additions & 0 deletions src/tests/unit/role-extends.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import test from 'ava';

import {
ResourceRoleCreate,
ResourceRoleRead,
ResourceRoleUpdate,
RoleCreate,
RoleRead,
RoleUpdate,
} from '../../openapi/types';

// Compile-time guard for the `extends` role-inheritance field on the six generated role types.
// Removing `extends?: Array<string>` from any of them makes this file fail to compile under
// `yarn build` (build:types -> tsc): TS2322 on the create/update object literals (excess property)
// and TS2339 on the read member access. The runtime assertions below exist only so the test:unit
// ava glob exercises the file; the substantive check is that it type-checks.
const roleCreate: RoleCreate = { key: 'editor', name: 'Editor', extends: ['viewer'] };
const roleUpdate: RoleUpdate = { extends: ['viewer'] };
const roleReadExtends: Array<string> | undefined = ({} as RoleRead).extends;

const resourceRoleCreate: ResourceRoleCreate = {
key: 'editor',
name: 'Editor',
extends: ['viewer'],
};
const resourceRoleUpdate: ResourceRoleUpdate = { extends: ['viewer'] };
const resourceRoleReadExtends: Array<string> | undefined = ({} as ResourceRoleRead).extends;

test('Role and ResourceRole types expose the `extends` inheritance field', (t) => {
t.deepEqual(roleCreate.extends, ['viewer']);
t.deepEqual(roleUpdate.extends, ['viewer']);
t.is(roleReadExtends, undefined);
t.deepEqual(resourceRoleCreate.extends, ['viewer']);
t.deepEqual(resourceRoleUpdate.extends, ['viewer']);
t.is(resourceRoleReadExtends, undefined);
});