pact-foundation / pact-foundation/pact-reference

pact_consumer: `each_like!` and nested structs

Open
#22 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Rust
Stars
106
Forks
53
Avg merge
1h 37m
Merged PRs (30d)
2

Description

The PR #18 contains an each_like! macro which mimics Ruby's ArrayLike matcher. This generates a #{path}[*].* rule:

      def handle_array_like array_like, path, match_type
        record_rule "#{path}", 'min' => array_like.min
        record_match_type_rule "#{path}[*].*", 'type'
        recurse array_like.contents, "#{path}[*]", :array_like
      end

@bethesque argues that the #{path}[*].* rule is unnecessary.

We could remove that rule from Rust, but then we'd want to add a fields_like! macro so that you could write:

// This is an incredibly common Rust use case when generating JSON from domain objects.
each_like!(fields_like!(strip_null_fields(json!(DomainObject::factory()))

The each_like! would generate "#{path}" => { "matches": "type" }, and the fields_like! would generate the "#{path}[*].*" => { "matches": "type" } that each_like! generates now. Maybe fields_like! should also include a build-in strip_null_fields?

This is trivial to implement; so it's purely a design question. What do people think?

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Review PR #18 and Bethesque's linked comment first, then compare the proposed each_like! and fields_like! macro semantics for nested structs and generated JSON rules. Done means reaching and documenting a decision on whether to remove the wildcard rule, add fields_like!, and include strip_null_fields; the issue does not name implementation files or tests.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
testing-qa
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.