Skip to content

Commit

Permalink
Merge 0.17 into 0.18... one more time. (#1124)
Browse files Browse the repository at this point in the history
* Add changelog entries for 0.17.7-12

* [skip ci] remove extra newline

* Backport service interpreter (address #1111) (#1118)

* Fix rendering of deprecated annotation in mixins (#1123)

Co-authored-by: ghostbuster91 <ghostbuster91@users.noreply.github.com>
Co-authored-by: David Francoeur <dfrancoeur04@gmail.com>

* Only transform AWS shapes named after standard shapes (#1127)

* Fixes AWS AwsStandardTypesTransformer bug

Only structure members can carry the `@default` trait.

* Fix sandbox

* add missing newline

---------

Co-authored-by: Olivier Mélois <baccata64@gmail.com>
Co-authored-by: Miguel Vilá <miguelvilag@gmail.com>
Co-authored-by: Kasper Kondzielski <kghost0@gmail.com>
Co-authored-by: ghostbuster91 <ghostbuster91@users.noreply.github.com>
Co-authored-by: David Francoeur <dfrancoeur04@gmail.com>
Co-authored-by: Olivier Mélois <olivier.melois@disneystreaming.com>
  • Loading branch information
7 people committed Aug 1, 2023
1 parent 9d39efc commit 51af4e1
Show file tree
Hide file tree
Showing 12 changed files with 247 additions and 29 deletions.
78 changes: 77 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ See https://github.com/disneystreaming/smithy4s/pull/921
### Structure Patterns

Allows for marking string types with the `alloy#structurePattern` trait. This trait indicates that a given pattern, with parameters, applies to a given string and that this string should
actually be parsed into a structure where the members of the structure are derived from the parameters in the string pattern.
actually be parsed into a structure where the members of the structure are derived from the parameters in the string pattern.

See https://github.com/disneystreaming/smithy4s/pull/942

Expand All @@ -42,6 +42,82 @@ When the smithy4sRenderOptics setting is enabled, Lenses and Prisms will be rend

See https://github.com/disneystreaming/smithy4s/pull/1103

# 0.17.14

* Only transform AWS shapes named after standard shapes in [#1127](https://github.com/disneystreaming/smithy4s/pull/1127)
* Fixes AWS AwsStandardTypesTransformer bug by in [1129](https://github.com/disneystreaming/smithy4s/pull/1129)

# 0.17.13

* Backports Service interpreter logic introduced in [#908](https://github.com/disneystreaming/smithy4s/pull/908).
* Fixes rendering of deprecated annotations in mixins in [#1123](https://github.com/disneystreaming/smithy4s/pull/1123)

# 0.17.12

* Remove reserved types in https://github.com/disneystreaming/smithy4s/pull/1052

Remove a legacy mechanism of dealing with name conflicts in generated types. Fixes #1051

* Flatten AWS newtypes in https://github.com/disneystreaming/smithy4s/pull/1110

Adjusts the rendering of Smithy shapes from AWS specs, as it would've often been inconvenient due to the change above.

* Bump webjar dependency to 0.47 in https://github.com/disneystreaming/smithy4s/pull/1100

Updates a previously frozen dependency to alleviate potential security issues.

# 0.17.11

This is mostly a bugfix and cleanup release.

* [aws] Keep casing in file credential provider in https://github.com/disneystreaming/smithy4s/pull/1076

Resolves a case-sensitivity issue in the file-based AWS credentials provider.

* Deprecate `ClientBuilder.use`, add `.make` in https://github.com/disneystreaming/smithy4s/pull/1073

Deprecates a method - the migration path would be just to move to another one with the same shape.

* Error transformations as middleware in https://github.com/disneystreaming/smithy4s/pull/1084

Changes the error transformation logic in the http4s servers so that it's implemented using the (public) per-endpoint middleware construct.

# 0.17.10

* Revert original behavior where middleware get all errors in https://github.com/disneystreaming/smithy4s/pull/1034

This change adds a fix for an accidental behavior change around error handling/capture in middlewares.

## Other changes

* Adding a comment in flatMapErrors in https://github.com/disneystreaming/smithy4s/pull/1030

# 0.17.9

* Update smithy-model to 1.31.0, alloy to 0.2.2 in https://github.com/disneystreaming/smithy4s/pull/1022

# 0.17.8

* backport of [improve: fallback unspecified members of deprecated trait to N/A] in https://github.com/disneystreaming/smithy4s/pull/989
* Dynamic module guide in https://github.com/disneystreaming/smithy4s/pull/960
* Add an option to encode missing fields as nulls in https://github.com/disneystreaming/smithy4s/pull/995

# 0.17.7

Make sure error handling logic in routing is applied before and after middleware application .

* Add course link to learning resources in https://github.com/disneystreaming/smithy4s/pull/965
* Http4s: pre- and post-error handling middleware in https://github.com/disneystreaming/smithy4s/pull/877

# 0.17.6

This release is backward binary-compatible with the previous releases from the 0.17.x lineage.

## Bug fixes

* Fixes a [bug](https://github.com/disneystreaming/smithy4s/pull/898) related to swagger-ui redirects that would occur with empty paths.
* Fixes a [bug](https://github.com/disneystreaming/smithy4s/pull/904) related to the undocumented "dynamic" module not respecting the order of fields specified in smithy models

# 0.17.5

This release is backward binary-compatible with the previous releases from the 0.17.x lineage.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package com.amazonaws.dynamodb

import smithy4s.Hints
import smithy4s.Newtype
import smithy4s.Schema
import smithy4s.ShapeId
import smithy4s.schema.Schema.bijection
import smithy4s.schema.Schema.string

object ErrorMessage extends Newtype[String] {
val id: ShapeId = ShapeId("com.amazonaws.dynamodb", "ErrorMessage")
val hints: Hints = Hints.empty
val underlyingSchema: Schema[String] = string.withId(id).addHints(hints)
implicit val schema: Schema[ErrorMessage] = bijection(underlyingSchema, asBijection)
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,14 @@ import smithy4s.Hints
import smithy4s.Schema
import smithy4s.ShapeId
import smithy4s.ShapeTag
import smithy4s.schema.Schema.string
import smithy4s.schema.Schema.struct

/** <p>An error occurred on the server side.</p>
* @param message
* <p>The server encountered an internal error trying to fulfill the request.</p>
*/
final case class InternalServerError(message: Option[String] = None) extends Throwable {
override def getMessage(): String = message.orNull
final case class InternalServerError(message: Option[ErrorMessage] = None) extends Throwable {
override def getMessage(): String = message.map(_.value).orNull
}
object InternalServerError extends ShapeTag.Companion[InternalServerError] {
val id: ShapeId = ShapeId("com.amazonaws.dynamodb", "InternalServerError")
Expand All @@ -23,7 +22,7 @@ object InternalServerError extends ShapeTag.Companion[InternalServerError] {
)

implicit val schema: Schema[InternalServerError] = struct(
string.optional[InternalServerError]("message", _.message).addHints(smithy.api.Documentation("<p>The server encountered an internal error trying to fulfill the request.</p>")),
ErrorMessage.schema.optional[InternalServerError]("message", _.message).addHints(smithy.api.Documentation("<p>The server encountered an internal error trying to fulfill the request.</p>")),
){
InternalServerError.apply
}.withId(id).addHints(hints)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ package object dynamodb {
val DynamoDB = DynamoDBGen

type ListTablesInputLimit = com.amazonaws.dynamodb.ListTablesInputLimit.Type
type ErrorMessage = com.amazonaws.dynamodb.ErrorMessage.Type
type TableNameList = com.amazonaws.dynamodb.TableNameList.Type
/** @param member
* <p>An endpoint information details.</p>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package smithy4s.example


@deprecated(message = "A compelling reason", since = "0.0.1")
trait DeprecatedMixin {
@deprecated(message = "N/A", since = "N/A")
def strings: Option[List[String]]
def other: Option[List[String]]
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import smithy4s.schema.Schema.string
import smithy4s.schema.Schema.struct

@deprecated(message = "A compelling reason", since = "0.0.1")
final case class DeprecatedStructure(@deprecated(message = "N/A", since = "N/A") name: Option[String] = None, nameV2: Option[String] = None, strings: Option[List[String]] = None)
final case class DeprecatedStructure(@deprecated(message = "N/A", since = "N/A") strings: Option[List[String]] = None, other: Option[List[String]] = None, @deprecated(message = "N/A", since = "N/A") name: Option[String] = None, nameV2: Option[String] = None) extends DeprecatedMixin
object DeprecatedStructure extends ShapeTag.Companion[DeprecatedStructure] {
val id: ShapeId = ShapeId("smithy4s.example", "DeprecatedStructure")

Expand All @@ -17,9 +17,10 @@ object DeprecatedStructure extends ShapeTag.Companion[DeprecatedStructure] {
)

implicit val schema: Schema[DeprecatedStructure] = struct(
Strings.underlyingSchema.optional[DeprecatedStructure]("strings", _.strings).addHints(smithy.api.Deprecated(message = None, since = None)),
Strings.underlyingSchema.optional[DeprecatedStructure]("other", _.other),
string.optional[DeprecatedStructure]("name", _.name).addHints(smithy.api.Deprecated(message = None, since = None)),
string.optional[DeprecatedStructure]("nameV2", _.nameV2),
Strings.underlyingSchema.optional[DeprecatedStructure]("strings", _.strings),
){
DeprecatedStructure.apply
}.withId(id).addHints(hints)
Expand Down
16 changes: 12 additions & 4 deletions modules/codegen/src/smithy4s/codegen/internals/Renderer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -761,7 +761,13 @@ private[internals] class Renderer(compilationUnit: CompilationUnit) { self =>
} else Line.empty
block(line"trait $name$ext") {
lines(
fields.map(f => line"def ${fieldToRenderLine(f, noDefault = true)}")
fields.map { f =>
lines(
deprecationAnnotation(f.hints),
Line.empty,
line"def ${fieldToRenderLine(f, noDefault = true)}"
)
}
)
}
}
Expand Down Expand Up @@ -1100,12 +1106,14 @@ private[internals] class Renderer(compilationUnit: CompilationUnit) { self =>
)
}

deprecationAnnotation(hints).appendIf(_.nonEmpty)(Line.space) +
line"$name: " + tpeAndDefault
line"$name: " + tpeAndDefault
}
}
private def renderArgs(fields: List[Field]): Line = fields
.map(fieldToRenderLine(_))
.map { f =>
deprecationAnnotation(f.hints).appendIf(_.nonEmpty)(Line.space) +
fieldToRenderLine(f)
}
.intercalate(Line.comma)

private def renderEnum(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,16 +65,20 @@ class AwsStandardTypesTransformer extends ProjectionTransformer {
.map[Boolean](canReplace)
.orElse(false)
}
.map[Shape](shape => {
.map[Shape] { shape =>
val target = model.expectShape(shape.getTarget)
val replacementShape = replaceWith(shape.getTarget)
// Member shapes can only carry the `@default` trait IF
// their container is a structures
val canCarryDefault =
model.expectShape(shape.getContainer()).isStructureShape()

shape
.toBuilder()
.target(replacementShape)
.copyDefaultTrait(target)
.when(canCarryDefault)(_.copyDefaultTrait(target))
.build()
})
}
.orElse(shape)
}

Expand All @@ -84,7 +88,8 @@ class AwsStandardTypesTransformer extends ProjectionTransformer {
private def canReplace(shape: Shape): Boolean = {
shape.isInstanceOf[SimpleShape] &&
isAwsShape(shape) &&
onlySupportedTraits(shape.getAllTraits)
onlySupportedTraits(shape.getAllTraits) &&
hasStandardName(shape)
}

@annotation.nowarn
Expand All @@ -96,15 +101,41 @@ class AwsStandardTypesTransformer extends ProjectionTransformer {
t.isInstanceOf[DefaultTrait] || t.isInstanceOf[BoxTrait]
})

private def hasStandardName(shape: Shape): Boolean =
AwsStandardTypesTransformer.standardSimpleShapes.contains(
shape.getId().getName()
)

}

object AwsStandardTypesTransformer {

val name: String = "AwsStandardTypesTransformer"

val standardSimpleShapes = Set(
"Integer",
"Short",
"Long",
"Float",
"Double",
"BigInteger",
"BigDecimal",
"Byte",
"Blob",
"Boolean",
"String",
"Document",
"Timestamp"
)

private[transformers] final implicit class MemberShapeBuilderOps(
val builder: MemberShape.Builder
) extends AnyVal {
def when(condition: Boolean)(
mutation: MemberShape.Builder => MemberShape.Builder
): MemberShape.Builder =
if (condition)(mutation(builder)) else builder

def copyDefaultTrait(shape: Shape): MemberShape.Builder = {
val defaultTraitOpt = toOption(shape.getTrait(classOf[DefaultTrait]))

Expand Down
Loading

0 comments on commit 51af4e1

Please sign in to comment.