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] scala-cask generates reference to UUIDData class but does not generate it #20215

Open
DavidGoodenough opened this issue Dec 1, 2024 · 4 comments

Comments

@DavidGoodenough
Copy link

DavidGoodenough commented Dec 1, 2024

Description

I realise that UUIDs are not properly supported by scala-cask yet, but it should generate invalid code.

In a routes file in which there is a reference there is the following for comprehension:-

    val result = for {
      uUID <- Parsed
        .fromTry(UUIDData.manyFromJsonStringValidated(request.bodyAsString))
        .mapError(e =>
          s"Error parsing json as an array of UUID from >${request.bodyAsString}< : ${e}"
        ) /* array */
      resultTry <- Parsed.eval(service.v1TimesheetsToggleDeferredPost(uUID))
      result    <- Parsed.fromTry(resultTry)
    } yield result

and UUIDData is flagged as not found. manyFromJsonStringValidated seems to be the only method on this class that is called.

It would be really helpful BTW if UUID support was added for type: "string" format: "uuid" objects. Where in the code am I likely to find the right place to intercept this and add support either by adding an import of a given implicit Conversion or explicitly converting the String value to a UUID using UUID.fromString on each use?

openapi-generator version

7.10.0

@wing328
Copy link
Member

wing328 commented Dec 2, 2024

thanks for reporting the issue

cc @aaronp

@DavidGoodenough
Copy link
Author

I notice that you already include an asUUID method in the ...api.package.scala source that you generate, which correctly uses UUID.fromString to parse the UUID from its string form. Presumably all that is needed to support strings properly would be to recognise the format on a type: "string" object when it is uuid, and use asUUID.

@DavidGoodenough
Copy link
Author

For reasons that are not clear to me, your code assumed java.util.UUID, rather than the Scala equivalent, and upickle does not understand the java.util version, only the Scala version.

Would be a good idea to move to the Scala version? Otherwise it will be necessary to write some upickle code to handle the java version.

@DavidGoodenough
Copy link
Author

I was wrong, upickle does understand java.util.UUID, but cask does not accept it as an endpoint parameter.

So rather than:-

  @cask.get("/user/:uniqueid") 
  def getUserProfile(uniqueId: UUID) = {
    // TODO process the request
  } 

it should be:-

  @cask.get("/user/:uniqueId") 
  def getUserProfile(uniqueId: String) = {
    val uuid = UUID.fromString(uniqeId)
    // TODO processing
  }

If you use the UUID as the argument, the compilation of the initialize() (which is a great big macro) fails complaining that "no reader of type java.util.UUID found for parameter uniqueId"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants