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, bump cadl-ranch #2820

Merged
merged 13 commits into from
Jun 18, 2024
1 change: 0 additions & 1 deletion typespec-extension/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@
"lodash": "~4.17.21"
},
"devDependencies": {
"@azure-tools/typespec-autorest": "0.43.0",
Copy link
Member Author

Choose a reason for hiding this comment

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

It is removed from @azure-tools/typespec-azure-resource-manager

"@azure-tools/typespec-azure-core": "0.43.0",
"@azure-tools/typespec-azure-resource-manager": "0.43.0",
"@azure-tools/typespec-azure-rulesets": "0.43.0",
Expand Down
2 changes: 2 additions & 0 deletions typespec-extension/src/code-model-builder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,8 @@ export class CodeModelBuilder {
extensions: {
"x-ms-skip-url-encoding": schema instanceof UriSchema,
},
// // make the logic same as TCGC, which takes the server-side default of host as client-side default
// clientDefaultValue: getDefaultValue(it.defaultValue),
});
}

Expand Down
15 changes: 15 additions & 0 deletions typespec-extension/src/type-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
Type,
TypeNameOptions,
Union,
Value,
getTypeName,
isNullType,
isTemplateDeclaration,
Expand Down Expand Up @@ -95,6 +96,20 @@ export function getNonNullSdkType(type: SdkType): SdkType {
return type.kind === "nullable" ? type.type : type;
}

export function getDefaultValue(value: Value | undefined): any {
if (value) {
switch (value.valueKind) {
case "StringValue":
return value.value;
case "NumericValue":
return value.value;
case "BooleanValue":
return value.value;
}
}
return undefined;
}

export function getDurationFormat(encode: EncodeData): DurationSchema["format"] {
let format: DurationSchema["format"] = "duration-rfc3339";
// duration encoded as seconds
Expand Down
11 changes: 9 additions & 2 deletions typespec-tests/Generate.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -35,16 +35,21 @@ $generateScript = {
} elseif ($tspFile -match "type[\\/]enum[\\/]fixed[\\/]") {
# override namespace for reserved keyword "enum"
$tspOptions += " --option ""@azure-tools/typespec-java.namespace=com.type.enums.fixed"""
} elseif ($tspFile -match "resiliency[\\/]srv-driven[\\/]old.tsp") {
} elseif ($tspFile -match "resiliency[\\/]srv-driven[\\/]old\.tsp") {
# override namespace for "resiliency/srv-driven/old.tsp" (make it different to that from "main.tsp")
$tspOptions += " --option ""@azure-tools/typespec-java.namespace=com.resiliency.servicedriven.v1"""
# enable advanced versioning for resiliency test
$tspOptions += " --option ""@azure-tools/typespec-java.advanced-versioning=true"""
$tspOptions += " --option ""@azure-tools/typespec-java.api-version=all"""
} elseif ($tspFile -match "resiliency[\\/]srv-driven[\\/]main.tsp") {
} elseif ($tspFile -match "resiliency[\\/]srv-driven[\\/]main\.tsp") {
# enable advanced versioning for resiliency test
$tspOptions += " --option ""@azure-tools/typespec-java.advanced-versioning=true"""
$tspOptions += " --option ""@azure-tools/typespec-java.api-version=all"""
} elseif ($tspFile -match "azure[\\/]arm[\\/].*[\\/]main\.tsp") {
# for mgmt, do not generate tests due to random mock values
$tspOptions += " --option ""@azure-tools/typespec-java.generate-tests=false"""
# also generate with group-etag-headers=false since mgmt doesn't support etag grouping yet
$tspOptions += " --option ""@azure-tools/typespec-java.group-etag-headers=false"""
} elseif ($tspFile -match "tsp[\\/]versioning.tsp") {
# test generating from specific api-version
$tspOptions += " --option ""@azure-tools/typespec-java.api-version=2022-09-01"""
Expand All @@ -61,6 +66,8 @@ $generateScript = {
$tspOptions += " --option ""@azure-tools/typespec-java.stream-style-serialization=true"""
# for mgmt, do not generate tests due to random mock values
$tspOptions += " --option ""@azure-tools/typespec-java.generate-tests=false"""
# also generate with group-etag-headers=false since mgmt doesn't support etag grouping yet
$tspOptions += " --option ""@azure-tools/typespec-java.group-etag-headers=false"""
}

# Test customization for one of the TypeSpec definitions - naming.tsp
Expand Down
2 changes: 1 addition & 1 deletion typespec-tests/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"testserver-run": "npx cadl-ranch serve ./node_modules/@azure-tools/cadl-ranch-specs/http --coverageFile ./cadl-ranch-coverage-java.json"
},
"dependencies": {
"@azure-tools/cadl-ranch-specs": "0.33.4",
"@azure-tools/cadl-ranch-specs": "0.34.0",
"@azure-tools/typespec-java": "file:/../typespec-extension/azure-tools-typespec-java-0.17.0.tgz"
},
"devDependencies": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import com._specs_.azure.clientgenerator.core.usage.implementation.ModelInOperationsImpl;
import com._specs_.azure.clientgenerator.core.usage.models.InputModel;
import com._specs_.azure.clientgenerator.core.usage.models.OutputModel;
import com._specs_.azure.clientgenerator.core.usage.models.RoundTripModel;
import com.azure.core.annotation.Generated;
import com.azure.core.annotation.ReturnType;
import com.azure.core.annotation.ServiceClient;
Expand Down Expand Up @@ -96,6 +97,56 @@ public Mono<Response<BinaryData>> outputToInputOutputWithResponse(RequestOptions
return this.serviceClient.outputToInputOutputWithResponseAsync(requestOptions);
}

/**
* "ResultModel" should be usage=output, as it is read-only and does not exist in request body.
*
* Expected body parameter:
* ```json
* {
* }
* ```
*
* Expected response body:
* ```json
* {
* "name": &lt;any string&gt;
* }
* ```.
* <p><strong>Request Body Schema</strong></p>
*
* <pre>{@code
* {
* result (Required): {
* name: String (Required)
* }
* }
* }</pre>
*
* <p><strong>Response Body Schema</strong></p>
*
* <pre>{@code
* {
* result (Required): {
* name: String (Required)
* }
* }
* }</pre>
*
* @param body The body parameter.
* @param requestOptions The options to configure the HTTP request before HTTP client sends it.
* @throws HttpResponseException thrown if the request is rejected by server.
* @throws ClientAuthenticationException thrown if the request is rejected by server on status code 401.
* @throws ResourceNotFoundException thrown if the request is rejected by server on status code 404.
* @throws ResourceModifiedException thrown if the request is rejected by server on status code 409.
* @return the response body along with {@link Response} on successful completion of {@link Mono}.
*/
@Generated
@ServiceMethod(returns = ReturnType.SINGLE)
public Mono<Response<BinaryData>> modelInReadOnlyPropertyWithResponse(BinaryData body,
RequestOptions requestOptions) {
return this.serviceClient.modelInReadOnlyPropertyWithResponseAsync(body, requestOptions);
}

/**
* Expected body parameter:
* ```json
Expand Down Expand Up @@ -144,4 +195,39 @@ public Mono<OutputModel> outputToInputOutput() {
return outputToInputOutputWithResponse(requestOptions).flatMap(FluxUtil::toMono)
.map(protocolMethodData -> protocolMethodData.toObject(OutputModel.class));
}

/**
* "ResultModel" should be usage=output, as it is read-only and does not exist in request body.
*
* Expected body parameter:
* ```json
* {
* }
* ```
*
* Expected response body:
* ```json
* {
* "name": &lt;any string&gt;
* }
* ```.
*
* @param body The body parameter.
* @throws IllegalArgumentException thrown if parameters fail the validation.
* @throws HttpResponseException thrown if the request is rejected by server.
* @throws ClientAuthenticationException thrown if the request is rejected by server on status code 401.
* @throws ResourceNotFoundException thrown if the request is rejected by server on status code 404.
* @throws ResourceModifiedException thrown if the request is rejected by server on status code 409.
* @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
* @return the response body on successful completion of {@link Mono}.
*/
@Generated
@ServiceMethod(returns = ReturnType.SINGLE)
public Mono<RoundTripModel> modelInReadOnlyProperty(RoundTripModel body) {
// Generated convenience method for modelInReadOnlyPropertyWithResponse
RequestOptions requestOptions = new RequestOptions();
return modelInReadOnlyPropertyWithResponse(BinaryData.fromObject(body), requestOptions)
.flatMap(FluxUtil::toMono)
.map(protocolMethodData -> protocolMethodData.toObject(RoundTripModel.class));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import com._specs_.azure.clientgenerator.core.usage.implementation.ModelInOperationsImpl;
import com._specs_.azure.clientgenerator.core.usage.models.InputModel;
import com._specs_.azure.clientgenerator.core.usage.models.OutputModel;
import com._specs_.azure.clientgenerator.core.usage.models.RoundTripModel;
import com.azure.core.annotation.Generated;
import com.azure.core.annotation.ReturnType;
import com.azure.core.annotation.ServiceClient;
Expand Down Expand Up @@ -94,6 +95,55 @@ public Response<BinaryData> outputToInputOutputWithResponse(RequestOptions reque
return this.serviceClient.outputToInputOutputWithResponse(requestOptions);
}

/**
* "ResultModel" should be usage=output, as it is read-only and does not exist in request body.
*
* Expected body parameter:
* ```json
* {
* }
* ```
*
* Expected response body:
* ```json
* {
* "name": &lt;any string&gt;
* }
* ```.
* <p><strong>Request Body Schema</strong></p>
*
* <pre>{@code
* {
* result (Required): {
* name: String (Required)
* }
* }
* }</pre>
*
* <p><strong>Response Body Schema</strong></p>
*
* <pre>{@code
* {
* result (Required): {
* name: String (Required)
* }
* }
* }</pre>
*
* @param body The body parameter.
* @param requestOptions The options to configure the HTTP request before HTTP client sends it.
* @throws HttpResponseException thrown if the request is rejected by server.
* @throws ClientAuthenticationException thrown if the request is rejected by server on status code 401.
* @throws ResourceNotFoundException thrown if the request is rejected by server on status code 404.
* @throws ResourceModifiedException thrown if the request is rejected by server on status code 409.
* @return the response body along with {@link Response}.
*/
@Generated
@ServiceMethod(returns = ReturnType.SINGLE)
public Response<BinaryData> modelInReadOnlyPropertyWithResponse(BinaryData body, RequestOptions requestOptions) {
return this.serviceClient.modelInReadOnlyPropertyWithResponse(body, requestOptions);
}

/**
* Expected body parameter:
* ```json
Expand Down Expand Up @@ -140,4 +190,38 @@ public OutputModel outputToInputOutput() {
RequestOptions requestOptions = new RequestOptions();
return outputToInputOutputWithResponse(requestOptions).getValue().toObject(OutputModel.class);
}

/**
* "ResultModel" should be usage=output, as it is read-only and does not exist in request body.
*
* Expected body parameter:
* ```json
* {
* }
* ```
*
* Expected response body:
* ```json
* {
* "name": &lt;any string&gt;
* }
* ```.
*
* @param body The body parameter.
* @throws IllegalArgumentException thrown if parameters fail the validation.
* @throws HttpResponseException thrown if the request is rejected by server.
* @throws ClientAuthenticationException thrown if the request is rejected by server on status code 401.
* @throws ResourceNotFoundException thrown if the request is rejected by server on status code 404.
* @throws ResourceModifiedException thrown if the request is rejected by server on status code 409.
* @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
* @return the response.
*/
@Generated
@ServiceMethod(returns = ReturnType.SINGLE)
public RoundTripModel modelInReadOnlyProperty(RoundTripModel body) {
// Generated convenience method for modelInReadOnlyPropertyWithResponse
RequestOptions requestOptions = new RequestOptions();
return modelInReadOnlyPropertyWithResponse(BinaryData.fromObject(body), requestOptions).getValue()
.toObject(RoundTripModel.class);
}
}
Loading
Loading