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

smithy.api.HttpApiKeyAuth.scala Maven / Gradle / Ivy

There is a newer version: 0.19.0-41-91762fb
Show newest version
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

/** An HTTP-specific authentication scheme that sends an arbitrary API key in
  * a header or query string parameter.
  * @param name
  *   Defines the name of the HTTP header or query string parameter that
  *   contains the API key.
  * @param in
  *   Defines the location of where the key is serialized. This value can
  *   be set to `"header"` or `"query"`.
  * @param scheme
  *   Defines the security scheme to use in the ``Authorization`` header.
  *   This can only be set if the "in" property is set to ``header``.
  */
final case class HttpApiKeyAuth(name: NonEmptyString, in: HttpApiKeyLocations, scheme: Option[NonEmptyString] = None)

object HttpApiKeyAuth extends ShapeTag.Companion[HttpApiKeyAuth] {
  val id: ShapeId = ShapeId("smithy.api", "httpApiKeyAuth")

  val hints: Hints = Hints(
    smithy.api.Documentation("An HTTP-specific authentication scheme that sends an arbitrary API key in\na header or query string parameter."),
    smithy.api.Trait(selector = Some("service"), structurallyExclusive = None, conflicts = None, breakingChanges = Some(List(smithy.api.TraitDiffRule(change = smithy.api.TraitChangeType.REMOVE.widen, severity = smithy.api.Severity.ERROR.widen, path = None, message = None)))),
    smithy.api.AuthDefinition(traits = None),
  ).lazily

  // constructor using the original order from the spec
  private def make(name: NonEmptyString, in: HttpApiKeyLocations, scheme: Option[NonEmptyString]): HttpApiKeyAuth = HttpApiKeyAuth(name, in, scheme)

  implicit val schema: Schema[HttpApiKeyAuth] = recursive(struct(
    NonEmptyString.schema.required[HttpApiKeyAuth]("name", _.name).addHints(smithy.api.Documentation("Defines the name of the HTTP header or query string parameter that\ncontains the API key.")),
    HttpApiKeyLocations.schema.required[HttpApiKeyAuth]("in", _.in).addHints(smithy.api.Documentation("Defines the location of where the key is serialized. This value can\nbe set to `\"header\"` or `\"query\"`.")),
    NonEmptyString.schema.optional[HttpApiKeyAuth]("scheme", _.scheme).addHints(smithy.api.Documentation("Defines the security scheme to use in the ``Authorization`` header.\nThis can only be set if the \"in\" property is set to ``header``.")),
  )(make).withId(id).addHints(hints))
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy