Repository navigation
feat(openapi): #2037 Update overlay export shape for standard mergers - #2086
Conversation
… mergers The previous overlay export targeted '....examples' directly and put each example as a top-level key under 'update'. Standard OpenAPI overlay mergers (e.g. github.com/speakeasy-api/openapi/overlay/loader) struggle to apply that shape when the target node does not already contain an 'examples' map, since the merger cannot create the intermediate path. Reported by @ludovic-pourrat in microcks#2037. Restructure each emitted action so the target stops at the parent node (parameter, requestBody content type, response content type) and 'update' carries an explicit 'examples' wrapper that the merger can deep-merge into the target whether or not 'examples' exists there yet: - target: "$.paths['/p'].post.requestBody.content['application/json']" update: examples: my-example: value: ... summary: My Example Per @lbroudoux's design call on the issue: - Replace the current shape in place rather than introducing an OPENAPI_OVERLAY_V2 exporter; the current shape is broken with the standard merger anyway and the change stays compliant with the same overlay-1.0.0 specification version. - Use the request/response name as 'summary' since Microcks does not carry a separate description on examples. - Slugify keys with the simple lower-case + space-to-dash transform proposed by @ludovic-pourrat. The output is YAML written through Jackson, which serialises as UTF-8 by default, so latin and other non-ASCII characters in names round-trip cleanly through the slug. Refactor the three emission sites (query parameter, requestBody, response) to share a single createExampleUpdate helper that owns the new shape, so future additions stay consistent. Switch the response status segment from '.responses.<code>.' to ".responses['<code>'].", matching @ludovic-pourrat's draft and aligning with the bracketed JSONPath syntax used everywhere else in the target paths. OpenAPIOverlayExporterTest already snapshots the full YAML output; update all five EXPECTED_EXPORT_ACTION_* fixtures to lock the new shape in. The regression test will fail-loud on any future drift. Existing-examples behaviour: standard overlay mergers deep-merge the 'update' object into the target node, so an existing 'examples' map at the target path keeps its entries while the new ones from this overlay are added. The fixture-based snapshot test pins the exact shape we send to the merger, and the merge semantics are the merger's responsibility - this exporter only owns the shape. Signed-off-by: Git-HimanshuRathi <[email protected]>
|
@lbroudoux let me know if any changes are required. |
dipak0000812
left a comment
There was a problem hiding this comment.
Looks like a solid improvement overall and the new structure makes sense for merging.
Left a few small comments around parsing, slug generation, and the change in export format—just want to make sure we’re safe on edge cases and existing usage.
Happy to take another look after updates 👍
| ObjectNode exampleNode = updateNode.putObject(response.getName()); | ||
| exampleNode.put("value", response.getContent()); | ||
| private String toExampleKey(String name) { | ||
| return name.toLowerCase().replace(" ", "-"); |
There was a problem hiding this comment.
The slug generation is pretty simple (lowercase + replace space).
Could this lead to collisions or issues with special characters?
| ObjectNode exampleNode = examplesNode.putObject(toExampleKey(name)); | ||
| exampleNode.put("value", value); | ||
| exampleNode.put("summary", name); | ||
| } |
There was a problem hiding this comment.
Good extraction of shared logic into createExampleUpdate(), improves readability and avoids duplication.
|
@dipak0000812 thanks for the review, however I'd like to wait for maintainer review before making any changes to current PR. |
|
@lbroudoux could u review this one also ? |
Summary
Resolves #2037.
The previous overlay export targeted ....examples directly and placed each example as a top-level key under update. Standard OpenAPI overlay mergers (e.g. https://github.com/speakeasy-api/openapi/overlay/loader) struggle with this structure when the target node does not already contain an examples map, since the merger cannot create intermediate paths.
This PR restructures each emitted action so that:
This allows mergers to deep-merge cleanly, regardless of whether examples already exists.
New format
Design Decisions
Backward Compatibility
Replaced the existing format in-place instead of introducing a new exporter (OPENAPI_OVERLAY_V2).
Reason:
Summary Source
Slugification
Uses:
java name.toLowerCase().replace(" ", "-")
Existing Examples Handling
Notable Cleanups
Extracted shared logic into:
java createExampleUpdate(actionNode, name, value)
This removes duplication across:
Updated response path format:
.responses.200.content[...] → .responses['200'].content[...]
This aligns with consistent JSONPath bracket notation.
Test Plan
Updated OpenAPIOverlayExporterTest
Verified locally:
mvn spotless:check -pl webapp
Post-merge validation:
Related Issues