Skip to content

feat: ComponentProperty / ComponentPropertyDefinition を type 別スキーマに分割#46

Merged
amotarao merged 3 commits into
mainfrom
split-component-property-definition
Mar 20, 2026
Merged

feat: ComponentProperty / ComponentPropertyDefinition を type 別スキーマに分割#46
amotarao merged 3 commits into
mainfrom
split-component-property-definition

Conversation

@amotarao

@amotarao amotarao commented Mar 6, 2026

Copy link
Copy Markdown
Member

Summary

fix #44

ComponentPropertyDefinition

スキーマ type defaultValue 固有フィールド
BooleanComponentPropertyDefinition BOOLEAN boolean
TextComponentPropertyDefinition TEXT string
VariantComponentPropertyDefinition VARIANT string variantOptions (required)
InstanceSwapComponentPropertyDefinition INSTANCE_SWAP string preferredValues (required)

ComponentProperty

スキーマ type value 固有フィールド
BooleanComponentProperty BOOLEAN boolean
TextComponentProperty TEXT string
VariantComponentProperty VARIANT string boundVariables (required)
InstanceSwapComponentProperty INSTANCE_SWAP string preferredValues (required)

🤖 Generated with Claude Code

plainbrew/figma-rest-api-spec#2 の変更を適用。

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Mar 6, 2026

Copy link
Copy Markdown
📝 Walkthrough

Walkthrough

The OpenAPI spec replaces a single ComponentPropertyType enum and monolithic property schemas with discriminated oneOf unions, adding four type-specific Definition and Property public schemas: Boolean, Text, Variant, and InstanceSwap, with discriminator mappings on type.

Changes

Cohort / File(s) Summary
OpenAPI Schema Restructuring
packages/figma-rest-api-spec/openapi.yaml
Replaced ComponentPropertyType enum and flattened schemas with discriminated oneOf unions. Added BooleanComponentPropertyDefinition, TextComponentPropertyDefinition, VariantComponentPropertyDefinition, InstanceSwapComponentPropertyDefinition and corresponding public variants BooleanComponentProperty, TextComponentProperty, VariantComponentProperty, InstanceSwapComponentProperty. Updated ComponentPropertyDefinition and ComponentProperty to use discriminators mapping type to the new schemas; adjusted nested fields (e.g., boundVariables, variantOptions, preferredValues) to the new variant schemas.
Changeset / Release Note
.changeset/young-islands-open.md
Added changeset indicating a minor version bump and a short note (Japanese) describing the split of ComponentPropertyDefinition / ComponentProperty by type.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

Poem

🐰 I hopped through schemas, soft and spry,

BOOLEAN, TEXT, VARIANT caught my eye.
INSTANCE_SWAP joined the play,
Four little types now lead the way —
A carrot-coded union, neat and spry.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly summarizes the main change: splitting ComponentProperty and ComponentPropertyDefinition schemas by type using a discriminated union pattern.
Description check ✅ Passed The description provides relevant context about splitting schemas by type field, implementing discriminated unions with oneOf+discriminator, and includes detailed tables of the new schema variants.
Linked Issues check ✅ Passed The PR fixes issue #44 by splitting ComponentProperty and ComponentPropertyDefinition into type-specific schemas with discriminated unions as intended.
Out of Scope Changes check ✅ Passed All changes are within scope: the PR splits component property schemas, removes the unused ComponentPropertyType enum, and updates references accordingly.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch split-component-property-definition

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@packages/figma-rest-api-spec/openapi.yaml`:
- Around line 5566-5574: The schema currently marks preferredValues and
boundVariables as required which is incorrect; update the OpenAPI components
schemas that reference preferredValues (the schema listing type, defaultValue,
preferredValues and items $ref
"#/components/schemas/InstanceSwapPreferredValue") and any schema that includes
boundVariables to remove those property names from their required arrays so both
preferredValues and boundVariables become optional (leave their property
definitions intact). Locate the relevant component schemas (the one referencing
InstanceSwapPreferredValue and the schemas around the other occurrences noted)
and delete "preferredValues" and "boundVariables" from each schema's required
list so the properties remain defined but are no longer required.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 1aac072c-75f1-4075-aa42-5294b5168545

📥 Commits

Reviewing files that changed from the base of the PR and between e082aea and 08ca3cc.

📒 Files selected for processing (1)
  • packages/figma-rest-api-spec/openapi.yaml

Comment on lines 5566 to +5574
preferredValues:
type: array
items:
$ref: "#/components/schemas/InstanceSwapPreferredValue"
description: Preferred values for this property. Only applicable if type is
`INSTANCE_SWAP`.
description: Preferred values for this property.
required:
- type
- defaultValue
- preferredValues

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major

🧩 Analysis chain

🌐 Web query:

Figma REST API property types INSTANCE_SWAP preferredValues optional required

💡 Result:

In the Figma REST API, preferredValues is only applicable to INSTANCE_SWAP component properties, and it is optional (not required).

  • ComponentPropertyDefinition

    • Required:
      • type (BOOLEAN | INSTANCE_SWAP | TEXT | VARIANT)
      • defaultValue (Boolean | String)
    • Optional:
      • variantOptions? (only exists for VARIANT)
      • preferredValues? (only exists for INSTANCE_SWAP) [1]
  • ComponentProperty (property values on an instance)

    • Required:
      • type
      • value
    • Optional:
      • preferredValues? (only exists for INSTANCE_SWAP) [1]
  • preferredValues element shape: InstanceSwapPreferredValue

    • Required fields:
      • type: COMPONENT or COMPONENT_SET
      • key: string (the component/component-set key) [1]

So, for INSTANCE_SWAP, preferredValues may be present, but clients should treat it as optional and handle it being absent. [1]

Sources


🌐 Web query:

Figma API ComponentProperty boundVariables optional documentation

💡 Result:

In Figma’s APIs, boundVariables is optional and only present/populated when something is actually bound to a Variable.

  • Plugin API (component properties): ComponentPropertyDefinitions notes that a component property can optionally be bound to a Variable; when it is, the boundVariables structure is populated with a VariableAlias (otherwise it’s absent/empty). [1]
  • REST API (nodes in file JSON): nodes expose a boundVariables map that may include a componentProperties sub-map (by property name) when component properties are variable-bound; if nothing is bound, that map/field won’t be present. [2]
  • REST API type reference: boundVariables is documented as a (custom) property type, reinforcing it as a node field that may appear depending on bindings. [3]

Docs: [1] ComponentPropertyDefinitions (Plugin API), [2] REST API “Files” / global node properties, [3] REST API “File property types”.


🌐 Web query:

site:figma.com REST API property definitions ComponentProperty INSTANCE_SWAP

💡 Result:

In the Figma REST API file JSON, component property definitions are represented as a map of ComponentPropertyDefinition objects (typically exposed under a node’s componentPropertyDefinitions for COMPONENT / COMPONENT_SET nodes).

For an instance swap property, the definition shape is:

  • type: INSTANCE_SWAP
  • defaultValue: string (the initial value for instances; REST type is Boolean | String)
  • preferredValues?: array of InstanceSwapPreferredValue (only present for INSTANCE_SWAP)
    • each preferred value includes:
      • type: "COMPONENT" or "COMPONENT_SET"
      • key: the component / component set key

The relevant REST type definitions are documented under ComponentPropertyDefinition, ComponentPropertyType, and InstanceSwapPreferredValue. [1]

The same “definitions map” concept (and the note that INSTANCE_SWAP definitions can include preferredValues) is also described in Figma’s ComponentPropertyDefinitions reference. [2]

Sources: [1] (developers.figma.com) [2] (developers.figma.com)

Citations:


Make preferredValues and boundVariables optional in schema, not required.

According to official Figma REST API documentation, preferredValues for INSTANCE_SWAP is optional and only appears when defined. Similarly, boundVariables is optional and only present when something is actually bound to a variable. The current schema incorrectly marks these as required, which breaks compatibility with the actual API behavior and will cause validation failures and client generation errors.

Required schema changes
     InstanceSwapComponentPropertyDefinition:
       ...
       required:
         - type
         - defaultValue
-        - preferredValues

     VariantComponentProperty:
       ...
       required:
         - type
         - value
-        - boundVariables

     InstanceSwapComponentProperty:
       ...
       required:
         - type
         - value
-        - preferredValues

Applies to lines 5566-5574, 5631-5641, 5653-5661.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@packages/figma-rest-api-spec/openapi.yaml` around lines 5566 - 5574, The
schema currently marks preferredValues and boundVariables as required which is
incorrect; update the OpenAPI components schemas that reference preferredValues
(the schema listing type, defaultValue, preferredValues and items $ref
"#/components/schemas/InstanceSwapPreferredValue") and any schema that includes
boundVariables to remove those property names from their required arrays so both
preferredValues and boundVariables become optional (leave their property
definitions intact). Locate the relevant component schemas (the one referencing
InstanceSwapPreferredValue and the schemas around the other occurrences noted)
and delete "preferredValues" and "boundVariables" from each schema's required
list so the properties remain defined but are no longer required.

@amotarao amotarao requested a review from iromonek39 March 6, 2026 12:15
@amotarao amotarao changed the title feat: ComponentPropertyDefinition / ComponentProperty を type 別スキーマに分割 feat: ComponentProperty / ComponentPropertyDefinition を type 別スキーマに分割 Mar 8, 2026
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

♻️ Duplicate comments (1)
packages/figma-rest-api-spec/openapi.yaml (1)

5546-5566: ⚠️ Potential issue | 🟠 Major

Keep preferredValues optional, and don't narrow boundVariables to only VARIANT.

Line 5566 and Line 5653 make preferredValues required even though Figma documents it as an INSTANCE_SWAP-only optional field. After the split, boundVariables is also both required on Line 5632 and only present on VariantComponentProperty, while Figma documents it as an optional field on ComponentProperty generally, populated only when a variable is actually bound. In this shape, valid responses will fail validation, and valid BOOLEAN/TEXT/INSTANCE_SWAP properties can no longer carry boundVariables. (developers.figma.com)

🛠️ Proposed fix
     InstanceSwapComponentPropertyDefinition:
       ...
       required:
         - type
         - defaultValue
-        - preferredValues

     VariantComponentProperty:
       ...
       required:
         - type
         - value
-        - boundVariables

     InstanceSwapComponentProperty:
       ...
       required:
         - type
         - value
-        - preferredValues

Also move the existing boundVariables shape into a shared optional base for all ComponentProperty variants, or duplicate it onto BooleanComponentProperty, TextComponentProperty, and InstanceSwapComponentProperty.

Also applies to: 5581-5653

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@packages/figma-rest-api-spec/openapi.yaml` around lines 5546 - 5566, The
schema incorrectly makes preferredValues required on
InstanceSwapComponentPropertyDefinition and restricts boundVariables to
VariantComponentProperty; update the OpenAPI definitions so preferredValues is
optional in InstanceSwapComponentPropertyDefinition (remove it from required)
and move or duplicate the boundVariables schema into the shared
ComponentProperty base (or add it as an optional property on
BooleanComponentProperty, TextComponentProperty, and
InstanceSwapComponentProperty) so boundVariables remains optional for all
component property types; locate and edit
InstanceSwapComponentPropertyDefinition, VariantComponentProperty,
ComponentProperty (and BooleanComponentProperty/TextComponentProperty) to apply
these changes.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Duplicate comments:
In `@packages/figma-rest-api-spec/openapi.yaml`:
- Around line 5546-5566: The schema incorrectly makes preferredValues required
on InstanceSwapComponentPropertyDefinition and restricts boundVariables to
VariantComponentProperty; update the OpenAPI definitions so preferredValues is
optional in InstanceSwapComponentPropertyDefinition (remove it from required)
and move or duplicate the boundVariables schema into the shared
ComponentProperty base (or add it as an optional property on
BooleanComponentProperty, TextComponentProperty, and
InstanceSwapComponentProperty) so boundVariables remains optional for all
component property types; locate and edit
InstanceSwapComponentPropertyDefinition, VariantComponentProperty,
ComponentProperty (and BooleanComponentProperty/TextComponentProperty) to apply
these changes.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: b85b1c8f-eb57-4634-9207-fe639119f420

📥 Commits

Reviewing files that changed from the base of the PR and between 08ca3cc and c90e1c5.

📒 Files selected for processing (2)
  • .changeset/young-islands-open.md
  • packages/figma-rest-api-spec/openapi.yaml
✅ Files skipped from review due to trivial changes (1)
  • .changeset/young-islands-open.md

@iromonek39 iromonek39 left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

LGTM!!

@amotarao amotarao merged commit 17eb8a1 into main Mar 20, 2026
4 checks passed
@amotarao amotarao deleted the split-component-property-definition branch March 20, 2026 13:43
@github-actions github-actions Bot mentioned this pull request Mar 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Figma Slots に関する型を追加

2 participants