smithy.api.XmlNamespace.scala Maven / Gradle / Ivy
package smithy.api
import smithy4s.Hints
import smithy4s.Schema
import smithy4s.ShapeId
import smithy4s.ShapeTag
import smithy4s.schema.Schema.recursive
import smithy4s.schema.Schema.struct
/** Adds an xmlns namespace definition URI to an XML element.
* @param uri
* The namespace URI for scoping this XML element.
* @param prefix
* The prefix for the given namespace.
*/
final case class XmlNamespace(uri: NonEmptyString, prefix: Option[NonEmptyString] = None)
object XmlNamespace extends ShapeTag.Companion[XmlNamespace] {
val id: ShapeId = ShapeId("smithy.api", "xmlNamespace")
val hints: Hints = Hints(
smithy.api.Documentation("Adds an xmlns namespace definition URI to an XML element."),
smithy.api.Trait(selector = Some(":is(service, member, simpleType, list, map, structure, union)"), structurallyExclusive = None, conflicts = Some(List(smithy.api.NonEmptyString("smithy.api#xmlAttribute"))), breakingChanges = Some(List(smithy.api.TraitDiffRule(change = smithy.api.TraitChangeType.ANY.widen, severity = smithy.api.Severity.ERROR.widen, path = None, message = None)))),
).lazily
// constructor using the original order from the spec
private def make(uri: NonEmptyString, prefix: Option[NonEmptyString]): XmlNamespace = XmlNamespace(uri, prefix)
implicit val schema: Schema[XmlNamespace] = recursive(struct(
NonEmptyString.schema.required[XmlNamespace]("uri", _.uri).addHints(smithy.api.Documentation("The namespace URI for scoping this XML element.")),
NonEmptyString.schema.validated(smithy.api.Pattern(s"^[a-zA-Z_][a-zA-Z_0-9-]*$$")).optional[XmlNamespace]("prefix", _.prefix).addHints(smithy.api.Documentation("The prefix for the given namespace.")),
)(make).withId(id).addHints(hints))
}