Skip to content

Identifier name collision for case-variant values #525

@aorabdel

Description

@aorabdel

Summary

When identifiers that differ only by case (e.g., "mHz" vs "MHz"), the generator emits duplicate identifiers names. This causes a compilation error for redeclared identifiers.

Minimal repro

Minimal Schema:

{
  "title": "Frequency",
  "unit": {
    "type": "string",
    "enum": ["mHz", "MHz"]
  }
}

Command:

go-jsonschema -p main schema.json

Observed output

Generated constants include both of the following, which collide (redeclared identifier):

const SchemaJsonMHz SchemaJson = "mHz"
const SchemaJsonMHz SchemaJson = "MHz"

Expected behavior

Identifiers should be uniquely named even when values differ only by case.

Why this happens (preliminary analysis)

In internal/x/text/cases.go Identifierize() is calling c.Capitalize(Part)in order to normalizes the case, so both "mHz" and "MHz" become "MHz".

Environment

  • go-jsonschema version: v0.22.0
  • Go version: 1.25.5

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions