All Downloads are FREE. Search and download functionalities are using the official Maven repository.

scala-cask.model.mustache Maven / Gradle / Ivy

There is a newer version: 7.9.0
Show newest version
{{>licenseInfo}}
// this model was generated using model.mustache
package {{modelPackage}}
{{#imports}}import {{import}}
{{/imports}}
import scala.util.control.NonFatal

// see https://com-lihaoyi.github.io/upickle/
import upickle.default.{ReadWriter => RW, macroRW}
import upickle.default.*

{{#models}}
{{#model}}
case class {{classname}}(
  {{#vars}}
  {{#description}}
/* {{{description}}} */
  {{/description}}
  {{name}}: {{#isEnum}}{{^required}}Option[{{/required}}{{classname}}.{{datatypeWithEnum}}{{^required}}]{{/required}}{{/isEnum}}{{^isEnum}}{{{vendorExtensions.x-datatype-model}}}{{/isEnum}}{{^required}} = {{{vendorExtensions.x-defaultValue-model}}} {{/required}}{{^-last}},{{/-last}}

  {{/vars}}) {

  def asJson: String = asData.asJson

  def asData : {{classname}}Data = {
    {{classname}}Data(
        {{#vars}}
            {{name}} = {{name}}{{#vendorExtensions.x-map-asModel}}.map(_.asData){{/vendorExtensions.x-map-asModel}}{{#vendorExtensions.x-wrap-in-optional}}.getOrElse({{{defaultValue}}}){{/vendorExtensions.x-wrap-in-optional}}{{^-last}},{{/-last}}
        {{/vars}}
    )
  }

}

object {{classname}}{

    given RW[{{classname}}] = {{classname}}Data.readWriter.bimap[{{classname}}](_.asData, _.asModel)

    enum Fields(fieldName : String) extends Field(fieldName) {
        {{#vars}}
            case {{name}} extends Fields("{{name}}")
        {{/vars}}
    }

{{#vars}}
    {{#isEnum}}
        // baseName={{{baseName}}}
        // nameInCamelCase = {{{nameInCamelCase}}}
        enum {{datatypeWithEnum}} derives ReadWriter {
        {{#_enum}}
            case {{.}}
        {{/_enum}}
        }
    {{/isEnum}}
{{/vars}}

}

{{/model}}
{{/models}}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy