From 232331233fc3d7fa381d4ac949841b43240488ee Mon Sep 17 00:00:00 2001 From: Devon Stewart Date: Sun, 23 Oct 2022 23:50:21 -0700 Subject: [PATCH] Adding a warning and a bit of context for what's missing --- .../generators/ProtocolGenerator.scala | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/modules/core/src/main/scala/dev/guardrail/generators/ProtocolGenerator.scala b/modules/core/src/main/scala/dev/guardrail/generators/ProtocolGenerator.scala index 57165fef81..6faa964af4 100644 --- a/modules/core/src/main/scala/dev/guardrail/generators/ProtocolGenerator.scala +++ b/modules/core/src/main/scala/dev/guardrail/generators/ProtocolGenerator.scala @@ -430,6 +430,23 @@ object ProtocolGenerator { fromEnum(nestedClassName.last, s, dtoPackage, components).map(Option(_)) ) .orRefine { case m: MapSchema => m } { m => + // TODO: #1591: What we are emitting here is the inner class `Z` in the expression: + // `foo: Option[Map[String, Z]]` + // Unfortunately, that means that if we wanted to properly parse and incorporate + // those fields, we would need to do something more creative like + // `case class Bar(prop: A, prop2: B, extra: Map[String, Z])` + // so we could do + // `foo: Option[Bar]` + // we would need an extra className for `Bar` (instead of just using nestedClassName), + // as well as to be more choosy about which fields we try to decode with `.as[Z]`, + // since we should intentionally and explicitly skip fields for which we have known + // mappings for, using the `additionalProperties` mapping only for fields we've never seen. + NonEmptyList.fromList(m.downField("properties", _.getProperties).indexedDistribute.toList).foreach { props => + println(s"""WARNING: Unsupported mixing of properties and additionalProperties. + | See https://github.com/guardrail-dev/guardrail/issues/1591 + | Ignored values: ${props.toList.map(_.showHistory).mkString(", ")} + |""".stripMargin) + } m.downField("additionalProperties", _.getAdditionalProperties) .indexedDistribute .flatTraverse(