Skip to content
Merged
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.
Original file line number Diff line number Diff line change
Expand Up @@ -1886,9 +1886,7 @@ export class CodeModelBuilder {

// group schema

// TODO: double check this suppression
// eslint-disable-next-line no-useless-assignment
let coreNamespace = this.namespace;
let coreNamespace;
if (this.isAzureV1()) {
coreNamespace = "com.azure.core.http";
} else {
Expand Down
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 @@ -60,7 +60,7 @@ private ClassType createClassType(ObjectSchema compositeType) {
&& isInternalModel(compositeType)) {
// internal type is not exposed to user
packageSuffixes = new String[] { settings.getImplementationSubpackage(), settings.getModelsSubpackage() };
} else if (isPageModel(compositeType)) {
} else if (isPagedModel(compositeType) && isChildrenAllInternal(compositeType)) {
// put class of Page<> type to implementation package
// for DPG from TypeSpec, these are not generated to class

Expand Down Expand Up @@ -137,10 +137,26 @@ protected boolean isInnerModel(ObjectSchema compositeType) {
* @param compositeType object type
* @return whether the type is a Page model.
*/
private static boolean isPageModel(ObjectSchema compositeType) {
private static boolean isPagedModel(ObjectSchema compositeType) {
return compositeType.getUsage() != null && compositeType.getUsage().contains(SchemaContext.PAGED);
}

private static boolean isChildrenAllInternal(ObjectSchema compositeType) {
// If we move model to implementation package, we need to make sure it does not have child that need to be
// public
boolean ret = true;
if (compositeType.getChildren() != null && !CoreUtils.isNullOrEmpty(compositeType.getChildren().getAll())) {
ret = compositeType.getChildren()
.getAll()
.stream()
.noneMatch(s -> (s instanceof ObjectSchema)
&& !isPagedModel(((ObjectSchema) s))
&& (((ObjectSchema) s).getUsage() != null
&& ((ObjectSchema) s).getUsage().contains(SchemaContext.PUBLIC)));
}
return ret;
}

private static boolean isInternalModel(ObjectSchema compositeType) {
return compositeType.getUsage() != null && compositeType.getUsage().contains(SchemaContext.INTERNAL);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@
import com.azure.core.annotation.ReturnType;
import com.azure.core.annotation.ServiceMethod;
import com.azure.core.http.rest.PagedIterable;
import com.azure.core.http.rest.Response;
import com.azure.core.util.Context;
import tsptest.armstreamstyleserialization.fluent.models.ListResultSummary2Inner;
import tsptest.armstreamstyleserialization.models.Result;

/**
Expand Down Expand Up @@ -35,4 +37,70 @@ 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);

/**
* The list2 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> list2();

/**
* The list2 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> list2(Context context);

/**
* The summary2 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 response body along with {@link Response}.
*/
@ServiceMethod(returns = ReturnType.SINGLE)
Response<ListResultSummary2Inner> summary2WithResponse(Context context);

/**
* The summary2 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 response.
*/
@ServiceMethod(returns = ReturnType.SINGLE)
ListResultSummary2Inner summary2();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
// Code generated by Microsoft (R) TypeSpec Code Generator.

package tsptest.armstreamstyleserialization.fluent.models;

import com.azure.core.annotation.Immutable;
import com.azure.core.util.logging.ClientLogger;
import com.azure.json.JsonReader;
import com.azure.json.JsonToken;
import com.azure.json.JsonWriter;
import java.io.IOException;
import java.util.List;
import tsptest.armstreamstyleserialization.models.ListResult2;
import tsptest.armstreamstyleserialization.models.Result;

/**
* The ListResultSummary2 model.
*/
@Immutable
public final class ListResultSummary2Inner extends ListResult2 {
/*
* The summary property.
*/
private String summary;

/*
* The nextLink property.
*/
private String nextLink;

/*
* The items property.
*/
private List<Result> items;

/**
* Creates an instance of ListResultSummary2Inner class.
*/
private ListResultSummary2Inner() {
}

/**
* Get the summary property: The summary property.
*
* @return the summary value.
*/
public String summary() {
return this.summary;
}

/**
* Get the nextLink property: The nextLink property.
*
* @return the nextLink value.
*/
@Override
public String nextLink() {
return this.nextLink;
}

/**
* Get the items property: The items property.
*
* @return the items value.
*/
@Override
public List<Result> items() {
return this.items;
}

/**
* Validates the instance.
*
* @throws IllegalArgumentException thrown if the instance is not valid.
*/
@Override
public void validate() {
if (items() == null) {
throw LOGGER.atError()
.log(new IllegalArgumentException("Missing required property items in model ListResultSummary2Inner"));
} else {
items().forEach(e -> e.validate());
}
}

private static final ClientLogger LOGGER = new ClientLogger(ListResultSummary2Inner.class);

/**
* {@inheritDoc}
*/
@Override
public JsonWriter toJson(JsonWriter jsonWriter) throws IOException {
jsonWriter.writeStartObject();
jsonWriter.writeArrayField("items", items(), (writer, element) -> writer.writeJson(element));
jsonWriter.writeStringField("nextLink", nextLink());
jsonWriter.writeStringField("summary", this.summary);
return jsonWriter.writeEndObject();
}

/**
* Reads an instance of ListResultSummary2Inner from the JsonReader.
*
* @param jsonReader The JsonReader being read.
* @return An instance of ListResultSummary2Inner if the JsonReader was pointing to an instance of it, or null if it
* was pointing to JSON null.
* @throws IllegalStateException If the deserialized JSON object was missing any required properties.
* @throws IOException If an error occurs while reading the ListResultSummary2Inner.
*/
public static ListResultSummary2Inner fromJson(JsonReader jsonReader) throws IOException {
return jsonReader.readObject(reader -> {
ListResultSummary2Inner deserializedListResultSummary2Inner = new ListResultSummary2Inner();
while (reader.nextToken() != JsonToken.END_OBJECT) {
String fieldName = reader.getFieldName();
reader.nextToken();

if ("items".equals(fieldName)) {
List<Result> items = reader.readArray(reader1 -> Result.fromJson(reader1));
deserializedListResultSummary2Inner.items = items;
} else if ("nextLink".equals(fieldName)) {
deserializedListResultSummary2Inner.nextLink = reader.getString();
} else if ("summary".equals(fieldName)) {
deserializedListResultSummary2Inner.summary = reader.getString();
} else {
reader.skipChildren();
}
}

return deserializedListResultSummary2Inner;
});
}
}
Loading
Loading