@W-21680934 feat: add sourceMaps option to ApiDefinition#19
Merged
@W-21680934 feat: add sourceMaps option to ApiDefinition#19
Conversation
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
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
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Add optional
sourceMapsfield (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: