Porting fix from autorest.java (#4371)

https://github.com/Azure/autorest.java/pull/2943

Co-authored-by: Weidong Xu <weidxu@microsoft.com>
This commit is contained in:
Alan Zimmer 2024-09-09 22:56:09 -04:00 коммит произвёл GitHub
Родитель a714eea53c
Коммит c6809aa94d
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: B5690EEEBB952194
19 изменённых файлов: 1190 добавлений и 221 удалений

Просмотреть файл

@ -234,6 +234,24 @@ public final class ClientModelPropertiesManager {
}
}
// Temporary fix to a larger problem where the discriminator property is defined by a parent model, but not as
// a discriminator. This results in the discriminator property being serialized and deserialized twice as it
// shows up once as a regular property and once as a discriminator property. This will remove the regular
// property from the super properties and indicate that the discriminator came from a parent model.
if (discriminatorProperty != null) {
String serializedDiscriminatorName = discriminatorProperty.getProperty().getSerializedName();
ClientModelProperty removed;
if ((removed = superRequiredProperties.remove(serializedDiscriminatorName)) != null) {
discriminatorProperty = new ClientModelPropertyWithMetadata(model, removed.newBuilder()
.defaultValue(discriminatorProperty.getProperty().getDefaultValue()).build(),
true);
} else if ((removed = superSetterProperties.remove(serializedDiscriminatorName)) != null) {
discriminatorProperty = new ClientModelPropertyWithMetadata(model, removed.newBuilder()
.defaultValue(discriminatorProperty.getProperty().getDefaultValue()).build(),
true);
}
}
this.hasRequiredProperties = hasRequiredProperties;
this.requiredPropertiesCount = requiredProperties.size() + superRequiredProperties.size();
this.setterPropertiesCount = setterProperties.size() + superSetterProperties.size();

Просмотреть файл

@ -113,13 +113,13 @@ $generateScript = {
}
}
Set-Location ../../
Set-Location (Resolve-Path (Join-Path $PSScriptRoot '..' '..'))
npm install
npm run build
npm pack
Set-Location ./generator/http-client-generator-test
Set-Location $PSScriptRoot
if (Test-Path node_modules) {

Просмотреть файл

@ -0,0 +1,130 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
// Code generated by Microsoft (R) TypeSpec Code Generator.
package com.cadl.discriminatoredgecases;
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 com.cadl.discriminatoredgecases.implementation.DiscriminatorEdgeCasesClientImpl;
import com.cadl.discriminatoredgecases.models.ChildWithAnotherDiscriminator;
import com.cadl.discriminatoredgecases.models.ChildWithRequiredPropertyAsDiscriminator;
import reactor.core.publisher.Mono;
/**
* Initializes a new instance of the asynchronous DiscriminatorEdgeCasesClient type.
*/
@ServiceClient(builder = DiscriminatorEdgeCasesClientBuilder.class, isAsync = true)
public final class DiscriminatorEdgeCasesAsyncClient {
@Generated
private final DiscriminatorEdgeCasesClientImpl serviceClient;
/**
* Initializes an instance of DiscriminatorEdgeCasesAsyncClient class.
*
* @param serviceClient the service client implementation.
*/
@Generated
DiscriminatorEdgeCasesAsyncClient(DiscriminatorEdgeCasesClientImpl serviceClient) {
this.serviceClient = serviceClient;
}
/**
* The getChildRequiredDiscrim operation.
* <p><strong>Response Body Schema</strong></p>
*
* <pre>{@code
* {
* discriminator: String (Required)
* aProperty: String (Required)
* anotherProperty: String (Required)
* }
* }</pre>
*
* @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>> getChildRequiredDiscrimWithResponse(RequestOptions requestOptions) {
return this.serviceClient.getChildRequiredDiscrimWithResponseAsync(requestOptions);
}
/**
* The getChildNewDiscrim operation.
* <p><strong>Response Body Schema</strong></p>
*
* <pre>{@code
* {
* discriminator: String (Required)
* aProperty: String (Required)
* differentDiscriminator: String (Required)
* yetAnotherProperty: String (Required)
* }
* }</pre>
*
* @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>> getChildNewDiscrimWithResponse(RequestOptions requestOptions) {
return this.serviceClient.getChildNewDiscrimWithResponseAsync(requestOptions);
}
/**
* The getChildRequiredDiscrim operation.
*
* @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<ChildWithRequiredPropertyAsDiscriminator> getChildRequiredDiscrim() {
// Generated convenience method for getChildRequiredDiscrimWithResponse
RequestOptions requestOptions = new RequestOptions();
return getChildRequiredDiscrimWithResponse(requestOptions).flatMap(FluxUtil::toMono)
.map(protocolMethodData -> protocolMethodData.toObject(ChildWithRequiredPropertyAsDiscriminator.class));
}
/**
* The getChildNewDiscrim operation.
*
* @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<ChildWithAnotherDiscriminator> getChildNewDiscrim() {
// Generated convenience method for getChildNewDiscrimWithResponse
RequestOptions requestOptions = new RequestOptions();
return getChildNewDiscrimWithResponse(requestOptions).flatMap(FluxUtil::toMono)
.map(protocolMethodData -> protocolMethodData.toObject(ChildWithAnotherDiscriminator.class));
}
}

Просмотреть файл

@ -0,0 +1,127 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
// Code generated by Microsoft (R) TypeSpec Code Generator.
package com.cadl.discriminatoredgecases;
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.cadl.discriminatoredgecases.implementation.DiscriminatorEdgeCasesClientImpl;
import com.cadl.discriminatoredgecases.models.ChildWithAnotherDiscriminator;
import com.cadl.discriminatoredgecases.models.ChildWithRequiredPropertyAsDiscriminator;
/**
* Initializes a new instance of the synchronous DiscriminatorEdgeCasesClient type.
*/
@ServiceClient(builder = DiscriminatorEdgeCasesClientBuilder.class)
public final class DiscriminatorEdgeCasesClient {
@Generated
private final DiscriminatorEdgeCasesClientImpl serviceClient;
/**
* Initializes an instance of DiscriminatorEdgeCasesClient class.
*
* @param serviceClient the service client implementation.
*/
@Generated
DiscriminatorEdgeCasesClient(DiscriminatorEdgeCasesClientImpl serviceClient) {
this.serviceClient = serviceClient;
}
/**
* The getChildRequiredDiscrim operation.
* <p><strong>Response Body Schema</strong></p>
*
* <pre>{@code
* {
* discriminator: String (Required)
* aProperty: String (Required)
* anotherProperty: String (Required)
* }
* }</pre>
*
* @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> getChildRequiredDiscrimWithResponse(RequestOptions requestOptions) {
return this.serviceClient.getChildRequiredDiscrimWithResponse(requestOptions);
}
/**
* The getChildNewDiscrim operation.
* <p><strong>Response Body Schema</strong></p>
*
* <pre>{@code
* {
* discriminator: String (Required)
* aProperty: String (Required)
* differentDiscriminator: String (Required)
* yetAnotherProperty: String (Required)
* }
* }</pre>
*
* @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> getChildNewDiscrimWithResponse(RequestOptions requestOptions) {
return this.serviceClient.getChildNewDiscrimWithResponse(requestOptions);
}
/**
* The getChildRequiredDiscrim operation.
*
* @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 ChildWithRequiredPropertyAsDiscriminator getChildRequiredDiscrim() {
// Generated convenience method for getChildRequiredDiscrimWithResponse
RequestOptions requestOptions = new RequestOptions();
return getChildRequiredDiscrimWithResponse(requestOptions).getValue()
.toObject(ChildWithRequiredPropertyAsDiscriminator.class);
}
/**
* The getChildNewDiscrim operation.
*
* @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 ChildWithAnotherDiscriminator getChildNewDiscrim() {
// Generated convenience method for getChildNewDiscrimWithResponse
RequestOptions requestOptions = new RequestOptions();
return getChildNewDiscrimWithResponse(requestOptions).getValue().toObject(ChildWithAnotherDiscriminator.class);
}
}

Просмотреть файл

@ -2,7 +2,7 @@
// Licensed under the MIT License.
// Code generated by Microsoft (R) TypeSpec Code Generator.
package com.cadl.naming;
package com.cadl.discriminatoredgecases;
import com.azure.core.annotation.Generated;
import com.azure.core.annotation.ServiceClientBuilder;
@ -31,18 +31,18 @@ import com.azure.core.util.CoreUtils;
import com.azure.core.util.builder.ClientBuilderUtil;
import com.azure.core.util.logging.ClientLogger;
import com.azure.core.util.serializer.JacksonAdapter;
import com.cadl.naming.implementation.NamingClientImpl;
import com.cadl.discriminatoredgecases.implementation.DiscriminatorEdgeCasesClientImpl;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Objects;
/**
* A builder for creating a new instance of the NamingClient type.
* A builder for creating a new instance of the DiscriminatorEdgeCasesClient type.
*/
@ServiceClientBuilder(serviceClients = { NamingClient.class, NamingAsyncClient.class })
public final class NamingClientBuilder implements HttpTrait<NamingClientBuilder>,
ConfigurationTrait<NamingClientBuilder>, EndpointTrait<NamingClientBuilder> {
@ServiceClientBuilder(serviceClients = { DiscriminatorEdgeCasesClient.class, DiscriminatorEdgeCasesAsyncClient.class })
public final class DiscriminatorEdgeCasesClientBuilder implements HttpTrait<DiscriminatorEdgeCasesClientBuilder>,
ConfigurationTrait<DiscriminatorEdgeCasesClientBuilder>, EndpointTrait<DiscriminatorEdgeCasesClientBuilder> {
@Generated
private static final String SDK_NAME = "name";
@ -50,16 +50,17 @@ public final class NamingClientBuilder implements HttpTrait<NamingClientBuilder>
private static final String SDK_VERSION = "version";
@Generated
private static final Map<String, String> PROPERTIES = CoreUtils.getProperties("cadl-naming.properties");
private static final Map<String, String> PROPERTIES
= CoreUtils.getProperties("cadl-discriminatoredgecases.properties");
@Generated
private final List<HttpPipelinePolicy> pipelinePolicies;
/**
* Create an instance of the NamingClientBuilder.
* Create an instance of the DiscriminatorEdgeCasesClientBuilder.
*/
@Generated
public NamingClientBuilder() {
public DiscriminatorEdgeCasesClientBuilder() {
this.pipelinePolicies = new ArrayList<>();
}
@ -74,7 +75,7 @@ public final class NamingClientBuilder implements HttpTrait<NamingClientBuilder>
*/
@Generated
@Override
public NamingClientBuilder pipeline(HttpPipeline pipeline) {
public DiscriminatorEdgeCasesClientBuilder pipeline(HttpPipeline pipeline) {
if (this.pipeline != null && pipeline == null) {
LOGGER.atInfo().log("HttpPipeline is being set to 'null' when it was previously configured.");
}
@ -93,7 +94,7 @@ public final class NamingClientBuilder implements HttpTrait<NamingClientBuilder>
*/
@Generated
@Override
public NamingClientBuilder httpClient(HttpClient httpClient) {
public DiscriminatorEdgeCasesClientBuilder httpClient(HttpClient httpClient) {
this.httpClient = httpClient;
return this;
}
@ -109,7 +110,7 @@ public final class NamingClientBuilder implements HttpTrait<NamingClientBuilder>
*/
@Generated
@Override
public NamingClientBuilder httpLogOptions(HttpLogOptions httpLogOptions) {
public DiscriminatorEdgeCasesClientBuilder httpLogOptions(HttpLogOptions httpLogOptions) {
this.httpLogOptions = httpLogOptions;
return this;
}
@ -125,7 +126,7 @@ public final class NamingClientBuilder implements HttpTrait<NamingClientBuilder>
*/
@Generated
@Override
public NamingClientBuilder clientOptions(ClientOptions clientOptions) {
public DiscriminatorEdgeCasesClientBuilder clientOptions(ClientOptions clientOptions) {
this.clientOptions = clientOptions;
return this;
}
@ -141,7 +142,7 @@ public final class NamingClientBuilder implements HttpTrait<NamingClientBuilder>
*/
@Generated
@Override
public NamingClientBuilder retryOptions(RetryOptions retryOptions) {
public DiscriminatorEdgeCasesClientBuilder retryOptions(RetryOptions retryOptions) {
this.retryOptions = retryOptions;
return this;
}
@ -151,7 +152,7 @@ public final class NamingClientBuilder implements HttpTrait<NamingClientBuilder>
*/
@Generated
@Override
public NamingClientBuilder addPolicy(HttpPipelinePolicy customPolicy) {
public DiscriminatorEdgeCasesClientBuilder addPolicy(HttpPipelinePolicy customPolicy) {
Objects.requireNonNull(customPolicy, "'customPolicy' cannot be null.");
pipelinePolicies.add(customPolicy);
return this;
@ -168,7 +169,7 @@ public final class NamingClientBuilder implements HttpTrait<NamingClientBuilder>
*/
@Generated
@Override
public NamingClientBuilder configuration(Configuration configuration) {
public DiscriminatorEdgeCasesClientBuilder configuration(Configuration configuration) {
this.configuration = configuration;
return this;
}
@ -184,7 +185,7 @@ public final class NamingClientBuilder implements HttpTrait<NamingClientBuilder>
*/
@Generated
@Override
public NamingClientBuilder endpoint(String endpoint) {
public DiscriminatorEdgeCasesClientBuilder endpoint(String endpoint) {
this.endpoint = endpoint;
return this;
}
@ -199,25 +200,25 @@ public final class NamingClientBuilder implements HttpTrait<NamingClientBuilder>
* Sets The retry policy that will attempt to retry failed requests, if applicable.
*
* @param retryPolicy the retryPolicy value.
* @return the NamingClientBuilder.
* @return the DiscriminatorEdgeCasesClientBuilder.
*/
@Generated
public NamingClientBuilder retryPolicy(RetryPolicy retryPolicy) {
public DiscriminatorEdgeCasesClientBuilder retryPolicy(RetryPolicy retryPolicy) {
this.retryPolicy = retryPolicy;
return this;
}
/**
* Builds an instance of NamingClientImpl with the provided parameters.
* Builds an instance of DiscriminatorEdgeCasesClientImpl with the provided parameters.
*
* @return an instance of NamingClientImpl.
* @return an instance of DiscriminatorEdgeCasesClientImpl.
*/
@Generated
private NamingClientImpl buildInnerClient() {
private DiscriminatorEdgeCasesClientImpl buildInnerClient() {
this.validateClient();
HttpPipeline localPipeline = (pipeline != null) ? pipeline : createHttpPipeline();
NamingClientImpl client
= new NamingClientImpl(localPipeline, JacksonAdapter.createDefaultSerializerAdapter(), this.endpoint);
DiscriminatorEdgeCasesClientImpl client = new DiscriminatorEdgeCasesClientImpl(localPipeline,
JacksonAdapter.createDefaultSerializerAdapter(), this.endpoint);
return client;
}
@ -264,24 +265,24 @@ public final class NamingClientBuilder implements HttpTrait<NamingClientBuilder>
}
/**
* Builds an instance of NamingAsyncClient class.
* Builds an instance of DiscriminatorEdgeCasesAsyncClient class.
*
* @return an instance of NamingAsyncClient.
* @return an instance of DiscriminatorEdgeCasesAsyncClient.
*/
@Generated
public NamingAsyncClient buildAsyncClient() {
return new NamingAsyncClient(buildInnerClient().getNamingOps());
public DiscriminatorEdgeCasesAsyncClient buildAsyncClient() {
return new DiscriminatorEdgeCasesAsyncClient(buildInnerClient());
}
/**
* Builds an instance of NamingClient class.
* Builds an instance of DiscriminatorEdgeCasesClient class.
*
* @return an instance of NamingClient.
* @return an instance of DiscriminatorEdgeCasesClient.
*/
@Generated
public NamingClient buildClient() {
return new NamingClient(buildInnerClient().getNamingOps());
public DiscriminatorEdgeCasesClient buildClient() {
return new DiscriminatorEdgeCasesClient(buildInnerClient());
}
private static final ClientLogger LOGGER = new ClientLogger(NamingClientBuilder.class);
private static final ClientLogger LOGGER = new ClientLogger(DiscriminatorEdgeCasesClientBuilder.class);
}

Просмотреть файл

@ -2,16 +2,13 @@
// Licensed under the MIT License.
// Code generated by Microsoft (R) TypeSpec Code Generator.
package com.cadl.naming.implementation;
package com.cadl.discriminatoredgecases.implementation;
import com.azure.core.annotation.BodyParam;
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.Post;
import com.azure.core.annotation.QueryParam;
import com.azure.core.annotation.ReturnType;
import com.azure.core.annotation.ServiceInterface;
import com.azure.core.annotation.ServiceMethod;
@ -20,217 +17,160 @@ 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.HttpPipeline;
import com.azure.core.http.HttpPipelineBuilder;
import com.azure.core.http.policy.RetryPolicy;
import com.azure.core.http.policy.UserAgentPolicy;
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.BinaryData;
import com.azure.core.util.Context;
import com.azure.core.util.FluxUtil;
import com.azure.core.util.serializer.JacksonAdapter;
import com.azure.core.util.serializer.SerializerAdapter;
import reactor.core.publisher.Mono;
/**
* An instance of this class provides access to all the operations defined in NamingOps.
* Initializes a new instance of the DiscriminatorEdgeCasesClient type.
*/
public final class NamingOpsImpl {
public final class DiscriminatorEdgeCasesClientImpl {
/**
* The proxy service used to perform REST calls.
*/
private final NamingOpsService service;
private final DiscriminatorEdgeCasesClientService service;
/**
* The service client containing this operation class.
* Service host.
*/
private final NamingClientImpl client;
private final String endpoint;
/**
* Initializes an instance of NamingOpsImpl.
* Gets Service host.
*
* @param client the instance of the service client containing this operation class.
* @return the endpoint value.
*/
NamingOpsImpl(NamingClientImpl client) {
this.service
= RestProxy.create(NamingOpsService.class, client.getHttpPipeline(), client.getSerializerAdapter());
this.client = client;
public String getEndpoint() {
return this.endpoint;
}
/**
* The interface defining all the services for NamingClientNamingOps to be used by the proxy service to perform REST
* calls.
* The HTTP pipeline to send requests through.
*/
private final HttpPipeline httpPipeline;
/**
* Gets The HTTP pipeline to send requests through.
*
* @return the httpPipeline value.
*/
public HttpPipeline getHttpPipeline() {
return this.httpPipeline;
}
/**
* The serializer to serialize an object into a string.
*/
private final SerializerAdapter serializerAdapter;
/**
* Gets The serializer to serialize an object into a string.
*
* @return the serializerAdapter value.
*/
public SerializerAdapter getSerializerAdapter() {
return this.serializerAdapter;
}
/**
* Initializes an instance of DiscriminatorEdgeCasesClient client.
*
* @param endpoint Service host.
*/
public DiscriminatorEdgeCasesClientImpl(String endpoint) {
this(new HttpPipelineBuilder().policies(new UserAgentPolicy(), new RetryPolicy()).build(),
JacksonAdapter.createDefaultSerializerAdapter(), endpoint);
}
/**
* Initializes an instance of DiscriminatorEdgeCasesClient client.
*
* @param httpPipeline The HTTP pipeline to send requests through.
* @param endpoint Service host.
*/
public DiscriminatorEdgeCasesClientImpl(HttpPipeline httpPipeline, String endpoint) {
this(httpPipeline, JacksonAdapter.createDefaultSerializerAdapter(), endpoint);
}
/**
* Initializes an instance of DiscriminatorEdgeCasesClient client.
*
* @param httpPipeline The HTTP pipeline to send requests through.
* @param serializerAdapter The serializer to serialize an object into a string.
* @param endpoint Service host.
*/
public DiscriminatorEdgeCasesClientImpl(HttpPipeline httpPipeline, SerializerAdapter serializerAdapter,
String endpoint) {
this.httpPipeline = httpPipeline;
this.serializerAdapter = serializerAdapter;
this.endpoint = endpoint;
this.service = RestProxy.create(DiscriminatorEdgeCasesClientService.class, this.httpPipeline,
this.getSerializerAdapter());
}
/**
* The interface defining all the services for DiscriminatorEdgeCasesClient to be used by the proxy service to
* perform REST calls.
*/
@Host("{endpoint}")
@ServiceInterface(name = "NamingClientNamingOp")
public interface NamingOpsService {
@Post("/naming")
@ServiceInterface(name = "DiscriminatorEdgeCas")
public interface DiscriminatorEdgeCasesClientService {
@Get("/model/childrequireddiscrim")
@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>> post(@HostParam("endpoint") String endpoint, @QueryParam("name") String name,
@HeaderParam("Content-Type") String contentType, @HeaderParam("Accept") String accept,
@BodyParam("application/json") BinaryData body, RequestOptions requestOptions, Context context);
@Post("/naming")
@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> postSync(@HostParam("endpoint") String endpoint, @QueryParam("name") String name,
@HeaderParam("Content-Type") String contentType, @HeaderParam("Accept") String accept,
@BodyParam("application/json") BinaryData body, RequestOptions requestOptions, Context context);
@Get("/naming")
@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>> getAnonymous(@HostParam("endpoint") String endpoint,
Mono<Response<BinaryData>> getChildRequiredDiscrim(@HostParam("endpoint") String endpoint,
@HeaderParam("Accept") String accept, RequestOptions requestOptions, Context context);
@Get("/naming")
@Get("/model/childrequireddiscrim")
@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> getAnonymousSync(@HostParam("endpoint") String endpoint,
Response<BinaryData> getChildRequiredDiscrimSync(@HostParam("endpoint") String endpoint,
@HeaderParam("Accept") String accept, RequestOptions requestOptions, Context context);
@Get("/model/childnewdiscrim")
@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>> getChildNewDiscrim(@HostParam("endpoint") String endpoint,
@HeaderParam("Accept") String accept, RequestOptions requestOptions, Context context);
@Get("/model/childnewdiscrim")
@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> getChildNewDiscrimSync(@HostParam("endpoint") String endpoint,
@HeaderParam("Accept") String accept, RequestOptions requestOptions, Context context);
}
/**
* summary of POST op
*
* description of POST op.
* <p><strong>Header Parameters</strong></p>
* <table border="1">
* <caption>Header Parameters</caption>
* <tr><th>Name</th><th>Type</th><th>Required</th><th>Description</th></tr>
* <tr><td>etag</td><td>String</td><td>No</td><td>summary of etag header parameter
*
* description of etag header parameter</td></tr>
* </table>
* You can add these to a request with {@link RequestOptions#addHeader}
* <p><strong>Request Body Schema</strong></p>
*
* <pre>{@code
* {
* parameters (Optional): {
* type: String(Type1/Type2) (Required)
* }
* }
* }</pre>
*
* The getChildRequiredDiscrim operation.
* <p><strong>Response Body Schema</strong></p>
*
* <pre>{@code
* {
* name: String (Required)
* data (Required): {
* data (Required): {
* &#64;data.kind: String (Required)
* }
* }
* type: String(Blob/File) (Required)
* status: String(Running/Completed/Failed) (Required)
* anonymous (Required): {
* last_error (Required): {
* code: String(server_error/rate_limit_exceeded/invalid_prompt) (Required)
* }
* }
* }
* }</pre>
*
* @param name summary of name query parameter
*
* description of name query parameter.
* @param body The body 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 summary of Response along with {@link Response} on successful completion of {@link Mono}.
*/
@ServiceMethod(returns = ReturnType.SINGLE)
public Mono<Response<BinaryData>> postWithResponseAsync(String name, BinaryData body,
RequestOptions requestOptions) {
final String contentType = "application/json";
final String accept = "application/json";
return FluxUtil.withContext(context -> service.post(this.client.getEndpoint(), name, contentType, accept, body,
requestOptions, context));
}
/**
* summary of POST op
*
* description of POST op.
* <p><strong>Header Parameters</strong></p>
* <table border="1">
* <caption>Header Parameters</caption>
* <tr><th>Name</th><th>Type</th><th>Required</th><th>Description</th></tr>
* <tr><td>etag</td><td>String</td><td>No</td><td>summary of etag header parameter
*
* description of etag header parameter</td></tr>
* </table>
* You can add these to a request with {@link RequestOptions#addHeader}
* <p><strong>Request Body Schema</strong></p>
*
* <pre>{@code
* {
* parameters (Optional): {
* type: String(Type1/Type2) (Required)
* }
* }
* }</pre>
*
* <p><strong>Response Body Schema</strong></p>
*
* <pre>{@code
* {
* name: String (Required)
* data (Required): {
* data (Required): {
* &#64;data.kind: String (Required)
* }
* }
* type: String(Blob/File) (Required)
* status: String(Running/Completed/Failed) (Required)
* anonymous (Required): {
* last_error (Required): {
* code: String(server_error/rate_limit_exceeded/invalid_prompt) (Required)
* }
* }
* }
* }</pre>
*
* @param name summary of name query parameter
*
* description of name query parameter.
* @param body The body 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 summary of Response along with {@link Response}.
*/
@ServiceMethod(returns = ReturnType.SINGLE)
public Response<BinaryData> postWithResponse(String name, BinaryData body, RequestOptions requestOptions) {
final String contentType = "application/json";
final String accept = "application/json";
return service.postSync(this.client.getEndpoint(), name, contentType, accept, body, requestOptions,
Context.NONE);
}
/**
* The getAnonymous operation.
* <p><strong>Response Body Schema</strong></p>
*
* <pre>{@code
* {
* name: String (Required)
* discriminator: String (Required)
* aProperty: String (Required)
* anotherProperty: String (Required)
* }
* }</pre>
*
@ -242,19 +182,21 @@ public final class NamingOpsImpl {
* @return the response body along with {@link Response} on successful completion of {@link Mono}.
*/
@ServiceMethod(returns = ReturnType.SINGLE)
public Mono<Response<BinaryData>> getAnonymousWithResponseAsync(RequestOptions requestOptions) {
public Mono<Response<BinaryData>> getChildRequiredDiscrimWithResponseAsync(RequestOptions requestOptions) {
final String accept = "application/json";
return FluxUtil
.withContext(context -> service.getAnonymous(this.client.getEndpoint(), accept, requestOptions, context));
return FluxUtil.withContext(
context -> service.getChildRequiredDiscrim(this.getEndpoint(), accept, requestOptions, context));
}
/**
* The getAnonymous operation.
* The getChildRequiredDiscrim operation.
* <p><strong>Response Body Schema</strong></p>
*
* <pre>{@code
* {
* name: String (Required)
* discriminator: String (Required)
* aProperty: String (Required)
* anotherProperty: String (Required)
* }
* }</pre>
*
@ -266,8 +208,61 @@ public final class NamingOpsImpl {
* @return the response body along with {@link Response}.
*/
@ServiceMethod(returns = ReturnType.SINGLE)
public Response<BinaryData> getAnonymousWithResponse(RequestOptions requestOptions) {
public Response<BinaryData> getChildRequiredDiscrimWithResponse(RequestOptions requestOptions) {
final String accept = "application/json";
return service.getAnonymousSync(this.client.getEndpoint(), accept, requestOptions, Context.NONE);
return service.getChildRequiredDiscrimSync(this.getEndpoint(), accept, requestOptions, Context.NONE);
}
/**
* The getChildNewDiscrim operation.
* <p><strong>Response Body Schema</strong></p>
*
* <pre>{@code
* {
* discriminator: String (Required)
* aProperty: String (Required)
* differentDiscriminator: String (Required)
* yetAnotherProperty: String (Required)
* }
* }</pre>
*
* @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}.
*/
@ServiceMethod(returns = ReturnType.SINGLE)
public Mono<Response<BinaryData>> getChildNewDiscrimWithResponseAsync(RequestOptions requestOptions) {
final String accept = "application/json";
return FluxUtil
.withContext(context -> service.getChildNewDiscrim(this.getEndpoint(), accept, requestOptions, context));
}
/**
* The getChildNewDiscrim operation.
* <p><strong>Response Body Schema</strong></p>
*
* <pre>{@code
* {
* discriminator: String (Required)
* aProperty: String (Required)
* differentDiscriminator: String (Required)
* yetAnotherProperty: String (Required)
* }
* }</pre>
*
* @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}.
*/
@ServiceMethod(returns = ReturnType.SINGLE)
public Response<BinaryData> getChildNewDiscrimWithResponse(RequestOptions requestOptions) {
final String accept = "application/json";
return service.getChildNewDiscrimSync(this.getEndpoint(), accept, requestOptions, Context.NONE);
}
}

Просмотреть файл

@ -4,8 +4,7 @@
/**
* <!-- start generated doc -->
* Package containing the implementations for Naming.
* description of Naming.
* Package containing the implementations for DiscriminatorEdgeCases.
* <!-- end generated doc -->
*/
package com.cadl.naming.implementation;
package com.cadl.discriminatoredgecases.implementation;

Просмотреть файл

@ -0,0 +1,143 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
// Code generated by Microsoft (R) TypeSpec Code Generator.
package com.cadl.discriminatoredgecases.models;
import com.azure.core.annotation.Generated;
import com.azure.core.annotation.Immutable;
import com.azure.json.JsonReader;
import com.azure.json.JsonToken;
import com.azure.json.JsonWriter;
import java.io.IOException;
/**
* The ChildWithAnotherDiscriminator model.
*/
@Immutable
public class ChildWithAnotherDiscriminator extends ParentWithRequiredProperty {
/*
* Discriminator property for ChildWithAnotherDiscriminator.
*/
@Generated
private String differentDiscriminator = "ChildWithAnotherDiscriminator";
/*
* The yetAnotherProperty property.
*/
@Generated
private final String yetAnotherProperty;
/**
* Creates an instance of ChildWithAnotherDiscriminator class.
*
* @param discriminator the discriminator value to set.
* @param aProperty the aProperty value to set.
* @param yetAnotherProperty the yetAnotherProperty value to set.
*/
@Generated
protected ChildWithAnotherDiscriminator(String discriminator, String aProperty, String yetAnotherProperty) {
super(discriminator, aProperty);
this.yetAnotherProperty = yetAnotherProperty;
}
/**
* Get the differentDiscriminator property: Discriminator property for ChildWithAnotherDiscriminator.
*
* @return the differentDiscriminator value.
*/
@Generated
public String getDifferentDiscriminator() {
return this.differentDiscriminator;
}
/**
* Get the yetAnotherProperty property: The yetAnotherProperty property.
*
* @return the yetAnotherProperty value.
*/
@Generated
public String getYetAnotherProperty() {
return this.yetAnotherProperty;
}
/**
* {@inheritDoc}
*/
@Generated
@Override
public JsonWriter toJson(JsonWriter jsonWriter) throws IOException {
jsonWriter.writeStartObject();
jsonWriter.writeStringField("discriminator", getDiscriminator());
jsonWriter.writeStringField("aProperty", getAProperty());
jsonWriter.writeStringField("yetAnotherProperty", this.yetAnotherProperty);
jsonWriter.writeStringField("differentDiscriminator", this.differentDiscriminator);
return jsonWriter.writeEndObject();
}
/**
* Reads an instance of ChildWithAnotherDiscriminator from the JsonReader.
*
* @param jsonReader The JsonReader being read.
* @return An instance of ChildWithAnotherDiscriminator 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 ChildWithAnotherDiscriminator.
*/
@Generated
public static ChildWithAnotherDiscriminator fromJson(JsonReader jsonReader) throws IOException {
return jsonReader.readObject(reader -> {
String discriminatorValue = null;
try (JsonReader readerToUse = reader.bufferObject()) {
readerToUse.nextToken(); // Prepare for reading
while (readerToUse.nextToken() != JsonToken.END_OBJECT) {
String fieldName = readerToUse.getFieldName();
readerToUse.nextToken();
if ("differentDiscriminator".equals(fieldName)) {
discriminatorValue = readerToUse.getString();
break;
} else {
readerToUse.skipChildren();
}
}
// Use the discriminator value to determine which subtype should be deserialized.
if ("anotherValue".equals(discriminatorValue)) {
return GrandChildWithAnotherDiscriminator.fromJson(readerToUse.reset());
} else {
return fromJsonKnownDiscriminator(readerToUse.reset());
}
}
});
}
@Generated
static ChildWithAnotherDiscriminator fromJsonKnownDiscriminator(JsonReader jsonReader) throws IOException {
return jsonReader.readObject(reader -> {
String discriminator = null;
String aProperty = null;
String yetAnotherProperty = null;
String differentDiscriminator = null;
while (reader.nextToken() != JsonToken.END_OBJECT) {
String fieldName = reader.getFieldName();
reader.nextToken();
if ("discriminator".equals(fieldName)) {
discriminator = reader.getString();
} else if ("aProperty".equals(fieldName)) {
aProperty = reader.getString();
} else if ("yetAnotherProperty".equals(fieldName)) {
yetAnotherProperty = reader.getString();
} else if ("differentDiscriminator".equals(fieldName)) {
differentDiscriminator = reader.getString();
} else {
reader.skipChildren();
}
}
ChildWithAnotherDiscriminator deserializedChildWithAnotherDiscriminator
= new ChildWithAnotherDiscriminator(discriminator, aProperty, yetAnotherProperty);
deserializedChildWithAnotherDiscriminator.differentDiscriminator = differentDiscriminator;
return deserializedChildWithAnotherDiscriminator;
});
}
}

Просмотреть файл

@ -0,0 +1,141 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
// Code generated by Microsoft (R) TypeSpec Code Generator.
package com.cadl.discriminatoredgecases.models;
import com.azure.core.annotation.Generated;
import com.azure.core.annotation.Immutable;
import com.azure.json.JsonReader;
import com.azure.json.JsonToken;
import com.azure.json.JsonWriter;
import java.io.IOException;
/**
* The ChildWithRequiredPropertyAsDiscriminator model.
*/
@Immutable
public class ChildWithRequiredPropertyAsDiscriminator extends ParentWithRequiredProperty {
/*
* Discriminator property for ChildWithRequiredPropertyAsDiscriminator.
*/
@Generated
private String discriminator = "ChildWithRequiredPropertyAsDiscriminator";
/*
* The anotherProperty property.
*/
@Generated
private final String anotherProperty;
/**
* Creates an instance of ChildWithRequiredPropertyAsDiscriminator class.
*
* @param discriminator the discriminator value to set.
* @param aProperty the aProperty value to set.
* @param anotherProperty the anotherProperty value to set.
*/
@Generated
protected ChildWithRequiredPropertyAsDiscriminator(String discriminator, String aProperty, String anotherProperty) {
super(discriminator, aProperty);
this.anotherProperty = anotherProperty;
}
/**
* Get the discriminator property: Discriminator property for ChildWithRequiredPropertyAsDiscriminator.
*
* @return the discriminator value.
*/
@Generated
@Override
public String getDiscriminator() {
return this.discriminator;
}
/**
* Get the anotherProperty property: The anotherProperty property.
*
* @return the anotherProperty value.
*/
@Generated
public String getAnotherProperty() {
return this.anotherProperty;
}
/**
* {@inheritDoc}
*/
@Generated
@Override
public JsonWriter toJson(JsonWriter jsonWriter) throws IOException {
jsonWriter.writeStartObject();
jsonWriter.writeStringField("aProperty", getAProperty());
jsonWriter.writeStringField("anotherProperty", this.anotherProperty);
jsonWriter.writeStringField("discriminator", this.discriminator);
return jsonWriter.writeEndObject();
}
/**
* Reads an instance of ChildWithRequiredPropertyAsDiscriminator from the JsonReader.
*
* @param jsonReader The JsonReader being read.
* @return An instance of ChildWithRequiredPropertyAsDiscriminator 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 ChildWithRequiredPropertyAsDiscriminator.
*/
@Generated
public static ChildWithRequiredPropertyAsDiscriminator fromJson(JsonReader jsonReader) throws IOException {
return jsonReader.readObject(reader -> {
String discriminatorValue = null;
try (JsonReader readerToUse = reader.bufferObject()) {
readerToUse.nextToken(); // Prepare for reading
while (readerToUse.nextToken() != JsonToken.END_OBJECT) {
String fieldName = readerToUse.getFieldName();
readerToUse.nextToken();
if ("discriminator".equals(fieldName)) {
discriminatorValue = readerToUse.getString();
break;
} else {
readerToUse.skipChildren();
}
}
// Use the discriminator value to determine which subtype should be deserialized.
if ("aValue".equals(discriminatorValue)) {
return GrandChildWithRequiredProperty.fromJson(readerToUse.reset());
} else {
return fromJsonKnownDiscriminator(readerToUse.reset());
}
}
});
}
@Generated
static ChildWithRequiredPropertyAsDiscriminator fromJsonKnownDiscriminator(JsonReader jsonReader)
throws IOException {
return jsonReader.readObject(reader -> {
String aProperty = null;
String anotherProperty = null;
String discriminator = null;
while (reader.nextToken() != JsonToken.END_OBJECT) {
String fieldName = reader.getFieldName();
reader.nextToken();
if ("aProperty".equals(fieldName)) {
aProperty = reader.getString();
} else if ("anotherProperty".equals(fieldName)) {
anotherProperty = reader.getString();
} else if ("discriminator".equals(fieldName)) {
discriminator = reader.getString();
} else {
reader.skipChildren();
}
}
ChildWithRequiredPropertyAsDiscriminator deserializedChildWithRequiredPropertyAsDiscriminator
= new ChildWithRequiredPropertyAsDiscriminator(discriminator, aProperty, anotherProperty);
deserializedChildWithRequiredPropertyAsDiscriminator.discriminator = discriminator;
return deserializedChildWithRequiredPropertyAsDiscriminator;
});
}
}

Просмотреть файл

@ -0,0 +1,101 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
// Code generated by Microsoft (R) TypeSpec Code Generator.
package com.cadl.discriminatoredgecases.models;
import com.azure.core.annotation.Generated;
import com.azure.core.annotation.Immutable;
import com.azure.json.JsonReader;
import com.azure.json.JsonToken;
import com.azure.json.JsonWriter;
import java.io.IOException;
/**
* The GrandChildWithAnotherDiscriminator model.
*/
@Immutable
public final class GrandChildWithAnotherDiscriminator extends ChildWithAnotherDiscriminator {
/*
* Discriminator property for ChildWithAnotherDiscriminator.
*/
@Generated
private String differentDiscriminator = "anotherValue";
/**
* Creates an instance of GrandChildWithAnotherDiscriminator class.
*
* @param discriminator the discriminator value to set.
* @param aProperty the aProperty value to set.
* @param yetAnotherProperty the yetAnotherProperty value to set.
*/
@Generated
private GrandChildWithAnotherDiscriminator(String discriminator, String aProperty, String yetAnotherProperty) {
super(discriminator, aProperty, yetAnotherProperty);
}
/**
* Get the differentDiscriminator property: Discriminator property for ChildWithAnotherDiscriminator.
*
* @return the differentDiscriminator value.
*/
@Generated
@Override
public String getDifferentDiscriminator() {
return this.differentDiscriminator;
}
/**
* {@inheritDoc}
*/
@Generated
@Override
public JsonWriter toJson(JsonWriter jsonWriter) throws IOException {
jsonWriter.writeStartObject();
jsonWriter.writeStringField("discriminator", getDiscriminator());
jsonWriter.writeStringField("aProperty", getAProperty());
jsonWriter.writeStringField("yetAnotherProperty", getYetAnotherProperty());
jsonWriter.writeStringField("differentDiscriminator", this.differentDiscriminator);
return jsonWriter.writeEndObject();
}
/**
* Reads an instance of GrandChildWithAnotherDiscriminator from the JsonReader.
*
* @param jsonReader The JsonReader being read.
* @return An instance of GrandChildWithAnotherDiscriminator 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 GrandChildWithAnotherDiscriminator.
*/
@Generated
public static GrandChildWithAnotherDiscriminator fromJson(JsonReader jsonReader) throws IOException {
return jsonReader.readObject(reader -> {
String discriminator = null;
String aProperty = null;
String yetAnotherProperty = null;
String differentDiscriminator = "anotherValue";
while (reader.nextToken() != JsonToken.END_OBJECT) {
String fieldName = reader.getFieldName();
reader.nextToken();
if ("discriminator".equals(fieldName)) {
discriminator = reader.getString();
} else if ("aProperty".equals(fieldName)) {
aProperty = reader.getString();
} else if ("yetAnotherProperty".equals(fieldName)) {
yetAnotherProperty = reader.getString();
} else if ("differentDiscriminator".equals(fieldName)) {
differentDiscriminator = reader.getString();
} else {
reader.skipChildren();
}
}
GrandChildWithAnotherDiscriminator deserializedGrandChildWithAnotherDiscriminator
= new GrandChildWithAnotherDiscriminator(discriminator, aProperty, yetAnotherProperty);
deserializedGrandChildWithAnotherDiscriminator.differentDiscriminator = differentDiscriminator;
return deserializedGrandChildWithAnotherDiscriminator;
});
}
}

Просмотреть файл

@ -0,0 +1,97 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
// Code generated by Microsoft (R) TypeSpec Code Generator.
package com.cadl.discriminatoredgecases.models;
import com.azure.core.annotation.Generated;
import com.azure.core.annotation.Immutable;
import com.azure.json.JsonReader;
import com.azure.json.JsonToken;
import com.azure.json.JsonWriter;
import java.io.IOException;
/**
* The GrandChildWithRequiredProperty model.
*/
@Immutable
public final class GrandChildWithRequiredProperty extends ChildWithRequiredPropertyAsDiscriminator {
/*
* Discriminator property for ChildWithRequiredPropertyAsDiscriminator.
*/
@Generated
private String discriminator = "aValue";
/**
* Creates an instance of GrandChildWithRequiredProperty class.
*
* @param discriminator the discriminator value to set.
* @param aProperty the aProperty value to set.
* @param anotherProperty the anotherProperty value to set.
*/
@Generated
private GrandChildWithRequiredProperty(String discriminator, String aProperty, String anotherProperty) {
super(discriminator, aProperty, anotherProperty);
}
/**
* Get the discriminator property: Discriminator property for ChildWithRequiredPropertyAsDiscriminator.
*
* @return the discriminator value.
*/
@Generated
@Override
public String getDiscriminator() {
return this.discriminator;
}
/**
* {@inheritDoc}
*/
@Generated
@Override
public JsonWriter toJson(JsonWriter jsonWriter) throws IOException {
jsonWriter.writeStartObject();
jsonWriter.writeStringField("aProperty", getAProperty());
jsonWriter.writeStringField("anotherProperty", getAnotherProperty());
jsonWriter.writeStringField("discriminator", this.discriminator);
return jsonWriter.writeEndObject();
}
/**
* Reads an instance of GrandChildWithRequiredProperty from the JsonReader.
*
* @param jsonReader The JsonReader being read.
* @return An instance of GrandChildWithRequiredProperty 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 GrandChildWithRequiredProperty.
*/
@Generated
public static GrandChildWithRequiredProperty fromJson(JsonReader jsonReader) throws IOException {
return jsonReader.readObject(reader -> {
String aProperty = null;
String anotherProperty = null;
String discriminator = "aValue";
while (reader.nextToken() != JsonToken.END_OBJECT) {
String fieldName = reader.getFieldName();
reader.nextToken();
if ("aProperty".equals(fieldName)) {
aProperty = reader.getString();
} else if ("anotherProperty".equals(fieldName)) {
anotherProperty = reader.getString();
} else if ("discriminator".equals(fieldName)) {
discriminator = reader.getString();
} else {
reader.skipChildren();
}
}
GrandChildWithRequiredProperty deserializedGrandChildWithRequiredProperty
= new GrandChildWithRequiredProperty(discriminator, aProperty, anotherProperty);
deserializedGrandChildWithRequiredProperty.discriminator = discriminator;
return deserializedGrandChildWithRequiredProperty;
});
}
}

Просмотреть файл

@ -0,0 +1,105 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
// Code generated by Microsoft (R) TypeSpec Code Generator.
package com.cadl.discriminatoredgecases.models;
import com.azure.core.annotation.Generated;
import com.azure.core.annotation.Immutable;
import com.azure.json.JsonReader;
import com.azure.json.JsonSerializable;
import com.azure.json.JsonToken;
import com.azure.json.JsonWriter;
import java.io.IOException;
/**
* The ParentWithRequiredProperty model.
*/
@Immutable
public class ParentWithRequiredProperty implements JsonSerializable<ParentWithRequiredProperty> {
/*
* The discriminator property.
*/
@Generated
private final String discriminator;
/*
* The aProperty property.
*/
@Generated
private final String aProperty;
/**
* Creates an instance of ParentWithRequiredProperty class.
*
* @param discriminator the discriminator value to set.
* @param aProperty the aProperty value to set.
*/
@Generated
protected ParentWithRequiredProperty(String discriminator, String aProperty) {
this.discriminator = discriminator;
this.aProperty = aProperty;
}
/**
* Get the discriminator property: The discriminator property.
*
* @return the discriminator value.
*/
@Generated
public String getDiscriminator() {
return this.discriminator;
}
/**
* Get the aProperty property: The aProperty property.
*
* @return the aProperty value.
*/
@Generated
public String getAProperty() {
return this.aProperty;
}
/**
* {@inheritDoc}
*/
@Generated
@Override
public JsonWriter toJson(JsonWriter jsonWriter) throws IOException {
jsonWriter.writeStartObject();
jsonWriter.writeStringField("discriminator", this.discriminator);
jsonWriter.writeStringField("aProperty", this.aProperty);
return jsonWriter.writeEndObject();
}
/**
* Reads an instance of ParentWithRequiredProperty from the JsonReader.
*
* @param jsonReader The JsonReader being read.
* @return An instance of ParentWithRequiredProperty 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 ParentWithRequiredProperty.
*/
@Generated
public static ParentWithRequiredProperty fromJson(JsonReader jsonReader) throws IOException {
return jsonReader.readObject(reader -> {
String discriminator = null;
String aProperty = null;
while (reader.nextToken() != JsonToken.END_OBJECT) {
String fieldName = reader.getFieldName();
reader.nextToken();
if ("discriminator".equals(fieldName)) {
discriminator = reader.getString();
} else if ("aProperty".equals(fieldName)) {
aProperty = reader.getString();
} else {
reader.skipChildren();
}
}
return new ParentWithRequiredProperty(discriminator, aProperty);
});
}
}

Просмотреть файл

@ -4,8 +4,7 @@
/**
* <!-- start generated doc -->
* Package containing the data models for Naming.
* description of Naming.
* Package containing the data models for DiscriminatorEdgeCases.
* <!-- end generated doc -->
*/
package com.cadl.naming.models;
package com.cadl.discriminatoredgecases.models;

Просмотреть файл

@ -4,8 +4,7 @@
/**
* <!-- start generated doc -->
* Package containing the classes for Naming.
* description of Naming.
* Package containing the classes for DiscriminatorEdgeCases.
* <!-- end generated doc -->
*/
package com.cadl.naming;
package com.cadl.discriminatoredgecases;

Просмотреть файл

@ -0,0 +1,21 @@
{
"flavor": "Azure",
"CrossLanguageDefinitionId": {
"com.cadl.discriminatoredgecases.DiscriminatorEdgeCasesAsyncClient": "Cadl.DiscriminatorEdgeCases.DiscriminatorEdgeCasesOp",
"com.cadl.discriminatoredgecases.DiscriminatorEdgeCasesAsyncClient.getChildNewDiscrim": "Cadl.DiscriminatorEdgeCases.DiscriminatorEdgeCasesOp.getChildNewDiscrim",
"com.cadl.discriminatoredgecases.DiscriminatorEdgeCasesAsyncClient.getChildNewDiscrimWithResponse": "Cadl.DiscriminatorEdgeCases.DiscriminatorEdgeCasesOp.getChildNewDiscrim",
"com.cadl.discriminatoredgecases.DiscriminatorEdgeCasesAsyncClient.getChildRequiredDiscrim": "Cadl.DiscriminatorEdgeCases.DiscriminatorEdgeCasesOp.getChildRequiredDiscrim",
"com.cadl.discriminatoredgecases.DiscriminatorEdgeCasesAsyncClient.getChildRequiredDiscrimWithResponse": "Cadl.DiscriminatorEdgeCases.DiscriminatorEdgeCasesOp.getChildRequiredDiscrim",
"com.cadl.discriminatoredgecases.DiscriminatorEdgeCasesClient": "Cadl.DiscriminatorEdgeCases.DiscriminatorEdgeCasesOp",
"com.cadl.discriminatoredgecases.DiscriminatorEdgeCasesClient.getChildNewDiscrim": "Cadl.DiscriminatorEdgeCases.DiscriminatorEdgeCasesOp.getChildNewDiscrim",
"com.cadl.discriminatoredgecases.DiscriminatorEdgeCasesClient.getChildNewDiscrimWithResponse": "Cadl.DiscriminatorEdgeCases.DiscriminatorEdgeCasesOp.getChildNewDiscrim",
"com.cadl.discriminatoredgecases.DiscriminatorEdgeCasesClient.getChildRequiredDiscrim": "Cadl.DiscriminatorEdgeCases.DiscriminatorEdgeCasesOp.getChildRequiredDiscrim",
"com.cadl.discriminatoredgecases.DiscriminatorEdgeCasesClient.getChildRequiredDiscrimWithResponse": "Cadl.DiscriminatorEdgeCases.DiscriminatorEdgeCasesOp.getChildRequiredDiscrim",
"com.cadl.discriminatoredgecases.DiscriminatorEdgeCasesClientBuilder": "Cadl.DiscriminatorEdgeCases.DiscriminatorEdgeCasesOp",
"com.cadl.discriminatoredgecases.models.ChildWithAnotherDiscriminator": "Cadl.DiscriminatorEdgeCases.ChildWithAnotherDiscriminator",
"com.cadl.discriminatoredgecases.models.ChildWithRequiredPropertyAsDiscriminator": "Cadl.DiscriminatorEdgeCases.ChildWithRequiredPropertyAsDiscriminator",
"com.cadl.discriminatoredgecases.models.GrandChildWithAnotherDiscriminator": "Cadl.DiscriminatorEdgeCases.GrandChildWithAnotherDiscriminator",
"com.cadl.discriminatoredgecases.models.GrandChildWithRequiredProperty": "Cadl.DiscriminatorEdgeCases.GrandChildWithRequiredProperty",
"com.cadl.discriminatoredgecases.models.ParentWithRequiredProperty": "Cadl.DiscriminatorEdgeCases.ParentWithRequiredProperty"
}
}

Просмотреть файл

@ -0,0 +1,38 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
// Code generated by Microsoft (R) TypeSpec Code Generator.
package com.cadl.discriminatoredgecases.generated;
// The Java test files under 'generated' package are generated for your reference.
// If you wish to modify these files, please copy them out of the 'generated' package, and modify there.
// See https://aka.ms/azsdk/dpg/java/tests for guide on adding a test.
import com.azure.core.http.HttpClient;
import com.azure.core.http.policy.HttpLogDetailLevel;
import com.azure.core.http.policy.HttpLogOptions;
import com.azure.core.test.TestMode;
import com.azure.core.test.TestProxyTestBase;
import com.azure.core.util.Configuration;
import com.cadl.discriminatoredgecases.DiscriminatorEdgeCasesClient;
import com.cadl.discriminatoredgecases.DiscriminatorEdgeCasesClientBuilder;
class DiscriminatorEdgeCasesClientTestBase extends TestProxyTestBase {
protected DiscriminatorEdgeCasesClient discriminatorEdgeCasesClient;
@Override
protected void beforeTest() {
DiscriminatorEdgeCasesClientBuilder discriminatorEdgeCasesClientbuilder
= new DiscriminatorEdgeCasesClientBuilder()
.endpoint(Configuration.getGlobalConfiguration().get("ENDPOINT", "endpoint"))
.httpClient(HttpClient.createDefault())
.httpLogOptions(new HttpLogOptions().setLogLevel(HttpLogDetailLevel.BASIC));
if (getTestMode() == TestMode.PLAYBACK) {
discriminatorEdgeCasesClientbuilder.httpClient(interceptorManager.getPlaybackClient());
} else if (getTestMode() == TestMode.RECORD) {
discriminatorEdgeCasesClientbuilder.addPolicy(interceptorManager.getRecordPolicy());
}
discriminatorEdgeCasesClient = discriminatorEdgeCasesClientbuilder.buildClient();
}
}

Просмотреть файл

@ -0,0 +1,54 @@
import "@typespec/rest";
import "@azure-tools/typespec-azure-core";
import "@azure-tools/typespec-client-generator-core";
using TypeSpec.Http;
using Azure.Core;
using Azure.ClientGenerator.Core;
@service({
title: "DiscriminatorEdgeCases",
})
namespace Cadl.DiscriminatorEdgeCases;
model ParentWithRequiredProperty {
discriminator: string;
aProperty: string;
}
@discriminator("discriminator")
model ChildWithRequiredPropertyAsDiscriminator extends ParentWithRequiredProperty {
anotherProperty: string;
}
@discriminator("differentDiscriminator")
model ChildWithAnotherDiscriminator extends ParentWithRequiredProperty {
yetAnotherProperty: string;
}
model GrandChildWithRequiredProperty extends ChildWithRequiredPropertyAsDiscriminator {
discriminator: "aValue";
}
model GrandChildWithAnotherDiscriminator extends ChildWithAnotherDiscriminator {
differentDiscriminator: "anotherValue";
}
@client({
service: Cadl.DiscriminatorEdgeCases,
name: "DiscriminatorEdgeCasesClient",
})
@route("/model")
interface DiscriminatorEdgeCasesOp {
@get
@route("/childrequireddiscrim")
getChildRequiredDiscrim(): {
@body body: ChildWithRequiredPropertyAsDiscriminator;
};
@get
@route("/childnewdiscrim")
getChildNewDiscrim(): {
@body body: ChildWithAnotherDiscriminator;
};
}

Просмотреть файл

@ -65,6 +65,7 @@
<configuration>
<finalName>${shade.finalName}</finalName>
<minimizeJar>true</minimizeJar>
<createDependencyReducedPom>false</createDependencyReducedPom>
<entryPoints>
<entryPoint>${shade.mainClass}</entryPoint>
</entryPoints>