$ cnpm install @figma/rest-api-spec
This repository contains the OpenAPI specification and Typescript types for the Figma REST API.
Note: this specification is currently in beta. If you notice any inaccuracies with the specification, please file an issue in this repository.
The OpenAPI (v3.1.0) specification is located in the openapi/ directory. This specification can be used with a wide variety of tools to generate API documentation, client SDKs, and more.
The Typescript types are generated from the OpenAPI specification and are located in dist/.
We use a custom code generator to convert the OpenAPI spec to TypeScript. While there are a number of existing OpenAPI-to-Typescript code generators, we adopted a custom solution that produces output that we believe is more optimal for the Figma REST API. In particular:
Paint, VariableAlias, etc...).getFile -> GetFilePathParams, GetFileQueryParams, GetFileResponse). For API endpoints expecting a request body, the types are suffixed with RequestBody (e.g. postComments -> PostCommentsRequestBody).To use these types in your Typescript code, install the package:
npm install --save-dev @figma/rest-api-spec
Then import the types that you need:
import { type GetFileResponse } from '@figma/rest-api-spec'
// Many popular HTTP clients let you annotate response types
const result = await axios.get<GetFileResponse>(url);
result.data // This has type GetFileResponse
Copyright 2013 - present © cnpmjs.org | Home |