lpil / lpil/json-typedef

Schema with same enum will generate incorrect code

Open
#8 1 comment 0 reactions 0 assignees View on GitHub
bug
Dominant language
Gleam
Stars
50
Forks
10
PR merge metrics
No merged PRs in 30d

Description

Hi!

A schema like this:

```json
{
"properties": {
"my_field": { "enum": ["first", "second", "third"] }
},
"optionalProperties": {
"another_field": { "enum": ["first", "second"] }
}
}
```

Will generate two types for the enums:

```gleam
pub type Data {
Data(
my_field: DataMyField,
another_field: DataAnotherField,
)
}

pub type DataMyField {
Paragraph
Table
Heading
}

pub type DataAnotherField {
Paragraph
Table
}
```

Which is invalid Gleam code. I think the solution would be to suffix every cases with the type name?

Contributor guide

No contributing guide indexed for this repository

Research direction

Use the JSON schema in the issue as the reproduction input and inspect the generated Gleam output for the two enum types. Trace the generator entry point that derives enum type and case names, then verify that the output contains distinct valid constructors for both fields.

Written by the indexing model from the issue text.

Assessment

Tech stack
json
Domain
tooling
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.