Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
Bathtor opened this issue Jan 20, 2025 · 0 comments
Labels

Comments

@Bathtor
Copy link

Bathtor commented Jan 20, 2025

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

{
  "$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

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

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:
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.

@Bathtor Bathtor added the bug label Jan 20, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant