Skip to content

Commit 40bee3c

Browse files
committed
expose schema on source route
1 parent 3619104 commit 40bee3c

File tree

3 files changed

+13
-6
lines changed

3 files changed

+13
-6
lines changed

app/api/source/route.ts

+7-5
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,21 @@
11
import { join, resolve } from 'path'
22
import { NextResponse } from 'next/server'
33
import { glob } from 'glob'
4+
import { generateSchema } from '@anatine/zod-openapi'
5+
import { sources } from '@/sources'
46

57
export const GET = async (req: Request) => {
68
const { searchParams } = new URL(req.url)
79
const id = searchParams.get('id')
8-
9-
console.log('id', id)
10+
const source = sources.find((s) => s.id === id)
1011

1112
const basePath = join(resolve('./data'), id as string)
1213
const path = join(basePath, '**')
1314

14-
console.log('path', path)
1515
const files = await glob(path, { nodir: true })
1616

17-
console.log('files', files)
18-
return NextResponse.json(files.map((f) => f.replace(basePath, '').replace(/^\//, '')))
17+
return NextResponse.json({
18+
files: files.map((f) => f.replace(basePath, '').replace(/^\//, '')),
19+
schema: source?.schema ? generateSchema(source.schema) : undefined
20+
})
1921
}

sources/rigoletto/index.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
import { Source } from '../../types'
2+
import { rigolettoSchema } from './schema'
23

34
export const Rigoletto: Source = {
45
id: 'rigoletto',
56
name: 'Rigoletto',
67
description: 'Datenbank wassergefährdende Stoffe',
78
sourceName: 'Umweltbundesamt',
8-
sourceLink: 'https://webrigoletto.uba.de/Rigoletto/'
9+
sourceLink: 'https://webrigoletto.uba.de/Rigoletto/',
10+
schema: rigolettoSchema
911
}

types/index.ts

+3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import { ZodSchema } from 'zod'
2+
13
export type Exporter<ResultType = unknown> = () => Promise<
24
Array<{
35
targetFile: string
@@ -16,4 +18,5 @@ export interface Source {
1618
description: string
1719
sourceName: string
1820
sourceLink: string
21+
schema?: ZodSchema
1922
}

0 commit comments

Comments
 (0)