Skip to content

Commit 07a9937

Browse files
committed
chore: added openapi spec
1 parent 492bcbe commit 07a9937

File tree

2 files changed

+312
-1
lines changed

2 files changed

+312
-1
lines changed

scripts/build.ts

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { dirname, join } from 'node:path'
33
import { marked } from 'marked'
44
import { mkdirp } from 'mkdirp'
55
import slugify from 'slugify'
6-
import { parse } from 'yaml'
6+
import { parse, stringify } from 'yaml'
77

88
const slug = slugify.default
99
const REPO_URL = 'https://github.com/FullStackBulletin/fullstack-books'
@@ -22,6 +22,22 @@ await Promise.all([mkdirp(destPath), mkdirp(booksPath), mkdirp(authorsPath)])
2222
await cp(srcCoversPath, coversPath, { recursive: true })
2323
console.log(`Copied ${srcCoversPath} to ${coversPath}`)
2424

25+
// load and parse package.json
26+
const pkgPath = join(__dirname, '..', 'package.json')
27+
const pkg = JSON.parse(await readFile(pkgPath, 'utf-8'))
28+
29+
// load and parse the openapi spec
30+
const openapiPath = join(__dirname, '..', 'src', 'openapi.yml')
31+
const openApiData = parse(await readFile(openapiPath, 'utf-8'))
32+
openApiData.info.version = pkg.version // sync package.json version with openapi spec
33+
await writeFile(
34+
`${destPath}/openapi.json`,
35+
JSON.stringify(openApiData, null, 2),
36+
)
37+
console.log(`Written ${destPath}/openapi.json`)
38+
await writeFile(`${destPath}/openapi.yml`, stringify(openApiData))
39+
console.log(`Written ${destPath}/openapi.yml`)
40+
2541
// load and parse raw data from source file
2642
const sourcePath = join(__dirname, '..', 'src', 'books.yml')
2743
const rawData = parse(await readFile(sourcePath, 'utf-8'))

src/openapi.yml

Lines changed: 295 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,295 @@
1+
openapi: 3.1.0
2+
3+
servers:
4+
- description: Production
5+
url: https://fullstackbulletin.github.io/fullstack-books/
6+
7+
info:
8+
title: The full-stack books API
9+
version: 1.0.0
10+
description: A collection of books curated for full-stack developers and aspiring ones. Brought to you by FullStackBulletin
11+
contact:
12+
name: FullStack Bulletin
13+
url: https://fullstackbulletin.com
14+
15+
license:
16+
name: MIT
17+
url: https://github.com/FullStackBulletin/fullstack-books/blob/main/LICENSE
18+
19+
paths:
20+
/authors/ids.json:
21+
get:
22+
summary: Retrieve all the ids of the available book authors
23+
description: Retrieve all the ids of the available book authors
24+
operationId: getAllAuthorsIds
25+
responses:
26+
"200":
27+
description: OK
28+
content:
29+
application/json:
30+
schema:
31+
$ref: '#/components/schemas/AuthorIDs'
32+
33+
/authors/all.json:
34+
get:
35+
summary: Retrieve all the available book authors
36+
description: Retrieve all the available book authors
37+
operationId: getAllAuthors
38+
responses:
39+
"200":
40+
description: OK
41+
content:
42+
application/json:
43+
schema:
44+
type: array
45+
items:
46+
$ref: '#/components/schemas/Author'
47+
48+
/authors/stats.json:
49+
get:
50+
summary: Retrieve stats about the available book authors
51+
description: Retrieve stats about the available book authors
52+
operationId: getAuthorsStats
53+
responses:
54+
"200":
55+
description: OK
56+
content:
57+
application/json:
58+
schema:
59+
$ref: '#/components/schemas/Stats'
60+
61+
/authors/{authorId}.json:
62+
get:
63+
summary: Retrieve the details of a given author
64+
description: Retrieve the details of a given author
65+
operationId: getAuthor
66+
parameters:
67+
- in: path
68+
name: authorId
69+
required: true
70+
schema:
71+
$ref: '#/components/schemas/Author/properties/slug'
72+
responses:
73+
"200":
74+
description: OK
75+
content:
76+
application/json:
77+
schema:
78+
$ref: '#/components/schemas/AuthorWithBooks'
79+
80+
/books/ids.json:
81+
get:
82+
summary: Retrieve all the ids of the available books
83+
description: Retrieve all the ids of the available books
84+
operationId: getAllBookIds
85+
responses:
86+
"200":
87+
description: OK
88+
content:
89+
application/json:
90+
schema:
91+
$ref: '#/components/schemas/BookIDs'
92+
93+
/books/all.json:
94+
get:
95+
summary: Retrieve all the available books
96+
description: Retrieve all the available books
97+
operationId: getAllBooks
98+
responses:
99+
"200":
100+
description: OK
101+
content:
102+
application/json:
103+
schema:
104+
type: array
105+
items:
106+
$ref: '#/components/schemas/Book'
107+
108+
/books/stats.json:
109+
get:
110+
summary: Retrieve stats about the available books
111+
description: Retrieve stats about the available books
112+
operationId: getBooksStats
113+
responses:
114+
"200":
115+
description: OK
116+
content:
117+
application/json:
118+
schema:
119+
$ref: '#/components/schemas/Stats'
120+
121+
/books/{bookId}.json:
122+
get:
123+
summary: Retrieve the details of a given book
124+
description: Retrieve the details of a given book
125+
operationId: getBook
126+
parameters:
127+
- in: path
128+
name: bookId
129+
required: true
130+
schema:
131+
$ref: '#/components/schemas/Book/properties/slug'
132+
responses:
133+
"200":
134+
description: OK
135+
content:
136+
application/json:
137+
schema:
138+
$ref: '#/components/schemas/Book'
139+
140+
components:
141+
schemas:
142+
AuthorIDs:
143+
type: array
144+
items:
145+
$ref: '#/components/schemas/Author/properties/slug'
146+
147+
Stats:
148+
type: object
149+
properties:
150+
total:
151+
type: number
152+
examples:
153+
- 174
154+
all:
155+
type: string
156+
format: uri
157+
examples:
158+
- https://fullStackbulletin.github.io/fullstack-books/authors/all.json
159+
ids:
160+
type: string
161+
format: uri
162+
examples:
163+
- https://fullStackbulletin.github.io/fullstack-books/authors/ids.json
164+
urlPrefix:
165+
type: string
166+
format: uri
167+
examples:
168+
- https://fullStackbulletin.github.io/fullstack-books/authors
169+
170+
Author:
171+
type: object
172+
properties:
173+
name:
174+
type: string
175+
examples:
176+
- Kent Beck
177+
- Tom Greever
178+
- Don Norman
179+
slug:
180+
type: string
181+
examples:
182+
- kent-back
183+
- tom-greever
184+
- don-norman
185+
url:
186+
type: string
187+
format: uri
188+
examples:
189+
- https://fullStackbulletin.github.io/fullstack-books/authors/kent-back.json
190+
- https://fullStackbulletin.github.io/fullstack-books/authors/tom-greever.json
191+
- https://fullStackbulletin.github.io/fullstack-books/authors/don-norman.json
192+
193+
AuthorWithBooks:
194+
type: object
195+
properties:
196+
name:
197+
type: string
198+
examples:
199+
- Kent Beck
200+
- Tom Greever
201+
- Don Norman
202+
slug:
203+
type: string
204+
examples:
205+
- kent-back
206+
- tom-greever
207+
- don-norman
208+
url:
209+
type: string
210+
format: uri
211+
examples:
212+
- https://fullStackbulletin.github.io/fullstack-books/authors/kent-back.json
213+
- https://fullStackbulletin.github.io/fullstack-books/authors/tom-greever.json
214+
- https://fullStackbulletin.github.io/fullstack-books/authors/don-norman.json
215+
books:
216+
type: array
217+
items:
218+
$ref: '#/components/schemas/Book'
219+
220+
BookIDs:
221+
type: array
222+
items:
223+
$ref: '#/components/schemas/Book/properties/slug'
224+
225+
Book:
226+
type: object
227+
properties:
228+
slug:
229+
type: string
230+
examples:
231+
- indistractable-1-nir-eyal
232+
- learn-react-with-typescript-second-edition-2-carl-rippon
233+
- node-cookbook-4-bethany-griggs
234+
title:
235+
type: string
236+
examples:
237+
- Indistractable
238+
- Learn React with TypeScript - Second Edition
239+
- Node Cookbook
240+
subtitle:
241+
type: string
242+
examples:
243+
- ""
244+
- A beginner's guide to reactive web development with React 18 and TypeScript
245+
- Discover solutions, techniques, and best practices for server-side web development with Node.js 14
246+
edition:
247+
type: number
248+
examples:
249+
- 1
250+
- 2
251+
- 3
252+
- 4
253+
authors:
254+
type: array
255+
$ref: '#/components/schemas/Author'
256+
cover:
257+
type: string
258+
format: uri
259+
examples:
260+
- https://fullStackbulletin.github.io/fullstack-books/covers/indistractable-1-nir-eyal.jpg
261+
- https://fullStackbulletin.github.io/fullstack-books/covers/learn-react-with-typescript-second-edition-2-carl-rippon.jpg
262+
- https://fullStackbulletin.github.io/fullstack-books/covers/node-cookbook-4-bethany-griggs.jpg
263+
links:
264+
type: object
265+
properties:
266+
amazon_us:
267+
type: string
268+
format: uri
269+
examples:
270+
- https://www.amazon.com/dp/1526610205
271+
- https://www.amazon.com/dp/1804614203
272+
- https://www.amazon.com/dp/1838558756
273+
amazon_uk:
274+
type: string
275+
format: uri
276+
examples:
277+
- https://www.amazon.co.uk/dp/1526610205
278+
- https://www.amazon.co.uk/dp/1804614203
279+
- https://www.amazon.co.uk/dp/1838558756
280+
free:
281+
type: string
282+
format: uri
283+
examples:
284+
- https://marabos.nl/atomics/foreword.html
285+
description:
286+
type: string
287+
url:
288+
type: string
289+
format: uri
290+
examples:
291+
- https://fullStackbulletin.github.io/fullstack-books/books/Indistractable.json
292+
- https://fullStackbulletin.github.io/fullstack-books/books/Learn-React-with-TypeScript-Second-Edition.json
293+
- https://fullStackbulletin.github.io/fullstack-books/books/Node-Cookbook.json
294+
descriptionHtml:
295+
type: string

0 commit comments

Comments
 (0)