johnhungerford / generic-schema

2 stars 1 forks source link

Schema building dsl with configuration #22

Closed johnhungerford closed 2 years ago

johnhungerford commented 2 years ago
trait MyCustomConfiguration extends SchemaConfiguration {
    override def configure : Configuration = ???
}

...

import MyCustomConfiguration.dsl.*

val schema = 
    schema[ SomeType ]
        .product
        .addField(field[NestType].fieldName("nested_field").build)
        ...
        .updateComponent("nested_field"/"int_field")(_.withName("int"))
        .updateComponent("nested_field"/"str_field")(_.updateSchema(_.genericName("string")))))
        .build

Standardize methods:

johnhungerford commented 2 years ago
johnhungerford commented 2 years ago

Another possible pattern

val schema = MyCustomConfiguration.usingDsl { dsl =>
    import dsl.{*, given}

    schema[ SomeType ]
        .product
        .addField(field[NestType].fieldName("nested_field").build)
        ...
        .updateComponent("nested_field"/"int_field")(_.withName("int"))
        .updateComponent("nested_field"/"str_field")(_.updateSchema(_.genericName("string")))))
        .build
}
johnhungerford commented 2 years ago

Builder (only available with extensions in scope):

Schema.buildProduct[T]
Schema.buildCoproduct[T]
Schema.buildDerived[T]
Schema.buildPrimitive[T]

Schema.derived[T]  // no need to call .build
Schema.primitive[T](name, description, validators) // no need to call .build
johnhungerford commented 2 years ago

Closed with #29