diff --git a/core b/core index e6cf27481b..bdef8c0b9c 160000 --- a/core +++ b/core @@ -1 +1 @@ -Subproject commit e6cf27481b40f7b09e83c249cf3607bd6e1e3b99 +Subproject commit bdef8c0b9cc8cec9cd4e0cbe2b706bebd3688067 diff --git a/typespec-tests/src/main/java/tsptest/armstreamstyleserialization/models/SawShark.java b/typespec-tests/src/main/java/tsptest/armstreamstyleserialization/models/SawShark.java index dad701b3bc..49590e9c11 100644 --- a/typespec-tests/src/main/java/tsptest/armstreamstyleserialization/models/SawShark.java +++ b/typespec-tests/src/main/java/tsptest/armstreamstyleserialization/models/SawShark.java @@ -276,7 +276,6 @@ public void validate() { public JsonWriter toJson(JsonWriter jsonWriter) throws IOException { jsonWriter.writeStartObject(); jsonWriter.writeStringField("kind", this.kind); - jsonWriter.writeIntField("age", age()); jsonWriter.writeJsonField("properties", innerProperties()); jsonWriter.writeJsonField("anotherProperties", innerAnotherProperties()); jsonWriter.writeStringField("dna", this.dna); diff --git a/typespec-tests/src/main/java/tsptest/subclass/SubclassAsyncClient.java b/typespec-tests/src/main/java/tsptest/subclass/SubclassAsyncClient.java new file mode 100644 index 0000000000..b1dde9b3e0 --- /dev/null +++ b/typespec-tests/src/main/java/tsptest/subclass/SubclassAsyncClient.java @@ -0,0 +1,115 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +// Code generated by Microsoft (R) TypeSpec Code Generator. + +package tsptest.subclass; + +import com.azure.core.annotation.Generated; +import com.azure.core.annotation.ReturnType; +import com.azure.core.annotation.ServiceClient; +import com.azure.core.annotation.ServiceMethod; +import com.azure.core.exception.ClientAuthenticationException; +import com.azure.core.exception.HttpResponseException; +import com.azure.core.exception.ResourceModifiedException; +import com.azure.core.exception.ResourceNotFoundException; +import com.azure.core.http.rest.RequestOptions; +import com.azure.core.http.rest.Response; +import com.azure.core.util.BinaryData; +import com.azure.core.util.FluxUtil; +import reactor.core.publisher.Mono; +import tsptest.subclass.implementation.SubclassImpl; +import tsptest.subclass.models.Body; + +/** + * Initializes a new instance of the asynchronous SubclassClient type. + */ +@ServiceClient(builder = SubclassClientBuilder.class, isAsync = true) +public final class SubclassAsyncClient { + @Generated + private final SubclassImpl serviceClient; + + /** + * Initializes an instance of SubclassAsyncClient class. + * + * @param serviceClient the service client implementation. + */ + @Generated + SubclassAsyncClient(SubclassImpl serviceClient) { + this.serviceClient = serviceClient; + } + + /** + * The propertyInSubclass operation. + *

Request Body Schema

+ * + *
+     * {@code
+     * {
+     *     duplicateRequiredProperty (Optional): {
+     *         property: String (Required)
+     *         duplicateRequiredProperty: String (Required)
+     *     }
+     *     propertyChangedToRequired (Optional): {
+     *         propertyChangedToRequired: String (Required)
+     *     }
+     *     propertyChangedToConstant (Optional): {
+     *         propertyChangedToConstant: String (Required)
+     *     }
+     * }
+     * }
+     * 
+ * + *

Response Body Schema

+ * + *
+     * {@code
+     * {
+     *     duplicateRequiredProperty (Optional): {
+     *         property: String (Required)
+     *         duplicateRequiredProperty: String (Required)
+     *     }
+     *     propertyChangedToRequired (Optional): {
+     *         propertyChangedToRequired: String (Required)
+     *     }
+     *     propertyChangedToConstant (Optional): {
+     *         propertyChangedToConstant: String (Required)
+     *     }
+     * }
+     * }
+     * 
+ * + * @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 the response body along with {@link Response} on successful completion of {@link Mono}. + */ + @Generated + @ServiceMethod(returns = ReturnType.SINGLE) + public Mono> propertyInSubclassWithResponse(BinaryData body, RequestOptions requestOptions) { + return this.serviceClient.propertyInSubclassWithResponseAsync(body, requestOptions); + } + + /** + * The propertyInSubclass operation. + * + * @param body The body parameter. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws HttpResponseException thrown if the request is rejected by server. + * @throws ClientAuthenticationException thrown if the request is rejected by server on status code 401. + * @throws ResourceNotFoundException thrown if the request is rejected by server on status code 404. + * @throws ResourceModifiedException thrown if the request is rejected by server on status code 409. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return the response body on successful completion of {@link Mono}. + */ + @Generated + @ServiceMethod(returns = ReturnType.SINGLE) + public Mono propertyInSubclass(Body body) { + // Generated convenience method for propertyInSubclassWithResponse + RequestOptions requestOptions = new RequestOptions(); + return propertyInSubclassWithResponse(BinaryData.fromObject(body), requestOptions).flatMap(FluxUtil::toMono) + .map(protocolMethodData -> protocolMethodData.toObject(Body.class)); + } +} diff --git a/typespec-tests/src/main/java/tsptest/subclass/SubclassClient.java b/typespec-tests/src/main/java/tsptest/subclass/SubclassClient.java new file mode 100644 index 0000000000..775c767336 --- /dev/null +++ b/typespec-tests/src/main/java/tsptest/subclass/SubclassClient.java @@ -0,0 +1,113 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +// Code generated by Microsoft (R) TypeSpec Code Generator. + +package tsptest.subclass; + +import com.azure.core.annotation.Generated; +import com.azure.core.annotation.ReturnType; +import com.azure.core.annotation.ServiceClient; +import com.azure.core.annotation.ServiceMethod; +import com.azure.core.exception.ClientAuthenticationException; +import com.azure.core.exception.HttpResponseException; +import com.azure.core.exception.ResourceModifiedException; +import com.azure.core.exception.ResourceNotFoundException; +import com.azure.core.http.rest.RequestOptions; +import com.azure.core.http.rest.Response; +import com.azure.core.util.BinaryData; +import tsptest.subclass.implementation.SubclassImpl; +import tsptest.subclass.models.Body; + +/** + * Initializes a new instance of the synchronous SubclassClient type. + */ +@ServiceClient(builder = SubclassClientBuilder.class) +public final class SubclassClient { + @Generated + private final SubclassImpl serviceClient; + + /** + * Initializes an instance of SubclassClient class. + * + * @param serviceClient the service client implementation. + */ + @Generated + SubclassClient(SubclassImpl serviceClient) { + this.serviceClient = serviceClient; + } + + /** + * The propertyInSubclass operation. + *

Request Body Schema

+ * + *
+     * {@code
+     * {
+     *     duplicateRequiredProperty (Optional): {
+     *         property: String (Required)
+     *         duplicateRequiredProperty: String (Required)
+     *     }
+     *     propertyChangedToRequired (Optional): {
+     *         propertyChangedToRequired: String (Required)
+     *     }
+     *     propertyChangedToConstant (Optional): {
+     *         propertyChangedToConstant: String (Required)
+     *     }
+     * }
+     * }
+     * 
+ * + *

Response Body Schema

+ * + *
+     * {@code
+     * {
+     *     duplicateRequiredProperty (Optional): {
+     *         property: String (Required)
+     *         duplicateRequiredProperty: String (Required)
+     *     }
+     *     propertyChangedToRequired (Optional): {
+     *         propertyChangedToRequired: String (Required)
+     *     }
+     *     propertyChangedToConstant (Optional): {
+     *         propertyChangedToConstant: String (Required)
+     *     }
+     * }
+     * }
+     * 
+ * + * @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 the response body along with {@link Response}. + */ + @Generated + @ServiceMethod(returns = ReturnType.SINGLE) + public Response propertyInSubclassWithResponse(BinaryData body, RequestOptions requestOptions) { + return this.serviceClient.propertyInSubclassWithResponse(body, requestOptions); + } + + /** + * The propertyInSubclass operation. + * + * @param body The body parameter. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws HttpResponseException thrown if the request is rejected by server. + * @throws ClientAuthenticationException thrown if the request is rejected by server on status code 401. + * @throws ResourceNotFoundException thrown if the request is rejected by server on status code 404. + * @throws ResourceModifiedException thrown if the request is rejected by server on status code 409. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return the response. + */ + @Generated + @ServiceMethod(returns = ReturnType.SINGLE) + public Body propertyInSubclass(Body body) { + // Generated convenience method for propertyInSubclassWithResponse + RequestOptions requestOptions = new RequestOptions(); + return propertyInSubclassWithResponse(BinaryData.fromObject(body), requestOptions).getValue() + .toObject(Body.class); + } +} diff --git a/typespec-tests/src/main/java/tsptest/subclass/SubclassClientBuilder.java b/typespec-tests/src/main/java/tsptest/subclass/SubclassClientBuilder.java new file mode 100644 index 0000000000..13b233af8f --- /dev/null +++ b/typespec-tests/src/main/java/tsptest/subclass/SubclassClientBuilder.java @@ -0,0 +1,287 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +// Code generated by Microsoft (R) TypeSpec Code Generator. + +package tsptest.subclass; + +import com.azure.core.annotation.Generated; +import com.azure.core.annotation.ServiceClientBuilder; +import com.azure.core.client.traits.ConfigurationTrait; +import com.azure.core.client.traits.EndpointTrait; +import com.azure.core.client.traits.HttpTrait; +import com.azure.core.http.HttpClient; +import com.azure.core.http.HttpHeaders; +import com.azure.core.http.HttpPipeline; +import com.azure.core.http.HttpPipelineBuilder; +import com.azure.core.http.HttpPipelinePosition; +import com.azure.core.http.policy.AddDatePolicy; +import com.azure.core.http.policy.AddHeadersFromContextPolicy; +import com.azure.core.http.policy.AddHeadersPolicy; +import com.azure.core.http.policy.HttpLogOptions; +import com.azure.core.http.policy.HttpLoggingPolicy; +import com.azure.core.http.policy.HttpPipelinePolicy; +import com.azure.core.http.policy.HttpPolicyProviders; +import com.azure.core.http.policy.RequestIdPolicy; +import com.azure.core.http.policy.RetryOptions; +import com.azure.core.http.policy.RetryPolicy; +import com.azure.core.http.policy.UserAgentPolicy; +import com.azure.core.util.ClientOptions; +import com.azure.core.util.Configuration; +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 java.util.ArrayList; +import java.util.List; +import java.util.Map; +import java.util.Objects; +import tsptest.subclass.implementation.SubclassClientImpl; + +/** + * A builder for creating a new instance of the SubclassClient type. + */ +@ServiceClientBuilder(serviceClients = { SubclassClient.class, SubclassAsyncClient.class }) +public final class SubclassClientBuilder implements HttpTrait, + ConfigurationTrait, EndpointTrait { + @Generated + private static final String SDK_NAME = "name"; + + @Generated + private static final String SDK_VERSION = "version"; + + @Generated + private static final Map PROPERTIES = CoreUtils.getProperties("tsptest-subclass.properties"); + + @Generated + private final List pipelinePolicies; + + /** + * Create an instance of the SubclassClientBuilder. + */ + @Generated + public SubclassClientBuilder() { + this.pipelinePolicies = new ArrayList<>(); + } + + /* + * The HTTP client used to send the request. + */ + @Generated + private HttpClient httpClient; + + /** + * {@inheritDoc}. + */ + @Generated + @Override + public SubclassClientBuilder httpClient(HttpClient httpClient) { + this.httpClient = httpClient; + return this; + } + + /* + * The HTTP pipeline to send requests through. + */ + @Generated + private HttpPipeline pipeline; + + /** + * {@inheritDoc}. + */ + @Generated + @Override + public SubclassClientBuilder pipeline(HttpPipeline pipeline) { + if (this.pipeline != null && pipeline == null) { + LOGGER.atInfo().log("HttpPipeline is being set to 'null' when it was previously configured."); + } + this.pipeline = pipeline; + return this; + } + + /* + * The logging configuration for HTTP requests and responses. + */ + @Generated + private HttpLogOptions httpLogOptions; + + /** + * {@inheritDoc}. + */ + @Generated + @Override + public SubclassClientBuilder httpLogOptions(HttpLogOptions httpLogOptions) { + this.httpLogOptions = httpLogOptions; + return this; + } + + /* + * The client options such as application ID and custom headers to set on a request. + */ + @Generated + private ClientOptions clientOptions; + + /** + * {@inheritDoc}. + */ + @Generated + @Override + public SubclassClientBuilder clientOptions(ClientOptions clientOptions) { + this.clientOptions = clientOptions; + return this; + } + + /* + * The retry options to configure retry policy for failed requests. + */ + @Generated + private RetryOptions retryOptions; + + /** + * {@inheritDoc}. + */ + @Generated + @Override + public SubclassClientBuilder retryOptions(RetryOptions retryOptions) { + this.retryOptions = retryOptions; + return this; + } + + /** + * {@inheritDoc}. + */ + @Generated + @Override + public SubclassClientBuilder addPolicy(HttpPipelinePolicy customPolicy) { + Objects.requireNonNull(customPolicy, "'customPolicy' cannot be null."); + pipelinePolicies.add(customPolicy); + return this; + } + + /* + * The configuration store that is used during construction of the service client. + */ + @Generated + private Configuration configuration; + + /** + * {@inheritDoc}. + */ + @Generated + @Override + public SubclassClientBuilder configuration(Configuration configuration) { + this.configuration = configuration; + return this; + } + + /* + * The service endpoint + */ + @Generated + private String endpoint; + + /** + * {@inheritDoc}. + */ + @Generated + @Override + public SubclassClientBuilder endpoint(String endpoint) { + this.endpoint = endpoint; + return this; + } + + /* + * The retry policy that will attempt to retry failed requests, if applicable. + */ + @Generated + private RetryPolicy retryPolicy; + + /** + * Sets The retry policy that will attempt to retry failed requests, if applicable. + * + * @param retryPolicy the retryPolicy value. + * @return the SubclassClientBuilder. + */ + @Generated + public SubclassClientBuilder retryPolicy(RetryPolicy retryPolicy) { + this.retryPolicy = retryPolicy; + return this; + } + + /** + * Builds an instance of SubclassClientImpl with the provided parameters. + * + * @return an instance of SubclassClientImpl. + */ + @Generated + private SubclassClientImpl buildInnerClient() { + this.validateClient(); + HttpPipeline localPipeline = (pipeline != null) ? pipeline : createHttpPipeline(); + SubclassClientImpl client + = new SubclassClientImpl(localPipeline, JacksonAdapter.createDefaultSerializerAdapter(), this.endpoint); + return client; + } + + @Generated + private void validateClient() { + // This method is invoked from 'buildInnerClient'/'buildClient' method. + // Developer can customize this method, to validate that the necessary conditions are met for the new client. + Objects.requireNonNull(endpoint, "'endpoint' cannot be null."); + } + + @Generated + private HttpPipeline createHttpPipeline() { + Configuration buildConfiguration + = (configuration == null) ? Configuration.getGlobalConfiguration() : configuration; + HttpLogOptions localHttpLogOptions = this.httpLogOptions == null ? new HttpLogOptions() : this.httpLogOptions; + ClientOptions localClientOptions = this.clientOptions == null ? new ClientOptions() : this.clientOptions; + List policies = new ArrayList<>(); + String clientName = PROPERTIES.getOrDefault(SDK_NAME, "UnknownName"); + String clientVersion = PROPERTIES.getOrDefault(SDK_VERSION, "UnknownVersion"); + String applicationId = CoreUtils.getApplicationId(localClientOptions, localHttpLogOptions); + policies.add(new UserAgentPolicy(applicationId, clientName, clientVersion, buildConfiguration)); + policies.add(new RequestIdPolicy()); + policies.add(new AddHeadersFromContextPolicy()); + HttpHeaders headers = CoreUtils.createHttpHeadersFromClientOptions(localClientOptions); + if (headers != null) { + policies.add(new AddHeadersPolicy(headers)); + } + this.pipelinePolicies.stream() + .filter(p -> p.getPipelinePosition() == HttpPipelinePosition.PER_CALL) + .forEach(p -> policies.add(p)); + HttpPolicyProviders.addBeforeRetryPolicies(policies); + policies.add(ClientBuilderUtil.validateAndGetRetryPolicy(retryPolicy, retryOptions, new RetryPolicy())); + policies.add(new AddDatePolicy()); + this.pipelinePolicies.stream() + .filter(p -> p.getPipelinePosition() == HttpPipelinePosition.PER_RETRY) + .forEach(p -> policies.add(p)); + HttpPolicyProviders.addAfterRetryPolicies(policies); + policies.add(new HttpLoggingPolicy(localHttpLogOptions)); + HttpPipeline httpPipeline = new HttpPipelineBuilder().policies(policies.toArray(new HttpPipelinePolicy[0])) + .httpClient(httpClient) + .clientOptions(localClientOptions) + .build(); + return httpPipeline; + } + + /** + * Builds an instance of SubclassAsyncClient class. + * + * @return an instance of SubclassAsyncClient. + */ + @Generated + public SubclassAsyncClient buildAsyncClient() { + return new SubclassAsyncClient(buildInnerClient().getSubclass()); + } + + /** + * Builds an instance of SubclassClient class. + * + * @return an instance of SubclassClient. + */ + @Generated + public SubclassClient buildClient() { + return new SubclassClient(buildInnerClient().getSubclass()); + } + + private static final ClientLogger LOGGER = new ClientLogger(SubclassClientBuilder.class); +} diff --git a/typespec-tests/src/main/java/tsptest/subclass/implementation/SubclassClientImpl.java b/typespec-tests/src/main/java/tsptest/subclass/implementation/SubclassClientImpl.java new file mode 100644 index 0000000000..5566742f36 --- /dev/null +++ b/typespec-tests/src/main/java/tsptest/subclass/implementation/SubclassClientImpl.java @@ -0,0 +1,107 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +// Code generated by Microsoft (R) TypeSpec Code Generator. + +package tsptest.subclass.implementation; + +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.util.serializer.JacksonAdapter; +import com.azure.core.util.serializer.SerializerAdapter; + +/** + * Initializes a new instance of the SubclassClient type. + */ +public final class SubclassClientImpl { + /** + * Service host. + */ + private final String endpoint; + + /** + * Gets Service host. + * + * @return the endpoint value. + */ + public String getEndpoint() { + return this.endpoint; + } + + /** + * 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; + } + + /** + * The SubclassImpl object to access its operations. + */ + private final SubclassImpl subclass; + + /** + * Gets the SubclassImpl object to access its operations. + * + * @return the SubclassImpl object. + */ + public SubclassImpl getSubclass() { + return this.subclass; + } + + /** + * Initializes an instance of SubclassClient client. + * + * @param endpoint Service host. + */ + public SubclassClientImpl(String endpoint) { + this(new HttpPipelineBuilder().policies(new UserAgentPolicy(), new RetryPolicy()).build(), + JacksonAdapter.createDefaultSerializerAdapter(), endpoint); + } + + /** + * Initializes an instance of SubclassClient client. + * + * @param httpPipeline The HTTP pipeline to send requests through. + * @param endpoint Service host. + */ + public SubclassClientImpl(HttpPipeline httpPipeline, String endpoint) { + this(httpPipeline, JacksonAdapter.createDefaultSerializerAdapter(), endpoint); + } + + /** + * Initializes an instance of SubclassClient 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 SubclassClientImpl(HttpPipeline httpPipeline, SerializerAdapter serializerAdapter, String endpoint) { + this.httpPipeline = httpPipeline; + this.serializerAdapter = serializerAdapter; + this.endpoint = endpoint; + this.subclass = new SubclassImpl(this); + } +} diff --git a/typespec-tests/src/main/java/tsptest/subclass/implementation/SubclassImpl.java b/typespec-tests/src/main/java/tsptest/subclass/implementation/SubclassImpl.java new file mode 100644 index 0000000000..92a552910a --- /dev/null +++ b/typespec-tests/src/main/java/tsptest/subclass/implementation/SubclassImpl.java @@ -0,0 +1,193 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +// Code generated by Microsoft (R) TypeSpec Code Generator. + +package tsptest.subclass.implementation; + +import com.azure.core.annotation.BodyParam; +import com.azure.core.annotation.ExpectedResponses; +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.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.BinaryData; +import com.azure.core.util.Context; +import com.azure.core.util.FluxUtil; +import reactor.core.publisher.Mono; + +/** + * An instance of this class provides access to all the operations defined in Subclass. + */ +public final class SubclassImpl { + /** + * The proxy service used to perform REST calls. + */ + private final SubclassService service; + + /** + * The service client containing this operation class. + */ + private final SubclassClientImpl client; + + /** + * Initializes an instance of SubclassImpl. + * + * @param client the instance of the service client containing this operation class. + */ + SubclassImpl(SubclassClientImpl client) { + this.service = RestProxy.create(SubclassService.class, client.getHttpPipeline(), client.getSerializerAdapter()); + this.client = client; + } + + /** + * The interface defining all the services for SubclassClientSubclass to be used by the proxy service to perform + * REST calls. + */ + @Host("{endpoint}") + @ServiceInterface(name = "SubclassClientSubclass") + public interface SubclassService { + @Post("/subclass/property-in-subclass") + @ExpectedResponses({ 200 }) + @UnexpectedResponseExceptionType(value = ClientAuthenticationException.class, code = { 401 }) + @UnexpectedResponseExceptionType(value = ResourceNotFoundException.class, code = { 404 }) + @UnexpectedResponseExceptionType(value = ResourceModifiedException.class, code = { 409 }) + @UnexpectedResponseExceptionType(HttpResponseException.class) + Mono> propertyInSubclass(@HostParam("endpoint") String endpoint, + @HeaderParam("Content-Type") String contentType, @HeaderParam("Accept") String accept, + @BodyParam("application/json") BinaryData body, RequestOptions requestOptions, Context context); + + @Post("/subclass/property-in-subclass") + @ExpectedResponses({ 200 }) + @UnexpectedResponseExceptionType(value = ClientAuthenticationException.class, code = { 401 }) + @UnexpectedResponseExceptionType(value = ResourceNotFoundException.class, code = { 404 }) + @UnexpectedResponseExceptionType(value = ResourceModifiedException.class, code = { 409 }) + @UnexpectedResponseExceptionType(HttpResponseException.class) + Response propertyInSubclassSync(@HostParam("endpoint") String endpoint, + @HeaderParam("Content-Type") String contentType, @HeaderParam("Accept") String accept, + @BodyParam("application/json") BinaryData body, RequestOptions requestOptions, Context context); + } + + /** + * The propertyInSubclass operation. + *

Request Body Schema

+ * + *
+     * {@code
+     * {
+     *     duplicateRequiredProperty (Optional): {
+     *         property: String (Required)
+     *         duplicateRequiredProperty: String (Required)
+     *     }
+     *     propertyChangedToRequired (Optional): {
+     *         propertyChangedToRequired: String (Required)
+     *     }
+     *     propertyChangedToConstant (Optional): {
+     *         propertyChangedToConstant: String (Required)
+     *     }
+     * }
+     * }
+     * 
+ * + *

Response Body Schema

+ * + *
+     * {@code
+     * {
+     *     duplicateRequiredProperty (Optional): {
+     *         property: String (Required)
+     *         duplicateRequiredProperty: String (Required)
+     *     }
+     *     propertyChangedToRequired (Optional): {
+     *         propertyChangedToRequired: String (Required)
+     *     }
+     *     propertyChangedToConstant (Optional): {
+     *         propertyChangedToConstant: String (Required)
+     *     }
+     * }
+     * }
+     * 
+ * + * @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 the response body along with {@link Response} on successful completion of {@link Mono}. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + public Mono> propertyInSubclassWithResponseAsync(BinaryData body, + RequestOptions requestOptions) { + final String contentType = "application/json"; + final String accept = "application/json"; + return FluxUtil.withContext(context -> service.propertyInSubclass(this.client.getEndpoint(), contentType, + accept, body, requestOptions, context)); + } + + /** + * The propertyInSubclass operation. + *

Request Body Schema

+ * + *
+     * {@code
+     * {
+     *     duplicateRequiredProperty (Optional): {
+     *         property: String (Required)
+     *         duplicateRequiredProperty: String (Required)
+     *     }
+     *     propertyChangedToRequired (Optional): {
+     *         propertyChangedToRequired: String (Required)
+     *     }
+     *     propertyChangedToConstant (Optional): {
+     *         propertyChangedToConstant: String (Required)
+     *     }
+     * }
+     * }
+     * 
+ * + *

Response Body Schema

+ * + *
+     * {@code
+     * {
+     *     duplicateRequiredProperty (Optional): {
+     *         property: String (Required)
+     *         duplicateRequiredProperty: String (Required)
+     *     }
+     *     propertyChangedToRequired (Optional): {
+     *         propertyChangedToRequired: String (Required)
+     *     }
+     *     propertyChangedToConstant (Optional): {
+     *         propertyChangedToConstant: String (Required)
+     *     }
+     * }
+     * }
+     * 
+ * + * @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 the response body along with {@link Response}. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + public Response propertyInSubclassWithResponse(BinaryData body, RequestOptions requestOptions) { + final String contentType = "application/json"; + final String accept = "application/json"; + return service.propertyInSubclassSync(this.client.getEndpoint(), contentType, accept, body, requestOptions, + Context.NONE); + } +} diff --git a/typespec-tests/src/main/java/tsptest/subclass/implementation/package-info.java b/typespec-tests/src/main/java/tsptest/subclass/implementation/package-info.java new file mode 100644 index 0000000000..4cc0977cd8 --- /dev/null +++ b/typespec-tests/src/main/java/tsptest/subclass/implementation/package-info.java @@ -0,0 +1,10 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +// Code generated by Microsoft (R) TypeSpec Code Generator. + +/** + * + * Package containing the implementations for Subclass. + * + */ +package tsptest.subclass.implementation; diff --git a/typespec-tests/src/main/java/tsptest/subclass/models/Body.java b/typespec-tests/src/main/java/tsptest/subclass/models/Body.java new file mode 100644 index 0000000000..432ee35a8b --- /dev/null +++ b/typespec-tests/src/main/java/tsptest/subclass/models/Body.java @@ -0,0 +1,154 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +// Code generated by Microsoft (R) TypeSpec Code Generator. + +package tsptest.subclass.models; + +import com.azure.core.annotation.Fluent; +import com.azure.core.annotation.Generated; +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 Body model. + */ +@Fluent +public final class Body implements JsonSerializable { + /* + * The duplicateRequiredProperty property. + */ + @Generated + private DuplicateRequiredProperty duplicateRequiredProperty; + + /* + * The propertyChangedToRequired property. + */ + @Generated + private PropertyChangedToRequired propertyChangedToRequired; + + /* + * The propertyChangedToConstant property. + */ + @Generated + private PropertyChangedToConstant propertyChangedToConstant; + + /** + * Creates an instance of Body class. + */ + @Generated + public Body() { + } + + /** + * Get the duplicateRequiredProperty property: The duplicateRequiredProperty property. + * + * @return the duplicateRequiredProperty value. + */ + @Generated + public DuplicateRequiredProperty getDuplicateRequiredProperty() { + return this.duplicateRequiredProperty; + } + + /** + * Set the duplicateRequiredProperty property: The duplicateRequiredProperty property. + * + * @param duplicateRequiredProperty the duplicateRequiredProperty value to set. + * @return the Body object itself. + */ + @Generated + public Body setDuplicateRequiredProperty(DuplicateRequiredProperty duplicateRequiredProperty) { + this.duplicateRequiredProperty = duplicateRequiredProperty; + return this; + } + + /** + * Get the propertyChangedToRequired property: The propertyChangedToRequired property. + * + * @return the propertyChangedToRequired value. + */ + @Generated + public PropertyChangedToRequired getPropertyChangedToRequired() { + return this.propertyChangedToRequired; + } + + /** + * Set the propertyChangedToRequired property: The propertyChangedToRequired property. + * + * @param propertyChangedToRequired the propertyChangedToRequired value to set. + * @return the Body object itself. + */ + @Generated + public Body setPropertyChangedToRequired(PropertyChangedToRequired propertyChangedToRequired) { + this.propertyChangedToRequired = propertyChangedToRequired; + return this; + } + + /** + * Get the propertyChangedToConstant property: The propertyChangedToConstant property. + * + * @return the propertyChangedToConstant value. + */ + @Generated + public PropertyChangedToConstant getPropertyChangedToConstant() { + return this.propertyChangedToConstant; + } + + /** + * Set the propertyChangedToConstant property: The propertyChangedToConstant property. + * + * @param propertyChangedToConstant the propertyChangedToConstant value to set. + * @return the Body object itself. + */ + @Generated + public Body setPropertyChangedToConstant(PropertyChangedToConstant propertyChangedToConstant) { + this.propertyChangedToConstant = propertyChangedToConstant; + return this; + } + + /** + * {@inheritDoc} + */ + @Generated + @Override + public JsonWriter toJson(JsonWriter jsonWriter) throws IOException { + jsonWriter.writeStartObject(); + jsonWriter.writeJsonField("duplicateRequiredProperty", this.duplicateRequiredProperty); + jsonWriter.writeJsonField("propertyChangedToRequired", this.propertyChangedToRequired); + jsonWriter.writeJsonField("propertyChangedToConstant", this.propertyChangedToConstant); + return jsonWriter.writeEndObject(); + } + + /** + * Reads an instance of Body from the JsonReader. + * + * @param jsonReader The JsonReader being read. + * @return An instance of Body if the JsonReader was pointing to an instance of it, or null if it was pointing to + * JSON null. + * @throws IOException If an error occurs while reading the Body. + */ + @Generated + public static Body fromJson(JsonReader jsonReader) throws IOException { + return jsonReader.readObject(reader -> { + Body deserializedBody = new Body(); + while (reader.nextToken() != JsonToken.END_OBJECT) { + String fieldName = reader.getFieldName(); + reader.nextToken(); + + if ("duplicateRequiredProperty".equals(fieldName)) { + deserializedBody.duplicateRequiredProperty = DuplicateRequiredProperty.fromJson(reader); + } else if ("propertyChangedToRequired".equals(fieldName)) { + deserializedBody.propertyChangedToRequired = PropertyChangedToRequired.fromJson(reader); + } else if ("propertyChangedToConstant".equals(fieldName)) { + deserializedBody.propertyChangedToConstant = PropertyChangedToConstant.fromJson(reader); + } else { + reader.skipChildren(); + } + } + + return deserializedBody; + }); + } +} diff --git a/typespec-tests/src/main/java/tsptest/subclass/models/DuplicateRequiredProperty.java b/typespec-tests/src/main/java/tsptest/subclass/models/DuplicateRequiredProperty.java new file mode 100644 index 0000000000..0444173953 --- /dev/null +++ b/typespec-tests/src/main/java/tsptest/subclass/models/DuplicateRequiredProperty.java @@ -0,0 +1,88 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +// Code generated by Microsoft (R) TypeSpec Code Generator. + +package tsptest.subclass.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 DuplicateRequiredProperty model. + */ +@Immutable +public final class DuplicateRequiredProperty extends DuplicateRequiredPropertyParent { + /* + * The duplicateRequiredProperty property. + */ + @Generated + private final String newRequiredProperty; + + /** + * Creates an instance of DuplicateRequiredProperty class. + * + * @param requiredProperty the requiredProperty value to set. + * @param newRequiredProperty the newRequiredProperty value to set. + */ + @Generated + public DuplicateRequiredProperty(String requiredProperty, String newRequiredProperty) { + super(requiredProperty, newRequiredProperty); + this.newRequiredProperty = newRequiredProperty; + } + + /** + * Get the newRequiredProperty property: The duplicateRequiredProperty property. + * + * @return the newRequiredProperty value. + */ + @Generated + public String getNewRequiredProperty() { + return this.newRequiredProperty; + } + + /** + * {@inheritDoc} + */ + @Generated + @Override + public JsonWriter toJson(JsonWriter jsonWriter) throws IOException { + jsonWriter.writeStartObject(); + jsonWriter.writeStringField("property", getRequiredProperty()); + jsonWriter.writeStringField("duplicateRequiredProperty", this.newRequiredProperty); + return jsonWriter.writeEndObject(); + } + + /** + * Reads an instance of DuplicateRequiredProperty from the JsonReader. + * + * @param jsonReader The JsonReader being read. + * @return An instance of DuplicateRequiredProperty 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 DuplicateRequiredProperty. + */ + @Generated + public static DuplicateRequiredProperty fromJson(JsonReader jsonReader) throws IOException { + return jsonReader.readObject(reader -> { + String requiredProperty = null; + String newRequiredProperty = null; + while (reader.nextToken() != JsonToken.END_OBJECT) { + String fieldName = reader.getFieldName(); + reader.nextToken(); + + if ("property".equals(fieldName)) { + requiredProperty = reader.getString(); + } else if ("duplicateRequiredProperty".equals(fieldName)) { + newRequiredProperty = reader.getString(); + } else { + reader.skipChildren(); + } + } + return new DuplicateRequiredProperty(requiredProperty, newRequiredProperty); + }); + } +} diff --git a/typespec-tests/src/main/java/tsptest/subclass/models/DuplicateRequiredPropertyParent.java b/typespec-tests/src/main/java/tsptest/subclass/models/DuplicateRequiredPropertyParent.java new file mode 100644 index 0000000000..14989bc2da --- /dev/null +++ b/typespec-tests/src/main/java/tsptest/subclass/models/DuplicateRequiredPropertyParent.java @@ -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 tsptest.subclass.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 DuplicateRequiredPropertyParent model. + */ +@Immutable +public class DuplicateRequiredPropertyParent implements JsonSerializable { + /* + * The property property. + */ + @Generated + private final String requiredProperty; + + /* + * The duplicateRequiredProperty property. + */ + @Generated + private final String duplicateRequiredProperty; + + /** + * Creates an instance of DuplicateRequiredPropertyParent class. + * + * @param requiredProperty the requiredProperty value to set. + * @param duplicateRequiredProperty the duplicateRequiredProperty value to set. + */ + @Generated + public DuplicateRequiredPropertyParent(String requiredProperty, String duplicateRequiredProperty) { + this.requiredProperty = requiredProperty; + this.duplicateRequiredProperty = duplicateRequiredProperty; + } + + /** + * Get the requiredProperty property: The property property. + * + * @return the requiredProperty value. + */ + @Generated + public String getRequiredProperty() { + return this.requiredProperty; + } + + /** + * Get the duplicateRequiredProperty property: The duplicateRequiredProperty property. + * + * @return the duplicateRequiredProperty value. + */ + @Generated + public String getDuplicateRequiredProperty() { + return this.duplicateRequiredProperty; + } + + /** + * {@inheritDoc} + */ + @Generated + @Override + public JsonWriter toJson(JsonWriter jsonWriter) throws IOException { + jsonWriter.writeStartObject(); + jsonWriter.writeStringField("property", this.requiredProperty); + jsonWriter.writeStringField("duplicateRequiredProperty", this.duplicateRequiredProperty); + return jsonWriter.writeEndObject(); + } + + /** + * Reads an instance of DuplicateRequiredPropertyParent from the JsonReader. + * + * @param jsonReader The JsonReader being read. + * @return An instance of DuplicateRequiredPropertyParent 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 DuplicateRequiredPropertyParent. + */ + @Generated + public static DuplicateRequiredPropertyParent fromJson(JsonReader jsonReader) throws IOException { + return jsonReader.readObject(reader -> { + String requiredProperty = null; + String duplicateRequiredProperty = null; + while (reader.nextToken() != JsonToken.END_OBJECT) { + String fieldName = reader.getFieldName(); + reader.nextToken(); + + if ("property".equals(fieldName)) { + requiredProperty = reader.getString(); + } else if ("duplicateRequiredProperty".equals(fieldName)) { + duplicateRequiredProperty = reader.getString(); + } else { + reader.skipChildren(); + } + } + return new DuplicateRequiredPropertyParent(requiredProperty, duplicateRequiredProperty); + }); + } +} diff --git a/typespec-tests/src/main/java/tsptest/subclass/models/PropertyChangedToConstant.java b/typespec-tests/src/main/java/tsptest/subclass/models/PropertyChangedToConstant.java new file mode 100644 index 0000000000..4112d8e0e6 --- /dev/null +++ b/typespec-tests/src/main/java/tsptest/subclass/models/PropertyChangedToConstant.java @@ -0,0 +1,77 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +// Code generated by Microsoft (R) TypeSpec Code Generator. + +package tsptest.subclass.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 PropertyChangedToConstant model. + */ +@Immutable +public final class PropertyChangedToConstant extends PropertyChangedToConstantParent { + /* + * The propertyChangedToConstant property. + */ + @Generated + private final String propertyChangedToConstant = "constantValue"; + + /** + * Creates an instance of PropertyChangedToConstant class. + */ + @Generated + public PropertyChangedToConstant() { + super("constantValue"); + } + + /** + * Get the propertyChangedToConstant property: The propertyChangedToConstant property. + * + * @return the propertyChangedToConstant value. + */ + @Generated + public String getPropertyChangedToConstant() { + return this.propertyChangedToConstant; + } + + /** + * {@inheritDoc} + */ + @Generated + @Override + public JsonWriter toJson(JsonWriter jsonWriter) throws IOException { + jsonWriter.writeStartObject(); + jsonWriter.writeStringField("propertyChangedToConstant", this.propertyChangedToConstant); + return jsonWriter.writeEndObject(); + } + + /** + * Reads an instance of PropertyChangedToConstant from the JsonReader. + * + * @param jsonReader The JsonReader being read. + * @return An instance of PropertyChangedToConstant 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 PropertyChangedToConstant. + */ + @Generated + public static PropertyChangedToConstant fromJson(JsonReader jsonReader) throws IOException { + return jsonReader.readObject(reader -> { + PropertyChangedToConstant deserializedPropertyChangedToConstant = new PropertyChangedToConstant(); + while (reader.nextToken() != JsonToken.END_OBJECT) { + String fieldName = reader.getFieldName(); + reader.nextToken(); + + reader.skipChildren(); + } + + return deserializedPropertyChangedToConstant; + }); + } +} diff --git a/typespec-tests/src/main/java/tsptest/subclass/models/PropertyChangedToConstantParent.java b/typespec-tests/src/main/java/tsptest/subclass/models/PropertyChangedToConstantParent.java new file mode 100644 index 0000000000..42ec9ff3a1 --- /dev/null +++ b/typespec-tests/src/main/java/tsptest/subclass/models/PropertyChangedToConstantParent.java @@ -0,0 +1,83 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +// Code generated by Microsoft (R) TypeSpec Code Generator. + +package tsptest.subclass.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 PropertyChangedToConstantParent model. + */ +@Immutable +public class PropertyChangedToConstantParent implements JsonSerializable { + /* + * The propertyChangedToConstant property. + */ + @Generated + private final String propertyChangedToConstant; + + /** + * Creates an instance of PropertyChangedToConstantParent class. + * + * @param propertyChangedToConstant the propertyChangedToConstant value to set. + */ + @Generated + public PropertyChangedToConstantParent(String propertyChangedToConstant) { + this.propertyChangedToConstant = propertyChangedToConstant; + } + + /** + * Get the propertyChangedToConstant property: The propertyChangedToConstant property. + * + * @return the propertyChangedToConstant value. + */ + @Generated + public String getPropertyChangedToConstant() { + return this.propertyChangedToConstant; + } + + /** + * {@inheritDoc} + */ + @Generated + @Override + public JsonWriter toJson(JsonWriter jsonWriter) throws IOException { + jsonWriter.writeStartObject(); + jsonWriter.writeStringField("propertyChangedToConstant", this.propertyChangedToConstant); + return jsonWriter.writeEndObject(); + } + + /** + * Reads an instance of PropertyChangedToConstantParent from the JsonReader. + * + * @param jsonReader The JsonReader being read. + * @return An instance of PropertyChangedToConstantParent 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 PropertyChangedToConstantParent. + */ + @Generated + public static PropertyChangedToConstantParent fromJson(JsonReader jsonReader) throws IOException { + return jsonReader.readObject(reader -> { + String propertyChangedToConstant = null; + while (reader.nextToken() != JsonToken.END_OBJECT) { + String fieldName = reader.getFieldName(); + reader.nextToken(); + + if ("propertyChangedToConstant".equals(fieldName)) { + propertyChangedToConstant = reader.getString(); + } else { + reader.skipChildren(); + } + } + return new PropertyChangedToConstantParent(propertyChangedToConstant); + }); + } +} diff --git a/typespec-tests/src/main/java/tsptest/subclass/models/PropertyChangedToRequired.java b/typespec-tests/src/main/java/tsptest/subclass/models/PropertyChangedToRequired.java new file mode 100644 index 0000000000..b71da97a6a --- /dev/null +++ b/typespec-tests/src/main/java/tsptest/subclass/models/PropertyChangedToRequired.java @@ -0,0 +1,82 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +// Code generated by Microsoft (R) TypeSpec Code Generator. + +package tsptest.subclass.models; + +import com.azure.core.annotation.Fluent; +import com.azure.core.annotation.Generated; +import com.azure.json.JsonReader; +import com.azure.json.JsonToken; +import com.azure.json.JsonWriter; +import java.io.IOException; + +/** + * The PropertyChangedToRequired model. + */ +@Fluent +public final class PropertyChangedToRequired extends PropertyChangedToRequiredParent { + /* + * The propertyChangedToRequired property. + */ + @Generated + private final String propertyChangedToRequired; + + /** + * Creates an instance of PropertyChangedToRequired class. + * + * @param propertyChangedToRequired the propertyChangedToRequired value to set. + */ + @Generated + public PropertyChangedToRequired(String propertyChangedToRequired) { + this.propertyChangedToRequired = propertyChangedToRequired; + } + + /** + * Get the propertyChangedToRequired property: The propertyChangedToRequired property. + * + * @return the propertyChangedToRequired value. + */ + @Generated + public String getPropertyChangedToRequired() { + return this.propertyChangedToRequired; + } + + /** + * {@inheritDoc} + */ + @Generated + @Override + public JsonWriter toJson(JsonWriter jsonWriter) throws IOException { + jsonWriter.writeStartObject(); + jsonWriter.writeStringField("propertyChangedToRequired", this.propertyChangedToRequired); + return jsonWriter.writeEndObject(); + } + + /** + * Reads an instance of PropertyChangedToRequired from the JsonReader. + * + * @param jsonReader The JsonReader being read. + * @return An instance of PropertyChangedToRequired 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 PropertyChangedToRequired. + */ + @Generated + public static PropertyChangedToRequired fromJson(JsonReader jsonReader) throws IOException { + return jsonReader.readObject(reader -> { + String propertyChangedToRequired = null; + while (reader.nextToken() != JsonToken.END_OBJECT) { + String fieldName = reader.getFieldName(); + reader.nextToken(); + + if ("propertyChangedToRequired".equals(fieldName)) { + propertyChangedToRequired = reader.getString(); + } else { + reader.skipChildren(); + } + } + return new PropertyChangedToRequired(propertyChangedToRequired); + }); + } +} diff --git a/typespec-tests/src/main/java/tsptest/subclass/models/PropertyChangedToRequiredParent.java b/typespec-tests/src/main/java/tsptest/subclass/models/PropertyChangedToRequiredParent.java new file mode 100644 index 0000000000..2ab1511ea6 --- /dev/null +++ b/typespec-tests/src/main/java/tsptest/subclass/models/PropertyChangedToRequiredParent.java @@ -0,0 +1,93 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +// Code generated by Microsoft (R) TypeSpec Code Generator. + +package tsptest.subclass.models; + +import com.azure.core.annotation.Fluent; +import com.azure.core.annotation.Generated; +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 PropertyChangedToRequiredParent model. + */ +@Fluent +public class PropertyChangedToRequiredParent implements JsonSerializable { + /* + * The propertyChangedToRequired property. + */ + @Generated + private String propertyChangedToRequired; + + /** + * Creates an instance of PropertyChangedToRequiredParent class. + */ + @Generated + public PropertyChangedToRequiredParent() { + } + + /** + * Get the propertyChangedToRequired property: The propertyChangedToRequired property. + * + * @return the propertyChangedToRequired value. + */ + @Generated + public String getPropertyChangedToRequired() { + return this.propertyChangedToRequired; + } + + /** + * Set the propertyChangedToRequired property: The propertyChangedToRequired property. + * + * @param propertyChangedToRequired the propertyChangedToRequired value to set. + * @return the PropertyChangedToRequiredParent object itself. + */ + @Generated + public PropertyChangedToRequiredParent setPropertyChangedToRequired(String propertyChangedToRequired) { + this.propertyChangedToRequired = propertyChangedToRequired; + return this; + } + + /** + * {@inheritDoc} + */ + @Generated + @Override + public JsonWriter toJson(JsonWriter jsonWriter) throws IOException { + jsonWriter.writeStartObject(); + jsonWriter.writeStringField("propertyChangedToRequired", this.propertyChangedToRequired); + return jsonWriter.writeEndObject(); + } + + /** + * Reads an instance of PropertyChangedToRequiredParent from the JsonReader. + * + * @param jsonReader The JsonReader being read. + * @return An instance of PropertyChangedToRequiredParent if the JsonReader was pointing to an instance of it, or + * null if it was pointing to JSON null. + * @throws IOException If an error occurs while reading the PropertyChangedToRequiredParent. + */ + @Generated + public static PropertyChangedToRequiredParent fromJson(JsonReader jsonReader) throws IOException { + return jsonReader.readObject(reader -> { + PropertyChangedToRequiredParent deserializedPropertyChangedToRequiredParent + = new PropertyChangedToRequiredParent(); + while (reader.nextToken() != JsonToken.END_OBJECT) { + String fieldName = reader.getFieldName(); + reader.nextToken(); + + if ("propertyChangedToRequired".equals(fieldName)) { + deserializedPropertyChangedToRequiredParent.propertyChangedToRequired = reader.getString(); + } else { + reader.skipChildren(); + } + } + + return deserializedPropertyChangedToRequiredParent; + }); + } +} diff --git a/typespec-tests/src/main/java/tsptest/subclass/models/package-info.java b/typespec-tests/src/main/java/tsptest/subclass/models/package-info.java new file mode 100644 index 0000000000..a14fc55334 --- /dev/null +++ b/typespec-tests/src/main/java/tsptest/subclass/models/package-info.java @@ -0,0 +1,10 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +// Code generated by Microsoft (R) TypeSpec Code Generator. + +/** + * + * Package containing the data models for Subclass. + * + */ +package tsptest.subclass.models; diff --git a/typespec-tests/src/main/java/tsptest/subclass/package-info.java b/typespec-tests/src/main/java/tsptest/subclass/package-info.java new file mode 100644 index 0000000000..925d7ab7f0 --- /dev/null +++ b/typespec-tests/src/main/java/tsptest/subclass/package-info.java @@ -0,0 +1,10 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +// Code generated by Microsoft (R) TypeSpec Code Generator. + +/** + * + * Package containing the classes for Subclass. + * + */ +package tsptest.subclass; diff --git a/typespec-tests/src/main/resources/tsptest-subclass.properties b/typespec-tests/src/main/resources/tsptest-subclass.properties new file mode 100644 index 0000000000..ca812989b4 --- /dev/null +++ b/typespec-tests/src/main/resources/tsptest-subclass.properties @@ -0,0 +1,2 @@ +name=${project.artifactId} +version=${project.version} diff --git a/typespec-tests/src/test/java/tsptest/subclass/SubclassPropertyTests.java b/typespec-tests/src/test/java/tsptest/subclass/SubclassPropertyTests.java new file mode 100644 index 0000000000..0d425cbad4 --- /dev/null +++ b/typespec-tests/src/test/java/tsptest/subclass/SubclassPropertyTests.java @@ -0,0 +1,33 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +package tsptest.subclass; + +import com.azure.core.util.BinaryData; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; +import tsptest.subclass.models.PropertyChangedToConstant; +import tsptest.subclass.models.PropertyChangedToRequired; + +public class SubclassPropertyTests { + + @Test + public void testPropertyChangedToRequired() { + PropertyChangedToRequired model = new PropertyChangedToRequired("value"); + String json = BinaryData.fromObject(model).toString(); + Assertions.assertEquals("{\"propertyChangedToRequired\":\"value\"}", json); + + model = BinaryData.fromString(json).toObject(PropertyChangedToRequired.class); + Assertions.assertEquals("value", model.getPropertyChangedToRequired()); + } + + @Test + public void testPropertyChangedToConstant() { + PropertyChangedToConstant model = new PropertyChangedToConstant(); + String json = BinaryData.fromObject(model).toString(); + Assertions.assertEquals("{\"propertyChangedToConstant\":\"constantValue\"}", json); + + model = BinaryData.fromString(json).toObject(PropertyChangedToConstant.class); + Assertions.assertEquals("constantValue", model.getPropertyChangedToConstant()); + } +} diff --git a/typespec-tests/src/test/java/tsptest/subclass/generated/SubclassClientTestBase.java b/typespec-tests/src/test/java/tsptest/subclass/generated/SubclassClientTestBase.java new file mode 100644 index 0000000000..5ade858bbc --- /dev/null +++ b/typespec-tests/src/test/java/tsptest/subclass/generated/SubclassClientTestBase.java @@ -0,0 +1,34 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +// Code generated by Microsoft (R) TypeSpec Code Generator. + +package tsptest.subclass.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.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 tsptest.subclass.SubclassClient; +import tsptest.subclass.SubclassClientBuilder; + +class SubclassClientTestBase extends TestProxyTestBase { + protected SubclassClient subclassClient; + + @Override + protected void beforeTest() { + SubclassClientBuilder subclassClientbuilder + = new SubclassClientBuilder().endpoint(Configuration.getGlobalConfiguration().get("ENDPOINT", "endpoint")) + .httpClient(getHttpClientOrUsePlayback(getHttpClients().findFirst().orElse(null))) + .httpLogOptions(new HttpLogOptions().setLogLevel(HttpLogDetailLevel.BASIC)); + if (getTestMode() == TestMode.RECORD) { + subclassClientbuilder.addPolicy(interceptorManager.getRecordPolicy()); + } + subclassClient = subclassClientbuilder.buildClient(); + + } +} diff --git a/typespec-tests/tsp/subclass.tsp b/typespec-tests/tsp/subclass.tsp new file mode 100644 index 0000000000..8f76d84f82 --- /dev/null +++ b/typespec-tests/tsp/subclass.tsp @@ -0,0 +1,58 @@ +import "@typespec/rest"; +import "@azure-tools/typespec-azure-core"; +import "@azure-tools/typespec-client-generator-core"; + +using TypeSpec.Http; + +@service(#{ title: "Subclass" }) +namespace TspTest.Subclass; + +model DuplicateRequiredPropertyParent { + @encodedName("application/json", "property") + requiredProperty: string; + + duplicateRequiredProperty: string; +} +model DuplicateRequiredProperty extends DuplicateRequiredPropertyParent { + @encodedName("application/json", "duplicateRequiredProperty") + newRequiredProperty: string; +} + +model PropertyChangedToRequiredParent { + propertyChangedToRequired?: string; +} +model PropertyChangedToRequired extends PropertyChangedToRequiredParent { + propertyChangedToRequired: string; +} + +model PropertyChangedToConstantParent { + propertyChangedToConstant: string; +} +model PropertyChangedToConstant extends PropertyChangedToConstantParent { + propertyChangedToConstant: "constantValue"; +} + +// Incompatible return type in Java method override +// model PropertyChangedToEnumParent { +// propertyChangedToEnum: string; +// } +// model PropertyChangedToEnum extends PropertyChangedToEnumParent { +// propertyChangedToEnum: EnumModel; +// } +// union EnumModel { +// string, +// "value1", +// } + +model Body { + duplicateRequiredProperty?: DuplicateRequiredProperty; + propertyChangedToRequired?: PropertyChangedToRequired; + propertyChangedToConstant?: PropertyChangedToConstant; +} + +@route("/subclass") +interface Subclass { + @post + @route("/property-in-subclass") + propertyInSubclass(@body body: Body): Body; +}