Skip to content

Commit

Permalink
Merge pull request disneystreaming#1561 from disneystreaming/merge-01…
Browse files Browse the repository at this point in the history
…8-into-019-jun14
  • Loading branch information
kubukoz authored Jul 24, 2024
2 parents a895e64 + 276535e commit 2a3f689
Show file tree
Hide file tree
Showing 97 changed files with 2,285 additions and 356 deletions.
8 changes: 5 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ on:
# midnight, every Monday and Thursday
- cron: '0 0 * * 1,4'

env:
SBT_OPTS: "-XX:MaxMetaspaceSize=4G -XX:MaxInlineLevel=20 -Xss2m -Xms512M -Xmx6G -XX:ReservedCodeCacheSize=256M"

concurrency:
group: ci-${{ github.ref }}
cancel-in-progress: true
Expand Down Expand Up @@ -62,8 +65,7 @@ jobs:
- name: Run tests
run: |
sbt test_$BUILD_KEY \
pushRemoteCache_$BUILD_KEY \
-J-Xmx4G
pushRemoteCache_$BUILD_KEY
- name: Run plugin tests
if: matrix.scalaVersion == '2_12' && matrix.scalaPlatform == 'jvm'
Expand Down Expand Up @@ -134,7 +136,7 @@ jobs:
- name: Publish ${{ github.ref }}
run: |
echo $PGP_SECRET | base64 --decode | gpg --import --no-tty --batch --yes
sbt 'pullRemoteCache; release' -J-Xmx2G
sbt 'pullRemoteCache; release'
env:
PGP_PASSPHRASE: ${{ secrets.PGP_PASSPHRASE }}
PGP_SECRET: ${{ secrets.PGP_SECRET }}
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -68,3 +68,5 @@ version

#smithy cli metadata
build/smithy/classpath.json

.sbtopts
File renamed without changes.
21 changes: 21 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,27 @@ Previously they'd be named after the **member target**, now they will use the na

There's usually only one instance of `EncoderK[F, A]` for a particular `F[_]`, and interpreters don't need to know what `A` is. For convenience, the type parameter has been moved to a type member.

# 0.18.23

## Validated newtypes [#1454](https://github.com/disneystreaming/smithy4s/pull/1454)

Add support for rendering constrained newtypes over Smithy primitives as validated newtypes. These types now have an `apply` method which returns either an error or a validated value.

# 0.18.22

* Add support for `@default` for `Timestamp` fields in https://github.com/disneystreaming/smithy4s/pull/1557

# 0.18.21

## Documentation fix

* Addition of a new `@scalaImport` trait to provide a mechanism to add additional imports to the generated code. Read the new [docs](https://disneystreaming.github.io/smithy4s/docs/codegen/customisation/scala-imports) for more info (see https://github.com/disneystreaming/smithy4s/pull/1550).
* Added support for parsing timestamps without seconds in https://github.com/disneystreaming/smithy4s/pull/1553.

# 0.18.20

* Change semantics of `Blob.equals` - Blobs do not take underlying type into consideration, just bytes in https://github.com/disneystreaming/smithy4s/pull/1526

# 0.18.19 - binary-breaking changes in `core`

**WARNING**: This release includes binary-breaking changes in the `core` module. This is indirectly caused by an upstream change in [smithy-lang/smithy](https://github.com/smithy-lang/smithy/).
Expand Down
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,3 +62,12 @@ ThisBuild / bloopAllowedCombos := Seq(
)
)
```

## Note for .sbtopts

You usually should use `.sbtopts` to add some more memory for `sbt`, as Smithy4s is complex. You copy the `.sbtopts.example` to `.sbtopts` and adjust the values to your needs:

```bash
cp .sbtopts.example .sbtopts
```

14 changes: 11 additions & 3 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,9 @@ lazy val core = projectMatrix
}
.taskValue
},
scalacOptions ++= Seq(
"-Wconf:msg=value noInlineDocumentSupport in class ProtocolDefinition is deprecated:silent"
),
libraryDependencies += Dependencies.collectionsCompat.value,
Compile / packageSrc / mappings ++= {
val base = (Compile / sourceManaged).value
Expand Down Expand Up @@ -414,7 +417,7 @@ lazy val codegen = projectMatrix
Dependencies.Alloy.core,
Dependencies.Alloy.openapi,
Dependencies.Smithytranslate.proto,
"com.lihaoyi" %% "os-lib" % "0.9.3",
"com.lihaoyi" %% "os-lib" % "0.10.1",
Dependencies.Circe.core.value,
Dependencies.Circe.parser.value,
Dependencies.Circe.generic.value,
Expand Down Expand Up @@ -471,6 +474,7 @@ lazy val codegenPlugin = (projectMatrix in file("modules/codegen-plugin"))
Compile / unmanagedSources / excludeFilter := { f =>
Glob("**/sbt-test/**").matches(f.toPath)
},
libraryDependencies += Dependencies.MunitV1.diff.value,
publishLocal := {
// make sure that core and codegen are published before the
// plugin is published
Expand Down Expand Up @@ -704,8 +708,8 @@ lazy val protobuf = projectMatrix
libraryDependencies ++= {
if (virtualAxes.value.contains(VirtualAxis.jvm))
Seq(
"com.google.protobuf" % "protobuf-java" % "3.24.0",
"com.google.protobuf" % "protobuf-java-util" % "3.24.0" % Test
"com.google.protobuf" % "protobuf-java" % "3.24.4",
"com.google.protobuf" % "protobuf-java-util" % "3.24.4" % Test
)
else
Seq(
Expand Down Expand Up @@ -941,6 +945,10 @@ lazy val bootstrapped = projectMatrix
Compile / PB.protoSources ++= Seq(
exampleGeneratedResourcesOutput.value
),
Compile / PB.protocExecutable := sys.env
.get("PROTOC_PATH")
.map(file(_))
.getOrElse((Compile / PB.protocExecutable).value),
Compile / PB.targets := Seq(
scalapb.gen() -> (Compile / sourceManaged).value / "scalapb"
),
Expand Down
6 changes: 3 additions & 3 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 11 additions & 9 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -2,30 +2,32 @@
inputs.nixpkgs.url = "github:nixos/nixpkgs";
inputs.flake-utils.url = "github:numtide/flake-utils";

outputs = { self, nixpkgs, flake-utils, ... }@inputs:
outputs = { nixpkgs, flake-utils, ... }:
flake-utils.lib.eachDefaultSystem (system:
let
pkgs = import nixpkgs { inherit system; };
shellPackages = [
"jre"
"sbt"
"nodejs-16_x"
"yarn"
shellPackages = with pkgs; [
temurin-jre-bin-17
nodejs-18_x
yarn
(pkgs.sbt.override { jre = pkgs.temurin-jre-bin-17; })
];
protobuf = pkgs.protobuf3_21;
in
{
devShells.default = pkgs.mkShell {
buildInputs = map (pkgName: pkgs.${pkgName}) shellPackages;
nativeBuildInputs = [ pkgs.openssl pkgs.zlib ];
buildInputs = shellPackages;
nativeBuildInputs = [ pkgs.openssl pkgs.zlib protobuf ];
welcomeMessage = ''
Welcome to the smithy4s Nix shell! 👋
Available packages:
${builtins.concatStringsSep "\n" (map (n : "- ${n}") shellPackages)}
${builtins.concatStringsSep "\n" (map (n : "- ${n.name}") shellPackages)}
'';

shellHook = ''
echo "$welcomeMessage"
'';
PROTOC_PATH = pkgs.lib.getExe protobuf;
};
}
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@
"paths": {
"/operation/{requiredLabel}": {
"post": {
"operationId": "Operation",
"operationId": "DefaultNullsOperation",
"requestBody": {
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/OperationRequestContent"
"$ref": "#/components/schemas/DefaultNullsOperationRequestContent"
}
}
},
Expand Down Expand Up @@ -78,7 +78,7 @@
],
"responses": {
"200": {
"description": "Operation 200 response",
"description": "DefaultNullsOperation 200 response",
"headers": {
"optional-header": {
"schema": {
Expand All @@ -102,18 +102,38 @@
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/OperationResponseContent"
"$ref": "#/components/schemas/DefaultNullsOperationResponseContent"
}
}
}
}
}
}
},
"/timestamp-operation": {
"post": {
"operationId": "TimestampOperation",
"requestBody": {
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/TimestampOperationRequestContent"
}
}
},
"required": true
},
"responses": {
"200": {
"description": "TimestampOperation 200 response"
}
}
}
}
},
"components": {
"schemas": {
"OperationRequestContent": {
"DefaultNullsOperationRequestContent": {
"type": "object",
"properties": {
"optional": {
Expand All @@ -132,7 +152,7 @@
"requiredWithDefault"
]
},
"OperationResponseContent": {
"DefaultNullsOperationResponseContent": {
"type": "object",
"properties": {
"optional": {
Expand All @@ -150,6 +170,30 @@
"required": [
"requiredWithDefault"
]
},
"TimestampOperationRequestContent": {
"type": "object",
"properties": {
"httpDate": {
"type": "string",
"default": "Thu, 23 May 2024 10:20:30 GMT",
"format": "date-time"
},
"epochSeconds": {
"type": "number",
"default": 1716459630
},
"dateTime": {
"type": "string",
"default": "2024-05-23T10:20:30.000Z",
"format": "date-time"
}
},
"required": [
"dateTime",
"epochSeconds",
"httpDate"
]
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package smithy4s.example

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

final case class DefaultNullsOperationInput(optionalWithDefault: String = "optional-default", requiredLabel: String = "required-label-with-default", requiredWithDefault: String = "required-default", optionalHeaderWithDefault: String = "optional-header-with-default", requiredHeaderWithDefault: String = "required-header-with-default", optionalQueryWithDefault: String = "optional-query-with-default", requiredQueryWithDefault: String = "required-query-with-default", optional: Option[String] = None, optionalHeader: Option[String] = None, optionalQuery: Option[String] = None)

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

val hints: Hints = Hints(
smithy.api.Input(),
).lazily

// constructor using the original order from the spec
private def make(optional: Option[String], optionalWithDefault: String, requiredLabel: String, requiredWithDefault: String, optionalHeader: Option[String], optionalHeaderWithDefault: String, requiredHeaderWithDefault: String, optionalQuery: Option[String], optionalQueryWithDefault: String, requiredQueryWithDefault: String): DefaultNullsOperationInput = DefaultNullsOperationInput(optionalWithDefault, requiredLabel, requiredWithDefault, optionalHeaderWithDefault, requiredHeaderWithDefault, optionalQueryWithDefault, requiredQueryWithDefault, optional, optionalHeader, optionalQuery)

implicit val schema: Schema[DefaultNullsOperationInput] = struct(
string.optional[DefaultNullsOperationInput]("optional", _.optional),
string.field[DefaultNullsOperationInput]("optionalWithDefault", _.optionalWithDefault).addHints(smithy.api.Default(smithy4s.Document.fromString("optional-default"))),
string.required[DefaultNullsOperationInput]("requiredLabel", _.requiredLabel).addHints(smithy.api.Default(smithy4s.Document.fromString("required-label-with-default")), smithy.api.HttpLabel()),
string.required[DefaultNullsOperationInput]("requiredWithDefault", _.requiredWithDefault).addHints(smithy.api.Default(smithy4s.Document.fromString("required-default"))),
string.optional[DefaultNullsOperationInput]("optionalHeader", _.optionalHeader).addHints(smithy.api.HttpHeader("optional-header")),
string.field[DefaultNullsOperationInput]("optionalHeaderWithDefault", _.optionalHeaderWithDefault).addHints(smithy.api.Default(smithy4s.Document.fromString("optional-header-with-default")), smithy.api.HttpHeader("optional-header-with-default")),
string.required[DefaultNullsOperationInput]("requiredHeaderWithDefault", _.requiredHeaderWithDefault).addHints(smithy.api.Default(smithy4s.Document.fromString("required-header-with-default")), smithy.api.HttpHeader("required-header-with-default")),
string.optional[DefaultNullsOperationInput]("optionalQuery", _.optionalQuery).addHints(smithy.api.HttpQuery("optional-query")),
string.field[DefaultNullsOperationInput]("optionalQueryWithDefault", _.optionalQueryWithDefault).addHints(smithy.api.Default(smithy4s.Document.fromString("optional-query-with-default")), smithy.api.HttpQuery("optional-query-with-default")),
string.field[DefaultNullsOperationInput]("requiredQueryWithDefault", _.requiredQueryWithDefault).addHints(smithy.api.Default(smithy4s.Document.fromString("required-query-with-default")), smithy.api.HttpQuery("required-query-with-default")),
)(make).withId(id).addHints(hints)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package smithy4s.example

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

final case class DefaultNullsOperationOutput(optionalWithDefault: String = "optional-default", requiredWithDefault: String = "required-default", optionalHeaderWithDefault: String = "optional-header-with-default", requiredHeaderWithDefault: String = "required-header-with-default", optional: Option[String] = None, optionalHeader: Option[String] = None)

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

val hints: Hints = Hints(
smithy.api.Output(),
).lazily

// constructor using the original order from the spec
private def make(optional: Option[String], optionalWithDefault: String, requiredWithDefault: String, optionalHeader: Option[String], optionalHeaderWithDefault: String, requiredHeaderWithDefault: String): DefaultNullsOperationOutput = DefaultNullsOperationOutput(optionalWithDefault, requiredWithDefault, optionalHeaderWithDefault, requiredHeaderWithDefault, optional, optionalHeader)

implicit val schema: Schema[DefaultNullsOperationOutput] = struct(
string.optional[DefaultNullsOperationOutput]("optional", _.optional),
string.field[DefaultNullsOperationOutput]("optionalWithDefault", _.optionalWithDefault).addHints(smithy.api.Default(smithy4s.Document.fromString("optional-default"))),
string.required[DefaultNullsOperationOutput]("requiredWithDefault", _.requiredWithDefault).addHints(smithy.api.Default(smithy4s.Document.fromString("required-default"))),
string.optional[DefaultNullsOperationOutput]("optionalHeader", _.optionalHeader).addHints(smithy.api.HttpHeader("optional-header")),
string.field[DefaultNullsOperationOutput]("optionalHeaderWithDefault", _.optionalHeaderWithDefault).addHints(smithy.api.Default(smithy4s.Document.fromString("optional-header-with-default")), smithy.api.HttpHeader("optional-header-with-default")),
string.required[DefaultNullsOperationOutput]("requiredHeaderWithDefault", _.requiredHeaderWithDefault).addHints(smithy.api.Default(smithy4s.Document.fromString("required-header-with-default")), smithy.api.HttpHeader("required-header-with-default")),
)(make).withId(id).addHints(hints)
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import smithy4s.schema.Schema.string
import smithy4s.schema.Schema.struct
import smithy4s.schema.Schema.timestamp

final case class DefaultTest(one: Int = 1, two: String = "test", three: List[String] = List(), four: List[String] = List(), five: String = "", six: Int = 0, seven: Document = smithy4s.Document.nullDoc, eight: Map[String, String] = Map(), nine: Short = 0, ten: Double = 0.0d, eleven: Float = 0.0f, twelve: Long = 0L, thirteen: Timestamp = Timestamp(0, 0), fourteen: Timestamp = Timestamp(0, 0), fifteen: Timestamp = Timestamp(0, 0), sixteen: Byte = 0, seventeen: Blob = Blob.empty, eighteen: Boolean = false)
final case class DefaultTest(one: Int = 1, two: String = "test", three: List[String] = List(), four: List[String] = List(), five: String = "", six: Int = 0, seven: Document = smithy4s.Document.nullDoc, eight: Map[String, String] = Map(), nine: Short = 0, ten: Double = 0.0d, eleven: Float = 0.0f, twelve: Long = 0L, thirteen: Timestamp = Timestamp(0L, 0), fourteen: Timestamp = Timestamp(0L, 0), fifteen: Timestamp = Timestamp(0L, 0), sixteen: Byte = 0, seventeen: Blob = Blob.empty, eighteen: Boolean = false)

object DefaultTest extends ShapeTag.Companion[DefaultTest] {
val id: ShapeId = ShapeId("smithy4s.example", "DefaultTest")
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package smithy4s.example

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

object NonValidatedString extends Newtype[String] {
val id: ShapeId = ShapeId("smithy4s.example", "NonValidatedString")
val hints: Hints = Hints.empty
val underlyingSchema: Schema[String] = string.withId(id).addHints(hints).validated(smithy.api.Length(min = Some(1L), max = None)).validated(smithy.api.Pattern("[a-zA-Z0-9]+"))
implicit val schema: Schema[NonValidatedString] = bijection(underlyingSchema, asBijection)
}
Loading

0 comments on commit 2a3f689

Please sign in to comment.