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

tsp, tcgc, adopt sdkpackage #2861

Merged
merged 110 commits into from
Aug 22, 2024
Merged

Conversation

haolingdong-msft
Copy link
Member

@haolingdong-msft haolingdong-msft commented Jul 15, 2024

Link #2665

WIP, have not cleaned up code in emitter yet, will let you know once it's done. But would like to create PR to track generated code diff. I'm checking the diffs generated impl files. Especially on accept and content-type headers, as well as descriptions.

Latest API view and diff summary: #2665 (comment)

-------- update on 8/7----------------
api view and diff summary: #2665 (comment)

I have also done a round of code clean up. If you have time, please feel free to take a look in the meanwhile I'm fixing the two diffs.
--------update on 8/9--------------------
Note that after adopting new SdkclientType design, those previously constant endpoint would be overridable, so there are diffs generated: 955620e
---------update on 8/12---------------------
new api-view: https://apiview.dev/Assemblies/Review/e0cf256f814e456bac0f0d751bd4aa9f/e0f4e0c3e4704de89332b6229b14ad64?diffRevisionId=fbdae726b3a04e839587766478ca88eb&diffOnly=true

Diff summary in the issue: #2665 (comment)

-----------8/13 update------
latest api view: https://apiview.dev/Assemblies/Review/e0cf256f814e456bac0f0d751bd4aa9f/0e83c8742b5942379d330f0e8f40b667?diffRevisionId=af2d36f4bf4243a39d2cab13ace75d25&diffOnly=true

public API diff:

  • allow override endpoint for constant tsp endpoint definition
  • parameter order, I will sync to sdk repo to see if there is existing sdk impacted, if not, I will keep the parameter order change.
image

impl diff:

  • allowReserved on path not supoprted by TCGC.

--------------------update on 8/19----------------------
API view:
https://apiview.dev/Assemblies/Review/e0cf256f814e456bac0f0d751bd4aa9f/b6c1bc44f2a64d90bd19587aab003913?diffRevisionId=1eed99f40d2d46f0a66d7184e26c5d86&diffOnly=true

API view diff

  1. endpoint always overridable - expected
  2. parameter order change for spread parameter case. - will regen on sdk repo to see the impact
    Reason: There is limitation on parameters list of SdkServiceMethod that it cannot map to corresponding SdkHttpOperation's parameters/bodyType which causes we can't use the SdkServiceMethod.parameters. TCGC is considering adding a mapping for us to map SdkServiceMethod's parameters to SdkHttpOperation's parameters and bodyType. But before it is supported, we are now using SdkServiceMethod.SdkHttpOperation.
    For spread parameters, we will process the parameters and bodyType under SdkHttpOperation. So the order is first query/header/path parameters, then body parameter.

Notable changes comparing to last version:

# Conflicts:
#	typespec-extension/src/code-model-builder.ts
# Conflicts:
#	typespec-extension/src/code-model-builder.ts
#	typespec-tests/src/main/java/com/cadl/internal/InternalAsyncClient.java
#	typespec-tests/src/main/java/com/cadl/internal/InternalClient.java
#	typespec-tests/src/main/java/com/cadl/internal/implementation/InternalOpsImpl.java
#	typespec-tests/src/main/java/com/cadl/literalservice/implementation/LiteralOpsImpl.java
#	typespec-tests/src/main/java/com/cadl/longrunning/implementation/LongRunningClientImpl.java
#	typespec-tests/src/main/java/com/cadl/naming/NamingAsyncClient.java
#	typespec-tests/src/main/java/com/cadl/naming/NamingClient.java
#	typespec-tests/src/main/java/com/cadl/naming/implementation/NamingOpsImpl.java
#	typespec-tests/src/main/java/com/cadl/optional/OptionalAsyncClient.java
#	typespec-tests/src/main/java/com/cadl/optional/OptionalClient.java
#	typespec-tests/src/main/java/com/cadl/optional/implementation/OptionalOpsImpl.java
#	typespec-tests/src/main/java/com/cadl/wiretype/implementation/WireTypeOpsImpl.java
This reverts commit 07a773f.

# Conflicts:
#	typespec-tests/src/main/java/com/cadl/internal/InternalAsyncClient.java
#	typespec-tests/src/main/java/com/cadl/internal/InternalClient.java
#	typespec-tests/src/main/java/com/cadl/internal/implementation/InternalOpsImpl.java
#	typespec-tests/src/main/java/com/cadl/literalservice/implementation/LiteralOpsImpl.java
#	typespec-tests/src/main/java/com/cadl/longrunning/implementation/LongRunningClientImpl.java
#	typespec-tests/src/main/java/com/cadl/naming/NamingAsyncClient.java
#	typespec-tests/src/main/java/com/cadl/naming/NamingClient.java
#	typespec-tests/src/main/java/com/cadl/naming/implementation/NamingOpsImpl.java
#	typespec-tests/src/main/java/com/cadl/optional/OptionalAsyncClient.java
#	typespec-tests/src/main/java/com/cadl/optional/OptionalClient.java
#	typespec-tests/src/main/java/com/cadl/optional/implementation/OptionalOpsImpl.java
#	typespec-tests/src/main/java/com/cadl/wiretype/implementation/WireTypeOpsImpl.java
#	typespec-tests/src/samples/java/com/cadl/flatten/generated/FlattenOpSend.java
# Please enter a commit message to explain why this merge is necessary,
# especially if it merges an updated upstream into a topic branch.
#
# Lines starting with '#' will be ignored, and an empty message aborts
# the commit.
# Conflicts:
#	typespec-extension/src/code-model-builder.ts
# Conflicts:
#	typespec-extension/src/code-model-builder.ts
# Conflicts:
#	typespec-extension/src/code-model-builder.ts
# Conflicts:
#	typespec-tests/src/main/java/com/cadl/armresourceprovider/implementation/ChildResourcesInterfacesClientImpl.java
@weidongxu-microsoft
Copy link
Member

Then what's this line for?

    if (opParameter.kind !== "property") {

In TCGC, for both spread and non-spread, SdkHttpOperation.parameters would only contain query/header/path parameters.

@haolingdong-msft
Copy link
Member Author

haolingdong-msft commented Aug 19, 2024

Then what's this line for?

    if (opParameter.kind !== "property") {

In TCGC, for both spread and non-spread, SdkHttpOperation.parameters would only contain query/header/path parameters.

it is property of the body model.
Because body parameter and query/header/path parameters are processed seperately, so I guess there is no need to check existing parameter for body parameter. Please correct me if I understand wrongly.

// header/query/path params
for (const opParameter of parameters) {
this.addParameterOrBodyPropertyToCodeModelRequest(opParameter, op, request, schema, parameter);
}
// body param
if (bodyParameter) {
if (bodyParameter.type.kind === "model") {
for (const bodyProperty of bodyParameter.type.properties) {
if (bodyProperty.kind === "property") {
this.addParameterOrBodyPropertyToCodeModelRequest(bodyProperty, op, request, schema, parameter);
}
}
}
}

@weidongxu-microsoft
Copy link
Member

weidongxu-microsoft commented Aug 20, 2024

In TCGC, for both spread and non-spread, SdkHttpOperation.parameters would only contain query/header/path parameters.

it is property of the body model. Because body parameter and query/header/path parameters are processed seperately, so I guess there is no need to check existing parameter for body parameter. Please correct me if I understand wrongly.

// header/query/path params
for (const opParameter of parameters) {
this.addParameterOrBodyPropertyToCodeModelRequest(opParameter, op, request, schema, parameter);
}
// body param
if (bodyParameter) {
if (bodyParameter.type.kind === "model") {
for (const bodyProperty of bodyParameter.type.properties) {
if (bodyProperty.kind === "property") {
this.addParameterOrBodyPropertyToCodeModelRequest(bodyProperty, op, request, schema, parameter);
}
}
}
}

Yes, I think it is not needed in your code. And that is the reason I am verifying whether TCGC gives you the "property" type parameter.

Also, from this code, the order of parameters of "spread" op is not what TCGC gives you. It is by your code, that non-property parameter is processed, then the property of the bodyParam is processed.

The order in TCGC on this would be in its SdkServiceMethod, and I assume you didn't use that type.

I likely going to refactor and use SdkServiceMethod later (probably during option bag impl). But please check that your order here is same as order in SdkServiceMethod (just take a look on param in it, for the cadl-ranch case that we see the change in apivew -- spreadParameterWithInnerAlias I think). I would want to avoid the case that we change it today, then had to change it again after migrating to SdkServiceMethod.

@haolingdong-msft
Copy link
Member Author

haolingdong-msft commented Aug 20, 2024

In TCGC, for both spread and non-spread, SdkHttpOperation.parameters would only contain query/header/path parameters.

it is property of the body model. Because body parameter and query/header/path parameters are processed seperately, so I guess there is no need to check existing parameter for body parameter. Please correct me if I understand wrongly.

// header/query/path params
for (const opParameter of parameters) {
this.addParameterOrBodyPropertyToCodeModelRequest(opParameter, op, request, schema, parameter);
}
// body param
if (bodyParameter) {
if (bodyParameter.type.kind === "model") {
for (const bodyProperty of bodyParameter.type.properties) {
if (bodyProperty.kind === "property") {
this.addParameterOrBodyPropertyToCodeModelRequest(bodyProperty, op, request, schema, parameter);
}
}
}
}

Yes, I think it is not needed in your code. And that is the reason I am verifying whether TCGC gives you the "property" type parameter

Also, from this code, the order of parameters of "spread" op is not what TCGC gives you. It is by your code, that non-property parameter is processed, then the property of the bodyParam is processed.

The order in TCGC on this would be in its SdkServiceMethod, and I assume you didn't use that type.

I likely going to refactor and use SdkServiceMethod later (probably during option bag impl). But please check that your order here is same as order in SdkServiceMethod (just take a look on param in it, for the cadl-ranch case that we see the change in apivew -- spreadParameterWithInnerAlias I think). I would want to avoid the case that we change it today, then had to change it again after migrating to SdkServiceMethod.

No, it is not same as SdkServiceMethod's parameters, as SdkServiceMethod returns body and non-body parameters together in TSP compiler's order.
But there is limitation on parameters list of SdkServiceMethod that it cannot map to corresponding SdkHttpOperation's parameters/bodyType which causes we can't use the SdkServiceMethod.parameters. TCGC is considering adding a mapping for us to map SdkServiceMethod's parameters to SdkHttpOperation's parameters and bodyType. But before it is supported, we are now using SdkServiceMethod.SdkHttpOperation.
For spread parameters, we will process the parameters and bodyType under SdkHttpOperation. So the order is first query/header/path parameters, then body parameter.
I'm afraid the order would change later if we use SdkServiceMethod.

Copy link
Member

@weidongxu-microsoft weidongxu-microsoft left a comment

Choose a reason for hiding this comment

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

Mostly LGTM


You can use 0.20.0 for next version

# Conflicts:
#	typespec-extension/changelog.md
#	typespec-extension/package.json
#	typespec-extension/src/code-model-builder.ts
#	typespec-tests/package.json
typespec-extension/changelog.md Show resolved Hide resolved
typespec-extension/src/code-model-builder.ts Show resolved Hide resolved
typespec-extension/src/code-model-builder.ts Outdated Show resolved Hide resolved
typespec-extension/src/code-model-builder.ts Outdated Show resolved Hide resolved
typespec-extension/src/code-model-builder.ts Show resolved Hide resolved
*/
private isArmSynthesizedServer(server: HttpServer): boolean {
return this.isArm() && (!server.parameters || server.parameters.size == 0);
.filter((version) => !excludePreview || pinnedApiVersion.includes("preview") || !version.includes("preview"));
Copy link
Member

Choose a reason for hiding this comment

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

Yeah, we should use isStable to not duplicate the logic of checking for -preview string and also should be case insensitive.

typespec-extension/src/code-model-builder.ts Show resolved Hide resolved
typespec-extension/src/code-model-builder.ts Outdated Show resolved Hide resolved
@haolingdong-msft haolingdong-msft merged commit c0c7949 into Azure:main Aug 22, 2024
5 checks passed
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.

4 participants