glideapps / glideapps/quicktype

[BUG]: Generating Scala3 uPickle from JSON Schema is missing ReadWriter annotation for enums

Open
#2,677 1 comment 0 reactions 0 assignees View on GitHub
bug
Dominant language
TypeScript
Stars
13.9k
Forks
1.2k
Avg merge
8h 53m
Merged PRs (30d)
369

Description

## Issue Type

Output

## Context (Environment, Version, Language)

Input Format: JSON Schema
Output Language: Scala3+uPickle

CLI, npm, or app.quicktype.io: CLI
Version: 23.0.170

## Description

In the generated Scala3 output there is a missing `ReadWriter` annotation for the generated `enum Color`, which leads to a build failure while the uPickle macro is trying run:
```
No given instance of type ReadersVersionSpecific_this.Reader[
[error] | quicktype.Color] was found.
```

## Input Data

```json
{
"$schema": "https://json-schema.org/draft/2019-09/schema",
"definitions": {
"Color" : {
"type" : "string",
"enum": ["Red", "Green", "Blue"]
},
"Monster" : {
"type" : "object",
"properties" : {
"name" : {
"type" : "string"
},
"color" : {
"$ref" : "#/definitions/Color"
}
},
"required" : ["name", "color"],
"additionalProperties" : false
}
},
"$ref" : "#/definitions/Monster"
}
```

## Expected Behaviour / Output

```scala
package quicktype

import upickle.default.*

case class Monster (
val color : Color,
val name : String
) derives ReadWriter

enum Color derives ReadWriter :
case Blue,Green,Red
```

## Current Behaviour / Output

```scala
package quicktype

import upickle.default.*

case class Monster (
val color : Color,
val name : String
) derives ReadWriter

enum Color :
case Blue,Green,Red

```

## Steps to Reproduce

It also reproduces in the webapp, so easiest repro is:

1. paste above json into webapp and JSON Schema as source
2. Select Scala3 and uPickle as target
3. Try to compile the resulting code with with a minimal sbt project. Something along the lines of:
```scala
val scala3Version = "3.6.2"

lazy val root = project
.in(file("."))
.settings(
name := "Quicktype Test",
version := "0.1.0-SNAPSHOT",

scalaVersion := scala3Version,
libraryDependencies += "com.lihaoyi" %%% "upickle" % "4.1.0"
)
```

## Possible Solution

Just adjust the generator to add the necessary derive for enums.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.