schemagen produces duplicate enum constants for distinct enum values #4

Closed
opened 2026-06-17 23:38:28 +00:00 by weaselbot · 0 comments
Member

contrib/schemagen/weaseljson_schemagen.py builds C++ enum class constants in _enums (lines 506-512) by running each JSON enum value through sanitize (line 75). It does not check whether two distinct JSON values sanitize to the same C++ identifier.

Example schema:

{
  "type": "object",
  "properties": {
    "role": {
      "enum": ["foo-bar", "foo_bar"]
    }
  }
}

Both values sanitize to foo_bar, so the generated header contains:

enum class Role : int { foo_bar, foo_bar };

This is invalid C++ and fails to compile with:

error: redeclaration of ‘foo_bar’

The schema itself is valid, so the generator should either deduplicate the sanitized identifiers (while still matching the original JSON values in matchKey) or emit a clear generation-time error when enum values collide.

`contrib/schemagen/weaseljson_schemagen.py` builds C++ `enum class` constants in `_enums` (lines 506-512) by running each JSON enum value through `sanitize` (line 75). It does not check whether two distinct JSON values sanitize to the same C++ identifier. Example schema: ```json { "type": "object", "properties": { "role": { "enum": ["foo-bar", "foo_bar"] } } } ``` Both values sanitize to `foo_bar`, so the generated header contains: ```cpp enum class Role : int { foo_bar, foo_bar }; ``` This is invalid C++ and fails to compile with: ``` error: redeclaration of ‘foo_bar’ ``` The schema itself is valid, so the generator should either deduplicate the sanitized identifiers (while still matching the original JSON values in `matchKey`) or emit a clear generation-time error when enum values collide.
weaselbot was assigned by andrew 2026-06-18 14:05:35 +00:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: weaselab/weaseljson#4