Skip to content

fix: resolve endpoint in command serializer #162

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

Merged
merged 2 commits into from
Apr 24, 2020

Conversation

AllanZhengYP
Copy link
Contributor

@AllanZhengYP AllanZhengYP commented Apr 24, 2020

Replaces: #161
Fixes: #158
CodeGen: aws/aws-sdk-js-v3#1106

The SerDeContext contains endpoint config that used to be a provider
function returning a promise of Endpoint
,
and it is resolved in serializer middleware. It introduces mismatch
between SerDeContext type and the value, where the value contains
resolved endpoint but the type is a provider function returning Endpoint
promise. This change assumes the SerDeContext.endpoint is actually
a provider function and only resolve the promise when constructing
a request.

This change also fixes a bug introduced in #160. By default the parsed
endpoint will have a default path: /, which will then incorrectly
override the path from operation model. By this change, the default
endpoint or endpoint supplied from client constructor can only override
the hostname, protocol, and port part of the request.
Whereas path and query will always be generated from the model.
This behavior will also be align with V2 SDK

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

@AllanZhengYP AllanZhengYP force-pushed the fix-context-endpoint branch 2 times, most recently from ab24cb0 to 02f9506 Compare April 24, 2020 20:32
@AllanZhengYP AllanZhengYP marked this pull request as ready for review April 24, 2020 21:31
@AllanZhengYP AllanZhengYP requested a review from kstich April 24, 2020 21:38
The endpoint used to be a function returning a promise of Endpoint,
and it is resolved in serializer parameter. It introduces mismatch
between SerDeContext type and the value, where the value contains
resolved endpoint but the type is a provider function returning Endpoint
promise. This change assumes the SerDeContext.endpoint is actually
a provider function and only resolve the promise when constructing
a request.

This change also fix the issue that the request resolved path got
overwritten by '/'. Now only the hostname, port and scheme from
client endpoint config is persisted when creating a request.
@AllanZhengYP AllanZhengYP force-pushed the fix-context-endpoint branch from 02f9506 to fb5e27e Compare April 24, 2020 21:59
@@ -227,16 +227,19 @@ private void generateOperationSerializer(
HttpProtocolGeneratorUtils.writeHostPrefix(context, operation);
}

writer.write("const {hostname, protocol = \"https\", port} = await context.endpoint();");
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you add comments describing what this setup is doing and why it's necessary, in each of the files?

@AllanZhengYP AllanZhengYP requested a review from kstich April 24, 2020 23:04
@AllanZhengYP AllanZhengYP merged commit 571d40c into smithy-lang:master Apr 24, 2020
srchase pushed a commit to srchase/smithy-typescript that referenced this pull request Mar 17, 2023
* fix: resolve endpoint in command serializer

The endpoint used to be a function returning a promise of Endpoint,
and it is resolved in serializer parameter. It introduces mismatch
between SerDeContext type and the value, where the value contains
resolved endpoint but the type is a provider function returning Endpoint
promise. This change assumes the SerDeContext.endpoint is actually
a provider function and only resolve the promise when constructing
a request.

This change also fix the issue that the request resolved path got
overwritten by '/'. Now only the hostname, port and scheme from
client endpoint config is persisted when creating a request.

* add inline documents
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.

Request endpoint is overwritten by serializer
2 participants