Skip to content

Read enum on properties everywhere allowed values are used - #1569

Merged
jochenchrist merged 1 commit into
odcs-3.2.0from
feat/odcs-3.2.0-enum
Sep 3, 2026
Merged

Read enum on properties everywhere allowed values are used#1569
jochenchrist merged 1 commit into
odcs-3.2.0from
feat/odcs-3.2.0-enum

Conversation

@jochenchrist

Copy link
Copy Markdown
Contributor

Part of #1560 (#1557). Targets the odcs-3.2.0 branch.

ODCS v3.2.0 (RFC 0033) declares allowed values as enum, a list of entries with a value and optional label, description, id, tags, customProperties, authoritativeDefinitions.

One resolver

datacontract/model/enum_values.py reads enum first, then the legacy representations in order: logicalTypeOptions.enum, the enum custom property (list or JSON string, from DCS), the invalidValues quality rule. It replaces seven private copies in the avro, jsonschema, great-expectations, data-caterer and sodacl exporters, the check builder and the dbt test mapping. The check builder and sodacl export pass include_quality_rule=False, because they turn the quality rule into a check of its own and would otherwise check it twice.

Producers

datacontract import from JSON Schema, Avro (including optional enums in unions, whose symbols were dropped before), Protobuf and DCS writes enum entries instead of an invalidValues rule or avroSymbols/enumValues custom properties (enumValues stays for the protobuf numbers). create_property gained an enum argument.

Consumers that can carry more than values

  • datacontract test: field_enum check from the entries
  • pydantic-model: enumerated string and integer properties become typing.Literal[...]
  • protobuf: enum blocks numbered from each entry's id when numeric, else by position
  • avro: a property with physicalType: enum and values exports as an Avro enum without needing the avroType custom property
  • html: an "Allowed values" list with label and description
  • dcs: field.enum from any representation

Tests

New tests/test_enum_values.py (resolver priority, DuckDB end-to-end pass and fail, every exporter, JSON Schema and DCS import). Avro and protobuf import expectations updated to the entries. Full suite: 2323 passed.

Docs: docs/docs/schema.md uses enum entries in its examples and notes that logicalTypeOptions.enum is still accepted.

🤖 Generated with Claude Code

https://claude.ai/code/session_01C1xhK6DjRLWND1ntBcS8fG

ODCS v3.2.0 declares allowed values as enum, a list of entries with a
value and optional label, description, id, tags and more. One resolver in
datacontract/model/enum_values.py reads it ahead of the three legacy
representations (logicalTypeOptions.enum, the enum custom property, the
invalidValues rule) and replaces the seven private copies in the
exporters, the check builder and the dbt test mapping. The check builder
and sodacl export skip the quality-rule source, which they turn into a
check of their own.

Importers from JSON Schema, Avro, Protobuf and DCS write enum entries
instead of an invalidValues rule or custom properties. Pydantic export
types enumerated strings and integers as typing.Literal, protobuf export
numbers entries from their id, Avro export treats physicalType enum with
values as an Avro enum, and HTML export lists the values with labels and
descriptions.
@jochenchrist jochenchrist mentioned this pull request Sep 2, 2026
6 tasks
@jochenchrist
jochenchrist merged commit 2bcf792 into odcs-3.2.0 Sep 3, 2026
2 checks passed
@jochenchrist
jochenchrist deleted the feat/odcs-3.2.0-enum branch September 3, 2026 07:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant