Skip to content

fix(openapi): preserve array-form (JSON Schema / OAS 3.1) schema examples#95

Merged
h3xxit merged 1 commit into
devfrom
fix/openapi-array-form-examples
Jun 24, 2026
Merged

fix(openapi): preserve array-form (JSON Schema / OAS 3.1) schema examples#95
h3xxit merged 1 commit into
devfrom
fix/openapi-array-form-examples

Conversation

@h3xxit

@h3xxit h3xxit commented Jun 24, 2026

Copy link
Copy Markdown
Member

Problem (P2)

Schema-level examples declared as a JSON Schema list were silently lost during conversion:

"schema": { "type": "string", "examples": ["ok", "done"] }   // -> dropped

Root cause

_extract_examples only recognized examples as an OpenAPI map of named Example Objects (isinstance(obj["examples"], dict)), so it returned nothing for the list form. Meanwhile _schema_without_example_keys strips examples from the schema before it is spread onto the property. Before that strip the list passed through raw; after it (added when normalizing examples), the list is extracted as nothing and removed — net data loss. JSON Schema (and OpenAPI 3.1 schema objects) define examples as a list of values.

Fix

_extract_examples now handles all three shapes:

  • example (single value)
  • examples as a map of Example Objects (OpenAPI 3.0) — value per entry, $ref resolved
  • examples as a list of literal values (JSON Schema / OAS 3.1) — extended verbatim

The two forms can't collide: a media type object's examples is always a map, a schema's is always a list.

Tests

New test_openapi_converter_array_form_schema_examples covering array-form schema examples on both request body and response. Full converter suite: 6 passed.

Bumps utcp-http 1.1.9 → 1.1.10.

Note: same bug fixed in typescript-utcp (PR #29).

🤖 Generated with Claude Code


Summary by cubic

Preserves array-form schema examples (JSON Schema / OAS 3.1) in the OpenAPI converter. Prevents silent data loss so examples appear on request and response models.

  • Bug Fixes

    • _extract_examples now supports single example, examples map (OAS 3.0, $ref resolved), and examples list (JSON Schema/OAS 3.1).
    • Added test covering array-form schema examples for request body and response.
  • Dependencies

    • Bump utcp-http to 1.1.10.

Written for commit 8b32145. Summary will update on new commits.

Review in cubic

_extract_examples only handled 'examples' as an OpenAPI map of named Example
Objects, while _schema_without_example_keys strips 'examples' from schemas
before spreading. So a JSON Schema / OpenAPI 3.1 schema-level 'examples' list
was extracted as nothing and then dropped - silent data loss.

Handle the list form too: list entries are literal example values; the map
form keeps its Example Object 'value' handling. Adds a test covering array-form
schema examples on both request body and response. Bumps utcp-http
1.1.9 -> 1.1.10.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@h3xxit h3xxit merged commit 8b32145 into dev Jun 24, 2026
10 checks passed
@h3xxit h3xxit deleted the fix/openapi-array-form-examples branch June 24, 2026 22:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant