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

oneOf object property results in uncompilable code #1904

Closed
mberndt123 opened this issue Dec 24, 2023 · 0 comments · Fixed by #1905
Closed

oneOf object property results in uncompilable code #1904

mberndt123 opened this issue Dec 24, 2023 · 0 comments · Fixed by #1905

Comments

@mberndt123
Copy link
Contributor

mberndt123 commented Dec 24, 2023

Hey here,

Here's a schema that results in uncompilable code:

openapi: 3.0.0
info:
  title: XXXXXX
  version: 0.1.0
paths: {}
components:
  schemas:
    X:
      type: object
      properties:
        links:
          oneOf:
            - type: object

The code generated looks like this:

/*
 * This file was generated by guardrail (https://github.com/guardrail-dev/guardrail).
 * Modifications will be overwritten; instead edit the OpenAPI/Swagger spec file.
 */
package swagger.definitions
import cats.syntax.either._
import io.circe.syntax._
import cats.instances.all._
import _root_.swagger.Implicits._
case class X(links: Option[X.Links] = None)
object X {
  implicit val encodeX: _root_.io.circe.Encoder.AsObject[X] = {
    _root_.io.circe.Encoder.AsObject.instance[X](a => _root_.io.circe.JsonObject.fromIterable(_root_.scala.Vector(("links", a.links.asJson))))
  }
  implicit val decodeX: _root_.io.circe.Decoder[X] = new _root_.io.circe.Decoder[X] { final def apply(c: _root_.io.circe.HCursor): _root_.io.circe.Decoder.Result[X] = for (v0 <- c.downField("links").as[Option[X.Links]]) yield X(v0) }
}

As you can see, case class X contains a field of type Option[X.Links], but there is no Links type defined in the X object.

Obviously the oneOf thing is useless here and when I just write links: { "type": "object" } instead it works. But I'm using a schema provided by an API vendor that contains constructs like this, and I'd like to be able to use it as-is.

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

Successfully merging a pull request may close this issue.

1 participant