Skip to content

Commit

Permalink
Add openapi.yaml support (#119)
Browse files Browse the repository at this point in the history
  • Loading branch information
G4brym authored Jan 29, 2024
1 parent e1272be commit 665b38e
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 129 deletions.
189 changes: 60 additions & 129 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@
"dependencies": {
"@asteasolutions/zod-to-openapi": "^5.3.1",
"itty-router": "4.0.26",
"js-yaml": "^4.1.0",
"openapi3-ts": "^4.1.2",
"zod": "^3.21.4"
}
Expand Down
13 changes: 13 additions & 0 deletions src/openapi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import { OpenAPIRegistryMerger } from './zod/registry'
import { z } from 'zod'
import { OpenAPIObject } from 'openapi3-ts/oas31'
import { OpenAPIRoute } from './route'
const yaml = require('js-yaml')

export type Route = <
RequestType = IRequest,
Expand Down Expand Up @@ -240,6 +241,18 @@ export function OpenAPIRouter<
status: 200,
})
})

router.get(
(options?.openapi_url || '/openapi.json').replace('.json', '.yaml'),
() => {
return new Response(yaml.dump(getGeneratedSchema()), {
headers: {
'content-type': 'text/yaml;charset=UTF-8',
},
status: 200,
})
}
)
}

if (options?.aiPlugin && options?.openapi_url !== null) {
Expand Down

0 comments on commit 665b38e

Please sign in to comment.