Update response body with properties to the generated OpenAPI Specification
Nobody has claimed this yet.
- Dominant language
- TypeScript
- Stars
- 11.2k
- Forks
- 899
- Avg merge
- 2d 24m
- Merged PRs (30d)
- 40
Description
Describe the feature
Context
In addition to the response code "200" and description "OK" in the OpenAPI Specification I would love to see the return types of a handler as properties as well. I've included an example below.
Notes
- For now, the OpenAPI Specification is available with an experimental config for now.
- The OpenAPI specification is available on http://localhost:3000/_nitro/openapi.json
Documentation
Technical details
The (hardcoded for now) commented out lines are what I like to see implemented:
function getPaths(): PathsObject {
const paths: PathsObject = {};
for (const h of handlersMeta) {
const { route, parameters } = normalizeRoute(h.route);
const tags = defaultTags(h.route);
const method = (h.method || "get").toLowerCase();
const item: PathItemObject = {
[method]: <OperationObject>{
tags,
parameters,
responses: {
200: {
description: "OK",
// content: {
// "application/json": {
// schema: {
// properties: {
// success: {
// type: "boolean",
// },
// },
// },
// },
// },
},
},
},
};
if (paths[route] === undefined) {
paths[route] = item;
} else {
Object.assign(paths[route], item);
}
}
return paths;
}
File: https://github.com/unjs/nitro/blob/main/src/runtime/routes/openapi.ts
This results in an addition to Swagger with an Example Value as well:
http://localhost:3000/_nitro/swagger
Acceptance criteria
- The properties, return object of an eventHandler should be included and displayed in:
- The OpenAPI Specification
- The Swagger OpenAPI Specification
Additional information
- Would you be willing to help implement this feature?
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Read src/runtime/routes/openapi.ts and the linked OpenAPI response documentation first. Inspect how the generated /_nitro/openapi.json and /_nitro/swagger represent handler responses, then determine how eventHandler return objects can be included in response schemas. Done means response properties appear in both generated specifications.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- openapi, typescript
- Domain
- api
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100