1 | |
2 | |
3 | * Validate an API |
4 | * Validates an API definition for uploading to your ReadMe project. |
5 | */ |
6 | export async function main(auth: RT.Readme, body: Body) { |
7 | const url = new URL(`https://api.readme.com/v2/validate/api`) |
8 |
|
9 | const formData = new FormData() |
10 | for (const [k, v] of Object.entries(body)) { |
11 | if (v !== undefined && v !== '') { |
12 | formData.append(k, String(v)) |
13 | } |
14 | } |
15 | const response = await fetch(url, { |
16 | method: 'POST', |
17 | headers: { |
18 | Authorization: 'Bearer ' + auth.apiKey |
19 | }, |
20 | body: formData |
21 | }) |
22 | if (!response.ok) { |
23 | const text = await response.text() |
24 | throw new Error(`${response.status} ${text}`) |
25 | } |
26 | return await response.json() |
27 | } |
28 |
|
29 | |
30 | |
31 | * This file was automatically generated by json-schema-to-typescript. |
32 | * DO NOT MODIFY IT BY HAND. Instead, modify the source JSONSchema file, |
33 | * and run json-schema-to-typescript to regenerate this file. |
34 | */ |
35 |
|
36 | |
37 | * The API definition to upload. We provide full support for OpenAPI 3.x and Swagger 2.0 and experimental support for Postman collections. |
38 | */ |
39 | export interface Body { |
40 | |
41 | * The API definition. |
42 | */ |
43 | schema?: { |
44 | [k: string]: unknown |
45 | } |
46 | |
47 | * The source that the API definition is being uploaded through. |
48 | */ |
49 | upload_source?: string |
50 | |
51 | * The URL where the API definition is hosted. |
52 | */ |
53 | url?: { |
54 | [k: string]: unknown |
55 | } |
56 | } |
57 |
|