Skip to content
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

docs: add more information about BLOB values in structures #1182

Merged
merged 3 commits into from
Mar 12, 2024

Conversation

kuhe
Copy link
Contributor

@kuhe kuhe commented Mar 7, 2024

aws/aws-sdk-js-v3#5240

The PR improves the inline documentation generated for structural hints for operation inputs and outputs.

It differentiates between input and output of the same Smithy type (BLOB). For TypeScript, the inputs are wider than a single type for convenience, and the output has mixin methods attached, again for user convenience.

For a sample diff, see first commit in aws/aws-sdk-js-v3#5864

Examples

output side

STREAMING_BLOB_VALUE

* // { // GetObjectOutput
* //   Body: "STREAMING_BLOB_VALUE",
* //   DeleteMarker: true || false,

becomes

* // { // GetObjectOutput
* //   Body: "<SdkStream>", // see @smithy/types -> StreamingBlobPayloadOutputTypes
* //   DeleteMarker: true || false,

BLOB_VALUE

 * //   Payload: { // SelectObjectContentEventStream Union: only one key present
 * //     Records: { // RecordsEvent
 * //       Payload: "BLOB_VALUE",
 * //     },

becomes

 * //   Payload: { // SelectObjectContentEventStream Union: only one key present
 * //     Records: { // RecordsEvent
 * //       Payload: new Uint8Array(),
 * //     },

input side

STREAMING_BLOB_VALUE

 *   Body: "STREAMING_BLOB_VALUE",
 *   Bucket: "STRING_VALUE", // required
 *   CacheControl: "STRING_VALUE",

becomes

 *   Body: "MULTIPLE_TYPES_ACCEPTED", // see @smithy/types -> StreamingBlobPayloadInputTypes
 *   Bucket: "STRING_VALUE", // required
 *   CacheControl: "STRING_VALUE",

BLOB_VALUE

 *   RawMessage: { // RawMessage
 *     Data: "BLOB_VALUE", // required
 *   },

becomes

 *   RawMessage: { // RawMessage
 *     Data: new Uint8Array(), // e.g. Buffer.from("") or new TextEncoder().encode("")     // required
 *   },

@@ -46,7 +47,8 @@ public abstract class StructureExampleGenerator {
*/
public static String generateStructuralHintDocumentation(Shape shape, Model model, boolean isComment) {
StringBuilder buffer = new StringBuilder();
shape(shape, buffer, model, 0, new ShapeTracker());
boolean isInput = shape.hasTrait(InputTrait.class);
Copy link
Contributor

@syall syall Mar 8, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's better to define isInput from where generateStructuralHintDocumentation() is called.

This is mostly because I'm unsure if smithy-typescript applies input / output traits if the corresponding structures are missing the traits.

// TODO: Not using below because it would break existing AWS SDKs. Maybe it should be configurable
// so generic SDKs call this by default, but AWS SDKs can opt-out of it via a setting.
// runner.createDedicatedInputsAndOutputs();

Just to be safe, I think it's better to pass in the isInput boolean at these locations:

@kuhe kuhe merged commit d929795 into smithy-lang:main Mar 12, 2024
7 checks passed
@kuhe kuhe deleted the docs/blob branch March 12, 2024 18:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants