-
Notifications
You must be signed in to change notification settings - Fork 194
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
Produce &[T]
instead of Option<&[T]>
for list fields
#2995
Changes from all commits
e7424f0
103f35e
ada8fcb
83ea856
7a939a9
ed5a19d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -41,16 +41,19 @@ const val CODEGEN_SETTINGS = "codegen" | |
open class CoreCodegenConfig( | ||
open val formatTimeoutSeconds: Int = defaultFormatTimeoutSeconds, | ||
open val debugMode: Boolean = defaultDebugMode, | ||
open val flattenCollectionAccessors: Boolean = defaultFlattenMode, | ||
drganjoo marked this conversation as resolved.
Show resolved
Hide resolved
|
||
) { | ||
companion object { | ||
const val defaultFormatTimeoutSeconds = 20 | ||
const val defaultDebugMode = false | ||
const val defaultFlattenMode = false | ||
|
||
fun fromNode(node: Optional<ObjectNode>): CoreCodegenConfig = | ||
if (node.isPresent) { | ||
CoreCodegenConfig( | ||
formatTimeoutSeconds = node.get().getNumberMemberOrDefault("formatTimeoutSeconds", defaultFormatTimeoutSeconds).toInt(), | ||
debugMode = node.get().getBooleanMemberOrDefault("debugMode", defaultDebugMode), | ||
flattenCollectionAccessors = node.get().getBooleanMemberOrDefault("flattenCollectionAccessors", defaultFlattenMode), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Will this change allow someone on the server side to override how we generate accessor methods for collection types by setting "flattenCollectionAccessor" in smithy-build.json? If the user cannot set this in the settings, then disregard the following: Currently, on the server side that behavior is controlled by whether the field is marked as This approach is fine for optional server inputs, where not sending a value for a collection (resulting in None) and sending an empty collection are treated the same by the business logic. However, there are scenarios where the server's output could make a meaningful distinction between an empty list and a None list. Additionally, using There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this is only the accessor method—it has absolutely no impact on serialization, it's just for convenience when reading the field.
The only reason to do that is explicitly if you are trying to tell the difference. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh yes! only the accessor gets changed. The underlying serialization format and the field remains the same. |
||
) | ||
} else { | ||
CoreCodegenConfig( | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -37,6 +37,7 @@ import software.amazon.smithy.rust.codegen.core.smithy.RustSymbolProviderConfig | |
import software.amazon.smithy.rust.codegen.core.smithy.SymbolVisitor | ||
import software.amazon.smithy.rust.codegen.core.smithy.generators.BuilderGenerator | ||
import software.amazon.smithy.rust.codegen.core.smithy.generators.BuilderInstantiator | ||
import software.amazon.smithy.rust.codegen.core.smithy.generators.StructSettings | ||
import software.amazon.smithy.rust.codegen.core.smithy.generators.StructureGenerator | ||
import software.amazon.smithy.rust.codegen.core.smithy.module | ||
import software.amazon.smithy.rust.codegen.core.smithy.traits.SyntheticInputTrait | ||
|
@@ -194,7 +195,7 @@ fun StructureShape.renderWithModelBuilder( | |
) { | ||
val struct = this | ||
rustCrate.withModule(symbolProvider.moduleForShape(struct)) { | ||
StructureGenerator(model, symbolProvider, this, struct, emptyList()).render() | ||
StructureGenerator(model, symbolProvider, this, struct, emptyList(), StructSettings(true)).render() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we have a test someplace for There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. actually no! let me add one, good catch. (Although all existing server tests are testing this) |
||
implBlock(symbolProvider.toSymbol(struct)) { | ||
BuilderGenerator.renderConvenienceMethod(this, symbolProvider, struct) | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: which namespace do the rest of the settings lie in? For example, we don't have a
software.amazon.smithy.rust.codegen.core.smithy.generators.settings
namespace?