fix(openapi): preserve Swagger response examples

XU
7d ago
+114-0

Swagger 2 response examples are stored in responses.<status>.examples as a MIME-type-to-value map. The converter currently copies the response schema but drops those examples, so generated tools lose the sample response values supplied by the API.

Normalize the map values into an examples list before merging them with schema-level examples. Keep literal objects intact, including payload fields named value, $ref, or externalValue, and reuse the existing stable, type-aware deduplication.

This addresses only item 3 of #98. The request-body and parameter-content gaps remain outside this change. Refs #98.

Validation on Windows with Python 3.13.12:

  • Original source with the new regressions: 13 failed, 3 passed.
  • Fixed converter regressions and existing offline OpenAPI tests: 21 passed; all three new executable lines covered.
  • Full CI test selection and doctests: 624 passed, 9 Unix-specific CLI tests skipped, and one existing GraphQL integration test hit a connection timeout to countries.trevorblades.com. That test passed on its first rerun with the same code and environment.
  • git diff --check passed.

The new tests use in-memory Swagger documents and no external services. They cover raw values (including false, zero, empty values and null), serialization, schema references, multiple MIME types, response-status selection, and deduplication without collapsing distinct JSON types. Linux, macOS and the other Python versions in CI have not been run locally.