Skip to content

Commit 9fecd06

Browse files
authored
Add README and contribution guidelines (#1)
1 parent 7a88e2d commit 9fecd06

File tree

2 files changed

+41
-1
lines changed

2 files changed

+41
-1
lines changed

CONTRIBUTING.md

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# Contributing
2+
3+
If you notice any inaccuracies with the OpenAPI specification or Typescript types, please [file an issue](https://github.com/figma/rest-api-spec/issues).
4+
5+
For bug reports and feature requests for the Figma REST API itself, please [contact Figma support](https://help.figma.com/hc/en-us/requests/new).
6+
7+
Since the specification is auto-generated, we are not accepting pull requests in this repository.

README.md

+34-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,35 @@
11
# rest-api-spec
2-
OpenAPI specification and typings for the Figma REST API
2+
3+
This repository contains the OpenAPI specification and Typescript types for the [Figma REST API](https://www.figma.com/developers/api).
4+
5+
[Changelog](https://www.figma.com/developers/api#changelog)
6+
7+
Note: this specification is currently in beta. If you notice any inaccuracies with the specification, please [file an issue](https://github.com/figma/rest-api-spec/issues) in this repository.
8+
9+
## Usage
10+
11+
The OpenAPI (v3.1.0) specification is located in the `openapi/` directory. This specification can be used with a [wide variety of tools](https://tools.openapis.org/) to generate API documentation, client SDKs, and more.
12+
13+
The Typescript types are generated from the OpenAPI specification and are located in `dist/`.
14+
15+
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:
16+
17+
- 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...).
18+
- 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`).
19+
20+
To use these types in your Typescript code, install the package:
21+
22+
```sh
23+
npm install --save-dev @figma/rest-api-spec
24+
```
25+
26+
Then import the types that you need:
27+
28+
```ts
29+
import { GetFileResponse } from '@figma/rest-api-spec'
30+
31+
// Many popular HTTP clients let you annotate response types
32+
const result = await axios.get<GetFileResponse>(url);
33+
result.data // This has type GetFileResponse
34+
```
35+

0 commit comments

Comments
 (0)