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

alloy.DataExamples.scala Maven / Gradle / Ivy

There is a newer version: 0.19.0-41-91762fb
Show newest version
package alloy

import smithy4s.Hints
import smithy4s.Newtype
import smithy4s.Schema
import smithy4s.ShapeId
import smithy4s.schema.Schema.bijection
import smithy4s.schema.Schema.list
import smithy4s.schema.Schema.recursive

/** A trait for specifying what example data looks like. Differs from the `smithy.api#examples` trait in that
  * it can be used for any shape, not just operations. Below is an explanation of the different example formats
  * that are supported.
  * 1. SMITHY - this means that the examples will be using the `Document` abstraction and will be specified in
  * a protocol agnostic way
  * 2. JSON - this means the examples will use the `Document` abstraction, but will not be validated by the smithy
  * `NodeValidationVisitor` like the first type are. This type can be used to specify protocol specific examples
  * 3. STRING - this is just a string example and anything can be provided inside of the string.
  * This can be helpful for showing e.g. xml or another encoding that isn't JSON and therefore doesn't fit nicely
  *  with `Node` semantics
  */
object DataExamples extends Newtype[List[DataExample]] {
  val id: ShapeId = ShapeId("alloy", "dataExamples")
  val hints: Hints = Hints(
    smithy.api.Documentation("A trait for specifying what example data looks like. Differs from the `smithy.api#examples` trait in that\nit can be used for any shape, not just operations. Below is an explanation of the different example formats\nthat are supported.\n1. SMITHY - this means that the examples will be using the `Document` abstraction and will be specified in\na protocol agnostic way\n2. JSON - this means the examples will use the `Document` abstraction, but will not be validated by the smithy\n`NodeValidationVisitor` like the first type are. This type can be used to specify protocol specific examples\n3. STRING - this is just a string example and anything can be provided inside of the string.\nThis can be helpful for showing e.g. xml or another encoding that isn\'t JSON and therefore doesn\'t fit nicely\n with `Node` semantics"),
    smithy.api.Trait(selector = Some(":not(:test(service, operation, resource))"), structurallyExclusive = None, conflicts = None, breakingChanges = None),
  ).lazily
  val underlyingSchema: Schema[List[DataExample]] = list(DataExample.schema).withId(id).addHints(hints)
  implicit val schema: Schema[DataExamples] = recursive(bijection(underlyingSchema, asBijection))
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy