Skip to content

feat(openapi): emit segment + status as enums with real values#205

Merged
texture-fleet-agent[bot] merged 1 commit intomainfrom
meridian/segment-enum-openapi
May 6, 2026
Merged

feat(openapi): emit segment + status as enums with real values#205
texture-fleet-agent[bot] merged 1 commit intomainfrom
meridian/segment-enum-openapi

Conversation

@texture-fleet-agent
Copy link
Copy Markdown
Contributor

Summary

Fix the OpenAPI spec so Utility.segment is a real enum with the actual values returned by the API, not the \"One of: electric, gas, water, combined\" placeholder that's been misleading consumers.

Also enumerated Utility.status while I was in the file (small finite set, same treatment).

Before vs. after

Before:
```json
"segment": {
"type": "string",
"description": "One of: electric, gas, water, combined"
}
```

After:
```json
"segment": {
"type": "string",
"description": "Ownership / structural category of the utility. Sourced from EIA Form 861 filings plus manual review.",
"enum": [
"COMMUNITY_CHOICE_AGGREGATOR",
"DISTRIBUTION_COOPERATIVE",
"GENERATION_AND_TRANSMISSION",
"INVESTOR_OWNED_UTILITY",
"MUNICIPAL_UTILITY",
"POLITICAL_SUBDIVISION",
"TRANSMISSION_OPERATOR"
]
}
```

Approach

The generator's FieldDescriptionMap type now accepts either a plain string (backwards compatible — unchanged for every other field) or an { description, enum } object. When the object form is used, the generator emits a real enum array in the schema.

The enum values are pulled from the live DB:

```
SELECT DISTINCT segment FROM utilities WHERE deleted_at IS NULL ORDER BY segment;
```

Written next to the enum in a comment so the next engineer knows exactly how to refresh it if a new segment gets added (rare).

Test

  • 3 new tests in scripts/openapi/openapi-enum.test.ts — asserts segment + status emit as enums, have the key values, use uppercase snake_case, and the old buggy description is gone.
  • npm run test → 101/101 passing.
  • npm run lint:biome clean for touched files.
  • npm run build clean.
  • npm run openapi:check clean.

Context

From Morgan's Relay bug report (2026-05-06), bug #6. Full report: memory/specs/relay-commongrid-bugs-2026-05-06.md.

Cost Morgan some real time — initially filtered `segment=ELECTRIC_COOPERATIVE` (returned 0) before discovering the real value is DISTRIBUTION_COOPERATIVE. This should prevent that flavor of bug for future consumers.

Fixes ALL-734

Update the OpenAPI generator to accept enum hints in the per-resource
descriptions map. When a field's description is an `{ description, enum }`
object (instead of a plain string), the generator emits both a real
`enum` array and the description in the resulting schema.

Populated Utility.segment with the actual ownership categories returned
by the API (COMMUNITY_CHOICE_AGGREGATOR, DISTRIBUTION_COOPERATIVE,
GENERATION_AND_TRANSMISSION, INVESTOR_OWNED_UTILITY, MUNICIPAL_UTILITY,
POLITICAL_SUBDIVISION, TRANSMISSION_OPERATOR) instead of the incorrect
"One of: electric, gas, water, combined" placeholder.

Also emitted Utility.status as a real enum (ACTIVE, DEFUNCT, MERGED)
since it's similarly backed by a small finite set. Both sourced from
`SELECT DISTINCT <col> FROM utilities WHERE deleted_at IS NULL`.

Backwards compatible: existing descriptions stay as plain strings; only
fields that explicitly opt into the object form get an `enum` in the
spec. The FieldDescriptionMap type now supports both shapes, and the
generator switches on typeof value === "string".

Regression coverage in scripts/openapi/openapi-enum.test.ts asserts the
segment + status enums are present, uppercase snake_case, contain the
key values consumers filter on, and that the old "electric, gas, water"
description is gone.

From Morgan's Relay bug report (memory/specs/relay-commongrid-bugs-2026-05-06.md),
bug #6.

Fixes ALL-734
@vercel
Copy link
Copy Markdown

vercel Bot commented May 6, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
commongrid Ready Ready Preview, Comment May 6, 2026 10:32pm

Request Review

@texture-fleet-agent texture-fleet-agent Bot merged commit 511293f into main May 6, 2026
7 checks passed
@texture-fleet-agent texture-fleet-agent Bot deleted the meridian/segment-enum-openapi branch May 6, 2026 22:34
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