Skip to content

Commit 21ad54a

Browse files
tsp, bug fix on additionalProperties with derived model (#2703)
1 parent e2acc6f commit 21ad54a

23 files changed

+210
-273
lines changed

javagen/src/main/java/com/azure/autorest/template/StreamSerializationModelTemplate.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1290,7 +1290,8 @@ private static void createObjectAndReturn(JavaBlock methodBlock, String modelNam
12901290
if (propertiesManager.hasConstructorArguments()) {
12911291
if (propertiesManager.getSetterPropertiesCount() == 0
12921292
&& propertiesManager.getReadOnlyPropertiesCount() == 0
1293-
&& propertiesManager.getAdditionalProperties() == null) {
1293+
&& propertiesManager.getAdditionalProperties() == null
1294+
&& propertiesManager.getSuperAdditionalPropertiesProperty() == null) {
12941295
methodBlock.methodReturn("new " + modelName + "(" + constructorArgs + ")");
12951296
return;
12961297
}

typespec-extension/src/code-model-builder.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1923,7 +1923,9 @@ export class CodeModelBuilder {
19231923
});
19241924

19251925
// cache this now before we accidentally recurse on this type.
1926-
this.schemaCache.set(type, dictSchema);
1926+
if (!this.schemaCache.has(type)) {
1927+
this.schemaCache.set(type, dictSchema);
1928+
}
19271929

19281930
const elementSchema = this.processSchema(type.indexer.value, name);
19291931
dictSchema.elementType = elementSchema;
@@ -2155,7 +2157,9 @@ export class CodeModelBuilder {
21552157
this.codeModel.schemas.add(objectSchema);
21562158

21572159
// cache this now before we accidentally recurse on this type.
2158-
this.schemaCache.set(type, objectSchema);
2160+
if (!this.schemaCache.has(type)) {
2161+
this.schemaCache.set(type, objectSchema);
2162+
}
21592163

21602164
// discriminator
21612165
let discriminatorPropertyName: string | undefined = undefined;
@@ -2233,7 +2237,8 @@ export class CodeModelBuilder {
22332237
*/
22342238
const parentSchema = type.sourceModel
22352239
? this.processSchema(type.sourceModel, this.getName(type.sourceModel))
2236-
: this.processDictionarySchema(type, this.getName(type));
2240+
: // process self as pure Record (instead of Model = Record + properties), do not use cache
2241+
this.processDictionarySchema(type, this.getName(type));
22372242
objectSchema.parents = new Relations();
22382243
objectSchema.parents.immediate.push(parentSchema);
22392244
pushDistinct(objectSchema.parents.all, parentSchema);

typespec-tests/src/main/java/com/type/property/additionalproperties/ExtendsDifferentSpreadFloatAsyncClient.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,11 @@ public final class ExtendsDifferentSpreadFloatAsyncClient {
4444
*
4545
* <pre>{@code
4646
* {
47-
* derivedProp: double (Required)
47+
* name: String (Required)
4848
* (Optional): {
4949
* String: double (Required)
5050
* }
51+
* derivedProp: double (Required)
5152
* }
5253
* }</pre>
5354
*
@@ -70,10 +71,11 @@ public Mono<Response<BinaryData>> getWithResponse(RequestOptions requestOptions)
7071
*
7172
* <pre>{@code
7273
* {
73-
* derivedProp: double (Required)
74+
* name: String (Required)
7475
* (Optional): {
7576
* String: double (Required)
7677
* }
78+
* derivedProp: double (Required)
7779
* }
7880
* }</pre>
7981
*

typespec-tests/src/main/java/com/type/property/additionalproperties/ExtendsDifferentSpreadFloatClient.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,11 @@ public final class ExtendsDifferentSpreadFloatClient {
4242
*
4343
* <pre>{@code
4444
* {
45-
* derivedProp: double (Required)
45+
* name: String (Required)
4646
* (Optional): {
4747
* String: double (Required)
4848
* }
49+
* derivedProp: double (Required)
4950
* }
5051
* }</pre>
5152
*
@@ -68,10 +69,11 @@ public Response<BinaryData> getWithResponse(RequestOptions requestOptions) {
6869
*
6970
* <pre>{@code
7071
* {
71-
* derivedProp: double (Required)
72+
* name: String (Required)
7273
* (Optional): {
7374
* String: double (Required)
7475
* }
76+
* derivedProp: double (Required)
7577
* }
7678
* }</pre>
7779
*

typespec-tests/src/main/java/com/type/property/additionalproperties/ExtendsDifferentSpreadModelArrayAsyncClient.java

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -44,16 +44,17 @@ public final class ExtendsDifferentSpreadModelArrayAsyncClient {
4444
*
4545
* <pre>{@code
4646
* {
47-
* derivedProp (Required): [
48-
* (Required){
49-
* state: String (Required)
50-
* }
51-
* ]
47+
* knownProp: String (Required)
5248
* (Optional): {
5349
* String (Required): [
54-
* (recursive schema, see above)
50+
* (Required){
51+
* state: String (Required)
52+
* }
5553
* ]
5654
* }
55+
* derivedProp (Required): [
56+
* (recursive schema, see above)
57+
* ]
5758
* }
5859
* }</pre>
5960
*
@@ -76,16 +77,17 @@ public Mono<Response<BinaryData>> getWithResponse(RequestOptions requestOptions)
7677
*
7778
* <pre>{@code
7879
* {
79-
* derivedProp (Required): [
80-
* (Required){
81-
* state: String (Required)
82-
* }
83-
* ]
80+
* knownProp: String (Required)
8481
* (Optional): {
8582
* String (Required): [
86-
* (recursive schema, see above)
83+
* (Required){
84+
* state: String (Required)
85+
* }
8786
* ]
8887
* }
88+
* derivedProp (Required): [
89+
* (recursive schema, see above)
90+
* ]
8991
* }
9092
* }</pre>
9193
*

typespec-tests/src/main/java/com/type/property/additionalproperties/ExtendsDifferentSpreadModelArrayClient.java

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -42,16 +42,17 @@ public final class ExtendsDifferentSpreadModelArrayClient {
4242
*
4343
* <pre>{@code
4444
* {
45-
* derivedProp (Required): [
46-
* (Required){
47-
* state: String (Required)
48-
* }
49-
* ]
45+
* knownProp: String (Required)
5046
* (Optional): {
5147
* String (Required): [
52-
* (recursive schema, see above)
48+
* (Required){
49+
* state: String (Required)
50+
* }
5351
* ]
5452
* }
53+
* derivedProp (Required): [
54+
* (recursive schema, see above)
55+
* ]
5556
* }
5657
* }</pre>
5758
*
@@ -74,16 +75,17 @@ public Response<BinaryData> getWithResponse(RequestOptions requestOptions) {
7475
*
7576
* <pre>{@code
7677
* {
77-
* derivedProp (Required): [
78-
* (Required){
79-
* state: String (Required)
80-
* }
81-
* ]
78+
* knownProp: String (Required)
8279
* (Optional): {
8380
* String (Required): [
84-
* (recursive schema, see above)
81+
* (Required){
82+
* state: String (Required)
83+
* }
8584
* ]
8685
* }
86+
* derivedProp (Required): [
87+
* (recursive schema, see above)
88+
* ]
8789
* }
8890
* }</pre>
8991
*

typespec-tests/src/main/java/com/type/property/additionalproperties/ExtendsDifferentSpreadModelAsyncClient.java

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -44,12 +44,13 @@ public final class ExtendsDifferentSpreadModelAsyncClient {
4444
*
4545
* <pre>{@code
4646
* {
47-
* derivedProp (Required): {
48-
* state: String (Required)
49-
* }
47+
* knownProp: String (Required)
5048
* (Optional): {
51-
* String (Required): (recursive schema, see String above)
49+
* String (Required): {
50+
* state: String (Required)
51+
* }
5252
* }
53+
* derivedProp (Required): (recursive schema, see derivedProp above)
5354
* }
5455
* }</pre>
5556
*
@@ -72,12 +73,13 @@ public Mono<Response<BinaryData>> getWithResponse(RequestOptions requestOptions)
7273
*
7374
* <pre>{@code
7475
* {
75-
* derivedProp (Required): {
76-
* state: String (Required)
77-
* }
76+
* knownProp: String (Required)
7877
* (Optional): {
79-
* String (Required): (recursive schema, see String above)
78+
* String (Required): {
79+
* state: String (Required)
80+
* }
8081
* }
82+
* derivedProp (Required): (recursive schema, see derivedProp above)
8183
* }
8284
* }</pre>
8385
*

typespec-tests/src/main/java/com/type/property/additionalproperties/ExtendsDifferentSpreadModelClient.java

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -42,12 +42,13 @@ public final class ExtendsDifferentSpreadModelClient {
4242
*
4343
* <pre>{@code
4444
* {
45-
* derivedProp (Required): {
46-
* state: String (Required)
47-
* }
45+
* knownProp: String (Required)
4846
* (Optional): {
49-
* String (Required): (recursive schema, see String above)
47+
* String (Required): {
48+
* state: String (Required)
49+
* }
5050
* }
51+
* derivedProp (Required): (recursive schema, see derivedProp above)
5152
* }
5253
* }</pre>
5354
*
@@ -70,12 +71,13 @@ public Response<BinaryData> getWithResponse(RequestOptions requestOptions) {
7071
*
7172
* <pre>{@code
7273
* {
73-
* derivedProp (Required): {
74-
* state: String (Required)
75-
* }
74+
* knownProp: String (Required)
7675
* (Optional): {
77-
* String (Required): (recursive schema, see String above)
76+
* String (Required): {
77+
* state: String (Required)
78+
* }
7879
* }
80+
* derivedProp (Required): (recursive schema, see derivedProp above)
7981
* }
8082
* }</pre>
8183
*

typespec-tests/src/main/java/com/type/property/additionalproperties/ExtendsDifferentSpreadStringAsyncClient.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,11 @@ public final class ExtendsDifferentSpreadStringAsyncClient {
4444
*
4545
* <pre>{@code
4646
* {
47-
* derivedProp: String (Required)
47+
* id: double (Required)
4848
* (Optional): {
4949
* String: String (Required)
5050
* }
51+
* derivedProp: String (Required)
5152
* }
5253
* }</pre>
5354
*
@@ -70,10 +71,11 @@ public Mono<Response<BinaryData>> getWithResponse(RequestOptions requestOptions)
7071
*
7172
* <pre>{@code
7273
* {
73-
* derivedProp: String (Required)
74+
* id: double (Required)
7475
* (Optional): {
7576
* String: String (Required)
7677
* }
78+
* derivedProp: String (Required)
7779
* }
7880
* }</pre>
7981
*

typespec-tests/src/main/java/com/type/property/additionalproperties/ExtendsDifferentSpreadStringClient.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,11 @@ public final class ExtendsDifferentSpreadStringClient {
4242
*
4343
* <pre>{@code
4444
* {
45-
* derivedProp: String (Required)
45+
* id: double (Required)
4646
* (Optional): {
4747
* String: String (Required)
4848
* }
49+
* derivedProp: String (Required)
4950
* }
5051
* }</pre>
5152
*
@@ -68,10 +69,11 @@ public Response<BinaryData> getWithResponse(RequestOptions requestOptions) {
6869
*
6970
* <pre>{@code
7071
* {
71-
* derivedProp: String (Required)
72+
* id: double (Required)
7273
* (Optional): {
7374
* String: String (Required)
7475
* }
76+
* derivedProp: String (Required)
7577
* }
7678
* }</pre>
7779
*

typespec-tests/src/main/java/com/type/property/additionalproperties/implementation/ExtendsDifferentSpreadFloatsImpl.java

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -101,10 +101,11 @@ Response<Void> putSync(@HeaderParam("accept") String accept, @BodyParam("applica
101101
*
102102
* <pre>{@code
103103
* {
104-
* derivedProp: double (Required)
104+
* name: String (Required)
105105
* (Optional): {
106106
* String: double (Required)
107107
* }
108+
* derivedProp: double (Required)
108109
* }
109110
* }</pre>
110111
*
@@ -127,10 +128,11 @@ public Mono<Response<BinaryData>> getWithResponseAsync(RequestOptions requestOpt
127128
*
128129
* <pre>{@code
129130
* {
130-
* derivedProp: double (Required)
131+
* name: String (Required)
131132
* (Optional): {
132133
* String: double (Required)
133134
* }
135+
* derivedProp: double (Required)
134136
* }
135137
* }</pre>
136138
*
@@ -153,10 +155,11 @@ public Response<BinaryData> getWithResponse(RequestOptions requestOptions) {
153155
*
154156
* <pre>{@code
155157
* {
156-
* derivedProp: double (Required)
158+
* name: String (Required)
157159
* (Optional): {
158160
* String: double (Required)
159161
* }
162+
* derivedProp: double (Required)
160163
* }
161164
* }</pre>
162165
*
@@ -180,10 +183,11 @@ public Mono<Response<Void>> putWithResponseAsync(BinaryData body, RequestOptions
180183
*
181184
* <pre>{@code
182185
* {
183-
* derivedProp: double (Required)
186+
* name: String (Required)
184187
* (Optional): {
185188
* String: double (Required)
186189
* }
190+
* derivedProp: double (Required)
187191
* }
188192
* }</pre>
189193
*

0 commit comments

Comments
 (0)