oxidecomputer / oxidecomputer/typify

Generate tests to ensure type compatibility of non-generated types

Open
#582 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Rust
Stars
898
Forks
114
Avg merge
4h 18m
Merged PRs (30d)
14

Description

Typify generation is configurable, and in particular there are mechanisms (such as the replace imperative to the macro, or TypeSpaceSettings::with_replacement()) that cause types to be used from other crates rather than typify generating the type.

When types are generated, they are a translation of the schema into a type; when types are replaces, the full burden of ensuring equivalency or compatibility between the schema and type used falls to the consumer. If the supplied type is not compatible, there are a range of tricky to debug failures.

To help catch incompatibilities earlier, typify could generate test code that compares the JSON schema of the supplied type with the schema (i.e. the schema we don't use for type generation). This does assume that the supplied type implements JsonSchema... but that seems like it will often or typically be the case. It's important that failures of these generated tests are easy to comprehend and address. Since this is generated code, it would be easy to have unintelligible failures masked e.g. by a macro invocation. To that end, we'll probably want another crate in the typify ecosystem (typify-test?) that contains the explicit test code. The failures should make clear 1. the type being tested 2. the specific schema incompatibility and 3. the remediation (e.g. supply a compatible type or do generate the type).

Contributor guide

No contributing guide indexed for this repository

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

Start by tracing the replace macro imperative and TypeSpaceSettings::with_replacement() through typify's generation flow. Define how generated tests compare the supplied type's JsonSchema with the source schema, and ensure failures identify the type, incompatibility, and remediation such as generating the type instead.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
compilers, testing
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.