File tree Expand file tree Collapse file tree
apps/api/src/routes/content Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ import type { FastifyPluginAsync } from "fastify" ;
2+ import { Type , type TSchema } from "typebox" ;
3+
4+ export const createSchemaRoute = (
5+ path : string ,
6+ description : string ,
7+ schema : TSchema ,
8+ ) : FastifyPluginAsync => {
9+ const responseSchema = Type . Object (
10+ { } ,
11+ {
12+ additionalProperties : true ,
13+ description,
14+ examples : [ schema ] ,
15+ } ,
16+ ) ;
17+
18+ return async ( fastify ) => {
19+ fastify . get (
20+ path ,
21+ {
22+ schema : {
23+ description,
24+ response : {
25+ 200 : {
26+ description : "Successful" ,
27+ content : {
28+ "application/json" : {
29+ schema : responseSchema ,
30+ } ,
31+ } ,
32+ } ,
33+ } ,
34+ } ,
35+ } ,
36+ async ( _request , reply ) => {
37+ reply . code ( 200 ) ;
38+ reply . send ( schema ) ;
39+ } ,
40+ ) ;
41+ } ;
42+ } ;
Original file line number Diff line number Diff line change 1- import type { FastifyPluginAsync } from "fastify" ;
2- import { Type } from "typebox" ;
31import { AuthorMetaSchema } from "../../../../worker/src/tasks/sync-author/types.ts" ;
2+ import { createSchemaRoute } from "./createSchemaRoute.ts" ;
43
5- const SchemaAuthorResponseSchema = Type . Object (
6- { } ,
7- {
8- additionalProperties : true ,
9- description : "A JSON Schema document describing valid author frontmatter." ,
10- examples : [ AuthorMetaSchema ] ,
11- } ,
4+ const schemaAuthorRoutes = createSchemaRoute (
5+ "/content/schema/author" ,
6+ "Fetch the JSON Schema for author frontmatter, as validated by the sync worker." ,
7+ AuthorMetaSchema ,
128) ;
139
14- const schemaAuthorRoutes : FastifyPluginAsync = async ( fastify ) => {
15- fastify . get (
16- "/content/schema/author" ,
17- {
18- schema : {
19- description :
20- "Fetch the JSON Schema for author frontmatter, as validated by the sync worker." ,
21- response : {
22- 200 : {
23- description : "Successful" ,
24- content : {
25- "application/json" : {
26- schema : SchemaAuthorResponseSchema ,
27- } ,
28- } ,
29- } ,
30- } ,
31- } ,
32- } ,
33- async ( _request , reply ) => {
34- reply . code ( 200 ) ;
35- reply . send ( AuthorMetaSchema ) ;
36- } ,
37- ) ;
38- } ;
39-
4010export default schemaAuthorRoutes ;
Original file line number Diff line number Diff line change 1- import type { FastifyPluginAsync } from "fastify" ;
2- import { Type } from "typebox" ;
31import { CollectionMetaSchema } from "../../../../worker/src/tasks/sync-collection/types.ts" ;
2+ import { createSchemaRoute } from "./createSchemaRoute.ts" ;
43
5- const SchemaCollectionResponseSchema = Type . Object (
6- { } ,
7- {
8- additionalProperties : true ,
9- description :
10- "A JSON Schema document describing valid collection frontmatter." ,
11- examples : [ CollectionMetaSchema ] ,
12- } ,
4+ const schemaCollectionRoutes = createSchemaRoute (
5+ "/content/schema/collection" ,
6+ "Fetch the JSON Schema for collection frontmatter, as validated by the sync worker." ,
7+ CollectionMetaSchema ,
138) ;
149
15- const schemaCollectionRoutes : FastifyPluginAsync = async ( fastify ) => {
16- fastify . get (
17- "/content/schema/collection" ,
18- {
19- schema : {
20- description :
21- "Fetch the JSON Schema for collection frontmatter, as validated by the sync worker." ,
22- response : {
23- 200 : {
24- description : "Successful" ,
25- content : {
26- "application/json" : {
27- schema : SchemaCollectionResponseSchema ,
28- } ,
29- } ,
30- } ,
31- } ,
32- } ,
33- } ,
34- async ( _request , reply ) => {
35- reply . code ( 200 ) ;
36- reply . send ( CollectionMetaSchema ) ;
37- } ,
38- ) ;
39- } ;
40-
4110export default schemaCollectionRoutes ;
Original file line number Diff line number Diff line change 1- import type { FastifyPluginAsync } from "fastify" ;
2- import { Type } from "typebox" ;
31import { PostMetaSchema } from "../../../../worker/src/tasks/sync-post/types.ts" ;
2+ import { createSchemaRoute } from "./createSchemaRoute.ts" ;
43
5- const SchemaPostResponseSchema = Type . Object (
6- { } ,
7- {
8- additionalProperties : true ,
9- description : "A JSON Schema document describing valid post frontmatter." ,
10- examples : [ PostMetaSchema ] ,
11- } ,
4+ const schemaPostRoutes = createSchemaRoute (
5+ "/content/schema/post" ,
6+ "Fetch the JSON Schema for post frontmatter, as validated by the sync worker." ,
7+ PostMetaSchema ,
128) ;
139
14- const schemaPostRoutes : FastifyPluginAsync = async ( fastify ) => {
15- fastify . get (
16- "/content/schema/post" ,
17- {
18- schema : {
19- description :
20- "Fetch the JSON Schema for post frontmatter, as validated by the sync worker." ,
21- response : {
22- 200 : {
23- description : "Successful" ,
24- content : {
25- "application/json" : {
26- schema : SchemaPostResponseSchema ,
27- } ,
28- } ,
29- } ,
30- } ,
31- } ,
32- } ,
33- async ( _request , reply ) => {
34- reply . code ( 200 ) ;
35- reply . send ( PostMetaSchema ) ;
36- } ,
37- ) ;
38- } ;
39-
4010export default schemaPostRoutes ;
You can’t perform that action at this time.
0 commit comments