CatchCase

Generate an OpenAPI spec from your code

Paste your route handlers, JSDoc comments or database schemas. Get a valid OpenAPI 3.0 spec in YAML, with parameters, request bodies and response schemas.

How to use it

  1. Collect the route code and schemas Copy the routing code, controller files and TypeScript types or schemas for the endpoints you want documented.
  2. Paste the code and run the case Paste the fragments into the form. Include types, so request and response schemas are accurate.
  3. Validate and save the spec Paste the YAML into Swagger Editor to validate it, fix anything it flags, and save it to your repository.

The prompt

You are an expert backend engineer. I will provide you with source code from my backend application, including routing files, controllers, and comments/types. Generate a fully documented, valid OpenAPI 3.0 spec in YAML format. Source Code Fragments: [SOURCE_CODE] Make sure to: 1. Document all parameters, request bodies, and responses. 2. Use correct schemas and types (e.g. string, integer). 3. Provide ONLY valid YAML without markdown wrapping unless requested.

Example result

openapi: 3.0.3
info:
  title: Harbour Desk Bookings API
  version: 1.0.0
  description: Create, list, view and cancel meeting room bookings.
servers:
  - url: https://api.harbourdesk.example/v1
security:
  - bearerAuth: []
paths:
  /bookings:
    get:
      summary: List bookings
      operationId: listBookings
      parameters:
        - name: status
          in: query
          required: false
          schema:
            type: string
            enum: [confirmed, cancelled]
        - name: from
          in: query
          required: false
          description: Only bookings starting on or after this date
          schema:
            type: string
            format: date
      responses:
        '200':
          description: Bookings matching the filters
          content:
            application/json:
              schema:
                type: array
                items:
                  $ref: '#/components/schemas/Booking'
        '401':
          $ref: '#/components/responses/Unauthorized'
    post:
      summary: Create a booking
      operationId: createBooking
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/NewBooking'
      responses:
        '201':
          description: Booking created
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Booking'
        '400':
          $ref: '#/components/responses/BadRequest'
        '401':
          $ref: '#/components/responses/Unauthorized'
  /bookings/{id}:
    parameters:
      - name: id
        in: path
        required: true
        schema:
          type: string
          format: uuid
    get:
      summary: Get a booking
      operationId: getBooking
      responses:
        '200':
          description: The booking
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Booking'
        '401':
          $ref: '#/components/responses/Unauthorized'
        '404':
          $ref: '#/components/responses/NotFound'
    delete:
      summary: Cancel a booking
      operationId: cancelBooking
      responses:
        '204':
          description: Booking cancelled
        '401':
          $ref: '#/components/responses/Unauthorized'
        '404':
          $ref: '#/components/responses/NotFound'
        '409':
          description: The booking has already started and can't be cancelled
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
components:
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer
      bearerFormat: JWT
  schemas:
    Booking:
      type: object
      required: [id, roomId, start, end, guests, status, createdAt]
      properties:
        id:
          type: string
          format: uuid
        roomId:
          type: string
        start:
          type: string
          format: date-time
        end:
          type: string
          format: date-time
        guests:
          type: integer
          minimum: 1
          maximum: 20
        status:
          type: string
          enum: [confirmed, cancelled]
        createdAt:
          type: string
          format: date-time
    NewBooking:
      type: object
      required: [roomId, start, end, guests]
      properties:
        roomId:
          type: string
        start:
          type: string
          format: date-time
        end:
          type: string
          format: date-time
        guests:
          type: integer
          minimum: 1
          maximum: 20
    Error:
      type: object
      required: [error, code]
      properties:
        error:
          type: string
        code:
          type: string
  responses:
    BadRequest:
      description: The request body is invalid
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'
    Unauthorized:
      description: Missing or invalid bearer token
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'
    NotFound:
      description: No booking with this id
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'

Related cases