feat: generate spec-aware example files for Dart, JavaScript, and Python WebSocket clients#2139
feat: generate spec-aware example files for Dart, JavaScript, and Python WebSocket clients#2139Adi-204 wants to merge 49 commits into
Conversation
|
|
Important Review skippedDraft detected. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
What reviewer looks at during PR reviewThe following are ideal points maintainers look for during review. Reviewing these points yourself beforehand can help streamline the review process and reduce time to merge.
|
0661ca1 to
11e666a
Compare
… Dart Drop the maxOpsToList cap from ExampleSendInvocations and derive instanceName from the spec client name (lowerFirst for JS, toSnakeCase for Python) so the generated examples mirror Dart's spec-aware output. Integration snapshots regenerated.
Coverage for the generated example pipeline now lives entirely in the protocol-shared integration suite. Per-component snapshot tests for Example, ExampleMain, ExampleSendInvocations, and (Python only) ExampleHandlers are redundant with the integration snapshots and were locking in noise from helper bugs (toSnakeCase acronym splitting, getClientName double-suffix). Removing them across Dart, JS, and Python keeps the test surface focused on observable client output.
These per-client changesets are superseded; the unified @asyncapi/generator changeset for the example-generation feature will be added separately.
Refreshes the hand-maintained reference file to import the hoppscotch snapshot result and use HoppscotchClient, matching the rest of the protocol fixtures.
Restore packages/templates/clients/websocket/dart/example.dart to its master state. This file is out of scope for the dynamic-examples PR.
Remove the conditional newLines={hasSend ? 1 : 2} trick (JS, Python) and the unconditional newLines={2} on registerErrorHandler (Dart). The visual blank line before the try block was not load-bearing; dropping it removes a layout responsibility that was split across two siblings and unifies the three clients on default trailing newlines. Integration snapshots regenerated.
Drop the hasSend ternary and use a fixed newLines={2} on registerErrorHandler/registerOutgoingProcessor across Dart, JS, and Python. Restores the blank line before try (and adds one between the two register calls when both are present).
ExampleKeepAlive was a one-liner used only by ExampleMain. Inlining it matches the Dart/JS pattern (no dedicated keep-alive component) and removes a now-unnecessary file. Output is byte-identical \u2014 integration snapshots unchanged.
…ckage Move the per-client Example/Main/Imports/Handlers/OpenConnection/Close/ SendInvocations/OutgoingProcessor components from the dart, javascript and python websocket templates into @asyncapi/generator-components under components/example, gated by a `language` prop. Each template now imports Example from the shared package. Regenerate api_components.md.
…ents Main renders language-specific main-function bodies that are not reused across templates, so per AGENTS.md #4.5 it belongs in each template's local components/ directory rather than in @asyncapi/generator-components. - Delete Example.js, Main.js and their tests/snapshots from the shared components package; each websocket template (dart, javascript, python) now has its own components/Main.js and composes Imports/Handlers/ OpenConnection/Main/Close directly in its example.*.js entry. - Drop the now-unused needsTime prop from the shared Imports component. - Replace {@link X} JSDoc references in Close and OpenConnection with backtick code refs so the docs website's MDX parser does not treat them as JS expressions inside list items (fixes the unexpected-lazy micromark error on api_components.mdx). - Regenerate api_components.md.
|
🚀 Docs preview deployed |
Replace `String#replace(/regex/g, ...)` with `String#replaceAll(literal, ...)`, use `String.raw` for pure-backslash escapes, and use optional chaining for the `message.name` guard.
…acements Sonar's prefer-string-raw rule also fires on the `'\\\''` replacement argument in the single-quote escape step of toJsLiteral / toPyLiteral / toDartLiteral. Switch those to String.raw`\'` for consistency.
|



Description
example.dartwith a generated, spec-aware file emitted bytemplate/example.dart.js. The example uses the real exported client class, registers per-op receive handlers, runs a bounded send loop with payloads frommessage.examples(), and wraps everything in proper error handling.template/example.js.js, using async/await, try/catch, a boundedforloop, andmain()entry point.template/example.py.jsemits a spec-awareexample.pywith PEP 8 indentation, per-opregister_on_<op>_handlerregistration,time.sleep(30)keep-alive for receive-bearing specs (Python'sconnect()is non-blocking), andif __name__ == '__main__': main()entry point.<client>/components/, spec-awareness driven by two inline booleans (hasSend,hasReceive), four distinct body shapes (send+receive, send-only, receive-only, none), snapshot tests for components with conditional logic, integration snapshots regenerated to capture the newexample.*output per fixture, legacy example files left in place (cleanup is follow-up work), and one@asyncapi/generatorminor changeset.Related issue(s)
Fixes #1627
AI assistance
Generated-by:Cursor Agent (Claude Opus 4.8)