Skip to content

Commit

Permalink
Merge pull request #1494 from guardrail-dev/hotfix-for-core-0.71.0
Browse files Browse the repository at this point in the history
Adding missing Schema mappings
  • Loading branch information
blast-hardcheese authored May 26, 2022
2 parents f9ef600 + 3265ae3 commit 5617c57
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions modules/core/src/main/scala/dev/guardrail/SwaggerUtil.scala
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,8 @@ object SwaggerUtil {
extractFormat(fmt => stringType(None).map(log(fmt, _)))
)
.orRefine { case SchemaLiteral(x: UUIDSchema) => x }(const(uuidType()))
.orRefine { case SchemaLiteral(x: EmailSchema) => x }(const(stringType(None)))
.orRefine { case SchemaLiteral(x: PasswordSchema) => x }(const(stringType(None)))
.orRefine { case SchemaLiteral(x: StringSchema) if x.getType() == "file" => x }(extractFormat(fmt => fileType(None).map(log(fmt, _))))
.orRefine { case SchemaLiteral(x: StringSchema) if x.getFormat() == "password" => x }(const(stringType(None)))
.orRefine { case SchemaLiteral(x: StringSchema) if x.getFormat() == "email" => x }(const(stringType(None)))
Expand All @@ -148,6 +150,7 @@ object SwaggerUtil {
.orRefine { case SchemaLiteral(x: StringSchema) if x.getFormat() == "byte" => x }(const(bytesType()))
.orRefine { case SchemaLiteral(x: StringSchema) if x.getFormat() == "binary" => x }(extractFormat(fmt => fileType(None).map(log(fmt, _))))
.orRefine { case SchemaLiteral(x: StringSchema) => x }(extractFormat(fmt => stringType(None).map(log(fmt, _))))
.orRefine { case SchemaLiteral(x: ByteArraySchema) => x }(const(bytesType()))
.orRefine { case SchemaLiteral(x: NumberSchema) if x.getFormat() == "float" => x }(const(floatType()))
.orRefine { case SchemaLiteral(x: NumberSchema) if x.getFormat() == "double" => x }(const(doubleType()))
.orRefine { case SchemaLiteral(x: NumberSchema) => x }(extractFormat(fmt => numberType(fmt).map(log(fmt, _))))
Expand All @@ -173,7 +176,13 @@ object SwaggerUtil {
.orRefine { case SchemaLiteral(x: BinarySchema) => x }(extractFormat(fmt => fileType(None).map(log(fmt, _))))
.orRefine { case SchemaLiteral(x: ObjectSchema) => x }(extractFormat(fmt => objectType(fmt).map(log(fmt, _))))
.orRefine { case SchemaLiteral(x: MapSchema) => x }(extractFormat(fmt => objectType(fmt).map(log(fmt, _))))
.orRefine { case SchemaLiteral(x: JsonSchema) => x }(extractFormat(fmt => objectType(fmt).map(log(fmt, _))))
.orRefineFallback { schemaProjection =>
schemaProjection.unwrapTracker match {
case SchemaLiteral(x) =>
println(s"WARNING: Missing type mapping for ${x.getClass}, please report this at https://github.com/guardrail-dev/guardrail/issues")
case SchemaRef(schema, ref) => println(s"WARNING: Unexpected type mapping missing, $ref")
}
val schema = schemaProjection.map {
case SchemaLiteral(x) => x
case SchemaRef(SchemaLiteral(x), _) => x
Expand Down

0 comments on commit 5617c57

Please sign in to comment.