Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
changeKind: feature
packages:
- "@typespec/http-client-java"
---

Add clientRequired clientOption for Java emitter
9 changes: 5 additions & 4 deletions packages/http-client-java/emitter/src/code-model-builder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@ import {
DiagnosticError,
escapeJavaKeywords,
getNamespace,
isPropertyRequired,
optionBoolean,
pascalCase,
removeClientSuffix,
Expand Down Expand Up @@ -1527,7 +1528,7 @@ export class CodeModelBuilder {
implementation: parameterOnClient
? ImplementationLocation.Client
: ImplementationLocation.Method,
required: !param.optional,
required: isPropertyRequired(param),
nullable: nullable,
protocol: {
http: new HttpParameter(param.kind, {
Expand Down Expand Up @@ -1698,7 +1699,7 @@ export class CodeModelBuilder {
{
summary: sdkMethodParameter.summary,
implementation: ImplementationLocation.Method,
required: !sdkMethodParameter.optional,
required: isPropertyRequired(sdkMethodParameter),
nullable: false,
},
);
Expand Down Expand Up @@ -2046,7 +2047,7 @@ export class CodeModelBuilder {
const parameter = new Parameter(parameterName, sdkBody.doc ?? "", schema, {
summary: sdkBody.summary,
implementation: ImplementationLocation.Method,
required: !sdkBody.optional,
required: isPropertyRequired(sdkBody),
protocol: {
http: new HttpParameter(ParameterLocation.Body),
},
Expand Down Expand Up @@ -2975,7 +2976,7 @@ export class CodeModelBuilder {

const codeModelProperty = new Property(modelProperty.name, modelProperty.doc ?? "", schema, {
summary: modelProperty.summary,
required: !modelProperty.optional,
required: isPropertyRequired(modelProperty),
nullable: nullable,
readOnly: this.isReadOnly(modelProperty),
serializedName: getPropertySerializedName(modelProperty),
Expand Down
6 changes: 6 additions & 0 deletions packages/http-client-java/emitter/src/utils.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { DecoratedType, getClientOptions } from "@azure-tools/typespec-client-generator-core";
import { Diagnostic, Program, Type } from "@typespec/compiler";
import { spawn, SpawnOptions } from "child_process";

Expand Down Expand Up @@ -206,3 +207,8 @@ const JAVA_KEYWORDS: Set<string> = new Set<string>([
"volatile",
"while",
]);

export function isPropertyRequired(property: { optional: boolean } & DecoratedType): boolean {
const clientRequired = getClientOptions(property, "clientRequired") as boolean;
return clientRequired ?? !property.optional;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
// Code generated by Microsoft (R) TypeSpec Code Generator.

package tsptest.clientoption;

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.clientoption.implementation.ClientRequiredsImpl;
import tsptest.clientoption.models.ClientRequiredRequest;

/**
* Initializes a new instance of the asynchronous ClientOptionClient type.
*/
@ServiceClient(builder = ClientOptionClientBuilder.class, isAsync = true)
public final class ClientOptionAsyncClient {
@Generated
private final ClientRequiredsImpl serviceClient;

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

/**
* The post operation.
* <p><strong>Query Parameters</strong></p>
* <table border="1">
* <caption>Query Parameters</caption>
* <tr><th>Name</th><th>Type</th><th>Required</th><th>Description</th></tr>
* <tr><td>filter</td><td>String</td><td>No</td><td>The filter parameter</td></tr>
* </table>
* You can add these to a request with {@link RequestOptions#addQueryParam}
* <p><strong>Request Body Schema</strong></p>
*
* <pre>
* {@code
* {
* name: String (Required)
* timespan: Duration (Required)
* }
* }
* </pre>
*
* @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 {@link Response} on successful completion of {@link Mono}.
*/
@Generated
@ServiceMethod(returns = ReturnType.SINGLE)
public Mono<Response<Void>> postWithResponse(BinaryData body, RequestOptions requestOptions) {
return this.serviceClient.postWithResponseAsync(body, requestOptions);
}

/**
* The post operation.
*
* @param body The body parameter.
* @param filter The filter 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 A {@link Mono} that completes when a successful response is received.
*/
@Generated
@ServiceMethod(returns = ReturnType.SINGLE)
public Mono<Void> post(ClientRequiredRequest body, String filter) {
// Generated convenience method for postWithResponse
RequestOptions requestOptions = new RequestOptions();
if (filter != null) {
requestOptions.addQueryParam("filter", filter, false);
}
return postWithResponse(BinaryData.fromObject(body), requestOptions).flatMap(FluxUtil::toMono);
}

/**
* The post 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 A {@link Mono} that completes when a successful response is received.
*/
@Generated
@ServiceMethod(returns = ReturnType.SINGLE)
public Mono<Void> post(ClientRequiredRequest body) {
// Generated convenience method for postWithResponse
RequestOptions requestOptions = new RequestOptions();
return postWithResponse(BinaryData.fromObject(body), requestOptions).flatMap(FluxUtil::toMono);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
// Code generated by Microsoft (R) TypeSpec Code Generator.

package tsptest.clientoption;

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.clientoption.implementation.ClientRequiredsImpl;
import tsptest.clientoption.models.ClientRequiredRequest;

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

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

/**
* The post operation.
* <p><strong>Query Parameters</strong></p>
* <table border="1">
* <caption>Query Parameters</caption>
* <tr><th>Name</th><th>Type</th><th>Required</th><th>Description</th></tr>
* <tr><td>filter</td><td>String</td><td>No</td><td>The filter parameter</td></tr>
* </table>
* You can add these to a request with {@link RequestOptions#addQueryParam}
* <p><strong>Request Body Schema</strong></p>
*
* <pre>
* {@code
* {
* name: String (Required)
* timespan: Duration (Required)
* }
* }
* </pre>
*
* @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 {@link Response}.
*/
@Generated
@ServiceMethod(returns = ReturnType.SINGLE)
public Response<Void> postWithResponse(BinaryData body, RequestOptions requestOptions) {
return this.serviceClient.postWithResponse(body, requestOptions);
}

/**
* The post operation.
*
* @param body The body parameter.
* @param filter The filter 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.
*/
@Generated
@ServiceMethod(returns = ReturnType.SINGLE)
public void post(ClientRequiredRequest body, String filter) {
// Generated convenience method for postWithResponse
RequestOptions requestOptions = new RequestOptions();
if (filter != null) {
requestOptions.addQueryParam("filter", filter, false);
}
postWithResponse(BinaryData.fromObject(body), requestOptions).getValue();
}

/**
* The post 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.
*/
@Generated
@ServiceMethod(returns = ReturnType.SINGLE)
public void post(ClientRequiredRequest body) {
// Generated convenience method for postWithResponse
RequestOptions requestOptions = new RequestOptions();
postWithResponse(BinaryData.fromObject(body), requestOptions).getValue();
}
}
Loading
Loading