Skip to content

Commit b34a4b9

Browse files
committed
Export JS with JSON included
Removes the dependency on a runtime with fs access
1 parent 5cdeca0 commit b34a4b9

File tree

5 files changed

+43
-14
lines changed

5 files changed

+43
-14
lines changed

README.md

+5-1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@ This repo contains the OpenAPI specifications for Directus' API.
44

55
The static spec in this repo contains all the system endpoints and a definition for a generic `/items/{collection}` endpoint.
66

7+
## Usage
8+
9+
The spec is exported in 3 formats: `.yaml`, `.json`, and `.js`. The JS file is just an `export` of the same JSON but parsed into JS for ease of use in JS projects.
10+
711
## Requirements
812

913
The specification is written to work with OpenAPI version 3 and up.
@@ -18,4 +22,4 @@ Key that maps a system endpoint to its corresponding system collection.
1822

1923
### `x-codeSamples`
2024

21-
Examples of how to use the equivalent of the documented REST endpoint in the JS SDK and/or GraphQL endpoint.
25+
Examples of how to use the equivalent of the documented REST endpoint in the JS SDK and/or GraphQL endpoint.

index.js

-7
This file was deleted.

package.json

+4-2
Original file line numberDiff line numberDiff line change
@@ -10,21 +10,23 @@
1010
},
1111
"funding": "https://github.com/directus/directus?sponsor=1",
1212
"exports": {
13-
".": "./index.js",
13+
".": "./dist/index.js",
1414
"./package.json": "./package.json",
1515
"./oas.yaml": "./dist/oas.yaml",
1616
"./oas.json": "./dist/oas.json"
1717
},
1818
"main": "index.js",
1919
"scripts": {
2020
"dev": "nodemon --watch './openapi/**/*.yaml' --exec 'redocly bundle ./openapi/index.yaml -o ./dist/index.yaml && pnpm scalar serve ./dist/oas.yaml -p 5001' --ext yaml",
21-
"build": "redocly bundle ./openapi/index.yaml -o ./dist/oas.yaml && redocly bundle ./openapi/index.yaml -o ./dist/oas.json --ext json",
21+
"build": "redocly bundle ./openapi/index.yaml -o ./dist/oas.yaml && redocly bundle ./openapi/index.yaml -o ./dist/oas.json --ext json && jiti scripts/build-js.ts",
2222
"lint": "redocly lint --max-problems=1000 ./openapi/oas.yaml"
2323
},
2424
"license": "MIT",
2525
"devDependencies": {
2626
"@redocly/cli": "1.26.0",
2727
"@scalar/cli": "0.2.272",
28+
"@types/node": "22.10.2",
29+
"jiti": "2.4.2",
2830
"nodemon": "3.1.9",
2931
"openapi3-ts": "4.4.0"
3032
}

pnpm-lock.yaml

+27-4
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

scripts/build-js.ts

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import { readFileSync, writeFileSync } from 'node:fs';
2+
3+
const jsonString = readFileSync('./dist/oas.json');
4+
5+
const js = `export const spec = ${jsonString};`
6+
7+
writeFileSync('./dist/index.js', js);

0 commit comments

Comments
 (0)