fix(types): add extends to role and resource-role types (PER-16500) - #121
Conversation
zeevmoney
left a comment
There was a problem hiding this comment.
The extends addition itself is correct — it matches the backend exactly (extends: Optional[list[str]] on the shared _Editable base, inherited by RoleCreate/Read/Update; permit-backend .../schemas/schema_role.py:56-60). The blockers are scope and method, not the field.
There was a problem hiding this comment.
Pull request overview
This PR aims to align the SDK’s generated Role TypeScript interfaces with the Permit.io OpenAPI spec by adding the missing extends?: Array<string> field, enabling role inheritance in create/update flows and typed access when reading roles. It also includes runtime dependency upgrades and a logging implementation change to support newer pino/pino-pretty behavior.
Changes:
- Add
extends?: Array<string>toRoleRead,RoleCreate, andRoleUpdateinterfaces. - Update logger initialization to use
pino.transportwithpino-prettywhenconfig.log.jsonis false. - Bump multiple runtime dependencies (axios/lodash/path-to-regexp/pino/pino-pretty) and regenerate
yarn.lockaccordingly.
Reviewed changes
Copilot reviewed 5 out of 6 changed files in this pull request and generated 6 comments.
Show a summary per file
| File | Description |
|---|---|
| yarn.lock | Lockfile updates reflecting dependency upgrades and transitive changes. |
| package.json | Updates runtime dependency versions (axios/lodash/path-to-regexp/pino/pino-pretty). |
| src/logger.ts | Reworks logger creation to use pino-pretty transport instead of deprecated prettyPrint. |
| src/openapi/types/role-create.ts | Adds extends?: Array<string> to role creation type. |
| src/openapi/types/role-read.ts | Adds extends?: Array<string> to role read type. |
| src/openapi/types/role-update.ts | Adds extends?: Array<string> to role update type. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
The Permit API and OpenAPI spec define extends (Array<string>) on the role schemas, but it is missing from the generated TypeScript types, so consumers cannot type-safely set or read role inheritance. Add extends?: Array<string> to RoleCreate/Read/Update and ResourceRoleCreate/Read/Update, matching the generator's emitted style and field position so a future regeneration is a no-op. Add a unit test pinning the field on all six types; it fails to compile if any addition is reverted. The canonical fix (regenerate the client) is currently blocked: the pinned generator 6.2.1 cannot read the now-OpenAPI-3.1 spec and regenerates an all-any client (see permitio#130).
c57d16c to
023f1ce
Compare
|
Thanks for the review. Agreed on scope and the missing test, both fixed below. One note on the regenerate suggestion. Scope: dropped the Test: added On regenerating instead of hand-editing: I tried that first, and I also extended it to the |
Co-Authored-By: Codex <noreply@openai.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Summary
extends?: string[]field (the roles this role inherits permissions from) toRoleCreate,RoleRead,RoleUpdate,ResourceRoleCreate,ResourceRoleReadandResourceRoleUpdate, matching the public API spec.extendson all six public method signatures and check thatrolesandresourceRolescreate, update and get pass the field through unchanged.Linear
Details
Types
src/openapi/was last regenerated in March 2024, so the six role models have noextendsfield, although the API accepts and returns it. Each model now declares the property with the spec's description, in the generator's JSDoc style.Checked against
https://api.permit.io/v2/openapi.json(OpenAPI 3.1.0, fetched 2026-09-29):extendsis an optional, non-nullablearray<string>in all six schemas.Tests (
src/tests/unit/role-extends.spec.ts, run byyarn test:unit)roles.create/get/updateandresourceRoles.create/get/update,Pick<T, 'extends'>must equal{ extends?: Array<string> }exactly. This rejectsany,null, non-array values and a required field.build:typescompiles these assertions before AVA runs.extendsunchanged and get returns it unchanged (6 AVA cases).extendsin a wrapper). The previous test caught 18 of 67 and 0 of 6.Testing
yarn build: passesyarn lint: 0 errors (7 existing warnings in untouched test files)yarn test:unit: 54 passedyarn test:module-imports: 9 passedNotes
extends: nullshould omit the field instead.src/api/index.ts;rolesmaps;RoleCreateBulk;role-block.ts.role-extends.spec.tsuses AVA, like the rest ofmain. When the Vitest migration (test: migrate AVA→Vitest with event-based waits (stacked on #131) #132, folded into permitio 3.0.0: refactor SDK APIs, tests, and release validation #134) lands, it needs porting, and its type assertions must stay compiled.Original change by @Kyzgor; the test commits were added by the maintainers.
🤖 Generated with Claude Code
https://claude.ai/code/session_01PSoip6dghQ62bLQ6GBMwTA