Skip to content

Commit

Permalink
feat: Allow dynamic schema in openapi
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
runtologist committed Dec 5, 2023
1 parent 58e0594 commit e375fe8
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 @@ -559,7 +559,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 @@ -907,4 +908,9 @@ object JsonSchema {
)
}

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

}

0 comments on commit e375fe8

Please sign in to comment.