-
Notifications
You must be signed in to change notification settings - Fork 230
Rfc30/feature gate for generated crates #2183
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
Changes from all commits
9b70288
5c794cf
6403cec
1f33a5c
2fb7178
3513d7d
1717d72
e16ce62
14d5e1d
cc61ede
22ef698
7aaa744
8b12529
cd602bf
b90a1b2
1cefde2
af24d35
25ed6ff
6a3757e
a1dd430
8c0843d
d64ee3a
296ab7b
e0811b2
a5c2eb8
8ceb679
b3fa786
9f84174
a5970c0
4e8a72c
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 |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| /* | ||
| * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| */ | ||
|
|
||
| package software.amazon.smithy.rust.codegen.client.smithy.customize | ||
|
|
||
| import software.amazon.smithy.rust.codegen.client.smithy.ClientCodegenContext | ||
| import software.amazon.smithy.rust.codegen.core.rustlang.Feature | ||
| import software.amazon.smithy.rust.codegen.core.smithy.RustCrate | ||
|
|
||
| /** | ||
| * This class, | ||
| * - Adds serde as a dependency | ||
| * | ||
| */ | ||
| class SerdeDecorator : ClientCodegenDecorator { | ||
| override val name: String = "SerdeDecorator" | ||
| override val order: Byte = -1 | ||
|
|
||
| override fun extras(codegenContext: ClientCodegenContext, rustCrate: RustCrate) { | ||
| fun _feature(feature_name: String, crate_name: String): Feature { | ||
| return Feature(feature_name, false, listOf(crate_name + "/" + feature_name)) | ||
| } | ||
| rustCrate.mergeFeature(_feature("serde-serialize", "aws-smithy-types")) | ||
| rustCrate.mergeFeature(_feature("serde-deserialize", "aws-smithy-types")) | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change | ||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -446,6 +446,16 @@ class Attribute(val inner: Writable) { | |||||||||||||||||
| } | ||||||||||||||||||
| } | ||||||||||||||||||
|
|
||||||||||||||||||
| // These were supposed to be a part of companion object but we decided to move it out to here to avoid NPE | ||||||||||||||||||
| // You can find the discussion here. | ||||||||||||||||||
| // https://github.com/awslabs/smithy-rs/discussions/2248 | ||||||||||||||||||
| public fun SerdeSerialize(): Attribute { | ||||||||||||||||||
| return Attribute(cfgAttr(all(writable("aws_sdk_unstable"), feature("serde-serialize")), derive(RuntimeType.SerdeSerialize))) | ||||||||||||||||||
| } | ||||||||||||||||||
| public fun SerdeDeserialize(): Attribute { | ||||||||||||||||||
| return Attribute(cfgAttr(all(writable("aws_sdk_unstable"), feature("serde-deserialize")), derive(RuntimeType.SerdeDeserialize))) | ||||||||||||||||||
| } | ||||||||||||||||||
|
Comment on lines
+452
to
+457
Contributor
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. There's no need for these to be functions. Change them into values and put them in the companion object below.
Suggested change
Contributor
Author
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 causes NPE too. |
||||||||||||||||||
|
|
||||||||||||||||||
| companion object { | ||||||||||||||||||
| val AllowClippyBoxedLocal = Attribute(allow("clippy::boxed_local")) | ||||||||||||||||||
| val AllowClippyLetAndReturn = Attribute(allow("clippy::let_and_return")) | ||||||||||||||||||
|
|
@@ -498,6 +508,7 @@ class Attribute(val inner: Writable) { | |||||||||||||||||
| } | ||||||||||||||||||
|
|
||||||||||||||||||
| fun all(vararg attrMacros: Writable): Writable = macroWithArgs("all", *attrMacros) | ||||||||||||||||||
| fun cfgAttr(vararg attrMacros: Writable): Writable = macroWithArgs("cfg_attr", *attrMacros) | ||||||||||||||||||
|
|
||||||||||||||||||
| fun allow(lints: Collection<String>): Writable = macroWithArgs("allow", *lints.toTypedArray()) | ||||||||||||||||||
| fun allow(vararg lints: String): Writable = macroWithArgs("allow", *lints) | ||||||||||||||||||
|
|
||||||||||||||||||
| Original file line number | Diff line number | Diff line change | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,25 @@ | ||||||||||
| /* | ||||||||||
| * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||||||||||
| * SPDX-License-Identifier: Apache-2.0 | ||||||||||
| */ | ||||||||||
|
|
||||||||||
| package software.amazon.smithy.rust.codegen.core.smithy.generators | ||||||||||
|
|
||||||||||
| import software.amazon.smithy.model.Model | ||||||||||
| import software.amazon.smithy.model.shapes.StructureShape | ||||||||||
| import software.amazon.smithy.rust.codegen.core.rustlang.Attribute | ||||||||||
| import software.amazon.smithy.rust.codegen.core.rustlang.RustWriter | ||||||||||
| import software.amazon.smithy.rust.codegen.core.util.isEventStream | ||||||||||
|
|
||||||||||
| public object RenderSerdeAttribute { | ||||||||||
| public fun forStructureShape(writer: RustWriter, shape: StructureShape, model: Model) { | ||||||||||
| if (shape.members().none { it.isEventStream(model) }) { | ||||||||||
| writeAttributes(writer) | ||||||||||
| } | ||||||||||
| } | ||||||||||
|
|
||||||||||
| public fun writeAttributes(writer: RustWriter) { | ||||||||||
| Attribute("").SerdeSerialize().render(writer) | ||||||||||
| Attribute("").SerdeDeserialize().render(writer) | ||||||||||
|
Comment on lines
+22
to
+23
Contributor
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. After making the change suggested in my earlier comment, you can update this function like so:
Suggested change
Contributor
Author
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. No, this causes NPE. |
||||||||||
| } | ||||||||||
| } | ||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| /* | ||
| * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| */ | ||
|
|
||
| package software.amazon.smithy.rust.codegen.core.smithy.generators | ||
|
|
||
| import software.amazon.smithy.model.shapes.Shape | ||
| import software.amazon.smithy.model.traits.SensitiveTrait | ||
| import software.amazon.smithy.rust.codegen.core.rustlang.RustWriter | ||
| import software.amazon.smithy.rust.codegen.core.util.hasTrait | ||
|
|
||
| object SensitiveWarning { | ||
| private const val warningMessage = "/// This data may contain sensitive information; It will not be obscured when serialized.\n" | ||
| fun<T : Shape> addDoc(writer: RustWriter, shape: T) { | ||
| if (shape.hasTrait<SensitiveTrait>()) { | ||
| writer.writeInline(warningMessage) | ||
| } | ||
| } | ||
| } |
Uh oh!
There was an error while loading. Please reload this page.