Skip to content

Support empty media type objects (no schema, no examples) #10

@lanej

Description

@lanej

Support empty media type objects (no schema, no examples)

Summary

OpenAPI specs with completely empty media type objects (application/json: {}) fail generation with "empty schema not implemented" error. This is a valid OpenAPI pattern for responses where the structure is unknown, unspecified, or intentionally flexible.

Specs Affected

  • carriers/jitsu/specs/openapi.yaml - 19 locations with empty response content
  • Common in real-world APIs for default error responses or flexible success responses

Current Behavior

Minimal Reproduction

openapi: 3.0.1
info:
  title: Empty Media Type Test
  version: 1.0.0
paths:
  /shipments:
    post:
      operationId: createShipment
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              properties:
                tracking_number:
                  type: string
      responses:
        default:
          description: Default response
          content:
            application/json: {}
        '200':
          description: Success
          content:
            application/json: {}

Error Output

Feature "empty schema" is not implemented yet.
	ignore_not_implemented: ["empty schema"]
to skip unsupported operations.

Impact

  • Cannot generate complete clients for APIs with unspecified response structures
  • Requires using ignore_not_implemented: ["empty schema"] workaround
  • Skips entire operations rather than generating them with any type responses

Expected Behavior

When encountering application/json: {} (empty media type object):

  1. Generate as any type:

    type CreateShipmentOK any
    type CreateShipmentDefault any
  2. Or use empty struct for zero-schema responses:

    type CreateShipmentOK struct{}
    type CreateShipmentDefault struct{}
  3. Allow configuration:

    generator:
      empty_schema_handling: "any"  # or "empty_struct" or "skip"

Use Cases

Empty media type objects are valid in OpenAPI 3.x for:

  • Default error responses: Structure varies or is vendor-specific
  • Flexible success responses: API returns different shapes based on context
  • Legacy APIs: Documentation incomplete but API functional
  • Passthrough endpoints: Proxy/gateway patterns

Real-World Example (Jitsu API)

paths:
  /v3/parcels/{id}:
    delete:
      operationId: deleteParcel
      responses:
        default:
          description: default response
          content:
            application/json: {}  # Error structure unspecified
        2XX:
          description: default response
          content:
            application/json: {}  # Success - may be empty or vary

Comparison with Upstream

Checked ogen-go/ogen - this pattern also fails there. This is a general OpenAPI spec handling gap.

Proposed Solution

Option 1: Generate as interface{}/any (Recommended)

  • Treat {} media type as schema-less response
  • Generate Go type as any (Go 1.18+) or interface{}
  • Allows clients to decode arbitrary JSON

Option 2: Generate as empty struct

  • For responses with no expected body
  • Matches semantics of HTTP 204 No Content

Option 3: Make configurable

generator:
  empty_media_type_handling:
    mode: "any"  # or "empty_struct" or "skip"
    # Optional: per-status-code rules
    status_rules:
      default: "any"
      2XX: "empty_struct"

Workaround (Current)

Add to ogen.yml:

generator:
  ignore_not_implemented:
    - "empty schema"

Limitation: This skips the entire operation, preventing client generation for that endpoint.

OpenAPI Spec Compliance

Per OpenAPI 3.0.3 Media Type Object:

  • schema field is OPTIONAL
  • examples field is OPTIONAL
  • Empty media type object {} is valid - means content is present but structure is unspecified

Test Command

ogen --target /tmp/test --clean empty-media-type-test.yaml

Expected: Generate client with any typed responses
Actual: Fails with "empty schema not implemented"

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions