Giter VIP home page Giter VIP logo

rest-api-spec's Introduction

rest-api-spec

This repository contains the OpenAPI specification and Typescript types for the Figma REST API.

Changelog

Note: this specification is currently in beta. If you notice any inaccuracies with the specification, please file an issue in this repository.

Usage

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:

  • All OpenAPI schemas, responses, and request parameters are exported as named types. This exposes named types inside complex node properties (e.g. Paint, VariableAlias, etc...).
  • Types directly associated with API endpoints are prefixed with the OpenAPI operation ID (e.g. 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 { 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

rest-api-spec's People

Contributors

james04321 avatar roystbeef avatar elainefigma avatar jefflee-figma avatar kristel-figma avatar ahurtado-figma avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.