Skip to content

Commit

Permalink
added documentation for defineRouteMeta
Browse files Browse the repository at this point in the history
  • Loading branch information
eriksLapins committed Jan 22, 2024
1 parent 4b6f151 commit 21264e2
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 0 deletions.
1 change: 1 addition & 0 deletions docs/content/1.guide/2.auto-imports.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ Nitro is using [unjs/unimport](https://github.com/unjs/unimport) to auto import
- `defineCachedFunction(fn, options)`{lang=ts} / `cachedFunction(fn, options)`{lang=ts}
- `defineCachedEventHandler(handler, options)`{lang=ts} / `cachedEventHandler(handler, options)`{lang=ts}
- `defineRenderHandler(handler)`{lang=ts}
- `defineRouteMeta(options)`{lang=ts}
- `useRuntimeConfig(event?)`{lang=ts}
- `useAppConfig(event?)`{lang=ts}
- `useStorage(base?)`{lang=ts}
Expand Down
30 changes: 30 additions & 0 deletions docs/content/1.guide/3.routing.md
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,36 @@ export default defineEventHandler((event) => {
Returning anything from a middleware will close the request and should be avoided! Any returned value from middleware will be the response and further code will not be executed however **this is not recommended to do!**
::

### Route Meta

A function that takes in a ServerRouteMeta object and adds it to route meta during build time.

At the moment it is only used to better define the experimental OpenAPI documentation for server routes, but can also be used to add useful params to your routes.

```ts [/api/test.get.ts]
defineRouteMeta({
openAPI: {
tags: ["Nitro Server Routes"],
summary: "Routes for Nitro",
description: "Some longer description for the specific route",
responses: [
200: {
description: "OK",
},
404: {
description: "Not found",
},
],
},
});
```

You do not need to import `defineRouteMeta` as it is automatically imported thanks to [auto-import feature](/auto-imports).

::alert(type=info)
You do not need to specify the method and the route in the openAPI specification since that will be extracted automatically from the route.
::

### Execution Order

Middleware are executed in directory listing order.
Expand Down
4 changes: 4 additions & 0 deletions docs/content/3.config.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,10 @@ Enable experimental features.

Enable `/_nitro/swagger` and `/_nitro/openapi.json` endpoints.

You can adjust/modify the output by inputting the options in `defineRouteMeta()` (auto imported) under openAPI.

Follow the [openapi-typescript OperationObject type](https://github.com/drwpow/openapi-typescript/blob/main/packages/openapi-typescript/src/types.ts) or [swagger 3.0 specification](https://swagger.io/specification/v3/) to see the available options.

#### `wasm`

Enable WASM support
Expand Down

0 comments on commit 21264e2

Please sign in to comment.