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

[Circe refined] - validation information gets lost when referencing primitive types #1596

Open
stanislav-chetvertkov opened this issue Oct 9, 2022 · 1 comment

Comments

@stanislav-chetvertkov
Copy link
Contributor

When referencing primitive types with added validation properties the information on validation gets lost

definitions:
  Validated:
    type: object
    properties:
      v1:
        $ref: '#/definitions/Pattern'

  Pattern:
    type: string
    pattern: "[0-9]+"

generates

case class Validated(v1: Option[String] = None)

a possible solution is to treat primitive objects with validation as classes during the protocol generation phase

case class Validated(v1: Option[Pattern] = None)

case class Pattern(value: String Refined _root_.eu.timepit.refined.string.MatchesRegex[Pattern.`".*[0-9]+.*"`.T]) extends AnyVal
object Pattern {
  val `".*[0-9]+.*"` = _root_.shapeless.Witness(".*[0-9]+.*")
  // decode and encode as a primitive
}
@blast-hardcheese
Copy link
Member

This seems like a reasonable strategy.

Tracing through ProtocolGenerator's fromSwagger, it looks like it should be possible to conditionally enable this by just make extractProperties(model) return value: String Refined ... to bypass this rejection

The other half is whether $ref's will also need special casing, I would hope that it just works.

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

No branches or pull requests

2 participants