Skip to content

Commit 766ed97

Browse files
Update options.ts for rename-model (#3174)
1 parent fe46003 commit 766ed97

File tree

6 files changed

+43
-10
lines changed

6 files changed

+43
-10
lines changed

core

Submodule core updated 168 files

readme.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ Settings can be provided on the command line through `--name:value` or in a READ
9797
|`--enable-page-size`|Indicates that `maxpagesize` query parameter be supplied via `byPage` API in `PagedFlux` or `PagedIterable`, instead of via client method parameter.|
9898
|`--use-key-credential`|Indicates that builder uses `KeyCredential` for API key.|
9999
|`--graal-vm-config`|Generates GraalVM config under `resources/META-INF/native-image`.|
100+
|`--rename-model`|CSV. Rename classes. Each item is of pattern `from:to`.|
100101

101102
## Settings for minimal data-plane clients
102103

typespec-extension/src/options.ts

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ export interface DevOptions {
88
"debug"?: boolean;
99
"loglevel"?: "off" | "debug" | "info" | "warn" | "error";
1010
"java-temp-dir"?: string; // working directory for java codegen, e.g. transformed code-model file
11+
profile?: boolean; // enable performance profiling
1112
}
1213

1314
// see EmitterOptionsDev in code-model-builder.ts for a full list of options
@@ -116,13 +117,13 @@ export const EmitterOptionsSchema: JSONSchemaType<EmitterOptions> = {
116117
"Specify the Java class that to be executed by emitter for [code customization](https://github.com/Azure/autorest.java/blob/main/customization-base/README.md), during post-process.",
117118
nullable: true,
118119
},
119-
// "rename-model": {
120-
// type: ["string", "object"],
121-
// description:
122-
// "Rename the model classes, in case they cannot be renamed via TCGC. E.g., anonymous models or templated models. Format should be in key-value form. This option is for management-plane SDK.",
123-
// additionalProperties: true,
124-
// nullable: true,
125-
// },
120+
"rename-model": {
121+
type: ["string", "object"],
122+
description:
123+
"Rename the model classes, in case they cannot be renamed via TCGC. E.g., anonymous models or templated models. Format should be in key-value form.",
124+
additionalProperties: true,
125+
nullable: true,
126+
},
126127
// "add-inner": {
127128
// type: ["string", "array"],
128129
// description:
@@ -140,7 +141,7 @@ export const EmitterOptionsSchema: JSONSchemaType<EmitterOptions> = {
140141
// "preserve-model": {
141142
// type: ["string", "array"],
142143
// description:
143-
// "Generate the model cleasses, even if it is not used by any API. Format should be in array form. This option is for management-plane SDK.",
144+
// "Generate the model classes, even if it is not used by any API. Format should be in array form. This option is for management-plane SDK.",
144145
// items: { type: "string" },
145146
// nullable: true,
146147
// },
@@ -149,6 +150,13 @@ export const EmitterOptionsSchema: JSONSchemaType<EmitterOptions> = {
149150
// description: "Generate async APIs in Clients. This option is for management-plane SDK.",
150151
// nullable: true,
151152
// },
153+
// "property-include-always": {
154+
// type: ["string", "array"],
155+
// description:
156+
// "Specify that properties should always be serialized to JSON, even if its value is `null`. Format should be in array form. Each element be in form `<modelName>.<propertyName>`. This option is for management-plane SDK.",
157+
// items: { type: "string" },
158+
// nullable: true,
159+
// },
152160
// "resource-collection-associations": {
153161
// type: "array",
154162
// description:

typespec-tests/Generate.ps1

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,8 @@ $generateScript = {
9696
$tspOptions += " --option ""@azure-tools/typespec-java.generate-tests=false"""
9797
# test service-name
9898
$tspOptions += " --option ""@azure-tools/typespec-java.service-name=Arm Resource Provider"""
99+
# test property-include-always
100+
$tspOptions += " --option ""@azure-tools/typespec-java.property-include-always=FunctionConfiguration.input"""
99101
} elseif ($tspFile -match "subclient.tsp") {
100102
$tspOptions += " --option ""@azure-tools/typespec-java.enable-subclient=true"""
101103
# test for include-api-view-properties

typespec-tests/src/main/java/tsptest/armstreamstyleserialization/fluent/models/FunctionConfiguration.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,11 @@ public void validate() {
8686
@Override
8787
public JsonWriter toJson(JsonWriter jsonWriter) throws IOException {
8888
jsonWriter.writeStartObject();
89-
jsonWriter.writeStringField("input", this.input);
89+
if (input() != null) {
90+
jsonWriter.writeStringField("input", this.input);
91+
} else {
92+
jsonWriter.writeNullField("input");
93+
}
9094
jsonWriter.writeStringField("output", this.output);
9195
return jsonWriter.writeEndObject();
9296
}

typespec-tests/src/test/java/tsptest/armstreamstyleserialization/StreamStyleSerializationTests.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,13 @@
1212
import java.io.IOException;
1313
import java.io.StringWriter;
1414
import java.nio.charset.StandardCharsets;
15+
import java.util.Map;
1516
import java.util.concurrent.atomic.AtomicInteger;
1617
import org.junit.jupiter.api.Assertions;
1718
import org.junit.jupiter.api.Test;
1819
import org.utils.ArmUtils;
1920
import reactor.core.publisher.Mono;
21+
import tsptest.armstreamstyleserialization.fluent.models.FunctionConfiguration;
2022
import tsptest.armstreamstyleserialization.models.Error;
2123
import tsptest.armstreamstyleserialization.models.Priority;
2224
import tsptest.armstreamstyleserialization.models.SawShark;
@@ -85,6 +87,22 @@ public void testExpandableEnum() {
8587
Assertions.assertThrows(RuntimeException.class, () -> manager.priorities().setPriority(Priority.HIGH));
8688
}
8789

90+
@Test
91+
@SuppressWarnings("unchecked")
92+
public void testPropertyWithNullValue() {
93+
FunctionConfiguration functionConfiguration = new FunctionConfiguration();
94+
Map<String, Object> jsonDict
95+
= (Map<String, Object>) BinaryData.fromObject(functionConfiguration).toObject(Map.class);
96+
Assertions.assertTrue(jsonDict.containsKey("input"));
97+
Assertions.assertNull(jsonDict.get("input"));
98+
Assertions.assertFalse(jsonDict.containsKey("output"));
99+
100+
functionConfiguration = new FunctionConfiguration().withInput("input");
101+
jsonDict = (Map<String, Object>) BinaryData.fromObject(functionConfiguration).toObject(Map.class);
102+
Assertions.assertTrue(jsonDict.containsKey("input"));
103+
Assertions.assertEquals("input", jsonDict.get("input"));
104+
}
105+
88106
private static HttpClient createExpandableEnumHttpClient() {
89107
AtomicInteger callCount = new AtomicInteger();
90108
HttpClient httpClient = request -> {

0 commit comments

Comments
 (0)