Skip to content

Commit d238cee

Browse files
author
Fahad Zubair
committed
ModelModule to ServerRustModule.model
1 parent 9f51b41 commit d238cee

File tree

14 files changed

+36
-31
lines changed

14 files changed

+36
-31
lines changed

codegen-server/python/src/main/kotlin/software/amazon/smithy/rust/codegen/server/python/smithy/PythonServerCodegenVisitor.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ class PythonServerCodegenVisitor(
7878
serviceShape: ServiceShape,
7979
symbolVisitorConfig: SymbolVisitorConfig,
8080
publicConstrainedTypes: Boolean,
81+
includeConstraintShapeProvider: Boolean,
8182
) = RustServerCodegenPythonPlugin.baseSymbolProvider(model, serviceShape, symbolVisitorConfig, publicConstrainedTypes)
8283

8384
val serverSymbolProviders = ServerSymbolProviders.from(

codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/ConstrainedShapeSymbolProvider.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import software.amazon.smithy.model.traits.LengthTrait
2424
import software.amazon.smithy.rust.codegen.core.rustlang.RustModule
2525
import software.amazon.smithy.rust.codegen.core.rustlang.RustReservedWords
2626
import software.amazon.smithy.rust.codegen.core.rustlang.RustType
27+
import software.amazon.smithy.rust.codegen.core.rustlang.Visibility
2728
import software.amazon.smithy.rust.codegen.core.smithy.RustSymbolProvider
2829
import software.amazon.smithy.rust.codegen.core.smithy.WrappingSymbolProvider
2930
import software.amazon.smithy.rust.codegen.core.smithy.contextName

codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/ConstraintViolationSymbolProvider.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ class ConstraintViolationSymbolProvider(
101101
Pair(overriddenMemberModule.second, RustReservedWords.escapeIfNeeded(name).toSnakeCase())
102102
} else {
103103
// Need to use the context name so we get the correct name for maps.
104-
Pair(ModelsModule, RustReservedWords.escapeIfNeeded(this.contextName(serviceShape)).toSnakeCase())
104+
Pair(ServerRustModule.Model, RustReservedWords.escapeIfNeeded(this.contextName(serviceShape)).toSnakeCase())
105105
}
106106

107107
return RustModule.new(

codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/Constraints.kt

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,6 @@ import software.amazon.smithy.rust.codegen.core.rustlang.RustReservedWords
3232
import software.amazon.smithy.rust.codegen.core.rustlang.Visibility
3333
import software.amazon.smithy.rust.codegen.core.smithy.CodegenContext
3434
import software.amazon.smithy.rust.codegen.core.smithy.DirectedWalker
35-
import software.amazon.smithy.rust.codegen.core.smithy.ModelsModule
36-
import software.amazon.smithy.rust.codegen.core.smithy.contextName
3735
import software.amazon.smithy.rust.codegen.core.smithy.isOptional
3836
import software.amazon.smithy.rust.codegen.core.smithy.module
3937
import software.amazon.smithy.rust.codegen.core.util.UNREACHABLE
@@ -212,11 +210,11 @@ fun Shape.getParentAndInlineModuleForConstrainedMember(symbolProvider: SymbolPro
212210
val innerModule = RustModule.new(
213211
name = name,
214212
visibility = Visibility.PUBCRATE,
215-
parent = ModelsModule,
213+
parent = ServerRustModule.Model,
216214
inline = true,
217215
)
218216

219-
Pair(ModelsModule, innerModule)
217+
Pair(ServerRustModule.Model, innerModule)
220218
}
221219
}
222220
}

codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/ServerCodegenVisitor.kt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -295,7 +295,7 @@ open class ServerCodegenVisitor(
295295
) {
296296
if (codegenContext.settings.codegenConfig.publicConstrainedTypes || shape.isReachableFromOperationInput()) {
297297
val serverBuilderGenerator = ServerBuilderGenerator(codegenContext, shape, validationExceptionConversionGenerator)
298-
serverBuilderGenerator.render(writer)
298+
serverBuilderGenerator.render(rustCrate, writer)
299299
// FZ Rebase mine
300300
// val serverBuilderGenerator = ServerBuilderGenerator(codegenContext, shape)
301301
// serverBuilderGenerator.render(rustCrate, writer)
@@ -498,7 +498,8 @@ open class ServerCodegenVisitor(
498498
rustCrate.withModuleOrWithStructureBuilderModule(ServerRustModule.Model, shape, codegenContext) {
499499
ConstrainedNumberGenerator(codegenContext,
500500
rustCrate.createInlineModuleCreator(),
501-
shape,
501+
this,
502+
shape,
502503
validationExceptionConversionGenerator,
503504
).render()
504505
}

codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/UnconstrainedShapeSymbolProvider.kt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ import software.amazon.smithy.rust.codegen.core.rustlang.RustReservedWords
2121
import software.amazon.smithy.rust.codegen.core.rustlang.RustType
2222
import software.amazon.smithy.rust.codegen.core.rustlang.Visibility
2323
import software.amazon.smithy.rust.codegen.core.smithy.Default
24-
import software.amazon.smithy.rust.codegen.core.smithy.ModelsModule
2524
import software.amazon.smithy.rust.codegen.core.smithy.RustSymbolProvider
2625
import software.amazon.smithy.rust.codegen.core.smithy.WrappingSymbolProvider
2726
import software.amazon.smithy.rust.codegen.core.smithy.contextName

codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/testutil/ServerTestHelpers.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ fun serverTestCodegenContext(
121121
/**
122122
* In tests, we frequently need to generate a struct, a builder, and an impl block to access said builder.
123123
*/
124-
fun StructureShape.serverRenderWithModelBuilder(model: Model, symbolProvider: RustSymbolProvider, writer: RustWriter) {
124+
fun StructureShape.serverRenderWithModelBuilder(rustCrate: RustCrate, model: Model, symbolProvider: RustSymbolProvider, writer: RustWriter) {
125125
StructureGenerator(model, symbolProvider, writer, this, emptyList()).render()
126126
val serverCodegenContext = serverTestCodegenContext(model)
127127
// Note that this always uses `ServerBuilderGenerator` and _not_ `ServerBuilderGeneratorWithoutPublicConstrainedTypes`,

codegen-server/src/test/kotlin/software/amazon/smithy/rust/codegen/server/smithy/ConstraintsMemberShapeTest.kt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package software.amazon.smithy.rust.codegen.server.smithy
22

33
import org.junit.jupiter.api.Test
4+
import software.amazon.smithy.codegen.core.ReservedWordSymbolProvider
45
import software.amazon.smithy.model.Model
56
import software.amazon.smithy.model.shapes.ShapeId
67
import software.amazon.smithy.model.traits.RequiredTrait
@@ -20,11 +21,16 @@ import software.amazon.smithy.rust.codegen.core.testutil.unitTest
2021
import software.amazon.smithy.rust.codegen.core.util.runCommand
2122
import software.amazon.smithy.rust.codegen.core.util.toPascalCase
2223
import software.amazon.smithy.rust.codegen.core.util.toSnakeCase
24+
import software.amazon.smithy.rust.codegen.server.smithy.customizations.CustomValidationExceptionWithReasonDecorator
25+
import software.amazon.smithy.rust.codegen.server.smithy.customizations.ServerRequiredCustomizations
26+
import software.amazon.smithy.rust.codegen.server.smithy.customizations.SmithyValidationExceptionDecorator
2327
import software.amazon.smithy.rust.codegen.server.smithy.customize.CombinedServerCodegenDecorator
2428
import software.amazon.smithy.rust.codegen.server.smithy.testutil.serverTestCodegenContext
2529
import software.amazon.smithy.rust.codegen.server.smithy.testutil.serverTestSymbolProvider
2630
import java.io.File
2731
import java.nio.file.Path
32+
import java.util.logging.Level
33+
import java.util.logging.Logger
2834

2935
class ConstraintsMemberShapeTest {
3036
private val outputModelOnly = """

codegen-server/src/test/kotlin/software/amazon/smithy/rust/codegen/server/smithy/RustCrateInlineModuleComposingWriterTest.kt

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,6 @@ import software.amazon.smithy.rust.codegen.core.rustlang.Visibility
88
import software.amazon.smithy.rust.codegen.core.rustlang.comment
99
import software.amazon.smithy.rust.codegen.core.rustlang.rust
1010
import software.amazon.smithy.rust.codegen.core.rustlang.rustBlock
11-
import software.amazon.smithy.rust.codegen.core.rustlang.rustTemplate
12-
import software.amazon.smithy.rust.codegen.core.smithy.InputsModule
13-
import software.amazon.smithy.rust.codegen.core.smithy.ModelsModule
14-
import software.amazon.smithy.rust.codegen.core.smithy.OutputsModule
1511
import software.amazon.smithy.rust.codegen.core.smithy.RuntimeConfig
1612
import software.amazon.smithy.rust.codegen.core.smithy.RuntimeCrateLocation
1713
import software.amazon.smithy.rust.codegen.core.smithy.RustCrate
@@ -105,15 +101,15 @@ class RustCrateInlineModuleComposingWriterTest {
105101
@Test
106102
fun `simple inline module works`() {
107103
val testProject = TestWorkspace.testProject(serverTestSymbolProvider(model))
108-
val moduleA = createTestInlineModule(ModelsModule, "a")
109-
testProject.withModule(ModelsModule) {
104+
val moduleA = createTestInlineModule(ServerRustModule.Model, "a")
105+
testProject.withModule(ServerRustModule.Model) {
110106
testProject.getInlineModuleWriter().withInlineModule(this, moduleA) {
111107
helloWorld(this, "a")
112108
}
113109
}
114110

115111
testProject.getInlineModuleWriter().render()
116-
testProject.withModule(ModelsModule) {
112+
testProject.withModule(ServerRustModule.Model) {
117113
this.unitTest("test_a") {
118114
rust("crate::model::a::hello_world();")
119115
}
@@ -144,13 +140,13 @@ class RustCrateInlineModuleComposingWriterTest {
144140
"i" to createTestOrphanInlineModule("i"),
145141
)
146142

147-
modules["b"] = createTestInlineModule(ModelsModule, "b")
143+
modules["b"] = createTestInlineModule(ServerRustModule.Model, "b")
148144
modules["c"] = createTestInlineModule(modules["b"]!!, "c")
149-
modules["f"] = createTestInlineModule(OutputsModule, "f")
145+
modules["f"] = createTestInlineModule(ServerRustModule.Output, "f")
150146
modules["g"] = createTestInlineModule(modules["f"]!!, "g")
151-
modules["h"] = createTestInlineModule(OutputsModule, "h")
147+
modules["h"] = createTestInlineModule(ServerRustModule.Output, "h")
152148

153-
testProject.withModule(ModelsModule) {
149+
testProject.withModule(ServerRustModule.Model) {
154150
testProject.getInlineModuleWriter().withInlineModule(this, modules["a"]!!) {
155151
helloWorld(this, "a")
156152
}
@@ -173,13 +169,13 @@ class RustCrateInlineModuleComposingWriterTest {
173169

174170
// Write directly to an inline module without specifying the immediate parent. crate::model::b::c
175171
// should have a `hello_world` fn in it now.
176-
testProject.withModule(ModelsModule) {
172+
testProject.withModule(ServerRustModule.Model) {
177173
testProject.getInlineModuleWriter().withInlineModuleHierarchy(this, modules["c"]!!) {
178174
helloWorld(this, "c")
179175
}
180176
}
181177
// Write to a different top level module to confirm that works.
182-
testProject.withModule(InputsModule) {
178+
testProject.withModule(ServerRustModule.Model) {
183179
testProject.getInlineModuleWriter().withInlineModuleHierarchy(this, modules["e"]!!) {
184180
helloWorld(this, "e")
185181
}
@@ -200,12 +196,12 @@ class RustCrateInlineModuleComposingWriterTest {
200196

201197
// It should work even if the inner descendent module was added using `withInlineModuleHierarchy` and then
202198
// code is added to the intermediate module using `withInlineModuleHierarchyUsingCrate`
203-
testProject.withModule(OutputsModule) {
199+
testProject.withModule(ServerRustModule.Output) {
204200
testProject.getInlineModuleWriter().withInlineModuleHierarchy(this, modules["h"]!!) {
205201
testProject.getInlineModuleWriter().withInlineModuleHierarchy(this, modules["i"]!!) {
206202
helloWorld(this, "i")
207203
}
208-
testProject.withModule(ModelsModule) {
204+
testProject.withModule(ServerRustModule.Model) {
209205
// While writing to output::h::i, it should be able to a completely different module
210206
testProject.getInlineModuleWriter().withInlineModuleHierarchy(this, modules["b"]!!) {
211207
rustBlock("pub fn some_other_writer_wrote_this()") {
@@ -222,7 +218,7 @@ class RustCrateInlineModuleComposingWriterTest {
222218
// Render all of the code.
223219
testProject.getInlineModuleWriter().render()
224220

225-
testProject.withModule(ModelsModule) {
221+
testProject.withModule(ServerRustModule.Model) {
226222
this.unitTest("test_a") {
227223
rust("crate::model::a::hello_world();")
228224
rust("crate::model::a::bye_world();")

codegen-server/src/test/kotlin/software/amazon/smithy/rust/codegen/server/smithy/generators/ConstrainedBlobGeneratorTest.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ class ConstrainedBlobGeneratorTest {
7474
ConstrainedBlobGenerator(
7575
codegenContext,
7676
this.createTestInlineModuleCreator(),
77+
this,
7778
constrainedBlobShape,
7879
SmithyValidationExceptionConversionGenerator(codegenContext),
7980
).render()
@@ -133,6 +134,7 @@ class ConstrainedBlobGeneratorTest {
133134
ConstrainedBlobGenerator(
134135
codegenContext,
135136
writer.createTestInlineModuleCreator(),
137+
writer,
136138
constrainedBlobShape,
137139
SmithyValidationExceptionConversionGenerator(codegenContext),
138140
).render()

0 commit comments

Comments
 (0)