Skip to content

Commit

Permalink
feat: Allow dynamic schema in openapi (#2543)
Browse files Browse the repository at this point in the history
* feat: Allow dynamic schema in openapi

Openapi just constrains the possible values, but they are
always JSON. In case of dynamic schema we do not know
anything about the possible values, so we simply remove
all constraints.

* generate readme
  • Loading branch information
runtologist authored Dec 8, 2023
1 parent 2f9ba86 commit 24dcb13
Showing 1 changed file with 9 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -415,7 +415,7 @@ object JsonSchema {
case Schema.Lazy(schema0) =>
fromZSchemaMulti(schema0(), refType)
case Schema.Dynamic(_) =>
throw new IllegalArgumentException("Dynamic schema is not supported.")
JsonSchemas(AnyJson, None, Map.empty)
}
}

Expand All @@ -435,7 +435,7 @@ object JsonSchema {
JsonSchemas(
JsonSchema.ArrayType(Some(nested.root)),
ref,
nested.children + (nested.rootRef.get -> nested.root),
nested.children ++ (nested.rootRef.map(_ -> nested.root)),
)
}
}
Expand Down Expand Up @@ -563,7 +563,8 @@ object JsonSchema {
case Schema.Tuple2(left, right, _) => AllOfSchema(Chunk(fromZSchema(left, refType), fromZSchema(right, refType)))
case Schema.Either(left, right, _) => OneOfSchema(Chunk(fromZSchema(left, refType), fromZSchema(right, refType)))
case Schema.Lazy(schema0) => fromZSchema(schema0(), refType)
case Schema.Dynamic(_) => throw new IllegalArgumentException("Dynamic schema is not supported.")
case Schema.Dynamic(_) => AnyJson

}

sealed trait SchemaStyle extends Product with Serializable
Expand Down Expand Up @@ -911,4 +912,9 @@ object JsonSchema {
)
}

case object AnyJson extends JsonSchema {
override protected[openapi] def toSerializableSchema: SerializableJsonSchema =
SerializableJsonSchema()
}

}

0 comments on commit 24dcb13

Please sign in to comment.