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 multi-client packages generating a separate `ServiceVersion` enum per client when all clients share the same api-versions. The api-version comparison now compares version strings instead of `ApiVersion` object references, restoring a single shared `ServiceVersion` for such packages.
Original file line number Diff line number Diff line change
Expand Up @@ -842,9 +842,13 @@ export class CodeModelBuilder {
// first client, set it to sharedApiVersions
sharedApiVersions = apiVersions;
} else {
// Compare the api-version strings, not the ApiVersion object references. Each client
// builds its own ApiVersion instances (see `new ApiVersion()` above), so reference
// equality ("===") would always be false for clients that in fact share the same
// api-versions, incorrectly producing a separate ServiceVersion enum per client.
apiVersionSameForAllClients =
sharedApiVersions.length === apiVersions.length &&
sharedApiVersions.every((it, index) => it === apiVersions[index]);
sharedApiVersions.every((it, index) => it.version === apiVersions[index].version);
}
if (!apiVersionSameForAllClients) {
break;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
// Code generated by Microsoft (R) TypeSpec Code Generator.

package tsptest.multipleclientssameversion;

import com.azure.core.annotation.Generated;
import com.azure.core.annotation.ReturnType;
import com.azure.core.annotation.ServiceClient;
import com.azure.core.annotation.ServiceMethod;
import com.azure.core.exception.ClientAuthenticationException;
import com.azure.core.exception.HttpResponseException;
import com.azure.core.exception.ResourceModifiedException;
import com.azure.core.exception.ResourceNotFoundException;
import com.azure.core.http.rest.RequestOptions;
import com.azure.core.http.rest.Response;
import com.azure.core.util.BinaryData;
import com.azure.core.util.FluxUtil;
import reactor.core.publisher.Mono;
import tsptest.multipleclientssameversion.implementation.AlphaClientImpl;
import tsptest.multipleclientssameversion.models.Resource;

/**
* Initializes a new instance of the asynchronous AlphaClient type.
*/
@ServiceClient(builder = AlphaClientBuilder.class, isAsync = true)
public final class AlphaAsyncClient {
@Generated
private final AlphaClientImpl serviceClient;

/**
* Initializes an instance of AlphaAsyncClient class.
*
* @param serviceClient the service client implementation.
*/
@Generated
AlphaAsyncClient(AlphaClientImpl serviceClient) {
this.serviceClient = serviceClient;
}

/**
* The getAlpha operation.
* <p><strong>Response Body Schema</strong></p>
*
* <pre>
* {@code
* {
* id: String (Required)
* name: String (Required)
* }
* }
* </pre>
*
* @param id The id 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>> getAlphaWithResponse(String id, RequestOptions requestOptions) {
return this.serviceClient.getAlphaWithResponseAsync(id, requestOptions);
}

/**
* The getAlpha operation.
*
* @param id The id 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<Resource> getAlpha(String id) {
// Generated convenience method for getAlphaWithResponse
RequestOptions requestOptions = new RequestOptions();
return getAlphaWithResponse(id, requestOptions).flatMap(FluxUtil::toMono)
.map(protocolMethodData -> protocolMethodData.toObject(Resource.class));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
// Code generated by Microsoft (R) TypeSpec Code Generator.

package tsptest.multipleclientssameversion;

import com.azure.core.annotation.Generated;
import com.azure.core.annotation.ReturnType;
import com.azure.core.annotation.ServiceClient;
import com.azure.core.annotation.ServiceMethod;
import com.azure.core.exception.ClientAuthenticationException;
import com.azure.core.exception.HttpResponseException;
import com.azure.core.exception.ResourceModifiedException;
import com.azure.core.exception.ResourceNotFoundException;
import com.azure.core.http.rest.RequestOptions;
import com.azure.core.http.rest.Response;
import com.azure.core.util.BinaryData;
import tsptest.multipleclientssameversion.implementation.AlphaClientImpl;
import tsptest.multipleclientssameversion.models.Resource;

/**
* Initializes a new instance of the synchronous AlphaClient type.
*/
@ServiceClient(builder = AlphaClientBuilder.class)
public final class AlphaClient {
@Generated
private final AlphaClientImpl serviceClient;

/**
* Initializes an instance of AlphaClient class.
*
* @param serviceClient the service client implementation.
*/
@Generated
AlphaClient(AlphaClientImpl serviceClient) {
this.serviceClient = serviceClient;
}

/**
* The getAlpha operation.
* <p><strong>Response Body Schema</strong></p>
*
* <pre>
* {@code
* {
* id: String (Required)
* name: String (Required)
* }
* }
* </pre>
*
* @param id The id 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> getAlphaWithResponse(String id, RequestOptions requestOptions) {
return this.serviceClient.getAlphaWithResponse(id, requestOptions);
}

/**
* The getAlpha operation.
*
* @param id The id 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 Resource getAlpha(String id) {
// Generated convenience method for getAlphaWithResponse
RequestOptions requestOptions = new RequestOptions();
return getAlphaWithResponse(id, requestOptions).getValue().toObject(Resource.class);
}
}
Loading
Loading