Skip to content

@W-21680934 feat: add sourceMaps option to ApiDefinition#19

Merged
alexpmule merged 7 commits intomasterfrom
feat/source-maps-option
Apr 9, 2026
Merged

@W-21680934 feat: add sourceMaps option to ApiDefinition#19
alexpmule merged 7 commits intomasterfrom
feat/source-maps-option

Conversation

@alexpmule
Copy link
Copy Markdown
Contributor

@alexpmule alexpmule commented Apr 8, 2026

Add optional sourceMaps field (default: true) to ApiConfiguration. When set to false, the generator calls withoutSourceMaps() on AMF RenderOptions, omitting source map nodes from the output model.

This can reduce generated model size by up to 80% for large APIs (e.g. gRPC services with many operations). Source maps are only needed for editing tooling, not for browsing or display.

Usage in apis.json:

  "grpc/service.proto": {
    "type": "GRPC",
    "mime": "application/protobuf",
    "flattened": true,
    "sourceMaps": false
  }

Add optional `sourceMaps` field (default: true) to ApiConfiguration.
When set to false, the generator calls withoutSourceMaps() on AMF
RenderOptions, omitting source map nodes from the output model.

This can reduce generated model size by up to 80% for large APIs
(e.g. gRPC services with many operations). Source maps are only
needed for editing tooling, not for browsing or display.

Usage in apis.json:
  "grpc/service.proto": {
    "type": "GRPC",
    "mime": "application/protobuf",
    "flattened": true,
    "sourceMaps": false
  }

Made-with: Cursor
@alexpmule alexpmule self-assigned this Apr 8, 2026
The v0.3.0 migration accidentally made full and compact files identical
by applying withCompactUris() to both. This fix restores the semantic
difference from v0.2.x:

- <name>.json (full): expanded URIs, source maps on by default.
  Intended for editing tools and validators. Source maps can be
  disabled via sourceMaps: false in ApiConfiguration.

- <name>-compact.json: compact URIs (apiContract:WebAPI prefixes),
  never includes source maps. Optimized for display/browsing (e.g.
  API Console). Can reduce model size by up to 80% for large APIs.

Both files share the same parse and transform step; only the render
options differ, so there is no performance regression.

Made-with: Cursor
- Remove @context assertions for full model (expanded URIs don't carry @context)
- Fix gRPC WebAPI type check to match both compact and expanded URI forms
- Upgrade mocha to ^11.7.5

Made-with: Cursor
AMF v5 enables withCompactedEmission (which produces @graph JSON-LD)
by default. This broke consumers like amf-loader.ts that expect the
old array format [{"@id": "amf://id", ...}].

Now withoutCompactedEmission() is set explicitly so:
- Regular models: old array format (backward compatible with amf-loader)
- flattened: true models: @graph format (intentional, for large APIs)

Made-with: Cursor
… post-render

AMF v5 only includes declared types (doc:declares) in the serialised
@graph when withSourceMaps() is active. The previous compact render
(withCompactUris + withoutSourceMaps) silently dropped all declared types,
breaking amf-loader consumers that rely on declares for type resolution.

Fix:
- Render compact models with withSourceMaps() to preserve doc:declares
- Post-process output with stripSourceMaps() to remove source-map graph
  nodes and inline source-map properties
- Parse API a second time for the compact render to avoid baseUnit
  mutation caused by the first transform/render call

Made-with: Cursor
withCompactUris() was removed from compact model to preserve declared
types in @graph; as a result withCompactedEmission() no longer generates
@context. Validate structure with assertValidAmfModel() instead.

Made-with: Cursor
@alexpmule alexpmule merged commit e31fccc into master Apr 9, 2026
3 checks passed
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