From 29568bd34040538ca29f7f74de15886cbfd006fc Mon Sep 17 00:00:00 2001 From: xiaofeicao Date: Fri, 27 Mar 2026 18:38:53 +0800 Subject: [PATCH 1/4] fix --- .../emitter/src/code-model-builder.ts | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/packages/http-client-java/emitter/src/code-model-builder.ts b/packages/http-client-java/emitter/src/code-model-builder.ts index d7fe98b6fc8..c78af8da5c4 100644 --- a/packages/http-client-java/emitter/src/code-model-builder.ts +++ b/packages/http-client-java/emitter/src/code-model-builder.ts @@ -1522,12 +1522,22 @@ export class CodeModelBuilder { } const nullable = param.type.kind === "nullable"; + + // When Accept header is optional with constant type and has clientDefaultValue, + // treat as required constant — always sent, hidden from public API. + const isAcceptConstantWithDefault = + param.kind === "header" && + param.serializedName.toLowerCase() === "accept" && + param.optional && + sdkType.kind === "constant" && + param.clientDefaultValue !== undefined; + const parameter = new Parameter(parameterName, param.doc ?? "", schema, { summary: param.summary, implementation: parameterOnClient ? ImplementationLocation.Client : ImplementationLocation.Method, - required: !param.optional, + required: isAcceptConstantWithDefault || !param.optional, nullable: nullable, protocol: { http: new HttpParameter(param.kind, { From 37f53a61765d4f5cd4d7a3246a9e9eec08b09cbd Mon Sep 17 00:00:00 2001 From: xiaofeicao Date: Fri, 27 Mar 2026 19:05:03 +0800 Subject: [PATCH 2/4] fix --- .../emitter/src/code-model-builder.ts | 2 +- .../emitter/src/common/schemas/choice.ts | 6 ++++-- .../tsp/special-headers.tsp | 16 ++++++++++++++++ 3 files changed, 21 insertions(+), 3 deletions(-) diff --git a/packages/http-client-java/emitter/src/code-model-builder.ts b/packages/http-client-java/emitter/src/code-model-builder.ts index c78af8da5c4..eae4ac6705d 100644 --- a/packages/http-client-java/emitter/src/code-model-builder.ts +++ b/packages/http-client-java/emitter/src/code-model-builder.ts @@ -776,7 +776,7 @@ export class CodeModelBuilder { ); const parentAccessorPublic = Boolean( subClient.clientInitialization.initializedBy & InitializedByFlags.Parent || - subClient.clientInitialization.initializedBy === InitializedByFlags.Default, + subClient.clientInitialization.initializedBy === InitializedByFlags.Default, ); codeModelClient.addSubClient(codeModelSubclient, buildMethodPublic, parentAccessorPublic); } diff --git a/packages/http-client-java/emitter/src/common/schemas/choice.ts b/packages/http-client-java/emitter/src/common/schemas/choice.ts index 867460486a1..54288692862 100644 --- a/packages/http-client-java/emitter/src/common/schemas/choice.ts +++ b/packages/http-client-java/emitter/src/common/schemas/choice.ts @@ -12,7 +12,8 @@ import { SchemaUsage } from "./usage.js"; /** a schema that represents a choice of several values (ie, an 'enum') */ export interface ChoiceSchema - extends ValueSchema, SchemaUsage { + extends ValueSchema, + SchemaUsage { /** the schema type */ type: SchemaType.Choice; /** the primitive type for the choices */ @@ -39,7 +40,8 @@ export class ChoiceSchema /** a schema that represents a choice of several values (ie, an 'enum') */ export interface SealedChoiceSchema - extends ValueSchema, SchemaUsage { + extends ValueSchema, + SchemaUsage { /** the schema type */ type: SchemaType.SealedChoice; diff --git a/packages/http-client-java/generator/http-client-generator-test/tsp/special-headers.tsp b/packages/http-client-java/generator/http-client-generator-test/tsp/special-headers.tsp index 6d2f81b05b4..6208858168e 100644 --- a/packages/http-client-java/generator/http-client-generator-test/tsp/special-headers.tsp +++ b/packages/http-client-java/generator/http-client-generator-test/tsp/special-headers.tsp @@ -1,5 +1,6 @@ import "@typespec/rest"; import "@azure-tools/typespec-azure-core"; +import "@azure-tools/typespec-client-generator-core"; using TypeSpec.Http; using TypeSpec.Rest; @@ -110,3 +111,18 @@ interface SkipSpecialHeaders { }> >; } + +enum AcceptHeaderNoneConstant { + APPLICATION_JSON_METADATA_NONE: "application/json;odata.metadata=none", +} + +@route("/constant-optional-accept-header-with-default-value") +interface ConstantAcceptHeaderWithDefaultValueAsRequired { + @doc("Accept header with constant type and default value should be marked as required, before we support clientDefaultValue. Issue: https://github.com/microsoft/typespec/issues/10178") + @get + retrieve( + @header + @Azure.ClientGenerator.Core.Legacy.clientDefaultValue("application/json;odata.metadata=minimal") + accept?: "application/json;odata.metadata=minimal", + ): OkResponse; +} From 047edcfaf8984b014bd9827779b1216647f25c3a Mon Sep 17 00:00:00 2001 From: xiaofeicao Date: Fri, 27 Mar 2026 19:07:43 +0800 Subject: [PATCH 3/4] regen --- ...WithDefaultValueAsRequiredAsyncClient.java | 75 +++++++++++ ...eaderWithDefaultValueAsRequiredClient.java | 72 ++++++++++ .../SpecialHeadersClientBuilder.java | 28 +++- ...HeaderWithDefaultValueAsRequiredsImpl.java | 123 ++++++++++++++++++ .../RepeatabilityHeadersImpl.java | 8 +- .../SpecialHeadersClientImpl.java | 16 +++ 6 files changed, 317 insertions(+), 5 deletions(-) create mode 100644 packages/http-client-java/generator/http-client-generator-test/src/main/java/tsptest/specialheaders/ConstantAcceptHeaderWithDefaultValueAsRequiredAsyncClient.java create mode 100644 packages/http-client-java/generator/http-client-generator-test/src/main/java/tsptest/specialheaders/ConstantAcceptHeaderWithDefaultValueAsRequiredClient.java create mode 100644 packages/http-client-java/generator/http-client-generator-test/src/main/java/tsptest/specialheaders/implementation/ConstantAcceptHeaderWithDefaultValueAsRequiredsImpl.java diff --git a/packages/http-client-java/generator/http-client-generator-test/src/main/java/tsptest/specialheaders/ConstantAcceptHeaderWithDefaultValueAsRequiredAsyncClient.java b/packages/http-client-java/generator/http-client-generator-test/src/main/java/tsptest/specialheaders/ConstantAcceptHeaderWithDefaultValueAsRequiredAsyncClient.java new file mode 100644 index 00000000000..91aa8d7902b --- /dev/null +++ b/packages/http-client-java/generator/http-client-generator-test/src/main/java/tsptest/specialheaders/ConstantAcceptHeaderWithDefaultValueAsRequiredAsyncClient.java @@ -0,0 +1,75 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +// Code generated by Microsoft (R) TypeSpec Code Generator. + +package tsptest.specialheaders; + +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.FluxUtil; +import reactor.core.publisher.Mono; +import tsptest.specialheaders.implementation.ConstantAcceptHeaderWithDefaultValueAsRequiredsImpl; + +/** + * Initializes a new instance of the asynchronous SpecialHeadersClient type. + */ +@ServiceClient(builder = SpecialHeadersClientBuilder.class, isAsync = true) +public final class ConstantAcceptHeaderWithDefaultValueAsRequiredAsyncClient { + @Generated + private final ConstantAcceptHeaderWithDefaultValueAsRequiredsImpl serviceClient; + + /** + * Initializes an instance of ConstantAcceptHeaderWithDefaultValueAsRequiredAsyncClient class. + * + * @param serviceClient the service client implementation. + */ + @Generated + ConstantAcceptHeaderWithDefaultValueAsRequiredAsyncClient( + ConstantAcceptHeaderWithDefaultValueAsRequiredsImpl serviceClient) { + this.serviceClient = serviceClient; + } + + /** + * Accept header with constant type and default value should be marked as required, before we support + * clientDefaultValue. Issue: https://github.com/microsoft/typespec/issues/10178. + * + * @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 {@link Response} on successful completion of {@link Mono}. + */ + @Generated + @ServiceMethod(returns = ReturnType.SINGLE) + public Mono> retrieveWithResponse(RequestOptions requestOptions) { + return this.serviceClient.retrieveWithResponseAsync(requestOptions); + } + + /** + * Accept header with constant type and default value should be marked as required, before we support + * clientDefaultValue. Issue: https://github.com/microsoft/typespec/issues/10178. + * + * @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 A {@link Mono} that completes when a successful response is received. + */ + @Generated + @ServiceMethod(returns = ReturnType.SINGLE) + public Mono retrieve() { + // Generated convenience method for retrieveWithResponse + RequestOptions requestOptions = new RequestOptions(); + return retrieveWithResponse(requestOptions).flatMap(FluxUtil::toMono); + } +} diff --git a/packages/http-client-java/generator/http-client-generator-test/src/main/java/tsptest/specialheaders/ConstantAcceptHeaderWithDefaultValueAsRequiredClient.java b/packages/http-client-java/generator/http-client-generator-test/src/main/java/tsptest/specialheaders/ConstantAcceptHeaderWithDefaultValueAsRequiredClient.java new file mode 100644 index 00000000000..c22998e11dd --- /dev/null +++ b/packages/http-client-java/generator/http-client-generator-test/src/main/java/tsptest/specialheaders/ConstantAcceptHeaderWithDefaultValueAsRequiredClient.java @@ -0,0 +1,72 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +// Code generated by Microsoft (R) TypeSpec Code Generator. + +package tsptest.specialheaders; + +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 tsptest.specialheaders.implementation.ConstantAcceptHeaderWithDefaultValueAsRequiredsImpl; + +/** + * Initializes a new instance of the synchronous SpecialHeadersClient type. + */ +@ServiceClient(builder = SpecialHeadersClientBuilder.class) +public final class ConstantAcceptHeaderWithDefaultValueAsRequiredClient { + @Generated + private final ConstantAcceptHeaderWithDefaultValueAsRequiredsImpl serviceClient; + + /** + * Initializes an instance of ConstantAcceptHeaderWithDefaultValueAsRequiredClient class. + * + * @param serviceClient the service client implementation. + */ + @Generated + ConstantAcceptHeaderWithDefaultValueAsRequiredClient( + ConstantAcceptHeaderWithDefaultValueAsRequiredsImpl serviceClient) { + this.serviceClient = serviceClient; + } + + /** + * Accept header with constant type and default value should be marked as required, before we support + * clientDefaultValue. Issue: https://github.com/microsoft/typespec/issues/10178. + * + * @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 {@link Response}. + */ + @Generated + @ServiceMethod(returns = ReturnType.SINGLE) + public Response retrieveWithResponse(RequestOptions requestOptions) { + return this.serviceClient.retrieveWithResponse(requestOptions); + } + + /** + * Accept header with constant type and default value should be marked as required, before we support + * clientDefaultValue. Issue: https://github.com/microsoft/typespec/issues/10178. + * + * @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. + */ + @Generated + @ServiceMethod(returns = ReturnType.SINGLE) + public void retrieve() { + // Generated convenience method for retrieveWithResponse + RequestOptions requestOptions = new RequestOptions(); + retrieveWithResponse(requestOptions).getValue(); + } +} diff --git a/packages/http-client-java/generator/http-client-generator-test/src/main/java/tsptest/specialheaders/SpecialHeadersClientBuilder.java b/packages/http-client-java/generator/http-client-generator-test/src/main/java/tsptest/specialheaders/SpecialHeadersClientBuilder.java index 2ff09e435ba..0fb308920dc 100644 --- a/packages/http-client-java/generator/http-client-generator-test/src/main/java/tsptest/specialheaders/SpecialHeadersClientBuilder.java +++ b/packages/http-client-java/generator/http-client-generator-test/src/main/java/tsptest/specialheaders/SpecialHeadersClientBuilder.java @@ -46,10 +46,12 @@ EtagHeadersClient.class, EtagHeadersOptionalBodyClient.class, SkipSpecialHeadersClient.class, + ConstantAcceptHeaderWithDefaultValueAsRequiredClient.class, RepeatabilityHeadersAsyncClient.class, EtagHeadersAsyncClient.class, EtagHeadersOptionalBodyAsyncClient.class, - SkipSpecialHeadersAsyncClient.class }) + SkipSpecialHeadersAsyncClient.class, + ConstantAcceptHeaderWithDefaultValueAsRequiredAsyncClient.class }) public final class SpecialHeadersClientBuilder implements HttpTrait, ConfigurationTrait, EndpointTrait { @Generated @@ -332,6 +334,18 @@ public SkipSpecialHeadersAsyncClient buildSkipSpecialHeadersAsyncClient() { return new SkipSpecialHeadersAsyncClient(buildInnerClient().getSkipSpecialHeaders()); } + /** + * Builds an instance of ConstantAcceptHeaderWithDefaultValueAsRequiredAsyncClient class. + * + * @return an instance of ConstantAcceptHeaderWithDefaultValueAsRequiredAsyncClient. + */ + @Generated + public ConstantAcceptHeaderWithDefaultValueAsRequiredAsyncClient + buildConstantAcceptHeaderWithDefaultValueAsRequiredAsyncClient() { + return new ConstantAcceptHeaderWithDefaultValueAsRequiredAsyncClient( + buildInnerClient().getConstantAcceptHeaderWithDefaultValueAsRequireds()); + } + /** * Builds an instance of RepeatabilityHeadersClient class. * @@ -372,5 +386,17 @@ public SkipSpecialHeadersClient buildSkipSpecialHeadersClient() { return new SkipSpecialHeadersClient(buildInnerClient().getSkipSpecialHeaders()); } + /** + * Builds an instance of ConstantAcceptHeaderWithDefaultValueAsRequiredClient class. + * + * @return an instance of ConstantAcceptHeaderWithDefaultValueAsRequiredClient. + */ + @Generated + public ConstantAcceptHeaderWithDefaultValueAsRequiredClient + buildConstantAcceptHeaderWithDefaultValueAsRequiredClient() { + return new ConstantAcceptHeaderWithDefaultValueAsRequiredClient( + buildInnerClient().getConstantAcceptHeaderWithDefaultValueAsRequireds()); + } + private static final ClientLogger LOGGER = new ClientLogger(SpecialHeadersClientBuilder.class); } diff --git a/packages/http-client-java/generator/http-client-generator-test/src/main/java/tsptest/specialheaders/implementation/ConstantAcceptHeaderWithDefaultValueAsRequiredsImpl.java b/packages/http-client-java/generator/http-client-generator-test/src/main/java/tsptest/specialheaders/implementation/ConstantAcceptHeaderWithDefaultValueAsRequiredsImpl.java new file mode 100644 index 00000000000..e52eed98dfe --- /dev/null +++ b/packages/http-client-java/generator/http-client-generator-test/src/main/java/tsptest/specialheaders/implementation/ConstantAcceptHeaderWithDefaultValueAsRequiredsImpl.java @@ -0,0 +1,123 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +// Code generated by Microsoft (R) TypeSpec Code Generator. + +package tsptest.specialheaders.implementation; + +import com.azure.core.annotation.ExpectedResponses; +import com.azure.core.annotation.Get; +import com.azure.core.annotation.HeaderParam; +import com.azure.core.annotation.Host; +import com.azure.core.annotation.HostParam; +import com.azure.core.annotation.ReturnType; +import com.azure.core.annotation.ServiceInterface; +import com.azure.core.annotation.ServiceMethod; +import com.azure.core.annotation.UnexpectedResponseExceptionType; +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.http.rest.RestProxy; +import com.azure.core.util.Context; +import com.azure.core.util.FluxUtil; +import reactor.core.publisher.Mono; +import tsptest.specialheaders.SpecialHeadersServiceVersion; + +/** + * An instance of this class provides access to all the operations defined in + * ConstantAcceptHeaderWithDefaultValueAsRequireds. + */ +public final class ConstantAcceptHeaderWithDefaultValueAsRequiredsImpl { + /** + * The proxy service used to perform REST calls. + */ + private final ConstantAcceptHeaderWithDefaultValueAsRequiredsService service; + + /** + * The service client containing this operation class. + */ + private final SpecialHeadersClientImpl client; + + /** + * Initializes an instance of ConstantAcceptHeaderWithDefaultValueAsRequiredsImpl. + * + * @param client the instance of the service client containing this operation class. + */ + ConstantAcceptHeaderWithDefaultValueAsRequiredsImpl(SpecialHeadersClientImpl client) { + this.service = RestProxy.create(ConstantAcceptHeaderWithDefaultValueAsRequiredsService.class, + client.getHttpPipeline(), client.getSerializerAdapter()); + this.client = client; + } + + /** + * Gets Service version. + * + * @return the serviceVersion value. + */ + public SpecialHeadersServiceVersion getServiceVersion() { + return client.getServiceVersion(); + } + + /** + * The interface defining all the services for SpecialHeadersClientConstantAcceptHeaderWithDefaultValueAsRequireds + * to be used by the proxy service to perform REST calls. + */ + @Host("{endpoint}") + @ServiceInterface(name = "SpecialHeadersClientConstantAcceptHeaderWithDefaultValueAsRequireds") + public interface ConstantAcceptHeaderWithDefaultValueAsRequiredsService { + @Get("/constant-optional-accept-header-with-default-value") + @ExpectedResponses({ 200 }) + @UnexpectedResponseExceptionType(value = ClientAuthenticationException.class, code = { 401 }) + @UnexpectedResponseExceptionType(value = ResourceNotFoundException.class, code = { 404 }) + @UnexpectedResponseExceptionType(value = ResourceModifiedException.class, code = { 409 }) + @UnexpectedResponseExceptionType(HttpResponseException.class) + Mono> retrieve(@HostParam("endpoint") String endpoint, @HeaderParam("accept") String accept, + RequestOptions requestOptions, Context context); + + @Get("/constant-optional-accept-header-with-default-value") + @ExpectedResponses({ 200 }) + @UnexpectedResponseExceptionType(value = ClientAuthenticationException.class, code = { 401 }) + @UnexpectedResponseExceptionType(value = ResourceNotFoundException.class, code = { 404 }) + @UnexpectedResponseExceptionType(value = ResourceModifiedException.class, code = { 409 }) + @UnexpectedResponseExceptionType(HttpResponseException.class) + Response retrieveSync(@HostParam("endpoint") String endpoint, @HeaderParam("accept") String accept, + RequestOptions requestOptions, Context context); + } + + /** + * Accept header with constant type and default value should be marked as required, before we support + * clientDefaultValue. Issue: https://github.com/microsoft/typespec/issues/10178. + * + * @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 {@link Response} on successful completion of {@link Mono}. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + public Mono> retrieveWithResponseAsync(RequestOptions requestOptions) { + final String accept = "application/json;odata.metadata=minimal"; + return FluxUtil + .withContext(context -> service.retrieve(this.client.getEndpoint(), accept, requestOptions, context)); + } + + /** + * Accept header with constant type and default value should be marked as required, before we support + * clientDefaultValue. Issue: https://github.com/microsoft/typespec/issues/10178. + * + * @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 {@link Response}. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + public Response retrieveWithResponse(RequestOptions requestOptions) { + final String accept = "application/json;odata.metadata=minimal"; + return service.retrieveSync(this.client.getEndpoint(), accept, requestOptions, Context.NONE); + } +} diff --git a/packages/http-client-java/generator/http-client-generator-test/src/main/java/tsptest/specialheaders/implementation/RepeatabilityHeadersImpl.java b/packages/http-client-java/generator/http-client-generator-test/src/main/java/tsptest/specialheaders/implementation/RepeatabilityHeadersImpl.java index 26bfa81465b..4f40764de50 100644 --- a/packages/http-client-java/generator/http-client-generator-test/src/main/java/tsptest/specialheaders/implementation/RepeatabilityHeadersImpl.java +++ b/packages/http-client-java/generator/http-client-generator-test/src/main/java/tsptest/specialheaders/implementation/RepeatabilityHeadersImpl.java @@ -665,7 +665,7 @@ public PollerFlux beginCreateLroWithModelAsync(S RequestOptions requestOptions) { return PollerFlux.create(Duration.ofSeconds(1), () -> this.createLroWithResponseAsync(name, resource, requestOptions), - new tsptest.specialheaders.implementation.OperationLocationPollingStrategy<>( + new OperationLocationPollingStrategy<>( new PollingStrategyOptions(this.client.getHttpPipeline()) .setEndpoint("{endpoint}".replace("{endpoint}", this.client.getEndpoint())) .setContext(requestOptions != null && requestOptions.getContext() != null @@ -727,7 +727,7 @@ public SyncPoller beginCreateLroWithModel(String RequestOptions requestOptions) { return SyncPoller.createPoller(Duration.ofSeconds(1), () -> this.createLroWithResponse(name, resource, requestOptions), - new tsptest.specialheaders.implementation.SyncOperationLocationPollingStrategy<>( + new SyncOperationLocationPollingStrategy<>( new PollingStrategyOptions(this.client.getHttpPipeline()) .setEndpoint("{endpoint}".replace("{endpoint}", this.client.getEndpoint())) .setContext(requestOptions != null && requestOptions.getContext() != null @@ -789,7 +789,7 @@ public PollerFlux beginCreateLroAsync(String name, Binar RequestOptions requestOptions) { return PollerFlux.create(Duration.ofSeconds(1), () -> this.createLroWithResponseAsync(name, resource, requestOptions), - new tsptest.specialheaders.implementation.OperationLocationPollingStrategy<>( + new OperationLocationPollingStrategy<>( new PollingStrategyOptions(this.client.getHttpPipeline()) .setEndpoint("{endpoint}".replace("{endpoint}", this.client.getEndpoint())) .setContext(requestOptions != null && requestOptions.getContext() != null @@ -851,7 +851,7 @@ public SyncPoller beginCreateLro(String name, BinaryData RequestOptions requestOptions) { return SyncPoller.createPoller(Duration.ofSeconds(1), () -> this.createLroWithResponse(name, resource, requestOptions), - new tsptest.specialheaders.implementation.SyncOperationLocationPollingStrategy<>( + new SyncOperationLocationPollingStrategy<>( new PollingStrategyOptions(this.client.getHttpPipeline()) .setEndpoint("{endpoint}".replace("{endpoint}", this.client.getEndpoint())) .setContext(requestOptions != null && requestOptions.getContext() != null diff --git a/packages/http-client-java/generator/http-client-generator-test/src/main/java/tsptest/specialheaders/implementation/SpecialHeadersClientImpl.java b/packages/http-client-java/generator/http-client-generator-test/src/main/java/tsptest/specialheaders/implementation/SpecialHeadersClientImpl.java index 751531b9dab..db19ca9f7a2 100644 --- a/packages/http-client-java/generator/http-client-generator-test/src/main/java/tsptest/specialheaders/implementation/SpecialHeadersClientImpl.java +++ b/packages/http-client-java/generator/http-client-generator-test/src/main/java/tsptest/specialheaders/implementation/SpecialHeadersClientImpl.java @@ -128,6 +128,20 @@ public SkipSpecialHeadersImpl getSkipSpecialHeaders() { return this.skipSpecialHeaders; } + /** + * The ConstantAcceptHeaderWithDefaultValueAsRequiredsImpl object to access its operations. + */ + private final ConstantAcceptHeaderWithDefaultValueAsRequiredsImpl constantAcceptHeaderWithDefaultValueAsRequireds; + + /** + * Gets the ConstantAcceptHeaderWithDefaultValueAsRequiredsImpl object to access its operations. + * + * @return the ConstantAcceptHeaderWithDefaultValueAsRequiredsImpl object. + */ + public ConstantAcceptHeaderWithDefaultValueAsRequiredsImpl getConstantAcceptHeaderWithDefaultValueAsRequireds() { + return this.constantAcceptHeaderWithDefaultValueAsRequireds; + } + /** * Initializes an instance of SpecialHeadersClient client. * @@ -169,5 +183,7 @@ public SpecialHeadersClientImpl(HttpPipeline httpPipeline, SerializerAdapter ser this.etagHeaders = new EtagHeadersImpl(this); this.etagHeadersOptionalBodies = new EtagHeadersOptionalBodiesImpl(this); this.skipSpecialHeaders = new SkipSpecialHeadersImpl(this); + this.constantAcceptHeaderWithDefaultValueAsRequireds + = new ConstantAcceptHeaderWithDefaultValueAsRequiredsImpl(this); } } From ed696cd0da79b6567b4a0d88b889ccde1771f4ef Mon Sep 17 00:00:00 2001 From: xiaofeicao Date: Fri, 27 Mar 2026 19:09:58 +0800 Subject: [PATCH 4/4] add changelog for accept header constant with clientDefaultValue Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- .../accept-constant-clientdefaultvalue-2026-03-27.md | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 .chronus/changes/accept-constant-clientdefaultvalue-2026-03-27.md diff --git a/.chronus/changes/accept-constant-clientdefaultvalue-2026-03-27.md b/.chronus/changes/accept-constant-clientdefaultvalue-2026-03-27.md new file mode 100644 index 00000000000..40c431cfba4 --- /dev/null +++ b/.chronus/changes/accept-constant-clientdefaultvalue-2026-03-27.md @@ -0,0 +1,7 @@ +--- +changeKind: feature +packages: + - "@typespec/http-client-java" +--- + +Emitter support for constant optional Accept header with `@clientDefaultValue`. When an Accept header is optional with a constant type and has `@Legacy.clientDefaultValue`, the emitter now treats it as a required constant, ensuring the value is always sent and hidden from the public API.