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

http-client-java, bump typespec libs #5317

Merged
Show file tree
Hide file tree
Changes from 21 commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
027e066
http-client-java, bump cadl-ranch
weidongxu-microsoft Dec 9, 2024
9dffdf1
bump tcgc and cadl-ranch
weidongxu-microsoft Dec 9, 2024
3ef8254
npm audit fix
weidongxu-microsoft Dec 9, 2024
6036fd6
use type from SdkHttpOperation
weidongxu-microsoft Dec 9, 2024
c2871fb
revert cadl-ranch
weidongxu-microsoft Dec 9, 2024
6accd72
Merge branch 'main' into http-client-java_bump-cadl-ranch
weidongxu-microsoft Dec 9, 2024
5b2eba8
Revert "revert cadl-ranch"
weidongxu-microsoft Dec 10, 2024
0e71ee2
bump tcgc
weidongxu-microsoft Dec 10, 2024
f005e63
add test for error without body
weidongxu-microsoft Dec 10, 2024
270eea3
use nextLink
weidongxu-microsoft Dec 10, 2024
0a81c91
handle error without error model
weidongxu-microsoft Dec 10, 2024
ad29f41
nit
weidongxu-microsoft Dec 10, 2024
b99a3b8
bug fix, pageable
weidongxu-microsoft Dec 10, 2024
d113d53
local test
weidongxu-microsoft Dec 11, 2024
a52913c
remove core-json in unbranded, it was merged into core
weidongxu-microsoft Dec 11, 2024
9eac35c
comment out ExternalPackage JSON
weidongxu-microsoft Dec 11, 2024
e1aa59e
bump npm
weidongxu-microsoft Dec 11, 2024
db521e2
Merge branch 'main' into http-client-java_bump-cadl-ranch
weidongxu-microsoft Dec 11, 2024
f6ecfd1
make a SdkHttpOperationParameterType type
weidongxu-microsoft Dec 11, 2024
80fa206
use Lifecycle for visibility
weidongxu-microsoft Dec 11, 2024
d8cd6dd
regen
weidongxu-microsoft Dec 11, 2024
92110ef
nit
weidongxu-microsoft Dec 11, 2024
589d9dd
update local visibility test case
weidongxu-microsoft Dec 11, 2024
95b803c
Merge branch 'main' into http-client-java_bump-cadl-ranch
weidongxu-microsoft Dec 11, 2024
a7c73d9
bump 0.1.4
weidongxu-microsoft Dec 11, 2024
f0d1428
Merge branch 'main' into http-client-java_bump-cadl-ranch
weidongxu-microsoft Dec 11, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 17 additions & 22 deletions packages/http-client-java/emitter/src/code-model-builder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ import {
SdkDurationType,
SdkEnumType,
SdkEnumValueType,
SdkHeaderParameter,
SdkHttpErrorResponse,
SdkHttpOperation,
SdkHttpResponse,
Expand All @@ -64,7 +63,6 @@ import {
SdkModelPropertyType,
SdkModelType,
SdkPathParameter,
SdkQueryParameter,
SdkServiceMethod,
SdkType,
SdkUnionType,
Expand Down Expand Up @@ -164,6 +162,8 @@ import {
} from "./utils.js";
const { isEqual } = pkg;

type SdkHttpOperationParameterType = SdkHttpOperation["parameters"][number];

export class CodeModelBuilder {
private program: Program;
private typeNameOptions: TypeNameOptions;
Expand Down Expand Up @@ -969,20 +969,19 @@ export class CodeModelBuilder {
if (bodyType && bodyType.kind === "model") {
const itemName = sdkMethod.response.resultPath;
const nextLinkName = sdkMethod.nextLinkPath;
if (itemName && nextLinkName) {
op.extensions = op.extensions ?? {};
op.extensions["x-ms-pageable"] = {
itemName: itemName,
nextLinkName: nextLinkName,
};
weidongxu-microsoft marked this conversation as resolved.
Show resolved Hide resolved

op.responses?.forEach((r) => {
if (r instanceof SchemaResponse) {
this.trackSchemaUsage(r.schema, { usage: [SchemaContext.Paged] });
}
});
break;
}

op.extensions = op.extensions ?? {};
op.extensions["x-ms-pageable"] = {
itemName: itemName,
nextLinkName: nextLinkName,
};

op.responses?.forEach((r) => {
if (r instanceof SchemaResponse) {
this.trackSchemaUsage(r.schema, { usage: [SchemaContext.Paged] });
}
});
break;
}
}
}
Expand Down Expand Up @@ -1095,7 +1094,7 @@ export class CodeModelBuilder {

private processParameter(
op: CodeModelOperation,
param: SdkQueryParameter | SdkPathParameter | SdkHeaderParameter,
param: SdkHttpOperationParameterType,
clientContext: ClientContext,
) {
if (clientContext.apiVersions && isApiVersion(this.sdkContext, param)) {
Expand Down Expand Up @@ -1589,11 +1588,7 @@ export class CodeModelBuilder {
}

private addParameterOrBodyPropertyToCodeModelRequest(
opParameter:
| SdkPathParameter
| SdkHeaderParameter
| SdkQueryParameter
| SdkBodyModelPropertyType,
opParameter: SdkHttpOperationParameterType | SdkBodyModelPropertyType,
op: CodeModelOperation,
request: Request,
schema: ObjectSchema,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,6 @@ private Pom createGenericPom(Project project) {
List<String> dependencyIdentifiers = new ArrayList<>();
// for generic pom, stream style is always true
addDependencyIdentifier(dependencyIdentifiers, addedDependencyPrefixes, Project.Dependency.CLIENTCORE, false);
addDependencyIdentifier(dependencyIdentifiers, addedDependencyPrefixes, Project.Dependency.CLIENTCORE_JSON,
false);

// merge dependencies in POM and dependencies added above
dependencyIdentifiers.addAll(project.getPomDependencyIdentifiers()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ public class ExternalPackage {
public static final ExternalPackage CORE
= new Builder().packageName(CLIENTCORE_PACKAGE_NAME).groupId("io.clientcore").artifactId("core").build();

public static final ExternalPackage JSON = new Builder().packageName(CLIENTCORE_JSON_PACKAGE_NAME)
.groupId("io.clientcore")
.artifactId("core-json")
.build();
// public static final ExternalPackage JSON = new Builder().packageName(CLIENTCORE_JSON_PACKAGE_NAME)
// .groupId("io.clientcore")
// .artifactId("core-json")
// .build();

private final String packageName;
private final String groupId;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -211,9 +211,15 @@ protected void writeUnexpectedExceptions(ProxyMethod restAPIMethod, JavaInterfac
for (Map.Entry<ClassType, List<Integer>> exception : restAPIMethod.getUnexpectedResponseExceptionTypes()
.entrySet()) {
ClientModel errorModel = ClientModelUtil.getErrorModelFromException(exception.getKey());
interfaceBlock.annotation("UnexpectedResponseExceptionDetail(statusCode = {"
+ exception.getValue().stream().map(String::valueOf).collect(Collectors.joining(","))
+ " }, exceptionBodyClass = " + errorModel.getName() + ".class)");
if (errorModel == null) {
interfaceBlock.annotation("UnexpectedResponseExceptionDetail(statusCode = {"
+ exception.getValue().stream().map(String::valueOf).collect(Collectors.joining(","))
+ " })");
} else {
interfaceBlock.annotation("UnexpectedResponseExceptionDetail(statusCode = {"
+ exception.getValue().stream().map(String::valueOf).collect(Collectors.joining(","))
+ " }, exceptionBodyClass = " + errorModel.getName() + ".class)");
}
weidongxu-microsoft marked this conversation as resolved.
Show resolved Hide resolved
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,21 @@
"testserver-stop": "cadl-ranch server stop"
},
"dependencies": {
"@azure-tools/cadl-ranch-specs": "0.39.4",
"@azure-tools/cadl-ranch-specs": "0.39.5",
"@typespec/http-client-java": "file:/../../typespec-http-client-java-0.1.3.tgz",
"@typespec/http-client-java-tests": "file:"
},
"overrides": {
"@typespec/compiler": "~0.62.0",
"@typespec/http": "~0.62.0",
"@typespec/rest": "~0.62.0",
"@typespec/versioning": "~0.62.0",
"@typespec/openapi": "~0.62.0",
"@typespec/xml": "~0.62.0",
"@azure-tools/typespec-azure-core": "~0.48.0",
"@azure-tools/typespec-client-generator-core": "~0.48.4",
"@azure-tools/typespec-azure-resource-manager": "~0.48.0",
"@azure-tools/typespec-autorest": "~0.48.0"
"@typespec/compiler": "~0.63.0",
"@typespec/http": "~0.63.0",
"@typespec/rest": "~0.63.0",
"@typespec/versioning": "~0.63.0",
"@typespec/openapi": "~0.63.0",
"@typespec/xml": "~0.63.0",
"@azure-tools/typespec-azure-core": "~0.49.0",
"@azure-tools/typespec-client-generator-core": "~0.49.0",
"@azure-tools/typespec-azure-resource-manager": "~0.49.0",
"@azure-tools/typespec-autorest": "~0.49.0"
},
"private": true
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public final class OperationInner {
/*
* Localized display information for this particular operation.
*/
@JsonProperty(value = "display", access = JsonProperty.Access.WRITE_ONLY)
@JsonProperty(value = "display")
private OperationDisplay display;

/*
Expand All @@ -45,7 +45,7 @@ public final class OperationInner {
/*
* Extensible enum. Indicates the action type. "Internal" refers to actions that are for internal only APIs.
*/
@JsonProperty(value = "actionType")
@JsonProperty(value = "actionType", access = JsonProperty.Access.WRITE_ONLY)
weidongxu-microsoft marked this conversation as resolved.
Show resolved Hide resolved
private ActionType actionType;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -407,26 +407,6 @@ Mono<Response<BinaryData>> listStringsNext(@PathParam(value = "nextLink", encode
Response<BinaryData> listStringsNextSync(@PathParam(value = "nextLink", encoded = true) String nextLink,
@HostParam("endpoint") String endpoint, @HeaderParam("Accept") String accept, RequestOptions requestOptions,
Context context);

@Get("{nextLink}")
@ExpectedResponses({ 200 })
@UnexpectedResponseExceptionType(value = ClientAuthenticationException.class, code = { 401 })
@UnexpectedResponseExceptionType(value = ResourceNotFoundException.class, code = { 404 })
@UnexpectedResponseExceptionType(value = ResourceModifiedException.class, code = { 409 })
@UnexpectedResponseExceptionType(HttpResponseException.class)
Mono<Response<BinaryData>> listIntegersNext(@PathParam(value = "nextLink", encoded = true) String nextLink,
@HostParam("endpoint") String endpoint, @HeaderParam("Accept") String accept, RequestOptions requestOptions,
Context context);

@Get("{nextLink}")
@ExpectedResponses({ 200 })
@UnexpectedResponseExceptionType(value = ClientAuthenticationException.class, code = { 401 })
@UnexpectedResponseExceptionType(value = ResourceNotFoundException.class, code = { 404 })
@UnexpectedResponseExceptionType(value = ResourceModifiedException.class, code = { 409 })
@UnexpectedResponseExceptionType(HttpResponseException.class)
Response<BinaryData> listIntegersNextSync(@PathParam(value = "nextLink", encoded = true) String nextLink,
@HostParam("endpoint") String endpoint, @HeaderParam("Accept") String accept, RequestOptions requestOptions,
Context context);
}

/**
Expand Down Expand Up @@ -1290,7 +1270,7 @@ private Mono<PagedResponse<BinaryData>> listIntegersSinglePageAsync(RequestOptio
return FluxUtil
.withContext(context -> service.listIntegers(this.getEndpoint(), accept, requestOptions, context))
.map(res -> new PagedResponseBase<>(res.getRequest(), res.getStatusCode(), res.getHeaders(),
getValues(res.getValue(), "value"), getNextLink(res.getValue(), "nextLink"), null));
getValues(res.getValue(), "value"), null, null));
}

/**
Expand All @@ -1312,11 +1292,7 @@ private Mono<PagedResponse<BinaryData>> listIntegersSinglePageAsync(RequestOptio
*/
@ServiceMethod(returns = ReturnType.COLLECTION)
public PagedFlux<BinaryData> listIntegersAsync(RequestOptions requestOptions) {
RequestOptions requestOptionsForNextPage = new RequestOptions();
requestOptionsForNextPage.setContext(
requestOptions != null && requestOptions.getContext() != null ? requestOptions.getContext() : Context.NONE);
return new PagedFlux<>(() -> listIntegersSinglePageAsync(requestOptions),
nextLink -> listIntegersNextSinglePageAsync(nextLink, requestOptionsForNextPage));
return new PagedFlux<>(() -> listIntegersSinglePageAsync(requestOptions));
}

/**
Expand All @@ -1341,7 +1317,7 @@ private PagedResponse<BinaryData> listIntegersSinglePage(RequestOptions requestO
final String accept = "application/json";
Response<BinaryData> res = service.listIntegersSync(this.getEndpoint(), accept, requestOptions, Context.NONE);
return new PagedResponseBase<>(res.getRequest(), res.getStatusCode(), res.getHeaders(),
getValues(res.getValue(), "value"), getNextLink(res.getValue(), "nextLink"), null);
getValues(res.getValue(), "value"), null, null);
}

/**
Expand All @@ -1363,11 +1339,7 @@ private PagedResponse<BinaryData> listIntegersSinglePage(RequestOptions requestO
*/
@ServiceMethod(returns = ReturnType.COLLECTION)
public PagedIterable<BinaryData> listIntegers(RequestOptions requestOptions) {
RequestOptions requestOptionsForNextPage = new RequestOptions();
requestOptionsForNextPage.setContext(
requestOptions != null && requestOptions.getContext() != null ? requestOptions.getContext() : Context.NONE);
return new PagedIterable<>(() -> listIntegersSinglePage(requestOptions),
nextLink -> listIntegersNextSinglePage(nextLink, requestOptionsForNextPage));
return new PagedIterable<>(() -> listIntegersSinglePage(requestOptions));
}

/**
Expand Down Expand Up @@ -1540,62 +1512,6 @@ private PagedResponse<BinaryData> listStringsNextSinglePage(String nextLink, Req
getValues(res.getValue(), "value"), getNextLink(res.getValue(), "nextLink"), null);
}

/**
* Get the next page of items.
* <p><strong>Response Body Schema</strong></p>
*
* <pre>
* {@code
* int
* }
* </pre>
*
* @param nextLink The URL to get the next list of items.
* @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 PagedResponse} on successful completion of {@link Mono}.
*/
@ServiceMethod(returns = ReturnType.SINGLE)
private Mono<PagedResponse<BinaryData>> listIntegersNextSinglePageAsync(String nextLink,
RequestOptions requestOptions) {
final String accept = "application/json";
return FluxUtil
.withContext(
context -> service.listIntegersNext(nextLink, this.getEndpoint(), accept, requestOptions, context))
.map(res -> new PagedResponseBase<>(res.getRequest(), res.getStatusCode(), res.getHeaders(),
getValues(res.getValue(), "value"), getNextLink(res.getValue(), "nextLink"), null));
}

/**
* Get the next page of items.
* <p><strong>Response Body Schema</strong></p>
*
* <pre>
* {@code
* int
* }
* </pre>
*
* @param nextLink The URL to get the next list of items.
* @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 PagedResponse}.
*/
@ServiceMethod(returns = ReturnType.SINGLE)
private PagedResponse<BinaryData> listIntegersNextSinglePage(String nextLink, RequestOptions requestOptions) {
final String accept = "application/json";
Response<BinaryData> res
= service.listIntegersNextSync(nextLink, this.getEndpoint(), accept, requestOptions, Context.NONE);
return new PagedResponseBase<>(res.getRequest(), res.getStatusCode(), res.getHeaders(),
getValues(res.getValue(), "value"), getNextLink(res.getValue(), "nextLink"), null);
}

private List<BinaryData> getValues(BinaryData binaryData, String path) {
try {
Map<?, ?> obj = binaryData.toObject(Map.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@ model Diagnostic {
error: Error;
}

@error
model NotFoundErrorResponse is NotFoundResponse;

@route("/error")
interface ErrorOp {
read(): ResourceCreatedOrOkResponse<Diagnostic> | ErrorResponse;
read(): ResourceCreatedOrOkResponse<Diagnostic> | NotFoundErrorResponse | ErrorResponse;
}
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,6 @@ model BytesData extends Data {
@doc("Data as {@code byte[]}")
@clientName("dataAsBytes")
@encodedName("application/json", "data_bytes")
@projectedName("client", "noeffect")
data: bytes;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,26 +86,20 @@ model StringsList {
@items
value: string[];

@global.Azure.Core.nextLink
@nextLink
nextLink?: string;
}

@pagedResult
model Int32sList {
@items
value: int32[];

@global.Azure.Core.nextLink
nextLink?: string;
weidongxu-microsoft marked this conversation as resolved.
Show resolved Hide resolved
}

@pagedResult
model DateTimesList {
@items
value: utcDateTime[];

@global.Azure.Core.nextLink
nextLink?: string;
}

op CustomLongRunningOperation<
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ using Azure.ClientGenerator.Core;
namespace TspTest.Visibility;

model Dog {
@visibility("read") id: int32;
@visibility("update") secretName: string;
@visibility(Lifecycle.Read) id: int32;
weidongxu-microsoft marked this conversation as resolved.
Show resolved Hide resolved
@visibility(Lifecycle.Update) secretName: string;

// no flags are like specifying all flags at once, so in this case
// equivalent to @visibility("read", "write")
Expand All @@ -20,18 +20,18 @@ model Dog {

model RoundTripModel {
name: string;
@visibility("create", "update") secretName: string;
@visibility(Lifecycle.Create, Lifecycle.Update) secretName: string;
}

// The spread operator will copy all the properties of Dog into ReadDog,
// and withVisibility will remove any that don't match the current
// visibility setting
@withVisibility("read")
@withVisibility(Lifecycle.Read)
model ReadDog {
...Dog;
}

@withVisibility("write")
@withVisibility(Lifecycle.Create, Lifecycle.Update)
model WriteDog {
...Dog;
}
Expand Down
Loading
Loading