Skip to content

Update response body with properties to the generated OpenAPI Specification #2274

Description

@nickspaargaren

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

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:
Screenshot 2024-03-17 at 19 29 21
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?

Activity

  1. added
    pending triage
    on Mar 17, 2024
  2. added
    enhancement
    and removed
    pending triage
    on Sep 2, 2026
  3. added and removed on Oct 17, 2026
  4. added
    openapi
    and removed
    enhancement
    on Nov 10, 2026
  5. added theissue type on Nov 10, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    openapi

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions