From 8ee7ec2f8dbb7e30f53db13a63c0e1b9a6424231 Mon Sep 17 00:00:00 2001 From: Weidong Xu Date: Tue, 17 Dec 2024 16:05:27 +0800 Subject: [PATCH] http-client-java, add package-version option (#5387) tested locally. --- .../typespec/http/client/generator/Main.java | 2 +- .../fluent/TypeSpecFluentPlugin.java | 3 ++ .../generator/model/EmitterOptions.java | 33 ++++++------------- 3 files changed, 14 insertions(+), 24 deletions(-) diff --git a/packages/http-client-java/generator/http-client-generator/src/main/java/com/microsoft/typespec/http/client/generator/Main.java b/packages/http-client-java/generator/http-client-generator/src/main/java/com/microsoft/typespec/http/client/generator/Main.java index b5eea2d794..430c15ec40 100644 --- a/packages/http-client-java/generator/http-client-generator/src/main/java/com/microsoft/typespec/http/client/generator/Main.java +++ b/packages/http-client-java/generator/http-client-generator/src/main/java/com/microsoft/typespec/http/client/generator/Main.java @@ -162,7 +162,7 @@ private static void handleDPG(CodeModel codeModel, EmitterOptions emitterOptions } boolean includeApiViewProperties - = emitterOptions.includeApiViewProperties() != null && emitterOptions.includeApiViewProperties(); + = emitterOptions.getIncludeApiViewProperties() != null && emitterOptions.getIncludeApiViewProperties(); if (includeApiViewProperties && !CoreUtils.isNullOrEmpty(typeSpecPlugin.getCrossLanguageDefinitionMap())) { String flavor = emitterOptions.getFlavor() == null ? "azure" : emitterOptions.getFlavor(); StringBuilder sb diff --git a/packages/http-client-java/generator/http-client-generator/src/main/java/com/microsoft/typespec/http/client/generator/fluent/TypeSpecFluentPlugin.java b/packages/http-client-java/generator/http-client-generator/src/main/java/com/microsoft/typespec/http/client/generator/fluent/TypeSpecFluentPlugin.java index 1e003b3418..fbfb44daaf 100644 --- a/packages/http-client-java/generator/http-client-generator/src/main/java/com/microsoft/typespec/http/client/generator/fluent/TypeSpecFluentPlugin.java +++ b/packages/http-client-java/generator/http-client-generator/src/main/java/com/microsoft/typespec/http/client/generator/fluent/TypeSpecFluentPlugin.java @@ -49,6 +49,9 @@ public TypeSpecFluentPlugin(EmitterOptions emitterOptions, boolean sdkIntegratio if (emitterOptions.getArm()) { SETTINGS_MAP.put("fluent", "lite"); } + if (emitterOptions.getPackageVersion() != null) { + SETTINGS_MAP.put("package-version", emitterOptions.getPackageVersion()); + } SETTINGS_MAP.put("sdk-integration", sdkIntegration); SETTINGS_MAP.put("output-model-immutable", true); SETTINGS_MAP.put("uuid-as-string", true); diff --git a/packages/http-client-java/generator/http-client-generator/src/main/java/com/microsoft/typespec/http/client/generator/model/EmitterOptions.java b/packages/http-client-java/generator/http-client-generator/src/main/java/com/microsoft/typespec/http/client/generator/model/EmitterOptions.java index 3f3feb0cf6..82f00a96b6 100644 --- a/packages/http-client-java/generator/http-client-generator/src/main/java/com/microsoft/typespec/http/client/generator/model/EmitterOptions.java +++ b/packages/http-client-java/generator/http-client-generator/src/main/java/com/microsoft/typespec/http/client/generator/model/EmitterOptions.java @@ -29,7 +29,7 @@ public class EmitterOptions implements JsonSerializable { private String customTypeSubpackage; private String customizationClass; private Boolean includeApiViewProperties = true; - + private String packageVersion; private Boolean useObjectForUnknown = false; private Map polling = new HashMap<>(); private Boolean arm = false; @@ -102,7 +102,7 @@ public String getCustomizationClass() { return customizationClass; } - public Boolean includeApiViewProperties() { + public Boolean getIncludeApiViewProperties() { return includeApiViewProperties; } @@ -126,29 +126,14 @@ public String getFlavor() { return flavor; } + public String getPackageVersion() { + return packageVersion; + } + @Override public JsonWriter toJson(JsonWriter jsonWriter) throws IOException { - return jsonWriter.writeStartObject() - .writeStringField("namespace", namespace) - .writeStringField("output-dir", outputDir) - .writeStringField("flavor", flavor) - .writeStringField("service-name", serviceName) - .writeArrayField("service-versions", serviceVersions, JsonWriter::writeString) - .writeBooleanField("generate-tests", generateTests) - .writeBooleanField("generate-samples", generateSamples) - .writeBooleanField("enable-sync-stack", enableSyncStack) - .writeBooleanField("stream-style-serialization", streamStyleSerialization) - .writeBooleanField("partial-update", partialUpdate) - .writeStringField("custom-types", customTypes) - .writeStringField("custom-types-subpackage", customTypeSubpackage) - .writeStringField("customization-class", customizationClass) - .writeBooleanField("include-api-view-properties", includeApiViewProperties) - .writeBooleanField("use-object-for-unknown", useObjectForUnknown) - .writeMapField("polling", polling, JsonWriter::writeJson) - .writeBooleanField("arm", arm) - .writeStringField("models-subpackage", modelsSubpackage) - .writeJsonField("dev-options", devOptions) - .writeEndObject(); + // it does not need to be written to JSON + return jsonWriter.writeStartObject().writeEndObject(); } public static EmitterOptions fromJson(JsonReader jsonReader) throws IOException { @@ -189,6 +174,8 @@ public static EmitterOptions fromJson(JsonReader jsonReader) throws IOException options.arm = reader.getNullable(JsonReader::getBoolean); } else if ("models-subpackage".equals(fieldName)) { options.modelsSubpackage = emptyToNull(reader.getString()); + } else if ("package-version".equals(fieldName)) { + options.packageVersion = emptyToNull(reader.getString()); } else if ("dev-options".equals(fieldName)) { options.devOptions = DevOptions.fromJson(reader); } else {