Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
changeKind: fix
packages:
- "@typespec/http-client-java"
---

Fix result segments like "value" not found if defined in parent model.
7 changes: 7 additions & 0 deletions packages/http-client-java/emitter/src/operation-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,13 @@ export function findResponsePropertySegments(
const propertyArray: Property[] = [];

let currentSchemaProperties: Property[] | undefined = schema.properties;
if (currentSchemaProperties && schema.parents && schema.parents.all) {
for (const parent of schema.parents.all) {
if (parent instanceof ObjectSchema && parent.properties) {
currentSchemaProperties = currentSchemaProperties.concat(parent.properties);
}
}
}
for (const propertySegment of propertySegments) {
// abort if no properties in current schema. this should not happen though
if (!currentSchemaProperties) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,26 @@ public interface ItemsClient {
*/
@ServiceMethod(returns = ReturnType.COLLECTION)
PagedIterable<Result> list(Context context);

/**
* The summary operation.
*
* @throws com.azure.core.management.exception.ManagementException thrown if the request is rejected by server.
* @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
* @return the paginated response with {@link PagedIterable}.
*/
@ServiceMethod(returns = ReturnType.COLLECTION)
PagedIterable<Result> summary();

/**
* The summary operation.
*
* @param context The context to associate with this operation.
* @throws IllegalArgumentException thrown if parameters fail the validation.
* @throws com.azure.core.management.exception.ManagementException thrown if the request is rejected by server.
* @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
* @return the paginated response with {@link PagedIterable}.
*/
@ServiceMethod(returns = ReturnType.COLLECTION)
PagedIterable<Result> summary(Context context);
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import reactor.core.publisher.Mono;
import tsptest.armstreamstyleserialization.fluent.ItemsClient;
import tsptest.armstreamstyleserialization.implementation.models.ListResult;
import tsptest.armstreamstyleserialization.implementation.models.ListResultSummary;
import tsptest.armstreamstyleserialization.models.Result;

/**
Expand Down Expand Up @@ -78,6 +79,20 @@ Mono<Response<Flux<ByteBuffer>>> list(@HostParam("endpoint") String endpoint,
Response<BinaryData> listSync(@HostParam("endpoint") String endpoint, @HeaderParam("Accept") String accept,
Context context);

@Headers({ "Content-Type: application/json" })
@Get("/items/summary")
@ExpectedResponses({ 200 })
@UnexpectedResponseExceptionType(ManagementException.class)
Mono<Response<ListResultSummary>> summary(@HostParam("endpoint") String endpoint,
@HeaderParam("Accept") String accept, Context context);

@Headers({ "Content-Type: application/json" })
@Get("/items/summary")
@ExpectedResponses({ 200 })
@UnexpectedResponseExceptionType(ManagementException.class)
Response<ListResultSummary> summarySync(@HostParam("endpoint") String endpoint,
@HeaderParam("Accept") String accept, Context context);

@Headers({ "Content-Type: application/json" })
@Get("{nextLink}")
@ExpectedResponses({ 200 })
Expand All @@ -91,6 +106,20 @@ Mono<Response<ListResult>> listNext(@PathParam(value = "nextLink", encoded = tru
@UnexpectedResponseExceptionType(ManagementException.class)
Response<ListResult> listNextSync(@PathParam(value = "nextLink", encoded = true) String nextLink,
@HostParam("endpoint") String endpoint, @HeaderParam("Accept") String accept, Context context);

@Headers({ "Content-Type: application/json" })
@Get("{nextLink}")
@ExpectedResponses({ 200 })
@UnexpectedResponseExceptionType(ManagementException.class)
Mono<Response<ListResultSummary>> summaryNext(@PathParam(value = "nextLink", encoded = true) String nextLink,
@HostParam("endpoint") String endpoint, @HeaderParam("Accept") String accept, Context context);

@Headers({ "Content-Type: application/json" })
@Get("{nextLink}")
@ExpectedResponses({ 200 })
@UnexpectedResponseExceptionType(ManagementException.class)
Response<ListResultSummary> summaryNextSync(@PathParam(value = "nextLink", encoded = true) String nextLink,
@HostParam("endpoint") String endpoint, @HeaderParam("Accept") String accept, Context context);
}

/**
Expand Down Expand Up @@ -208,6 +237,107 @@ public PagedIterable<Result> list(Context context) {
return new PagedIterable<>(() -> listSinglePage(context), nextLink -> listNextSinglePage(nextLink, context));
}

/**
* The summary operation.
*
* @throws ManagementException thrown if the request is rejected by server.
* @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
* @return the response body along with {@link PagedResponse} on successful completion of {@link Mono}.
*/
@ServiceMethod(returns = ReturnType.SINGLE)
private Mono<PagedResponse<Result>> summarySinglePageAsync() {
if (this.client.getEndpoint() == null) {
return Mono.error(
new IllegalArgumentException("Parameter this.client.getEndpoint() is required and cannot be null."));
}
final String accept = "application/json";
return FluxUtil.withContext(context -> service.summary(this.client.getEndpoint(), accept, context))
.<PagedResponse<Result>>map(res -> new PagedResponseBase<>(res.getRequest(), res.getStatusCode(),
res.getHeaders(), res.getValue().items(), res.getValue().nextLink(), null))
.contextWrite(context -> context.putAll(FluxUtil.toReactorContext(this.client.getContext()).readOnly()));
}

/**
* The summary operation.
*
* @throws ManagementException thrown if the request is rejected by server.
* @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
* @return the paginated response with {@link PagedFlux}.
*/
@ServiceMethod(returns = ReturnType.COLLECTION)
private PagedFlux<Result> summaryAsync() {
return new PagedFlux<>(() -> summarySinglePageAsync(), nextLink -> summaryNextSinglePageAsync(nextLink));
}

/**
* The summary operation.
*
* @throws ManagementException thrown if the request is rejected by server.
* @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
* @return the response body along with {@link PagedResponse}.
*/
@ServiceMethod(returns = ReturnType.SINGLE)
private PagedResponse<Result> summarySinglePage() {
if (this.client.getEndpoint() == null) {
throw LOGGER.atError()
.log(new IllegalArgumentException(
"Parameter this.client.getEndpoint() is required and cannot be null."));
}
final String accept = "application/json";
Response<ListResultSummary> res = service.summarySync(this.client.getEndpoint(), accept, Context.NONE);
return new PagedResponseBase<>(res.getRequest(), res.getStatusCode(), res.getHeaders(), res.getValue().items(),
res.getValue().nextLink(), null);
}

/**
* The summary operation.
*
* @param context The context to associate with this operation.
* @throws IllegalArgumentException thrown if parameters fail the validation.
* @throws ManagementException thrown if the request is rejected by server.
* @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
* @return the response body along with {@link PagedResponse}.
*/
@ServiceMethod(returns = ReturnType.SINGLE)
private PagedResponse<Result> summarySinglePage(Context context) {
if (this.client.getEndpoint() == null) {
throw LOGGER.atError()
.log(new IllegalArgumentException(
"Parameter this.client.getEndpoint() is required and cannot be null."));
}
final String accept = "application/json";
Response<ListResultSummary> res = service.summarySync(this.client.getEndpoint(), accept, context);
return new PagedResponseBase<>(res.getRequest(), res.getStatusCode(), res.getHeaders(), res.getValue().items(),
res.getValue().nextLink(), null);
}

/**
* The summary operation.
*
* @throws ManagementException thrown if the request is rejected by server.
* @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
* @return the paginated response with {@link PagedIterable}.
*/
@ServiceMethod(returns = ReturnType.COLLECTION)
public PagedIterable<Result> summary() {
return new PagedIterable<>(() -> summarySinglePage(), nextLink -> summaryNextSinglePage(nextLink));
}

/**
* The summary operation.
*
* @param context The context to associate with this operation.
* @throws IllegalArgumentException thrown if parameters fail the validation.
* @throws ManagementException thrown if the request is rejected by server.
* @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
* @return the paginated response with {@link PagedIterable}.
*/
@ServiceMethod(returns = ReturnType.COLLECTION)
public PagedIterable<Result> summary(Context context) {
return new PagedIterable<>(() -> summarySinglePage(context),
nextLink -> summaryNextSinglePage(nextLink, context));
}

/**
* Get the next page of items.
*
Expand Down Expand Up @@ -286,5 +416,85 @@ private PagedResponse<Result> listNextSinglePage(String nextLink, Context contex
res.getValue().nextLink(), null);
}

/**
* Get the next page of items.
*
* @param nextLink The URL to get the next list of items.
* @throws IllegalArgumentException thrown if parameters fail the validation.
* @throws ManagementException thrown if the request is rejected by server.
* @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
* @return the response body along with {@link PagedResponse} on successful completion of {@link Mono}.
*/
@ServiceMethod(returns = ReturnType.SINGLE)
private Mono<PagedResponse<Result>> summaryNextSinglePageAsync(String nextLink) {
if (nextLink == null) {
return Mono.error(new IllegalArgumentException("Parameter nextLink is required and cannot be null."));
}
if (this.client.getEndpoint() == null) {
return Mono.error(
new IllegalArgumentException("Parameter this.client.getEndpoint() is required and cannot be null."));
}
final String accept = "application/json";
return FluxUtil
.withContext(context -> service.summaryNext(nextLink, this.client.getEndpoint(), accept, context))
.<PagedResponse<Result>>map(res -> new PagedResponseBase<>(res.getRequest(), res.getStatusCode(),
res.getHeaders(), res.getValue().items(), res.getValue().nextLink(), null))
.contextWrite(context -> context.putAll(FluxUtil.toReactorContext(this.client.getContext()).readOnly()));
}

/**
* Get the next page of items.
*
* @param nextLink The URL to get the next list of items.
* @throws IllegalArgumentException thrown if parameters fail the validation.
* @throws ManagementException thrown if the request is rejected by server.
* @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
* @return the response body along with {@link PagedResponse}.
*/
@ServiceMethod(returns = ReturnType.SINGLE)
private PagedResponse<Result> summaryNextSinglePage(String nextLink) {
if (nextLink == null) {
throw LOGGER.atError()
.log(new IllegalArgumentException("Parameter nextLink is required and cannot be null."));
}
if (this.client.getEndpoint() == null) {
throw LOGGER.atError()
.log(new IllegalArgumentException(
"Parameter this.client.getEndpoint() is required and cannot be null."));
}
final String accept = "application/json";
Response<ListResultSummary> res
= service.summaryNextSync(nextLink, this.client.getEndpoint(), accept, Context.NONE);
return new PagedResponseBase<>(res.getRequest(), res.getStatusCode(), res.getHeaders(), res.getValue().items(),
res.getValue().nextLink(), null);
}

/**
* Get the next page of items.
*
* @param nextLink The URL to get the next list of items.
* @param context The context to associate with this operation.
* @throws IllegalArgumentException thrown if parameters fail the validation.
* @throws ManagementException thrown if the request is rejected by server.
* @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
* @return the response body along with {@link PagedResponse}.
*/
@ServiceMethod(returns = ReturnType.SINGLE)
private PagedResponse<Result> summaryNextSinglePage(String nextLink, Context context) {
if (nextLink == null) {
throw LOGGER.atError()
.log(new IllegalArgumentException("Parameter nextLink is required and cannot be null."));
}
if (this.client.getEndpoint() == null) {
throw LOGGER.atError()
.log(new IllegalArgumentException(
"Parameter this.client.getEndpoint() is required and cannot be null."));
}
final String accept = "application/json";
Response<ListResultSummary> res = service.summaryNextSync(nextLink, this.client.getEndpoint(), accept, context);
return new PagedResponseBase<>(res.getRequest(), res.getStatusCode(), res.getHeaders(), res.getValue().items(),
res.getValue().nextLink(), null);
}

private static final ClientLogger LOGGER = new ClientLogger(ItemsClientImpl.class);
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,14 @@ public PagedIterable<Result> list(Context context) {
return this.serviceClient().list(context);
}

public PagedIterable<Result> summary() {
return this.serviceClient().summary();
}

public PagedIterable<Result> summary(Context context) {
return this.serviceClient().summary(context);
}

private ItemsClient serviceClient() {
return this.innerClient;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
* The ListResult model.
*/
@Immutable
public final class ListResult implements JsonSerializable<ListResult> {
public class ListResult implements JsonSerializable<ListResult> {
/*
* The items property.
*/
Expand All @@ -32,7 +32,7 @@ public final class ListResult implements JsonSerializable<ListResult> {
/**
* Creates an instance of ListResult class.
*/
private ListResult() {
protected ListResult() {
}

/**
Expand All @@ -44,6 +44,17 @@ public List<Result> items() {
return this.items;
}

/**
* Set the items property: The items property.
*
* @param items the items value to set.
* @return the ListResult object itself.
*/
ListResult withItems(List<Result> items) {
this.items = items;
return this;
}

/**
* Get the nextLink property: The nextLink property.
*
Expand All @@ -53,6 +64,17 @@ public String nextLink() {
return this.nextLink;
}

/**
* Set the nextLink property: The nextLink property.
*
* @param nextLink the nextLink value to set.
* @return the ListResult object itself.
*/
ListResult withNextLink(String nextLink) {
this.nextLink = nextLink;
return this;
}

/**
* Validates the instance.
*
Expand Down
Loading
Loading