@enzopita/adonisjs-openapi 0.2.0 → 0.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +7 -3
- package/build/src/generate.js +5 -4
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -59,7 +59,7 @@ export default defineConfig({
|
|
|
59
59
|
- `routes` takes `only` or `except`, with the same matchers as Tuyau's `generateRegistry()`: a substring, a regular expression, or a function of the route name.
|
|
60
60
|
- `info` is the OpenAPI Info Object: `title` and `version`, and optionally `summary`, `description`, `termsOfService`, `contact` and `license`.
|
|
61
61
|
- `tags` is copied to the document's top-level `tags`. Use it to describe the tags operations use and to set their order.
|
|
62
|
-
- `middlewareSecurity` maps a named middleware, such as `middleware.auth()`, to a key of `securitySchemes`. Routes behind it get the scheme in `security` and a `401` response.
|
|
62
|
+
- `middlewareSecurity` maps a named middleware, such as `middleware.auth()`, to a key of `securitySchemes`. Routes behind it get the scheme in `security` and a `401` response. A route behind several mapped middleware, such as `middleware.auth()` and `middleware.tenant()`, requires all their schemes together: they share one Security Requirement Object.
|
|
63
63
|
|
|
64
64
|
## Serve a docs page
|
|
65
65
|
|
|
@@ -80,7 +80,11 @@ openapiRoutes().use(middleware.auth({ guards: ['basic'] }))
|
|
|
80
80
|
|
|
81
81
|
`openapiRoutes()` returns the route group, so `.use()`, `.domain()`, `.prefix()` and `.as()` work on it. `.as('admin')` names the routes `admin.openapi.ui` and `admin.openapi.document`.
|
|
82
82
|
|
|
83
|
-
The page loads the document from a URL relative to the page, so it keeps working behind a proxy that serves the app under a path prefix. The generator leaves both routes out of the document, as it does every closure route.
|
|
83
|
+
The page loads the document from a URL relative to the page, so it keeps working behind a proxy that serves the app under a path prefix. The generator leaves both routes out of the document, as it does every closure route. Tuyau keeps named closure routes, so they appear in its client registry. To leave them out, exclude them where `adonisrc.ts` calls `generateRegistry()`:
|
|
84
|
+
|
|
85
|
+
```ts
|
|
86
|
+
generateRegistry({ routes: { except: [/^openapi\./] } })
|
|
87
|
+
```
|
|
84
88
|
|
|
85
89
|
### Turn the page on or off
|
|
86
90
|
|
|
@@ -249,7 +253,7 @@ When `.adonisjs/client/data.d.ts` exists, every type in its `Data` namespace bec
|
|
|
249
253
|
|
|
250
254
|
## How types become schemas
|
|
251
255
|
|
|
252
|
-
- A route must have a name and a controller handler. Closure routes are skipped
|
|
256
|
+
- A route must have a name and a controller handler. Closure routes are skipped.
|
|
253
257
|
- On `GET` routes, the validator fields become query parameters. On other methods they become the body, and the validator's `query` and `params` objects become query and path parameters.
|
|
254
258
|
- A body with a `vine.file()` field is sent as `multipart/form-data`.
|
|
255
259
|
- When VineJS cannot describe a field (a file, a custom rule), the generator uses the field's TypeScript type.
|
package/build/src/generate.js
CHANGED
|
@@ -115,10 +115,11 @@ export async function generateDocument(app, router, config) {
|
|
|
115
115
|
const body = readsQueryOnly ? undefined : fields;
|
|
116
116
|
const query = readsQueryOnly ? fields : input?.properties?.query;
|
|
117
117
|
const parameters = parametersFor(route, query, input?.properties?.params);
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
118
|
+
// Entries of `security` are alternatives, so the schemes a route requires together share one entry.
|
|
119
|
+
const schemes = route.middleware.flatMap(name => config.middlewareSecurity[name] ?? []);
|
|
120
|
+
const security = schemes.length
|
|
121
|
+
? [Object.fromEntries(schemes.map(scheme => [scheme, []]))]
|
|
122
|
+
: [];
|
|
122
123
|
const { responses: thrown, ...docs } = types.docs(route);
|
|
123
124
|
const operation = {
|
|
124
125
|
...docs,
|