Skip to content

Commit

Permalink
fix(openapi): handle same pattern for multiple endpoints
Browse files Browse the repository at this point in the history
  • Loading branch information
Julien-R44 committed May 20, 2024
1 parent fb9e904 commit cc62c62
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 4 deletions.
2 changes: 1 addition & 1 deletion packages/openapi/src/generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ export class OpenApiGenerator {
return {
method,
path: openApiPath,
spec: defu(this.metaStore.getComputed(options.path), {
spec: defu(this.metaStore.getComputed({ method, path: options.path }), {
...parameters,
responses: objectMap(responses, (status, schema) => {
return [
Expand Down
9 changes: 6 additions & 3 deletions packages/openapi/src/meta_store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,16 @@ export class MetaStore {
return this.#store.get(key)
}

getComputed(key: string) {
return this.#computedStore.get(key)
getComputed(options: { method: string; path: string }) {
return this.#computedStore.get(`${options.method.toUpperCase()}:${options.path}`)
}

compute() {
for (const [route, value] of this.#store) {
this.#computedStore.set(route.toJSON().pattern, value)
const serialized = route.toJSON()
for (const method of serialized.methods) {
this.#computedStore.set(`${method}:${serialized.pattern}`, value)
}
}
}
}
Expand Down
3 changes: 3 additions & 0 deletions playgrounds/openapi/start/routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ router
router.get('/random/:id', [MiscController, 'show']).openapi({
description: 'Get a random thing by id',
})
router.post('/random', [MiscController, 'store']).openapi({
description: 'Create a random thing',
})
})
.prefix('/misc')
.openapi({ tags: ['misc'] })

0 comments on commit cc62c62

Please sign in to comment.