@@ -527,6 +527,14 @@ object JsonCodecMaker {
527
527
*/
528
528
def makeCirceLike [A ]: JsonValueCodec [A ] = macro Impl .makeCirceLike[A ]
529
529
530
+ /**
531
+ * Replacements for the `make` call preconfigured to behave as expected by openapi specifications.
532
+ * */
533
+ def makeOpenapiLike [A ]: JsonValueCodec [A ] = macro Impl .makeOpenapiLike[A ]
534
+ def makeOpenapiEnumLike [A ]: JsonValueCodec [A ] = macro Impl .makeOpenapiEnumLike[A ]
535
+ def makeOpenapiADTLikeDefaultMapping [A ](discriminator : String ): JsonValueCodec [A ] = macro Impl .makeOpenapiADTLikeDefaultMapping[A ]
536
+ def makeOpenapiADTLike [A ](discriminator : String , mapping : PartialFunction [String , String ]): JsonValueCodec [A ] = macro Impl .makeOpenapiADTLike[A ]
537
+
530
538
/**
531
539
* A replacement for the `make` call with the
532
540
* `CodecMakerConfig.withTransientEmpty(false).withTransientDefault(false).withTransientNone(false).withDiscriminatorFieldName(None).withAdtLeafClassNameMapper(x => enforce_snake_case(simpleClassName(x))).withFieldNameMapper(enforce_snake_case).withJavaEnumValueNameMapper(enforce_snake_case)`
@@ -570,6 +578,24 @@ object JsonCodecMaker {
570
578
make(c)(CodecMakerConfig .withTransientEmpty(false ).withTransientDefault(false ).withTransientNone(false )
571
579
.withDiscriminatorFieldName(None ).withCirceLikeObjectEncoding(true ))
572
580
581
+ def makeOpenapiLike [A : c.WeakTypeTag ](c : blackbox.Context ): c.Expr [JsonValueCodec [A ]] =
582
+ make(c)(CodecMakerConfig .withTransientEmpty(false ).withTransientDefault(false )
583
+ .withRequireCollectionFields(true ).withAllowRecursiveTypes(true ))
584
+
585
+ def makeOpenapiEnumLike [A : c.WeakTypeTag ](c : blackbox.Context ): c.Expr [JsonValueCodec [A ]] =
586
+ make(c)(CodecMakerConfig .withTransientEmpty(false ).withTransientDefault(false )
587
+ .withRequireCollectionFields(true ).withAllowRecursiveTypes(true ).withDiscriminatorFieldName(scala.None ))
588
+
589
+ def makeOpenapiADTLikeDefaultMapping [A : c.WeakTypeTag ](c : blackbox.Context )(discriminator : c.Expr [String ]): c.Expr [JsonValueCodec [A ]] =
590
+ make(c)(CodecMakerConfig .withTransientEmpty(false ).withTransientDefault(false )
591
+ .withRequireCollectionFields(true ).withAllowRecursiveTypes(true )
592
+ .withRequireDiscriminatorFirst(false ).withDiscriminatorFieldName(Some (c.eval(c.Expr [String ](c.untypecheck(discriminator.tree.duplicate))))))
593
+
594
+ def makeOpenapiADTLike [A : c.WeakTypeTag ](c : blackbox.Context )(discriminator : c.Expr [String ], mapping : c.Expr [PartialFunction [String , String ]]): c.Expr [JsonValueCodec [A ]] =
595
+ make(c)(CodecMakerConfig .withTransientEmpty(false ).withTransientDefault(false )
596
+ .withRequireCollectionFields(true ).withAllowRecursiveTypes(true )
597
+ .withRequireDiscriminatorFirst(false ).withDiscriminatorFieldName(Some (c.eval(c.Expr [String ](c.untypecheck(discriminator.tree.duplicate))))).withAdtLeafClassNameMapper(x => c.eval(c.Expr [PartialFunction [String , String ]](c.untypecheck(mapping.tree.duplicate))).apply(com.github.plokhotnyuk.jsoniter_scala.macros.JsonCodecMaker .simpleClassName(x))))
598
+
573
599
def makeCirceLikeSnakeCased [A : c.WeakTypeTag ](c : blackbox.Context ): c.Expr [JsonValueCodec [A ]] =
574
600
make(c)(CodecMakerConfig .withTransientEmpty(false ).withTransientDefault(false ).withTransientNone(false )
575
601
.withDiscriminatorFieldName(None ).withAdtLeafClassNameMapper(x => enforce_snake_case(simpleClassName(x)))
0 commit comments