|
6 | 6 | import com.azure.json.JsonProviders;
|
7 | 7 | import com.azure.json.JsonReader;
|
8 | 8 | import com.azure.json.JsonToken;
|
| 9 | +import com.microsoft.typespec.http.client.generator.core.mapper.Mappers; |
| 10 | +import com.microsoft.typespec.http.client.generator.core.mapper.azurevnext.AzureVNextMapperFactory; |
| 11 | +import com.microsoft.typespec.http.client.generator.core.mapper.clientcore.ClientCoreMapperFactory; |
| 12 | +import com.microsoft.typespec.http.client.generator.core.template.Templates; |
| 13 | +import com.microsoft.typespec.http.client.generator.core.template.azurevnext.AzureVNextTemplateFactory; |
| 14 | +import com.microsoft.typespec.http.client.generator.core.template.clientcore.ClientCoreTemplateFactory; |
9 | 15 | import java.io.IOException;
|
10 | 16 | import java.util.ArrayList;
|
11 | 17 | import java.util.Arrays;
|
@@ -33,6 +39,7 @@ public class JavaSettings {
|
33 | 39 | private final String flavor;
|
34 | 40 | private final boolean noCustomHeaders;
|
35 | 41 | private final boolean disableTypedHeadersMethods;
|
| 42 | + private final boolean useRestProxy; |
36 | 43 |
|
37 | 44 | static void setHeader(String value) {
|
38 | 45 | if ("MICROSOFT_MIT".equals(value)) {
|
@@ -137,9 +144,6 @@ private JavaSettings(AutorestSettings autorestSettings) {
|
137 | 144 | this.modelerSettings = new ModelerSettings(
|
138 | 145 | host.getValueWithJsonReader("modelerfour", jsonReader -> jsonReader.readMap(JsonReader::readUntyped)));
|
139 | 146 |
|
140 |
| - // Whether to generate the Azure. |
141 |
| - this.azure = getBooleanValue(host, "azure-arm", false); |
142 |
| - |
143 | 147 | // Whether to generate the SDK integration.
|
144 | 148 | this.sdkIntegration = getBooleanValue(host, "sdk-integration", false);
|
145 | 149 |
|
@@ -178,7 +182,9 @@ private JavaSettings(AutorestSettings autorestSettings) {
|
178 | 182 | // The brand name we use to generate SDK.
|
179 | 183 | this.flavor = getStringValue(host, "flavor", "azure");
|
180 | 184 |
|
181 |
| - this.modelsSubpackage = getStringValue(host, "models-subpackage", isBranded(this.flavor) ? "models" : ""); |
| 185 | + updateFlavorFactories(); |
| 186 | + |
| 187 | + this.modelsSubpackage = getStringValue(host, "models-subpackage", isAzureV1() || isAzureV2() ? "models" : ""); |
182 | 188 |
|
183 | 189 | // The custom types that will be generated.
|
184 | 190 | String customTypes = getStringValue(host, "custom-types", "");
|
@@ -287,6 +293,8 @@ private JavaSettings(AutorestSettings autorestSettings) {
|
287 | 293 | // Whether to generate tests.
|
288 | 294 | this.generateTests = getBooleanValue(host, "generate-tests", false);
|
289 | 295 |
|
| 296 | + this.useRestProxy = getBooleanValue(host, "use-rest-proxy", false); |
| 297 | + |
290 | 298 | // Whether to generate the send request method.
|
291 | 299 | this.generateSendRequestMethod = false;
|
292 | 300 |
|
@@ -380,19 +388,37 @@ private JavaSettings(AutorestSettings autorestSettings) {
|
380 | 388 | this.useObjectForUnknown = getBooleanValue(host, "use-object-for-unknown", false);
|
381 | 389 | }
|
382 | 390 |
|
| 391 | + private void updateFlavorFactories() { |
| 392 | + if (isAzureV2()) { |
| 393 | + Mappers.setFactory(new AzureVNextMapperFactory()); |
| 394 | + Templates.setFactory(new AzureVNextTemplateFactory()); |
| 395 | + } else if (!isAzureV1()) { |
| 396 | + Mappers.setFactory(new ClientCoreMapperFactory()); |
| 397 | + Templates.setFactory(new ClientCoreTemplateFactory()); |
| 398 | + } |
| 399 | + } |
| 400 | + |
383 | 401 | /**
|
384 |
| - * Whether to generate with Azure branding. |
| 402 | + * Whether to generate with Azure V1. |
385 | 403 | *
|
386 |
| - * @return Whether to generate with Azure branding. |
| 404 | + * @return Whether to generate with Azure V1. |
387 | 405 | */
|
388 |
| - public boolean isBranded() { |
389 |
| - return isBranded(this.flavor); |
| 406 | + public boolean isAzureV1() { |
| 407 | + return isAzureV1(this.flavor); |
390 | 408 | }
|
391 | 409 |
|
392 |
| - private static boolean isBranded(String flavor) { |
| 410 | + private static boolean isAzureV1(String flavor) { |
393 | 411 | return "azure".equalsIgnoreCase(flavor);
|
394 | 412 | }
|
395 | 413 |
|
| 414 | + public boolean isAzureV2() { |
| 415 | + return "azurev2".equalsIgnoreCase(this.flavor); |
| 416 | + } |
| 417 | + |
| 418 | + public boolean useRestProxy() { |
| 419 | + return this.useRestProxy; |
| 420 | + } |
| 421 | + |
396 | 422 | private final String keyCredentialHeaderName;
|
397 | 423 |
|
398 | 424 | /**
|
@@ -426,17 +452,6 @@ public Set<String> getCredentialScopes() {
|
426 | 452 | return credentialScopes;
|
427 | 453 | }
|
428 | 454 |
|
429 |
| - private final boolean azure; |
430 |
| - |
431 |
| - /** |
432 |
| - * Whether to generate the Azure. |
433 |
| - * |
434 |
| - * @return Whether to generate the Azure. |
435 |
| - */ |
436 |
| - public final boolean isAzure() { |
437 |
| - return azure; |
438 |
| - } |
439 |
| - |
440 | 455 | private final String artifactId;
|
441 | 456 |
|
442 | 457 | /**
|
@@ -560,15 +575,6 @@ public final boolean isFluentPremium() {
|
560 | 575 | return fluent == Fluent.PREMIUM;
|
561 | 576 | }
|
562 | 577 |
|
563 |
| - /** |
564 |
| - * Whether to generate the Azure or Fluent. |
565 |
| - * |
566 |
| - * @return Whether to generate the Azure or Fluent. |
567 |
| - */ |
568 |
| - public final boolean isAzureOrFluent() { |
569 |
| - return isAzure() || isFluent(); |
570 |
| - } |
571 |
| - |
572 | 578 | // configure for model flatten in client
|
573 | 579 |
|
574 | 580 | /**
|
@@ -1156,7 +1162,7 @@ public boolean isDataPlaneClient() {
|
1156 | 1162 | * @return Whether the client is a vanilla client.
|
1157 | 1163 | */
|
1158 | 1164 | public boolean isVanilla() {
|
1159 |
| - return isBranded() && !isDataPlaneClient() && !isFluent(); |
| 1165 | + return isAzureV1() && !isDataPlaneClient() && !isFluent(); |
1160 | 1166 | }
|
1161 | 1167 |
|
1162 | 1168 | private final boolean useIterable;
|
|
0 commit comments