oxidecomputer / typify

compiler from JSON Schema into idiomatic Rust types
Apache License 2.0
392 stars 57 forks source link

Enum Name Collision #177

Open lsh opened 1 year ago

lsh commented 1 year ago

In the Vega example, an enum with __count__ and count outputs:

pub enum AggregateTransformOpsVariant0ItemVariant0 {
    #[serde(rename = "count")]
    Count,
    #[serde(rename = "__count__")]
    Count,
   // ...
}

I'm looking into whether __count__ is a spec bug and not meant to be exposed 😅 , but from a code gen perspective figuring out what to do with these collisions is probably worthwhile.

ahl commented 1 year ago

Yeah good catch!

ahl commented 1 year ago

This may be kind of a pain in the neck to fix. I've envisioned a "naming type" to which one could apply "inputs", say, the name from the json source, and "context", components that led to this (e.g. you see these reflected in AggregateTransformOpsVariant0ItemVariant0). Then one could "resolve" a collection of these types to find unique names with only the required amount of context.

For enum variants, each variant is effectively processed individually. We would want this sort of placeholder name generated for each; then we would resolve to a final name when we had the full set in hand. I expect we'd use the "type-state" pattern.

lsh commented 1 year ago

I would consider that totally fair as a "wontfix" criteria. Either way, thanks for looking into it!