A typed router for express based on type definitions from openapi-typegen
yarn add @sebspark/openapi-express`
or
npm install @sebspark/openapi-express`
import express from 'express'
import { TypedRouter } from '@sebspark/openapi-express'
import { MarketdataServer } from './schemas/marketdata'
import { getMarkets, getMarket } from './markets'
const api: MarketdataServer = {
'/markets': {
get: {
handler: async () => {
const markets = await getMarkets()
return [200, {data: markets}]
},
},
},
'/markets/:id': {
get: {
handler: async ({ params }) => {
const market = await getMarket(params.id)
return [200, {data: market}]
},
},
},
}
const router = TypedRouter(api)
const app = express()
app.use(router)
Example can be found in @sebspark/openapi-e2e