Skip to content

feat(openapi): #2037 Update overlay export shape for standard mergers - #2086

Merged
lbroudoux merged 1 commit into
microcks:masterfrom
Heyy-Himanshuu:feat/2037-overlay-export-format
May 12, 2026
Merged

lbroudoux merged 1 commit into
microcks:masterfrom
Heyy-Himanshuu:feat/2037-overlay-export-format

Conversation

@Heyy-Himanshuu

Copy link
Copy Markdown
Contributor

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:

  • The target points to the parent node (parameter, requestBody content type, or response content type)
  • The update explicitly includes an examples wrapper

This allows mergers to deep-merge cleanly, regardless of whether examples already exists.

New format

yaml - target: "$.paths['/p'].post.requestBody.content['application/json']"   update:     examples:       my-example:         value: ...         summary: My Example 

Design Decisions

Backward Compatibility

Replaced the existing format in-place instead of introducing a new exporter (OPENAPI_OVERLAY_V2).

Reason:

  • The previous format was incompatible with standard overlay mergers
  • The new format remains compliant with the same overlay: 1.0.0 specification

Summary Source

  • Uses the request/response name
  • Microcks does not currently store a separate description for examples
  • Name provides the best available semantic value

Slugification

Uses:
java name.toLowerCase().replace(" ", "-")

  • Matches the original proposal
  • YAML is serialized via Jackson → UTF-8 safe
  • Non-ASCII characters (e.g. Éclair Café → éclair-café) are preserved correctly

Existing Examples Handling

  • Shape correctness is validated via snapshot tests (OpenAPIOverlayExporterTest)
  • Merge behavior is delegated to the overlay merger
  • Exporter responsibility is limited to emitting a valid structure

Notable Cleanups

  • Extracted shared logic into:
    java createExampleUpdate(actionNode, name, value)
    This removes duplication across:

    • Query parameters
    • Request bodies
    • Responses
  • Updated response path format:
    .responses.200.content[...] → .responses['200'].content[...]
    This aligns with consistent JSONPath bracket notation.


Test Plan

  • Updated OpenAPIOverlayExporterTest

    • All EXPECTED_EXPORT_ACTION_* snapshots rewritten to match new structure
    • Snapshot tests ensure future regressions are caught
  • Verified locally:
    mvn spotless:check -pl webapp

  • Post-merge validation:

    • Export overlay from Microcks
    • Merge using speakeasy-api/openapi/overlay/loader
    • Confirm:
      • New examples are added
      • Existing examples remain intact

Related Issues

… 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]>
@Heyy-Himanshuu

Copy link
Copy Markdown
Contributor Author

@lbroudoux let me know if any changes are required.

@dipak0000812 dipak0000812 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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(" ", "-");

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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);
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good extraction of shared logic into createExampleUpdate(), improves readability and avoids duplication.

@Heyy-Himanshuu

Copy link
Copy Markdown
Contributor Author

@dipak0000812 thanks for the review, however I'd like to wait for maintainer review before making any changes to current PR.

@Heyy-Himanshuu

Copy link
Copy Markdown
Contributor Author

@lbroudoux could u review this one also ?

@lbroudoux lbroudoux left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! Thank you.

@lbroudoux lbroudoux added this to the 1.15.0 milestone May 12, 2026
@lbroudoux
lbroudoux merged commit 167550c into microcks:master May 12, 2026
15 checks passed
@Heyy-Himanshuu
Heyy-Himanshuu deleted the feat/2037-overlay-export-format branch May 12, 2026 14:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Overlay format for export examples | Proposal

3 participants