Skip to content

Commit

Permalink
http-client-java, bump typespec libs (microsoft#5317)
Browse files Browse the repository at this point in the history
bump for the new typespec versions

1. bug fix for pagination (when no `nextLink`)
2. improvement for unbranded error without body
3. remove `core-json` from unbranded, as it recently merged to `core`
  • Loading branch information
weidongxu-microsoft authored and Mingzhe Huang (from Dev Box) committed Dec 17, 2024
1 parent 071284e commit daa148b
Show file tree
Hide file tree
Showing 21 changed files with 625 additions and 536 deletions.
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,
};

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)");
}
}
}
}
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",
"@typespec/http-client-java": "file:/../../typespec-http-client-java-0.1.3.tgz",
"@azure-tools/cadl-ranch-specs": "0.39.5",
"@typespec/http-client-java": "file:/../../typespec-http-client-java-0.1.4.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)
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 @@ -75,6 +75,7 @@ public Mono<Response<BinaryData>> getWithResponse(RequestOptions requestOptions)
* <pre>
* {@code
* {
* secretName: String (Required)
* name: String (Required)
* }
* }
Expand Down Expand Up @@ -113,7 +114,7 @@ public Mono<Response<BinaryData>> createWithResponse(BinaryData dog, RequestOpti
* <pre>
* {@code
* {
* id: int (Required)
* secretName: String (Required)
* name: String (Required)
* }
* }
Expand All @@ -125,7 +126,6 @@ public Mono<Response<BinaryData>> createWithResponse(BinaryData dog, RequestOpti
* {@code
* {
* id: int (Required)
* secretName: String (Required)
* name: String (Required)
* }
* }
Expand Down Expand Up @@ -237,11 +237,11 @@ public Mono<Dog> create(WriteDog dog) {
*/
@Generated
@ServiceMethod(returns = ReturnType.SINGLE)
public Mono<Dog> query(ReadDog dog) {
public Mono<ReadDog> query(WriteDog dog) {
// Generated convenience method for queryWithResponse
RequestOptions requestOptions = new RequestOptions();
return queryWithResponse(BinaryData.fromObject(dog), requestOptions).flatMap(FluxUtil::toMono)
.map(protocolMethodData -> protocolMethodData.toObject(Dog.class));
.map(protocolMethodData -> protocolMethodData.toObject(ReadDog.class));
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ public Response<BinaryData> getWithResponse(RequestOptions requestOptions) {
* <pre>
* {@code
* {
* secretName: String (Required)
* name: String (Required)
* }
* }
Expand Down Expand Up @@ -111,7 +112,7 @@ public Response<BinaryData> createWithResponse(BinaryData dog, RequestOptions re
* <pre>
* {@code
* {
* id: int (Required)
* secretName: String (Required)
* name: String (Required)
* }
* }
Expand All @@ -123,7 +124,6 @@ public Response<BinaryData> createWithResponse(BinaryData dog, RequestOptions re
* {@code
* {
* id: int (Required)
* secretName: String (Required)
* name: String (Required)
* }
* }
Expand Down Expand Up @@ -233,10 +233,10 @@ public Dog create(WriteDog dog) {
*/
@Generated
@ServiceMethod(returns = ReturnType.SINGLE)
public Dog query(ReadDog dog) {
public ReadDog query(WriteDog dog) {
// Generated convenience method for queryWithResponse
RequestOptions requestOptions = new RequestOptions();
return queryWithResponse(BinaryData.fromObject(dog), requestOptions).getValue().toObject(Dog.class);
return queryWithResponse(BinaryData.fromObject(dog), requestOptions).getValue().toObject(ReadDog.class);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ public final class VisibilityWriteAsyncClient {
* <pre>
* {@code
* {
* secretName: String (Required)
* name: String (Required)
* }
* }
Expand Down
Loading

0 comments on commit daa148b

Please sign in to comment.