Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support unknown field retention trait #1409

Draft
wants to merge 19 commits into
base: series/0.18
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 15 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 38 additions & 3 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,9 @@ lazy val `aws-http4s` = projectMatrix
bootstrapped % "test->compile"
)
.settings(
// TODO: Remove once https://github.com/disneystreaming/alloy/pull/135 is
// merged and released.
resolvers ++= Resolver.sonatypeOssRepos("snapshots"),
libraryDependencies ++= {
Seq(
Dependencies.Fs2.io.value,
Expand All @@ -314,6 +317,9 @@ lazy val `aws-http4s` = projectMatrix
"-Wconf:msg=class RestXml in package (aws\\.)?protocols is deprecated:silent",
"-Wconf:msg=value noErrorWrapping in class RestXml is deprecated:silent"
),
Test / complianceTestRepositories := Seq(
"https://s01.oss.sonatype.org/content/repositories/snapshots"
),
Test / complianceTestDependencies := Seq(
Dependencies.Smithy.`aws-protocol-tests`
),
Expand Down Expand Up @@ -365,6 +371,9 @@ lazy val codegen = projectMatrix
"alloyVersion" -> Dependencies.Alloy.alloyVersion
),
buildInfoPackage := "smithy4s.codegen",
// TODO: Remove once https://github.com/disneystreaming/alloy/pull/135 is
// merged and released.
resolvers ++= Resolver.sonatypeOssRepos("snapshots"),
libraryDependencies ++= Seq(
Dependencies.Cats.core.value,
Dependencies.Smithy.model,
Expand Down Expand Up @@ -561,6 +570,9 @@ lazy val dynamic = projectMatrix
bootstrapped % "test->test;test->compile"
)
.settings(
// TODO: Remove once https://github.com/disneystreaming/alloy/pull/135 is
// merged and released.
resolvers ++= Resolver.sonatypeOssRepos("snapshots"),
libraryDependencies ++= munitDeps.value ++ Seq(
Dependencies.collectionsCompat.value,
Dependencies.Cats.core.value,
Expand Down Expand Up @@ -691,6 +703,9 @@ lazy val http4s = projectMatrix
)
.settings(
isMimaEnabled := true,
// TODO: Remove once https://github.com/disneystreaming/alloy/pull/135 is
// merged and released.
resolvers ++= Resolver.sonatypeOssRepos("snapshots"),
libraryDependencies ++= {
Seq(
Dependencies.Http4s.core.value,
Expand All @@ -708,6 +723,9 @@ lazy val http4s = projectMatrix
Test / allowedNamespaces := Seq(
"smithy4s.example.guides.auth"
),
Test / complianceTestRepositories := Seq(
"https://s01.oss.sonatype.org/content/repositories/snapshots"
),
Test / complianceTestDependencies := Seq(
Dependencies.Alloy.`protocol-tests`
),
Expand Down Expand Up @@ -798,6 +816,9 @@ lazy val transformers = projectMatrix
.in(file("modules/transformers"))
.settings(Smithy4sBuildPlugin.doNotPublishArtifact)
.settings(
// TODO: Remove once https://github.com/disneystreaming/alloy/pull/135 is
// merged and released.
resolvers ++= Resolver.sonatypeOssRepos("snapshots"),
libraryDependencies ++= Seq(
Dependencies.Smithy.model,
Dependencies.Smithy.build,
Expand Down Expand Up @@ -964,7 +985,10 @@ def genSmithy(config: Configuration) = Def.settings(
def genSmithyScala(config: Configuration) = genSmithyImpl(config).map(_._1)
def genSmithyResources(config: Configuration) = genSmithyImpl(config).map(_._2)

// SBT setting to specify artifacts to be included in the Smithy model for compliance testing
// SBT settings to specify repositories and their artifacts to be included in
// the Smithy model for compliance testing
val complianceTestRepositories =
SettingKey[Seq[String]]("complianceTestRepositories")
val complianceTestDependencies =
SettingKey[Seq[ModuleID]]("complianceTestDependencies")

Expand All @@ -976,6 +1000,8 @@ def dumpModel(config: Configuration): Def.Initialize[Task[Seq[File]]] =
Smithy4sBuildPlugin.Scala213
) / Compile / fullClasspath).value
.map(_.data)
val repos =
(config / complianceTestRepositories).?.value.getOrElse(Seq.empty)
val transforms = (config / smithy4sModelTransformers).value
lazy val modelTransformersCp = (transformers.jvm(
Smithy4sBuildPlugin.Scala213
Expand Down Expand Up @@ -1023,8 +1049,10 @@ def dumpModel(config: Configuration): Def.Initialize[Task[Seq[File]]] =
val s = (config / streams).value

val args =
if (transforms.isEmpty) List.empty
else List("--transformers", transforms.mkString(","))
(if (repos.isEmpty) List.empty
else List("--repositories", repos.mkString(","))) ++
(if (transforms.isEmpty) List.empty
else List("--transformers", transforms.mkString(",")))
val cached =
Tracked.inputChanged[List[String], Seq[File]](
s.cacheStoreFactory.make("input")
Expand Down Expand Up @@ -1077,6 +1105,8 @@ def genSmithyImpl(config: Configuration) = Def.task {
.getAbsolutePath()
val allowedNS = (config / allowedNamespaces).?.value.filterNot(_.isEmpty)
val skip = (config / smithy4sSkip).?.value.getOrElse(Seq.empty)
val smithy4sRepos =
(config / smithy4sRepositories).?.value.getOrElse(Seq.empty)
val smithy4sDeps =
(config / smithy4sDependencies).?.value.getOrElse(Seq.empty).map {
moduleId =>
Expand Down Expand Up @@ -1154,6 +1184,10 @@ def genSmithyImpl(config: Configuration) = Def.task {
List("--allowed-ns", allowedNS.get.mkString(","))
else Nil
val skipOpt = skip.flatMap(s => List("--skip", s))
val respositoriesOpt =
if (smithy4sRepos.nonEmpty)
List("--repositories", smithy4sRepos.mkString(","))
else Nil
val dependenciesOpt =
if (smithy4sDeps.nonEmpty)
List("--dependencies", smithy4sDeps.mkString(","))
Expand All @@ -1163,6 +1197,7 @@ def genSmithyImpl(config: Configuration) = Def.task {
allowedNsOpt ++
inputs ++
skipOpt ++
respositoriesOpt ++
dependenciesOpt

val cp = codegenCp
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,6 @@ object Endpoint extends ShapeTag.Companion[Endpoint] {

implicit val schema: Schema[Endpoint] = struct(
string.required[Endpoint]("Address", _.address).addHints(smithy.api.Documentation("<p>IP address of the endpoint.</p>")),
long.required[Endpoint]("CachePeriodInMinutes", _.cachePeriodInMinutes).addHints(smithy.api.Default(smithy4s.Document.fromDouble(0.0d)), smithy.api.Documentation("<p>Endpoint cache time to live (TTL) value.</p>")),
long.required[Endpoint]("CachePeriodInMinutes", _.cachePeriodInMinutes).addHints(smithy.api.Documentation("<p>Endpoint cache time to live (TTL) value.</p>"), smithy.api.Default(smithy4s.Document.fromDouble(0.0d))),
)(make).withId(id).addHints(hints)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package smithy4s.example

import smithy4s.Document
import smithy4s.Hints
import smithy4s.Schema
import smithy4s.ShapeId
import smithy4s.ShapeTag
import smithy4s.schema.Schema.document
import smithy4s.schema.Schema.string
import smithy4s.schema.Schema.struct

final case class DefaultRequiredUnknownFieldRetentionExample(retainedUnknownFields: Document = smithy4s.Document.nullDoc, foo: Option[String] = None, bar: Option[String] = None)

object DefaultRequiredUnknownFieldRetentionExample extends ShapeTag.Companion[DefaultRequiredUnknownFieldRetentionExample] {
val id: ShapeId = ShapeId("smithy4s.example", "DefaultRequiredUnknownFieldRetentionExample")

val hints: Hints = Hints.empty

// constructor using the original order from the spec
private def make(foo: Option[String], bar: Option[String], retainedUnknownFields: Document): DefaultRequiredUnknownFieldRetentionExample = DefaultRequiredUnknownFieldRetentionExample(retainedUnknownFields, foo, bar)

implicit val schema: Schema[DefaultRequiredUnknownFieldRetentionExample] = struct(
string.optional[DefaultRequiredUnknownFieldRetentionExample]("foo", _.foo),
string.optional[DefaultRequiredUnknownFieldRetentionExample]("bar", _.bar),
document.required[DefaultRequiredUnknownFieldRetentionExample]("retainedUnknownFields", _.retainedUnknownFields).addHints(smithy.api.Default(smithy4s.Document.nullDoc), alloy.UnknownJsonFieldRetention(), alloy.UnknownDocumentFieldRetention()),
)(make).withId(id).addHints(hints)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package smithy4s.example

import smithy4s.Document
import smithy4s.Hints
import smithy4s.Schema
import smithy4s.ShapeId
import smithy4s.ShapeTag
import smithy4s.schema.Schema.document
import smithy4s.schema.Schema.string
import smithy4s.schema.Schema.struct

final case class DefaultUnknownFieldRetentionExample(retainedUnknownFields: Document = smithy4s.Document.nullDoc, foo: Option[String] = None, bar: Option[String] = None)

object DefaultUnknownFieldRetentionExample extends ShapeTag.Companion[DefaultUnknownFieldRetentionExample] {
val id: ShapeId = ShapeId("smithy4s.example", "DefaultUnknownFieldRetentionExample")

val hints: Hints = Hints.empty

// constructor using the original order from the spec
private def make(foo: Option[String], bar: Option[String], retainedUnknownFields: Document): DefaultUnknownFieldRetentionExample = DefaultUnknownFieldRetentionExample(retainedUnknownFields, foo, bar)

implicit val schema: Schema[DefaultUnknownFieldRetentionExample] = struct(
string.optional[DefaultUnknownFieldRetentionExample]("foo", _.foo),
string.optional[DefaultUnknownFieldRetentionExample]("bar", _.bar),
document.field[DefaultUnknownFieldRetentionExample]("retainedUnknownFields", _.retainedUnknownFields).addHints(alloy.UnknownDocumentFieldRetention(), smithy.api.Default(smithy4s.Document.nullDoc), alloy.UnknownJsonFieldRetention()),
)(make).withId(id).addHints(hints)
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ object Integers extends ShapeTag.Companion[Integers] {

implicit val schema: Schema[Integers] = struct(
int.required[Integers]("int", _.int).addHints(alloy.proto.ProtoIndex(1)),
int.required[Integers]("sint", _.sint).addHints(alloy.proto.ProtoNumType.SIGNED.widen, alloy.proto.ProtoIndex(2)),
int.required[Integers]("uint", _.uint).addHints(alloy.proto.ProtoNumType.UNSIGNED.widen, alloy.proto.ProtoIndex(3)),
int.required[Integers]("fixedUint", _.fixedUint).addHints(alloy.proto.ProtoNumType.FIXED.widen, alloy.proto.ProtoIndex(4)),
int.required[Integers]("fixedSint", _.fixedSint).addHints(alloy.proto.ProtoNumType.FIXED_SIGNED.widen, alloy.proto.ProtoIndex(5)),
int.required[Integers]("sint", _.sint).addHints(alloy.proto.ProtoIndex(2), alloy.proto.ProtoNumType.SIGNED.widen),
int.required[Integers]("uint", _.uint).addHints(alloy.proto.ProtoIndex(3), alloy.proto.ProtoNumType.UNSIGNED.widen),
int.required[Integers]("fixedUint", _.fixedUint).addHints(alloy.proto.ProtoIndex(4), alloy.proto.ProtoNumType.FIXED.widen),
int.required[Integers]("fixedSint", _.fixedSint).addHints(alloy.proto.ProtoIndex(5), alloy.proto.ProtoNumType.FIXED_SIGNED.widen),
)(make).withId(id).addHints(hints)
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ object Longs extends ShapeTag.Companion[Longs] {

implicit val schema: Schema[Longs] = struct(
long.required[Longs]("long", _.long).addHints(alloy.proto.ProtoIndex(1)),
long.required[Longs]("slong", _.slong).addHints(alloy.proto.ProtoNumType.SIGNED.widen, alloy.proto.ProtoIndex(2)),
long.required[Longs]("ulong", _.ulong).addHints(alloy.proto.ProtoNumType.UNSIGNED.widen, alloy.proto.ProtoIndex(3)),
long.required[Longs]("fixedLong", _.fixedLong).addHints(alloy.proto.ProtoNumType.FIXED.widen, alloy.proto.ProtoIndex(4)),
long.required[Longs]("fixedSlong", _.fixedSlong).addHints(alloy.proto.ProtoNumType.FIXED_SIGNED.widen, alloy.proto.ProtoIndex(5)),
long.required[Longs]("slong", _.slong).addHints(alloy.proto.ProtoIndex(2), alloy.proto.ProtoNumType.SIGNED.widen),
long.required[Longs]("ulong", _.ulong).addHints(alloy.proto.ProtoIndex(3), alloy.proto.ProtoNumType.UNSIGNED.widen),
long.required[Longs]("fixedLong", _.fixedLong).addHints(alloy.proto.ProtoIndex(4), alloy.proto.ProtoNumType.FIXED.widen),
long.required[Longs]("fixedSlong", _.fixedSlong).addHints(alloy.proto.ProtoIndex(5), alloy.proto.ProtoNumType.FIXED_SIGNED.widen),
)(make).withId(id).addHints(hints)
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ object OperationInput extends ShapeTag.Companion[OperationInput] {
implicit val schema: Schema[OperationInput] = struct(
string.optional[OperationInput]("optional", _.optional),
string.field[OperationInput]("optionalWithDefault", _.optionalWithDefault).addHints(smithy.api.Default(smithy4s.Document.fromString("optional-default"))),
string.required[OperationInput]("requiredLabel", _.requiredLabel).addHints(smithy.api.Default(smithy4s.Document.fromString("required-label-with-default")), smithy.api.HttpLabel()),
string.required[OperationInput]("requiredLabel", _.requiredLabel).addHints(smithy.api.HttpLabel(), smithy.api.Default(smithy4s.Document.fromString("required-label-with-default"))),
string.required[OperationInput]("requiredWithDefault", _.requiredWithDefault).addHints(smithy.api.Default(smithy4s.Document.fromString("required-default"))),
string.optional[OperationInput]("optionalHeader", _.optionalHeader).addHints(smithy.api.HttpHeader("optional-header")),
string.field[OperationInput]("optionalHeaderWithDefault", _.optionalHeaderWithDefault).addHints(smithy.api.Default(smithy4s.Document.fromString("optional-header-with-default")), smithy.api.HttpHeader("optional-header-with-default")),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package smithy4s.example

import smithy4s.Document
import smithy4s.Hints
import smithy4s.Schema
import smithy4s.ShapeId
import smithy4s.ShapeTag
import smithy4s.schema.Schema.document
import smithy4s.schema.Schema.string
import smithy4s.schema.Schema.struct

final case class RequiredUnknownFieldRetentionExample(retainedUnknownFields: Document, foo: Option[String] = None, bar: Option[String] = None)

object RequiredUnknownFieldRetentionExample extends ShapeTag.Companion[RequiredUnknownFieldRetentionExample] {
val id: ShapeId = ShapeId("smithy4s.example", "RequiredUnknownFieldRetentionExample")

val hints: Hints = Hints.empty

// constructor using the original order from the spec
private def make(foo: Option[String], bar: Option[String], retainedUnknownFields: Document): RequiredUnknownFieldRetentionExample = RequiredUnknownFieldRetentionExample(retainedUnknownFields, foo, bar)

implicit val schema: Schema[RequiredUnknownFieldRetentionExample] = struct(
string.optional[RequiredUnknownFieldRetentionExample]("foo", _.foo),
string.optional[RequiredUnknownFieldRetentionExample]("bar", _.bar),
document.required[RequiredUnknownFieldRetentionExample]("retainedUnknownFields", _.retainedUnknownFields).addHints(alloy.UnknownDocumentFieldRetention(), alloy.UnknownJsonFieldRetention()),
)(make).withId(id).addHints(hints)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package smithy4s.example

import smithy4s.Document
import smithy4s.Hints
import smithy4s.Schema
import smithy4s.ShapeId
import smithy4s.ShapeTag
import smithy4s.schema.Schema.document
import smithy4s.schema.Schema.string
import smithy4s.schema.Schema.struct

final case class UnknownFieldRetentionExample(foo: Option[String] = None, bar: Option[String] = None, retainedUnknownFields: Option[Document] = None)

object UnknownFieldRetentionExample extends ShapeTag.Companion[UnknownFieldRetentionExample] {
val id: ShapeId = ShapeId("smithy4s.example", "UnknownFieldRetentionExample")

val hints: Hints = Hints.empty

// constructor using the original order from the spec
private def make(foo: Option[String], bar: Option[String], retainedUnknownFields: Option[Document]): UnknownFieldRetentionExample = UnknownFieldRetentionExample(foo, bar, retainedUnknownFields)

implicit val schema: Schema[UnknownFieldRetentionExample] = struct(
string.optional[UnknownFieldRetentionExample]("foo", _.foo),
string.optional[UnknownFieldRetentionExample]("bar", _.bar),
document.optional[UnknownFieldRetentionExample]("retainedUnknownFields", _.retainedUnknownFields).addHints(alloy.UnknownDocumentFieldRetention(), alloy.UnknownJsonFieldRetention()),
)(make).withId(id).addHints(hints)
}
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ object HelloWorldAuthServiceOperation {
.withInput(unit)
.withError(HealthCheckError.errorSchema)
.withOutput(HealthCheckOutput.schema)
.withHints(smithy.api.Auth(Set()), smithy.api.Http(method = smithy.api.NonEmptyString("GET"), uri = smithy.api.NonEmptyString("/health"), code = 200), smithy.api.Readonly())
.withHints(smithy.api.Http(method = smithy.api.NonEmptyString("GET"), uri = smithy.api.NonEmptyString("/health"), code = 200), smithy.api.Readonly(), smithy.api.Auth(Set()))
def wrap(input: Unit): HealthCheck = HealthCheck()
}
sealed trait HealthCheckError extends scala.Product with scala.Serializable { self =>
Expand Down
Loading
Loading