Repository navigation
feat: Add AsyncAPI reference support for message pacts (#557) - #559
mr-roman-vivint wants to merge 2 commits into
Conversation
…on#557) Implements pact-foundation#557 Added methods to IMessageBuilderV4: - WithComment(key, value) - Add key-value comment to interaction - WithTextComment(comment) - Add text comment to comments array - WithAsyncApiReference(operationId) - Link to AsyncAPI operation This enables PactFlow Bi-Directional Contract Testing with AsyncAPI specifications for message pacts. Changes: - FFI bindings for pactffi_set_comment and pactffi_add_text_comment - Driver layer implementation - V4 only (V3 doesn't support comments per Pact specification) - Unit, integration, and E2E tests - Sample code and documentation updates Breaking changes: None (additive change to V4 interface only)
mefellows
left a comment
There was a problem hiding this comment.
Some minor changes, with the primary one being the name of the reference.
I think we should make this a little less specific to AsyncAPI support. The underlying capability is really about adding arbitrary references to an interaction.
See example DSL for JS here: https://github.com/pact-foundation/pact-js/pull/1762/changes
It (references) could also be added to the HTTP interface, although that could be done in a separate PR if needed.
| /// If called multiple times, only the last operationId will be retained. | ||
| /// For multiple reference types, use WithComment() with a custom JSON structure. | ||
| /// </remarks> | ||
| IMessageBuilderV4 WithAsyncApiReference(string operationId); |
There was a problem hiding this comment.
I'd suggest changing this to something like
| IMessageBuilderV4 WithAsyncApiReference(string operationId); | |
| IMessageBuilderV4 WithReference(string group, string name, string value); |
| { | ||
| // Create the nested JSON structure: { "AsyncAPI": { "operationId": "..." } } | ||
| string referencesJson = $"{{\"AsyncAPI\":{{\"operationId\":\"{operationId}\"}}}}"; | ||
| this.driver.WithComment("references", referencesJson); |
There was a problem hiding this comment.
Technically, this would work actually and would allow you to do what's needed without bumping to a newer FFI version, although if there are other comments this might replace them (I think).
It is also supported by the pactffi_add_interaction_reference function which surgically adds that reference into any existing comments.
See https://github.com/pact-foundation/pact-js-core/pull/861/changes for addition of the FFI functions to enable it.
|
@adamrodger I've done a first pass at this based on the additions to other languages. I don't have any views on the .NET code themselves, so I'll leave that to you. |
…t-foundation#557) Implements pact-foundation#557 Changes based on review feedback: - Replace WithAsyncApiReference(operationId) with WithReference(group, name, value) for broader use cases - Remove WithComment() and WithTextComment() from public API (kept only WithReference) - Remove unused FFI binding pactffi_add_text_comment - Add Dictionary-based state to accumulate multiple references per interaction - Update all tests to use new API - Add test for multiple references (operationId + channel) Note: pactffi_add_interaction_reference from pact-js is not available in FFI 0.4.27, implemented using pactffi_set_comment with state accumulation instead.
|
@mefellows Thank you for the feedback and sorry for the delay, a lot of work. I've updated the implementation:
Regarding All tests pass. Let me know if you'd like any other changes. Thanks in advance! |
|
Thanks @mr-roman-vivint, this looks directionally better - I understand the reticence with bumping the FFI version. This is something that should be replaceable under the hood so the API doesn't change, but underlying implementation does. Will leave the rest to @adamrodger (maintainer). |
Links a sync message interaction to an external resource such as an
AsyncAPI operation via pactffi_add_interaction_reference, written to
comments.references.{group}.{name}. Same signature as the async
WithReference proposed in pact-foundation#559.
The FFI parses the value as JSON, so the driver encodes it to keep a
string reference value a string in the pact.
Links a sync message interaction to an external resource such as an
AsyncAPI operation via pactffi_add_interaction_reference, written to
comments.references.{group}.{name}. Same signature as the async
WithReference proposed in pact-foundation#559.
The FFI parses the value as JSON, so the driver encodes it to keep a
string reference value a string in the pact.
Links a sync message interaction to an external resource such as an
AsyncAPI operation via pactffi_add_interaction_reference, written to
comments.references.{group}.{name}. Same signature as the async
WithReference proposed in pact-foundation#559.
The FFI parses the value as JSON, so the driver encodes it to keep a
string reference value a string in the pact.
Closes #557
Summary
Implements AsyncAPI reference support for message pacts (#557)
Problem
PactNet lacked a way to programmatically add AsyncAPI operation references to message interactions, which is required for PactFlow BDCT with AsyncAPI.
Solution
Added three new methods to IMessageBuilderV4:
WithComment(key, value)- for custom key-value commentsWithTextComment(comment)- for text comments arrayWithAsyncApiReference(operationId)- convenience method for AsyncAPI refsChanges
Testing
All 411 tests passing. Added comprehensive test coverage.
Breaking Changes
None - additive change to IMessageBuilderV4 only.