Skip to content

Commit f0825a6

Browse files
Remove the unnecessary backward compatible stuff (#5346)
* resolve the left over for the constant refactors * regen * regen
1 parent f49c399 commit f0825a6

File tree

125 files changed

+54869
-49342
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

125 files changed

+54869
-49342
lines changed

samples/AnomalyDetector/tspCodeModel.json

Lines changed: 5797 additions & 5747 deletions
Large diffs are not rendered by default.

src/AutoRest.CSharp/Common/Input/CodeModelConverter.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ private InputNamespace CreateNamespace(Dictionary<ServiceRequest, InputOperation
5959

6060
return new(name: _codeModel.Language.Default.Name,
6161
clients: clients,
62+
constants: [],
6263
enums: _enumsCache.Values.ToArray(),
6364
models: models,
6465
apiVersions: GetApiVersions(),

src/AutoRest.CSharp/Common/Input/InputTypes/InputNamespace.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,24 +10,26 @@ internal record InputNamespace
1010
{
1111
public string Name { get; init; }
1212
public IReadOnlyList<string> ApiVersions { get; init; }
13+
public IReadOnlyList<InputLiteralType> Constants { get; init; }
1314
public IReadOnlyList<InputEnumType> Enums { get; init; }
1415
public IReadOnlyList<InputModelType> Models { get; init; }
1516
private IReadOnlyList<InputClient> Clients { get; init; } // we should not be using this because this only contains the top level clients
1617
public InputAuth Auth { get; init; }
1718
public IReadOnlyList<InputClient> AllClients { get; init; }
1819

19-
public InputNamespace(string name, IReadOnlyList<string> apiVersions, IReadOnlyList<InputEnumType> enums, IReadOnlyList<InputModelType> models, IReadOnlyList<InputClient> clients, InputAuth auth)
20+
public InputNamespace(string name, IReadOnlyList<string> apiVersions, IReadOnlyList<InputLiteralType> constants, IReadOnlyList<InputEnumType> enums, IReadOnlyList<InputModelType> models, IReadOnlyList<InputClient> clients, InputAuth auth)
2021
{
2122
Name = name;
2223
ApiVersions = apiVersions;
24+
Constants = constants;
2325
Enums = enums;
2426
Models = models;
2527
Clients = clients;
2628
Auth = auth;
2729
AllClients = EnumerateClients(clients);
2830
}
2931

30-
public InputNamespace() : this(name: string.Empty, apiVersions: Array.Empty<string>(), enums: Array.Empty<InputEnumType>(), models: Array.Empty<InputModelType>(), clients: Array.Empty<InputClient>(), auth: new InputAuth()) { }
32+
public InputNamespace() : this(name: string.Empty, apiVersions: Array.Empty<string>(), constants: Array.Empty<InputLiteralType>(), enums: Array.Empty<InputEnumType>(), models: Array.Empty<InputModelType>(), clients: Array.Empty<InputClient>(), auth: new InputAuth()) { }
3133

3234
private static IReadOnlyList<InputClient> EnumerateClients(IEnumerable<InputClient> clients)
3335
{

src/AutoRest.CSharp/Common/Input/InputTypes/Serialization/TypeSpecInputNamespaceConverter.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,14 @@ public override void Write(Utf8JsonWriter writer, InputNamespace value, JsonSeri
3535
IReadOnlyList<InputEnumType>? enums = null;
3636
IReadOnlyList<InputModelType>? models = null;
3737
IReadOnlyList<InputClient>? clients = null;
38+
IReadOnlyList<InputLiteralType>? constants = null;
3839
InputAuth? auth = null;
3940

4041
while (reader.TokenType != JsonTokenType.EndObject)
4142
{
4243
var isKnownProperty = reader.TryReadString("name", ref name)
4344
|| reader.TryReadComplexType("apiVersions", options, ref apiVersions)
45+
|| reader.TryReadComplexType("constants", options, ref constants)
4446
|| reader.TryReadComplexType("enums", options, ref enums)
4547
|| reader.TryReadComplexType("models", options, ref models)
4648
|| reader.TryReadComplexType("clients", options, ref clients)
@@ -55,6 +57,7 @@ public override void Write(Utf8JsonWriter writer, InputNamespace value, JsonSeri
5557
return new InputNamespace(
5658
name ?? throw new JsonException(),
5759
apiVersions ?? [],
60+
constants ?? [],
5861
enums ?? [],
5962
models ?? [],
6063
clients ?? [],

src/TypeSpec.Extension/Emitter.Csharp/src/backward-compatibility.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,10 +58,7 @@ export function transformCodeModel(codeModel: CodeModel): CodeModel {
5858
}
5959
}
6060
}
61-
return {
62-
...codeModel,
63-
constants: undefined // TODO -- this is a workaround to reduce the amount of changes in our tspCodeModel.json file. We could remove it later
64-
} as unknown as CodeModel;
61+
return codeModel;
6562
}
6663

6764
interface DecoratedType {

test/AutoRest.TestServerLowLevel.Tests/LowLevel/Generation/CollectionWritingTests.cs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,7 @@ public void ModelTypeCollectionProperties(string expectedModelCodes, string expe
6565
},
6666
null, new List<InputModelType>(), null, null, null, null);
6767

68-
var library = new DpgOutputLibraryBuilder(new InputNamespace("Cadl.TestServer.ModelCollectionProperties.Models", new List<string>(),
69-
new List<InputEnumType>(), new List<InputModelType> { elementModelType, collectionModelType }, new List<InputClient>(), new InputAuth()), default).Build(true);
68+
var library = new DpgOutputLibraryBuilder(new InputNamespace("Cadl.TestServer.ModelCollectionProperties.Models", [], [], [], [elementModelType, collectionModelType], [], new InputAuth()), default).Build(true);
7069

7170
ValidateGeneratedCodes("ModelCollectionModel", expectedModelCodes, expectedSerializationCodes, library);
7271
}
@@ -88,8 +87,7 @@ public void ModelType2DCollectionProperties(string expectedModelCodes, string ex
8887
},
8988
null, new List<InputModelType>(), null, null, null, null);
9089

91-
var library = new DpgOutputLibraryBuilder(new InputNamespace("Cadl.TestServer.ModelCollectionProperties.Models", new List<string>(),
92-
new List<InputEnumType>(), new List<InputModelType> { elementModelType, collectionModelType }, new List<InputClient>(), new InputAuth()), default).Build(true);
90+
var library = new DpgOutputLibraryBuilder(new InputNamespace("Cadl.TestServer.ModelCollectionProperties.Models", [], [], [], [elementModelType, collectionModelType], [], new InputAuth()), default).Build(true);
9391

9492
ValidateGeneratedCodes("ModelCollectionModel", expectedModelCodes, expectedSerializationCodes, library);
9593
}

test/AutoRest.TestServerLowLevel.Tests/LowLevel/Generation/DictionaryWritingTests.cs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,7 @@ public void RoundTripDictionaryProperties(string expectedModelCodes, string expe
1717
var model = new InputModelType("RoundTripModel", "Cadl.TestServer.DictionaryProperties.Models", "public", null, null, "Round-trip model with dictionary properties", InputModelTypeUsage.Input | InputModelTypeUsage.Output,
1818
DictionaryProperties, null, new List<InputModelType>(), null, null, null, null);
1919

20-
var library = new DpgOutputLibraryBuilder(new InputNamespace("Cadl.TestServer.DictionaryProperties.Models", new List<string>(),
21-
new List<InputEnumType>(), new List<InputModelType> { model, ElementModelType }, new List<InputClient>(), new InputAuth()), default).Build(true);
20+
var library = new DpgOutputLibraryBuilder(new InputNamespace("Cadl.TestServer.DictionaryProperties.Models", [], [], [], [model, ElementModelType], [], new InputAuth()), default).Build(true);
2221

2322
ValidateGeneratedCodes("RoundTripModel", expectedModelCodes, expectedSerializationCodes, library);
2423
}
@@ -29,8 +28,7 @@ public void InputDictionaryProperties(string expectedModelCodes, string expected
2928
var model = new InputModelType("InputModel", "Cadl.TestServer.DictionaryProperties.Models", "public", null, null, "Input model with dictionary properties", InputModelTypeUsage.Input,
3029
DictionaryProperties, null, new List<InputModelType>(), null, null, null, null);
3130

32-
var library = new DpgOutputLibraryBuilder(new InputNamespace("Cadl.TestServer.DictionaryProperties.Models", new List<string>(),
33-
new List<InputEnumType>(), new List<InputModelType> { model, ElementModelType }, new List<InputClient>(), new InputAuth()), default).Build(true);
31+
var library = new DpgOutputLibraryBuilder(new InputNamespace("Cadl.TestServer.DictionaryProperties.Models", [], [], [], [model, ElementModelType], [], new InputAuth()), default).Build(true);
3432

3533
ValidateGeneratedCodes("InputModel", expectedModelCodes, expectedSerializationCodes, library);
3634

@@ -42,8 +40,7 @@ public void OutputDictionaryProperties(string expectedModelCodes, string expecte
4240
var model = new InputModelType("OutputModel", "Cadl.TestServer.DictionaryProperties.Models", "public", null, null, "Output model with dictionary properties", InputModelTypeUsage.Output,
4341
DictionaryProperties, null, new List<InputModelType>(), null, null, null, null);
4442

45-
var library = new DpgOutputLibraryBuilder(new InputNamespace("Cadl.TestServer.DictionaryProperties.Models", new List<string>(),
46-
new List<InputEnumType>(), new List<InputModelType> { model, ElementModelType }, new List<InputClient>(), new InputAuth()), default).Build(true);
43+
var library = new DpgOutputLibraryBuilder(new InputNamespace("Cadl.TestServer.DictionaryProperties.Models", [], [], [], [model, ElementModelType], [], new InputAuth()), default).Build(true);
4744

4845
ValidateGeneratedCodes("OutputModel", expectedModelCodes, expectedSerializationCodes, library);
4946
}

test/AutoRest.TestServerLowLevel.Tests/LowLevel/Generation/EnumWritingTests.cs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,7 @@ public void RoundTripEnumProperties(string expectedModelCodes, string expectedSe
3939
new InputModelProperty("Language", "Language", string.Empty, "Required string enum value.", ExtensibleEnumType, null, true, false, false)
4040
},
4141
null, new List<InputModelType>(), null, null, null, null);
42-
var library = new DpgOutputLibraryBuilder(new InputNamespace("Cadl.TestServer.EnumPropertiesBasic", new List<string>(),
43-
new List<InputEnumType> { FixedEnumType, ExtensibleEnumType }, new List<InputModelType> { modelType }, new List<InputClient>(), new InputAuth()), default).Build(true);
42+
var library = new DpgOutputLibraryBuilder(new InputNamespace("Cadl.TestServer.EnumPropertiesBasic", [], [], [FixedEnumType, ExtensibleEnumType], [modelType], [], new InputAuth()), default).Build(true);
4443

4544
ValidateGeneratedCodes("RoundTripModel", expectedModelCodes, expectedSerializationCodes, library);
4645
}
@@ -55,8 +54,7 @@ public void InputEnumProperties(string expectedModelCodes, string expectedSerial
5554
new InputModelProperty("Language", "Language", string.Empty, "Required string enum value.", ExtensibleEnumType, null, true, false, false)
5655
},
5756
null, new List<InputModelType>(), null, null, null, null);
58-
var library = new DpgOutputLibraryBuilder(new InputNamespace("Cadl.TestServer.EnumPropertiesBasic", new List<string>(),
59-
new List<InputEnumType> { FixedEnumType, ExtensibleEnumType }, new List<InputModelType> { modelType }, new List<InputClient>(), new InputAuth()), default).Build(true);
57+
var library = new DpgOutputLibraryBuilder(new InputNamespace("Cadl.TestServer.EnumPropertiesBasic", [], [], [FixedEnumType, ExtensibleEnumType], [modelType], [], new InputAuth()), default).Build(true);
6058

6159
ValidateGeneratedCodes("InputModel", expectedModelCodes, expectedSerializationCodes, library);
6260
}
@@ -71,8 +69,7 @@ public void OutputEnumProperties(string expectedModelCodes, string expectedSeria
7169
new InputModelProperty("Language", "Language", string.Empty, "Required string enum value.", ExtensibleEnumType, null, true, false, false)
7270
},
7371
null, new List<InputModelType>(), null, null, null, null);
74-
var library = new DpgOutputLibraryBuilder(new InputNamespace("Cadl.TestServer.EnumPropertiesBasic", new List<string>(),
75-
new List<InputEnumType> { FixedEnumType, ExtensibleEnumType }, new List<InputModelType> { modelType }, new List<InputClient>(), new InputAuth()), default).Build(true);
72+
var library = new DpgOutputLibraryBuilder(new InputNamespace("Cadl.TestServer.EnumPropertiesBasic", [], [], [FixedEnumType, ExtensibleEnumType], [modelType], new List<InputClient>(), new InputAuth()), default).Build(true);
7673

7774
ValidateGeneratedCodes("OutputModel", expectedModelCodes, expectedSerializationCodes, library);
7875
}

test/AutoRest.TestServerLowLevel.Tests/LowLevel/Generation/NestedModelWritingTests.cs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,7 @@ public void RoundTripModel(string expectedModelCodes, string expectedSerializati
2222
},
2323
null, new List<InputModelType>(), null, null, null, null);
2424

25-
var library = new DpgOutputLibraryBuilder(new InputNamespace("NestedModelsBasic.Models", new List<string>(),
26-
new List<InputEnumType>(), new List<InputModelType> { model, NestedRoundTripOnlyModelType, NestedRoundTripSharedModelType }, new List<InputClient>(), new InputAuth()), default).Build(true);
25+
var library = new DpgOutputLibraryBuilder(new InputNamespace("NestedModelsBasic.Models", [], [], [], [model, NestedRoundTripOnlyModelType, NestedRoundTripSharedModelType], [], new InputAuth()), default).Build(true);
2726

2827
ValidateGeneratedCodes("RoundTripModel", expectedModelCodes, expectedSerializationCodes, library);
2928
}
@@ -40,8 +39,7 @@ public void InputModel(string expectedModelCodes, string expectedSerializationCo
4039
},
4140
null, new List<InputModelType>(), null, null, null, null);
4241

43-
var library = new DpgOutputLibraryBuilder(new InputNamespace("NestedModelsBasic.Models", new List<string>(),
44-
new List<InputEnumType>(), new List<InputModelType> { model, NestedInputOnlyModelType, NestedRoundTripSharedModelType }, new List<InputClient>(), new InputAuth()), default).Build(true);
42+
var library = new DpgOutputLibraryBuilder(new InputNamespace("NestedModelsBasic.Models", [], [], [], [model, NestedInputOnlyModelType, NestedRoundTripSharedModelType], [], new InputAuth()), default).Build(true);
4543

4644
ValidateGeneratedCodes("InputModel", expectedModelCodes, expectedSerializationCodes, library);
4745
}
@@ -58,8 +56,7 @@ public void OutpuModel(string expectedModelCodes, string expectedSerializationCo
5856
},
5957
null, new List<InputModelType>(), null, null, null, null);
6058

61-
var library = new DpgOutputLibraryBuilder(new InputNamespace("NestedModelsBasic.Models", new List<string>(),
62-
new List<InputEnumType>(), new List<InputModelType> { model, NestedOutputOnlyModelType, NestedRoundTripSharedModelType }, new List<InputClient>(), new InputAuth()), default).Build(true);
59+
var library = new DpgOutputLibraryBuilder(new InputNamespace("NestedModelsBasic.Models", [], [], [], [model, NestedOutputOnlyModelType, NestedRoundTripSharedModelType], [], new InputAuth()), default).Build(true);
6360

6461
ValidateGeneratedCodes("OutputModel", expectedModelCodes, expectedSerializationCodes, library);
6562
}

test/AutoRest.TestServerLowLevel.Tests/LowLevel/Generation/OptionalPropertyWritingTests.cs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,7 @@ public void RoundTripModel(string expectedModelCodes, string expectedSerializati
1515
var model = new InputModelType("RoundTripModel", "Cadl.TestServer.OptionalProperties.Models", "public", null, null, "Round-trip model with optional properties.", InputModelTypeUsage.Input | InputModelTypeUsage.Output,
1616
OptionalProperties, null, Array.Empty<InputModelType>(), null, null, null, null);
1717

18-
var library = new DpgOutputLibraryBuilder(new InputNamespace("Cadl.TestServer.OptionalProperties.Models", new List<string>(),
19-
new List<InputEnumType>(), new List<InputModelType> { ElementModelType, model }, new List<InputClient>(), new InputAuth()), default).Build(true);
18+
var library = new DpgOutputLibraryBuilder(new InputNamespace("Cadl.TestServer.OptionalProperties.Models", [], [], [], [ElementModelType, model], [], new InputAuth()), default).Build(true);
2019

2120
ValidateGeneratedCodes("RoundTripModel", expectedModelCodes, expectedSerializationCodes, library);
2221
}
@@ -28,8 +27,7 @@ public void InputModel(string expectedModelCodes, string expectedSerializationCo
2827
var model = new InputModelType("InputModel", "Cadl.TestServer.OptionalProperties.Models", "public", null, null, "Input model with optional properties.", InputModelTypeUsage.Input,
2928
OptionalProperties, null, Array.Empty<InputModelType>(), null, null, null, null);
3029

31-
var library = new DpgOutputLibraryBuilder(new InputNamespace("Cadl.TestServer.OptionalProperties.Models", new List<string>(),
32-
new List<InputEnumType>(), new List<InputModelType> { ElementModelType, model }, new List<InputClient>(), new InputAuth()), default).Build(true);
30+
var library = new DpgOutputLibraryBuilder(new InputNamespace("Cadl.TestServer.OptionalProperties.Models", [], [], [], [ElementModelType, model], [], new InputAuth()), default).Build(true);
3331

3432
ValidateGeneratedCodes("InputModel", expectedModelCodes, expectedSerializationCodes, library);
3533
}
@@ -41,8 +39,7 @@ public void OutputModel(string expectedModelCodes, string expectedSerializationC
4139
var model = new InputModelType("OutputModel", "Cadl.TestServer.OptionalProperties.Models", "public", null, null, "Output model with optional properties.", InputModelTypeUsage.Output,
4240
OptionalProperties, null, Array.Empty<InputModelType>(), null, null, null, null);
4341

44-
var library = new DpgOutputLibraryBuilder(new InputNamespace("Cadl.TestServer.OptionalProperties.Models", new List<string>(),
45-
new List<InputEnumType>(), new List<InputModelType> { ElementModelType, model }, new List<InputClient>(), new InputAuth()), default).Build(true);
42+
var library = new DpgOutputLibraryBuilder(new InputNamespace("Cadl.TestServer.OptionalProperties.Models", [], [], [], [ElementModelType, model], [], new InputAuth()), default).Build(true);
4643

4744
ValidateGeneratedCodes("OutputModel", expectedModelCodes, expectedSerializationCodes, library);
4845
}

0 commit comments

Comments
 (0)