Skip to content

Commit 7d706f9

Browse files
authored
sync core, prepare release typespec-java 0.36.0 (#3208)
* core on main * sync tests * prepare release typespec-java * changelog date * changelog * latest core * remove invalid line
1 parent 3642811 commit 7d706f9

29 files changed

+1795
-5
lines changed

core

Submodule core updated 34 files

typespec-extension/changelog.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# Release History
22

3+
## 0.36.0 (2025-10-20)
4+
5+
Compatible with compiler 1.5.0.
6+
7+
- Supported `customization-class` for mgmt libraries.
8+
39
## 0.35.0 (2025-10-09)
410

511
Compatible with compiler 1.5.0.

typespec-extension/package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

typespec-extension/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@azure-tools/typespec-java",
3-
"version": "0.35.0",
3+
"version": "0.36.0",
44
"description": "TypeSpec library for emitting Java client from the TypeSpec REST protocol binding",
55
"keywords": [
66
"TypeSpec"

typespec-tests/Generate.ps1

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,11 @@ $generateScript = {
9696
$tspOptions += " --option ""@azure-tools/typespec-java.property-include-always=FunctionConfiguration.input"""
9797
# enable client side validations
9898
$tspOptions += " --option ""@azure-tools/typespec-java.client-side-validations=true"""
99+
} elseif ($tspFile -match "arm-customization.tsp") {
100+
# for mgmt, do not generate tests due to random mock values
101+
$tspOptions += " --option ""@azure-tools/typespec-java.generate-tests=false"""
102+
# add customization code
103+
$tspOptions += " --option ""@azure-tools/typespec-java.customization-class=../../customization/src/main/java/KeyVaultCustomization.java"""
99104
} elseif ($tspFile -match "subclient.tsp") {
100105
$tspOptions += " --option ""@azure-tools/typespec-java.enable-subclient=true"""
101106
# test for include-api-view-properties
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
2+
// Licensed under the MIT License.
3+
4+
import com.azure.autorest.customization.ClassCustomization;
5+
import com.azure.autorest.customization.Customization;
6+
import com.azure.autorest.customization.LibraryCustomization;
7+
import com.azure.autorest.customization.PackageCustomization;
8+
import com.github.javaparser.ast.type.ClassOrInterfaceType;
9+
import org.slf4j.Logger;
10+
11+
public class KeyVaultCustomization extends Customization {
12+
@Override
13+
public void customize(LibraryCustomization customization, Logger logger) {
14+
PackageCustomization modelsPackage = customization.getPackage("tsptest.armcustomization.fluent.models");
15+
16+
customizeBaseResource(modelsPackage.getClass("VaultInner"));
17+
}
18+
19+
private void customizeBaseResource(ClassCustomization customization) {
20+
customization.customizeAst(ast -> {
21+
ast.getClassByName(customization.getClassName()).ifPresent(clazz -> {
22+
String resourceClassName = "com.azure.core.management.Resource";
23+
ast.addImport(resourceClassName);
24+
clazz.getExtendedTypes().clear();
25+
clazz.addExtendedType(new ClassOrInterfaceType(null, "Resource"));
26+
});
27+
});
28+
}
29+
}

typespec-tests/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
"@typespec/spector": "0.1.0-alpha.19",
1414
"@typespec/http-specs": "0.1.0-alpha.27",
1515
"@azure-tools/azure-http-specs": "0.1.0-alpha.31",
16-
"@azure-tools/typespec-java": "file:/../typespec-extension/azure-tools-typespec-java-0.35.0.tgz"
16+
"@azure-tools/typespec-java": "file:/../typespec-extension/azure-tools-typespec-java-0.36.0.tgz"
1717
},
1818
"devDependencies": {
1919
"@typespec/prettier-plugin-typespec": "^1.5.0",
Lines changed: 282 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,282 @@
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
2+
// Licensed under the MIT License.
3+
// Code generated by Microsoft (R) TypeSpec Code Generator.
4+
5+
package tsptest.armcustomization;
6+
7+
import com.azure.core.credential.TokenCredential;
8+
import com.azure.core.http.HttpClient;
9+
import com.azure.core.http.HttpPipeline;
10+
import com.azure.core.http.HttpPipelineBuilder;
11+
import com.azure.core.http.HttpPipelinePosition;
12+
import com.azure.core.http.policy.AddDatePolicy;
13+
import com.azure.core.http.policy.AddHeadersFromContextPolicy;
14+
import com.azure.core.http.policy.BearerTokenAuthenticationPolicy;
15+
import com.azure.core.http.policy.HttpLogOptions;
16+
import com.azure.core.http.policy.HttpLoggingPolicy;
17+
import com.azure.core.http.policy.HttpPipelinePolicy;
18+
import com.azure.core.http.policy.HttpPolicyProviders;
19+
import com.azure.core.http.policy.RequestIdPolicy;
20+
import com.azure.core.http.policy.RetryOptions;
21+
import com.azure.core.http.policy.RetryPolicy;
22+
import com.azure.core.http.policy.UserAgentPolicy;
23+
import com.azure.core.management.profile.AzureProfile;
24+
import com.azure.core.util.Configuration;
25+
import com.azure.core.util.CoreUtils;
26+
import com.azure.core.util.logging.ClientLogger;
27+
import java.time.Duration;
28+
import java.time.temporal.ChronoUnit;
29+
import java.util.ArrayList;
30+
import java.util.List;
31+
import java.util.Map;
32+
import java.util.Objects;
33+
import java.util.stream.Collectors;
34+
import tsptest.armcustomization.fluent.ArmCustomizationClient;
35+
import tsptest.armcustomization.implementation.ArmCustomizationClientBuilder;
36+
import tsptest.armcustomization.implementation.VaultsImpl;
37+
import tsptest.armcustomization.models.Vaults;
38+
39+
/**
40+
* Entry point to ArmCustomizationManager.
41+
* Arm Resource Provider management API.
42+
*/
43+
public final class ArmCustomizationManager {
44+
private Vaults vaults;
45+
46+
private final ArmCustomizationClient clientObject;
47+
48+
private ArmCustomizationManager(HttpPipeline httpPipeline, AzureProfile profile, Duration defaultPollInterval) {
49+
Objects.requireNonNull(httpPipeline, "'httpPipeline' cannot be null.");
50+
Objects.requireNonNull(profile, "'profile' cannot be null.");
51+
this.clientObject = new ArmCustomizationClientBuilder().pipeline(httpPipeline)
52+
.endpoint(profile.getEnvironment().getResourceManagerEndpoint())
53+
.subscriptionId(profile.getSubscriptionId())
54+
.defaultPollInterval(defaultPollInterval)
55+
.buildClient();
56+
}
57+
58+
/**
59+
* Creates an instance of ArmCustomization service API entry point.
60+
*
61+
* @param credential the credential to use.
62+
* @param profile the Azure profile for client.
63+
* @return the ArmCustomization service API instance.
64+
*/
65+
public static ArmCustomizationManager authenticate(TokenCredential credential, AzureProfile profile) {
66+
Objects.requireNonNull(credential, "'credential' cannot be null.");
67+
Objects.requireNonNull(profile, "'profile' cannot be null.");
68+
return configure().authenticate(credential, profile);
69+
}
70+
71+
/**
72+
* Creates an instance of ArmCustomization service API entry point.
73+
*
74+
* @param httpPipeline the {@link HttpPipeline} configured with Azure authentication credential.
75+
* @param profile the Azure profile for client.
76+
* @return the ArmCustomization service API instance.
77+
*/
78+
public static ArmCustomizationManager authenticate(HttpPipeline httpPipeline, AzureProfile profile) {
79+
Objects.requireNonNull(httpPipeline, "'httpPipeline' cannot be null.");
80+
Objects.requireNonNull(profile, "'profile' cannot be null.");
81+
return new ArmCustomizationManager(httpPipeline, profile, null);
82+
}
83+
84+
/**
85+
* Gets a Configurable instance that can be used to create ArmCustomizationManager with optional configuration.
86+
*
87+
* @return the Configurable instance allowing configurations.
88+
*/
89+
public static Configurable configure() {
90+
return new ArmCustomizationManager.Configurable();
91+
}
92+
93+
/**
94+
* The Configurable allowing configurations to be set.
95+
*/
96+
public static final class Configurable {
97+
private static final ClientLogger LOGGER = new ClientLogger(Configurable.class);
98+
private static final String SDK_VERSION = "version";
99+
private static final Map<String, String> PROPERTIES
100+
= CoreUtils.getProperties("azure-resourcemanager-armcustomization-generated.properties");
101+
102+
private HttpClient httpClient;
103+
private HttpLogOptions httpLogOptions;
104+
private final List<HttpPipelinePolicy> policies = new ArrayList<>();
105+
private final List<String> scopes = new ArrayList<>();
106+
private RetryPolicy retryPolicy;
107+
private RetryOptions retryOptions;
108+
private Duration defaultPollInterval;
109+
110+
private Configurable() {
111+
}
112+
113+
/**
114+
* Sets the http client.
115+
*
116+
* @param httpClient the HTTP client.
117+
* @return the configurable object itself.
118+
*/
119+
public Configurable withHttpClient(HttpClient httpClient) {
120+
this.httpClient = Objects.requireNonNull(httpClient, "'httpClient' cannot be null.");
121+
return this;
122+
}
123+
124+
/**
125+
* Sets the logging options to the HTTP pipeline.
126+
*
127+
* @param httpLogOptions the HTTP log options.
128+
* @return the configurable object itself.
129+
*/
130+
public Configurable withLogOptions(HttpLogOptions httpLogOptions) {
131+
this.httpLogOptions = Objects.requireNonNull(httpLogOptions, "'httpLogOptions' cannot be null.");
132+
return this;
133+
}
134+
135+
/**
136+
* Adds the pipeline policy to the HTTP pipeline.
137+
*
138+
* @param policy the HTTP pipeline policy.
139+
* @return the configurable object itself.
140+
*/
141+
public Configurable withPolicy(HttpPipelinePolicy policy) {
142+
this.policies.add(Objects.requireNonNull(policy, "'policy' cannot be null."));
143+
return this;
144+
}
145+
146+
/**
147+
* Adds the scope to permission sets.
148+
*
149+
* @param scope the scope.
150+
* @return the configurable object itself.
151+
*/
152+
public Configurable withScope(String scope) {
153+
this.scopes.add(Objects.requireNonNull(scope, "'scope' cannot be null."));
154+
return this;
155+
}
156+
157+
/**
158+
* Sets the retry policy to the HTTP pipeline.
159+
*
160+
* @param retryPolicy the HTTP pipeline retry policy.
161+
* @return the configurable object itself.
162+
*/
163+
public Configurable withRetryPolicy(RetryPolicy retryPolicy) {
164+
this.retryPolicy = Objects.requireNonNull(retryPolicy, "'retryPolicy' cannot be null.");
165+
return this;
166+
}
167+
168+
/**
169+
* Sets the retry options for the HTTP pipeline retry policy.
170+
* <p>
171+
* This setting has no effect, if retry policy is set via {@link #withRetryPolicy(RetryPolicy)}.
172+
*
173+
* @param retryOptions the retry options for the HTTP pipeline retry policy.
174+
* @return the configurable object itself.
175+
*/
176+
public Configurable withRetryOptions(RetryOptions retryOptions) {
177+
this.retryOptions = Objects.requireNonNull(retryOptions, "'retryOptions' cannot be null.");
178+
return this;
179+
}
180+
181+
/**
182+
* Sets the default poll interval, used when service does not provide "Retry-After" header.
183+
*
184+
* @param defaultPollInterval the default poll interval.
185+
* @return the configurable object itself.
186+
*/
187+
public Configurable withDefaultPollInterval(Duration defaultPollInterval) {
188+
this.defaultPollInterval
189+
= Objects.requireNonNull(defaultPollInterval, "'defaultPollInterval' cannot be null.");
190+
if (this.defaultPollInterval.isNegative()) {
191+
throw LOGGER
192+
.logExceptionAsError(new IllegalArgumentException("'defaultPollInterval' cannot be negative"));
193+
}
194+
return this;
195+
}
196+
197+
/**
198+
* Creates an instance of ArmCustomization service API entry point.
199+
*
200+
* @param credential the credential to use.
201+
* @param profile the Azure profile for client.
202+
* @return the ArmCustomization service API instance.
203+
*/
204+
public ArmCustomizationManager authenticate(TokenCredential credential, AzureProfile profile) {
205+
Objects.requireNonNull(credential, "'credential' cannot be null.");
206+
Objects.requireNonNull(profile, "'profile' cannot be null.");
207+
208+
String clientVersion = PROPERTIES.getOrDefault(SDK_VERSION, "UnknownVersion");
209+
210+
StringBuilder userAgentBuilder = new StringBuilder();
211+
userAgentBuilder.append("azsdk-java")
212+
.append("-")
213+
.append("tsptest.armcustomization")
214+
.append("/")
215+
.append(clientVersion);
216+
if (!Configuration.getGlobalConfiguration().get("AZURE_TELEMETRY_DISABLED", false)) {
217+
userAgentBuilder.append(" (")
218+
.append(Configuration.getGlobalConfiguration().get("java.version"))
219+
.append("; ")
220+
.append(Configuration.getGlobalConfiguration().get("os.name"))
221+
.append("; ")
222+
.append(Configuration.getGlobalConfiguration().get("os.version"))
223+
.append("; auto-generated)");
224+
} else {
225+
userAgentBuilder.append(" (auto-generated)");
226+
}
227+
228+
if (scopes.isEmpty()) {
229+
scopes.add(profile.getEnvironment().getManagementEndpoint() + "/.default");
230+
}
231+
if (retryPolicy == null) {
232+
if (retryOptions != null) {
233+
retryPolicy = new RetryPolicy(retryOptions);
234+
} else {
235+
retryPolicy = new RetryPolicy("Retry-After", ChronoUnit.SECONDS);
236+
}
237+
}
238+
List<HttpPipelinePolicy> policies = new ArrayList<>();
239+
policies.add(new UserAgentPolicy(userAgentBuilder.toString()));
240+
policies.add(new AddHeadersFromContextPolicy());
241+
policies.add(new RequestIdPolicy());
242+
policies.addAll(this.policies.stream()
243+
.filter(p -> p.getPipelinePosition() == HttpPipelinePosition.PER_CALL)
244+
.collect(Collectors.toList()));
245+
HttpPolicyProviders.addBeforeRetryPolicies(policies);
246+
policies.add(retryPolicy);
247+
policies.add(new AddDatePolicy());
248+
policies.add(new BearerTokenAuthenticationPolicy(credential, scopes.toArray(new String[0])));
249+
policies.addAll(this.policies.stream()
250+
.filter(p -> p.getPipelinePosition() == HttpPipelinePosition.PER_RETRY)
251+
.collect(Collectors.toList()));
252+
HttpPolicyProviders.addAfterRetryPolicies(policies);
253+
policies.add(new HttpLoggingPolicy(httpLogOptions));
254+
HttpPipeline httpPipeline = new HttpPipelineBuilder().httpClient(httpClient)
255+
.policies(policies.toArray(new HttpPipelinePolicy[0]))
256+
.build();
257+
return new ArmCustomizationManager(httpPipeline, profile, defaultPollInterval);
258+
}
259+
}
260+
261+
/**
262+
* Gets the resource collection API of Vaults.
263+
*
264+
* @return Resource collection API of Vaults.
265+
*/
266+
public Vaults vaults() {
267+
if (this.vaults == null) {
268+
this.vaults = new VaultsImpl(clientObject.getVaults(), this);
269+
}
270+
return vaults;
271+
}
272+
273+
/**
274+
* Gets wrapped service client ArmCustomizationClient providing direct access to the underlying auto-generated API
275+
* implementation, based on Azure REST API.
276+
*
277+
* @return Wrapped service client ArmCustomizationClient.
278+
*/
279+
public ArmCustomizationClient serviceClient() {
280+
return this.clientObject;
281+
}
282+
}

0 commit comments

Comments
 (0)