@@ -587,6 +587,52 @@ object JsonCodecMaker {
587587 */
588588 inline def makeCirceLikeSnakeCased [A ]: JsonValueCodec [A ] = $ {Impl .makeCirceLikeSnakeCased}
589589
590+ /**
591+ * Replacements for the `make` call preconfigured to behave as expected by openapi specifications:
592+ * `CodecMakerConfig.withTransientEmpty(false).withTransientDefault(false).withRequireCollectionFields(true).withAllowRecursiveTypes(true)`
593+ *
594+ * @tparam A a type that should be encoded and decoded by the derived codec
595+ * @return an instance of the derived codec
596+ */
597+ inline def makeOpenapiLike [A ]: JsonValueCodec [A ] = $ {Impl .makeOpenapiLike}
598+
599+ /**
600+ * Replacements for the `make` call preconfigured to behave as expected by openapi specifications:
601+ * `CodecMakerConfig.withTransientEmpty(false).withTransientDefault(false).withRequireCollectionFields(true).withAllowRecursiveTypes(true)`
602+ * with a privided discriminator field name.
603+ *
604+ * @tparam A a type that should be encoded and decoded by the derived codec
605+ * @param discriminatorFieldName a name of discriminator field
606+ * @return an instance of the derived codec
607+ */
608+ inline def makeOpenapiLike [A ](discriminatorFieldName : String ): JsonValueCodec [A ] =
609+ $ {Impl .makeOpenapiLike(' discriminatorFieldName )}
610+
611+ /**
612+ * Replacements for the `make` call preconfigured to behave as expected by openapi specifications:
613+ * `CodecMakerConfig.withTransientEmpty(false).withTransientDefault(false).withRequireCollectionFields(true).withAllowRecursiveTypes(true)`
614+ * with a privided discriminator field name and an ADT leaf-class name mapper with sequentionally applied function
615+ * that truncates to simple class name by default
616+ *
617+ * @tparam A a type that should be encoded and decoded by the derived codec
618+ * @param discriminatorFieldName a name of discriminator field
619+ * @param adtLeafClassNameMapper the function of mapping from string of case class/object full name to string value of
620+ * discriminator field
621+ * @return an instance of the derived codec
622+ */
623+ inline def makeOpenapiLike [A ](discriminatorFieldName : String , inline adtLeafClassNameMapper : PartialFunction [String , String ]): JsonValueCodec [A ] =
624+ $ {Impl .makeOpenapiLike(' discriminatorFieldName , ' adtLeafClassNameMapper )}
625+
626+ /**
627+ * Replacements for the `make` call preconfigured to behave as expected by openapi specifications:
628+ * `CodecMakerConfig.withTransientEmpty(false).withTransientDefault(false).withRequireCollectionFields(true).withAllowRecursiveTypes(true).withDiscriminatorFieldName(scala.None))`
629+ *
630+ * @tparam A a type that should be encoded and decoded by the derived codec
631+ * @return an instance of the derived codec
632+ */
633+ inline def makeOpenapiLikeWithoutDiscriminator [A ]: JsonValueCodec [A ] =
634+ $ {Impl .makeOpenapiLikeWithoutDiscriminator}
635+
590636 /**
591637 * Derives a codec for JSON values for the specified type `A` and a provided derivation configuration.
592638 *
@@ -652,6 +698,30 @@ object JsonCodecMaker {
652698 inlineOneValueClasses = false ,
653699 alwaysEmitDiscriminator = false ))
654700
701+ def makeOpenapiLike [A : Type ](using Quotes ): Expr [JsonValueCodec [A ]] =
702+ make(CodecMakerConfig .withTransientEmpty(false ).withTransientDefault(false )
703+ .withRequireCollectionFields(true ).withAllowRecursiveTypes(true ))
704+
705+ def makeOpenapiLike [A : Type ](discriminatorFieldName : Expr [String ])(using Quotes ): Expr [JsonValueCodec [A ]] =
706+ make(CodecMakerConfig .withTransientEmpty(false ).withTransientDefault(false )
707+ .withRequireCollectionFields(true ).withAllowRecursiveTypes(true )
708+ .withDiscriminatorFieldName(Some (discriminatorFieldName.valueOrAbort)))
709+
710+ def makeOpenapiLike [A : Type ](discriminatorFieldName : Expr [String ],
711+ adtLeafClassNameMapper : Expr [PartialFunction [String , String ]])(using Quotes ): Expr [JsonValueCodec [A ]] =
712+ make(
713+ CodecMakerConfig .withTransientEmpty(false ).withTransientDefault(false )
714+ .withRequireCollectionFields(true ).withAllowRecursiveTypes(true )
715+ .withDiscriminatorFieldName(Some (discriminatorFieldName.valueOrAbort))
716+ .withAdtLeafClassNameMapper(ExprPartialFunctionWrapper (adtLeafClassNameMapper).apply.unlift
717+ .compose(PartialFunction .fromFunction(simpleClassName))))
718+
719+ def makeOpenapiLikeWithoutDiscriminator [A : Type ](using Quotes ): Expr [JsonValueCodec [A ]] =
720+ make(CodecMakerConfig .withTransientEmpty(false ).withTransientDefault(false )
721+ .withRequireCollectionFields(true ).withAllowRecursiveTypes(true )
722+ .withDiscriminatorFieldName(None ))
723+
724+
655725 def makeWithSpecifiedConfig [A : Type ](config : Expr [CodecMakerConfig ])(using Quotes ): Expr [JsonValueCodec [A ]] = {
656726 import quotes .reflect ._
657727
0 commit comments