Skip to content

Prevent flattened additionalProperties keys from colliding with declared properties #1059

Description

@danieleades

Problem

For an object schema with declared properties and typed additionalProperties, Typify generates a struct containing the declared fields plus a public flattened map. Callers can insert a declared property name into that map. For example, a map entry named id can conflict with the struct's declared id field and may produce duplicate or ambiguous serialized keys.

Deserialization routes declared names to their declared fields, so unrestricted construction of the flattened map does not preserve the same invariant in both directions.

Possible direction

Represent additional-property keys with a generated newtype or map wrapper that rejects names reserved by declared properties. The exact representation should preserve normal map ergonomics while preventing invalid construction and serialization.

Coverage

Add tests for:

  • constructing the additional-properties map with a declared key;
  • serialization without duplicate/conflicting keys;
  • deserialization of declared and additional keys;
  • serialize/deserialize round trips.

This was identified while reviewing #1039 and is intentionally kept separate from that PR's narrow invalid-Rust fix.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions