Skip to content

Commit bf0d9cf

Browse files
authored
Merge branch 'main' into main
2 parents be1db16 + bab3bbb commit bf0d9cf

File tree

19 files changed

+352
-3
lines changed

19 files changed

+352
-3
lines changed

.changelog/1759416345.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
---
2+
applies_to: ["server"]
3+
authors: ["jasgin"]
4+
references: ["smithy-rs#4321"]
5+
breaking: false
6+
new_feature: true
7+
bug_fix: false
8+
---
9+
10+
Adds the custom traits `@validationException`, `@validationMessage`, `@validationFieldList`, `@validationFieldName`, and `@validationFieldMessage`
11+
for defining custom validation exceptions.

buildSrc/src/main/kotlin/CodegenTestCommon.kt

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -236,8 +236,13 @@ fun Project.registerGenerateSmithyBuildTask(
236236
this.tasks.register("generateSmithyBuild") {
237237
description = "generate smithy-build.json"
238238
outputs.file(project.projectDir.resolve("smithy-build.json"))
239-
// NOTE: This is not working.
240-
allCodegenTests.flatMap { it.imports }.forEach { inputs.file(project.projectDir.resolve(it)) }
239+
// Declare Smithy model files as inputs so task reruns when they change
240+
allCodegenTests.flatMap { it.imports }.forEach {
241+
val resolvedPath = project.projectDir.resolve(it)
242+
if (resolvedPath.exists()) {
243+
inputs.file(resolvedPath)
244+
}
245+
}
241246

242247
doFirst {
243248
project.projectDir.resolve("smithy-build.json")

codegen-server/build.gradle.kts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ extra["moduleName"] = "software.amazon.smithy.rust.codegen.server"
1616

1717
dependencies {
1818
implementation(project(":codegen-core"))
19+
implementation(project(":codegen-traits"))
1920
implementation(libs.smithy.aws.traits)
2021
implementation(libs.smithy.protocol.test.traits)
2122
implementation(libs.smithy.protocol.traits)

codegen-traits/build.gradle.kts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
/*
2+
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3+
* SPDX-License-Identifier: Apache-2.0
4+
*/
5+
6+
plugins {
7+
id("smithy-rs.kotlin-conventions")
8+
id("smithy-rs.publishing-conventions")
9+
}
10+
11+
description = "Smithy traits for Rust code generation"
12+
extra["displayName"] = "Smithy :: Rust :: Codegen :: Traits"
13+
extra["moduleName"] = "software.amazon.smithy.rust.codegen.traits"
14+
15+
dependencies {
16+
implementation(libs.smithy.model)
17+
testImplementation(libs.junit.jupiter)
18+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
/*
2+
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3+
* SPDX-License-Identifier: Apache-2.0
4+
*/
5+
6+
package software.amazon.smithy.rust.codegen.traits
7+
8+
import software.amazon.smithy.model.SourceLocation
9+
import software.amazon.smithy.model.node.Node
10+
import software.amazon.smithy.model.shapes.ShapeId
11+
import software.amazon.smithy.model.traits.AbstractTrait
12+
import software.amazon.smithy.model.traits.Trait
13+
14+
class ValidationExceptionTrait(
15+
sourceLocation: SourceLocation,
16+
) : AbstractTrait(ID, sourceLocation) {
17+
companion object {
18+
val ID: ShapeId = ShapeId.from("smithy.rust.codegen.traits#validationException")
19+
}
20+
21+
override fun createNode(): Node = Node.objectNode()
22+
23+
class Provider : AbstractTrait.Provider(ID) {
24+
override fun createTrait(
25+
target: ShapeId,
26+
value: Node,
27+
): Trait {
28+
val result = ValidationExceptionTrait(value.sourceLocation)
29+
result.setNodeCache(value)
30+
return result
31+
}
32+
}
33+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
/*
2+
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3+
* SPDX-License-Identifier: Apache-2.0
4+
*/
5+
6+
package software.amazon.smithy.rust.codegen.traits
7+
8+
import software.amazon.smithy.model.SourceLocation
9+
import software.amazon.smithy.model.node.Node
10+
import software.amazon.smithy.model.shapes.ShapeId
11+
import software.amazon.smithy.model.traits.AbstractTrait
12+
import software.amazon.smithy.model.traits.Trait
13+
14+
class ValidationFieldListTrait(
15+
sourceLocation: SourceLocation,
16+
) : AbstractTrait(ID, sourceLocation) {
17+
companion object {
18+
val ID: ShapeId = ShapeId.from("smithy.rust.codegen.traits#validationFieldList")
19+
}
20+
21+
override fun createNode(): Node = Node.objectNode()
22+
23+
class Provider : AbstractTrait.Provider(ID) {
24+
override fun createTrait(
25+
target: ShapeId,
26+
value: Node,
27+
): Trait {
28+
val result = ValidationFieldListTrait(value.sourceLocation)
29+
result.setNodeCache(value)
30+
return result
31+
}
32+
}
33+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
/*
2+
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3+
* SPDX-License-Identifier: Apache-2.0
4+
*/
5+
6+
package software.amazon.smithy.rust.codegen.traits
7+
8+
import software.amazon.smithy.model.SourceLocation
9+
import software.amazon.smithy.model.node.Node
10+
import software.amazon.smithy.model.shapes.ShapeId
11+
import software.amazon.smithy.model.traits.AbstractTrait
12+
import software.amazon.smithy.model.traits.Trait
13+
14+
class ValidationFieldMessageTrait(
15+
sourceLocation: SourceLocation,
16+
) : AbstractTrait(ID, sourceLocation) {
17+
companion object {
18+
val ID: ShapeId = ShapeId.from("smithy.rust.codegen.traits#validationFieldMessage")
19+
}
20+
21+
override fun createNode(): Node = Node.objectNode()
22+
23+
class Provider : AbstractTrait.Provider(ID) {
24+
override fun createTrait(
25+
target: ShapeId,
26+
value: Node,
27+
): Trait {
28+
val result = ValidationFieldMessageTrait(value.sourceLocation)
29+
result.setNodeCache(value)
30+
return result
31+
}
32+
}
33+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
/*
2+
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3+
* SPDX-License-Identifier: Apache-2.0
4+
*/
5+
6+
package software.amazon.smithy.rust.codegen.traits
7+
8+
import software.amazon.smithy.model.SourceLocation
9+
import software.amazon.smithy.model.node.Node
10+
import software.amazon.smithy.model.shapes.ShapeId
11+
import software.amazon.smithy.model.traits.AbstractTrait
12+
import software.amazon.smithy.model.traits.Trait
13+
14+
class ValidationFieldNameTrait(
15+
sourceLocation: SourceLocation,
16+
) : AbstractTrait(ID, sourceLocation) {
17+
companion object {
18+
val ID: ShapeId = ShapeId.from("smithy.rust.codegen.traits#validationFieldName")
19+
}
20+
21+
override fun createNode(): Node = Node.objectNode()
22+
23+
class Provider : AbstractTrait.Provider(ID) {
24+
override fun createTrait(
25+
target: ShapeId,
26+
value: Node,
27+
): Trait {
28+
val result = ValidationFieldNameTrait(value.sourceLocation)
29+
result.setNodeCache(value)
30+
return result
31+
}
32+
}
33+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
/*
2+
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3+
* SPDX-License-Identifier: Apache-2.0
4+
*/
5+
6+
package software.amazon.smithy.rust.codegen.traits
7+
8+
import software.amazon.smithy.model.SourceLocation
9+
import software.amazon.smithy.model.node.Node
10+
import software.amazon.smithy.model.shapes.ShapeId
11+
import software.amazon.smithy.model.traits.AbstractTrait
12+
import software.amazon.smithy.model.traits.Trait
13+
14+
class ValidationMessageTrait(
15+
sourceLocation: SourceLocation,
16+
) : AbstractTrait(ID, sourceLocation) {
17+
companion object {
18+
val ID: ShapeId = ShapeId.from("smithy.rust.codegen.traits#validationMessage")
19+
}
20+
21+
override fun createNode(): Node = Node.objectNode()
22+
23+
class Provider : AbstractTrait.Provider(ID) {
24+
override fun createTrait(
25+
target: ShapeId,
26+
value: Node,
27+
): Trait {
28+
val result = ValidationMessageTrait(value.sourceLocation)
29+
result.setNodeCache(value)
30+
return result
31+
}
32+
}
33+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
validation-exception.smithy

0 commit comments

Comments
 (0)