zio / zio-http

A next-generation Scala framework for building scalable, correct, and efficient HTTP clients and servers
https://zio.dev/zio-http
Apache License 2.0
800 stars 403 forks source link

`JsonSchema.fromZSchema` includes refs when `refType = SchemaStyle.Inline` #3168

Open guersam opened 1 month ago

guersam commented 1 month ago

Describe the bug JsonSchema.fromZSchema includes refs when refType = SchemaStyle.Inline.

To Reproduce Steps to reproduce the behaviour:

  1. Define nested case classes with Schema
  2. Convert the outer one's schema using JsonSchema.fromZSchema with refType = SchemaStyle.Inline
  3. Serialize the generated JsonSchema into a JSON string

scastie

Expected behaviour

All properties are inlined i.e. there are no $ref

Actual behavior

Nested object is still referenced by name

{
  "type" : 
    "object",
  "properties" : {
    "bar" : {
      "$ref" : "#/components/schemas/Bar"
    }
  },
  "required" : [
    "bar"
  ]
}

Additional context

It's needed for structured output when using OpenAI.

guersam commented 1 month ago

I tried simply replacing the hardcoded refType arguments in JsonSchema.fromZSchema with the outer refType, but it causes another bug that flattens nested case classes in properties field.