guardrail-dev / guardrail-dev/guardrail

Inline object not generated

Open
#1,643 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
Scala
Stars
541
Forks
138
PR merge metrics
No merged PRs in 30d

Description

```
"ApiError": {
"type": "object",
"properties": {
"attribute": {
"type": "string",
"description": "The attribute that this error applies to. Omitted if this error is not in the context of a resource, or cannot be isolated to a single attribute.\n"
},
"type": {
"type": "string",
"description": "A classification for this error, which can be used to render the appropriate custom error template, or take other programmatic actions.\n"
},
"details": {
"description": "Variables associated with this error that can be injected into a custom error template, or used to parameterize any other programatic actions.\n",
"allOf": [
{
"type": "object",
"additionalProperties": {
"type": "string"
}
}
]
},
"message": {
"type": "string",
"description": "A human-readable, English description of the error.\n"
}
}
},
```

Resulting code:

```
/*
* This file was generated by guardrail (https://github.com/guardrail-dev/guardrail).
* Modifications will be overwritten; instead edit the OpenAPI/Swagger spec file.
*/
package com.evenfinancial.finance.v1.http4s.client.definitions
import cats.syntax.either._
import io.circe.syntax._
import cats.instances.all._
import _root_.com.evenfinancial.finance.v1.http4s.client.Implicits._
case class ApiError(attribute: Option[String] = None, `type`: Option[String] = None, details: Option[ApiError.Details] = None, message: Option[String] = None)
object ApiError {
implicit val encodeApiError: _root_.io.circe.Encoder.AsObject[ApiError] = {
val readOnlyKeys = _root_.scala.Predef.Set[_root_.scala.Predef.String]()
_root_.io.circe.Encoder.AsObject.instance[ApiError](a => _root_.io.circe.JsonObject.fromIterable(_root_.scala.Vector(("attribute", a.attribute.asJson), ("type", a.`type`.asJson), ("details", a.details.asJson), ("message", a.message.asJson)))).mapJsonObject(_.filterKeys(key => !(readOnlyKeys contains key)))
}
implicit val decodeApiError: _root_.io.circe.Decoder[ApiError] = new _root_.io.circe.Decoder[ApiError] { final def apply(c: _root_.io.circe.HCursor): _root_.io.circe.Decoder.Result[ApiError] = for (v0 <- c.downField("attribute").as[Option[String]]; v1 <- c.downField("type").as[Option[String]]; v2 <- c.downField("details").as[Option[ApiError.Details]]; v3 <- c.downField("message").as[Option[String]]) yield ApiError(v0, v1, v2, v3) }
}

```

There's no `ApiError.Details` generated.

Contributor guide

Open the contributing guide

Research direction

Start by reproducing the shown OpenAPI schema and tracing the Scala code-generation path for inline objects, especially the ApiError details field. Confirm how inline allOf object definitions are handled and add coverage for this case. Done means ApiError.Details is generated and the resulting code compiles.

Written by the indexing model from the issue text.

Assessment

Tech stack
openapi, scala
Domain
devtools
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.