From cc6d79f22d2bd51e34a7319ba95c2d54ae5413d0 Mon Sep 17 00:00:00 2001 From: Devon Stewart Date: Sun, 23 Oct 2022 22:06:24 -0700 Subject: [PATCH] Adding support for dynamic additionalProperties --- .../dev/guardrail/generators/ProtocolGenerator.scala | 10 ++++++++++ 1 file changed, 10 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 e78b77ac64..57165fef81 100644 --- a/modules/core/src/main/scala/dev/guardrail/generators/ProtocolGenerator.scala +++ b/modules/core/src/main/scala/dev/guardrail/generators/ProtocolGenerator.scala @@ -429,6 +429,16 @@ object ProtocolGenerator { .orRefine { case s: StringSchema if Option(s.getEnum).map(_.asScala).exists(_.nonEmpty) => s }(s => fromEnum(nestedClassName.last, s, dtoPackage, components).map(Option(_)) ) + .orRefine { case m: MapSchema => m } { m => + m.downField("additionalProperties", _.getAdditionalProperties) + .indexedDistribute + .flatTraverse( + _.refine { case x: ObjectSchema => x }(obj => + fromModel(nestedClassName, obj, List.empty, concreteTypes, definitions, dtoPackage, supportPackage, defaultPropertyRequirement, components) + ).toOption.sequence + ) + .widen + } .getOrElse(Option.empty[Either[String, NestedProtocolElems[L]]].pure[F]) } yield defn