diff --git a/AutoRest/Generators/CSharp/Azure.CSharp.Tests/GlobalSuppressions.cs b/AutoRest/Generators/CSharp/Azure.CSharp.Tests/GlobalSuppressions.cs index 725603fb1ce5..113846cb0d13 100644 --- a/AutoRest/Generators/CSharp/Azure.CSharp.Tests/GlobalSuppressions.cs +++ b/AutoRest/Generators/CSharp/Azure.CSharp.Tests/GlobalSuppressions.cs @@ -8,10 +8,6 @@ // "In Suppression File". // You do not need to add suppressions to this file manually. -[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance", "CA1822:MarkMembersAsStatic", -Scope = "member", Target = "Microsoft.Rest.Generator.CSharp.Azure.Tests.AcceptanceTests.#ResourceFlatteningGenerationTest()", Justification="Non-static test classes allow fixtures")] -[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance", "CA1822:MarkMembersAsStatic", -Scope = "member", Target = "Microsoft.Rest.Generator.CSharp.Azure.Tests.AcceptanceTests.#EnsureStatusCode`1(System.Net.HttpStatusCode,System.Func`1>>)", Justification="Non-static test classes allow fixtures")] [assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Maintainability", "CA1502:AvoidExcessiveComplexity", Scope = "member", Target = "Microsoft.Rest.Generator.CSharp.Azure.Tests.AcceptanceTests.#LroSadPathTests()", Justification="Test code is straighforward")] [assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Reliability", "CA2000:Dispose objects before losing scope", @@ -24,10 +20,7 @@ Target = "Fixtures.Azure.AcceptanceTestsLro.Models.SubProduct.#ProvisioningStateValues", Justification="Necessary for read-only properties in serialization types")] [assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Reliability", "CA2000:Dispose objects before losing scope", Scope = "member", Target = "Microsoft.Rest.Generator.CSharp.Azure.Tests.AcceptanceTests.#XmsRequestClientIdTest()")] [assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Reliability", "CA2000:Dispose objects before losing scope", Scope = "member", Target = "Microsoft.Rest.Generator.CSharp.Azure.Tests.AcceptanceTests.#AzureODataTests()")] -[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance", "CA1822:MarkMembersAsStatic", Scope = "member", Target = "Microsoft.Rest.Generator.CSharp.Azure.Tests.CSharpAzureCodeNamingFrameworkTests.#ConvertsPageResultsToPageTypeTest()")] [assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA1710:IdentifiersShouldHaveCorrectSuffix", Scope = "type", Target = "Fixtures.Azure.AcceptanceTestsPaging.Models.Page`1")] -[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance", "CA1822:MarkMembersAsStatic", Scope = "member", Target = "Microsoft.Rest.Generator.CSharp.Azure.Tests.PageJsonTest.#TestNullPageDeSerialization()")] -[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance", "CA1822:MarkMembersAsStatic", Scope = "member", Target = "Microsoft.Rest.Generator.CSharp.Azure.Tests.PageJsonTest.#TestNextLinkDeSerialization()")] [assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode", Scope = "member", Target = "Fixtures.Azure.AcceptanceTestsLro.Models.Resource.#Id")] [assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode", Scope = "member", Target = "Fixtures.Azure.AcceptanceTestsLro.Models.Resource.#Type")] [assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode", Scope = "member", Target = "Fixtures.Azure.AcceptanceTestsLro.Models.Resource.#Name")] diff --git a/AutoRest/Generators/CSharp/CSharp.Tests/GlobalSuppressions.cs b/AutoRest/Generators/CSharp/CSharp.Tests/GlobalSuppressions.cs index dd1260862d26..85ac07db8665 100644 --- a/AutoRest/Generators/CSharp/CSharp.Tests/GlobalSuppressions.cs +++ b/AutoRest/Generators/CSharp/CSharp.Tests/GlobalSuppressions.cs @@ -16,23 +16,6 @@ [assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance", "CA1809:AvoidExcessiveLocals", Scope = "member", Target = "Microsoft.Rest.Generator.CSharp.Tests.AcceptanceTests.#ArrayTests()", Justification = "Fixture values for serialization")] [assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance", "CA1809:AvoidExcessiveLocals", Scope = "member", Target = "Microsoft.Rest.Generator.CSharp.Tests.AcceptanceTests.#DictionaryTests()", Justification = "Fixture values for serialization")] [assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance", "CA1809:AvoidExcessiveLocals", Scope = "member", Target = "Microsoft.Rest.Generator.CSharp.Tests.AcceptanceTests.#ComplexTests()", Justification = "Fixture values for serialization")] -[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance", "CA1822:MarkMembersAsStatic", Scope = "member", Target = "Microsoft.Rest.Generator.CSharp.Tests.CSharpCodeNamingFrameworkTests.#TypeNormalizationTest()", Justification = "Test classes must be non-static to allow fixtures")] -[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance", "CA1822:MarkMembersAsStatic", Scope = "member", Target = "Microsoft.Rest.Generator.CSharp.Tests.CSharpCodeNamingFrameworkTests.#TypeNormalizationWithComplexTypesTest()", Justification = "Test classes must be non-static to allow fixtures")] -[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance", "CA1822:MarkMembersAsStatic", Scope = "member", Target = "Microsoft.Rest.Generator.CSharp.Tests.CSharpCodeNamingFrameworkTests.#VerifyMethodRenaming()", Justification = "Test classes must be non-static to allow fixtures")] -[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance", "CA1822:MarkMembersAsStatic", Scope = "member", Target = "Microsoft.Rest.Generator.CSharp.Tests.CSharpCodeNamingFrameworkTests.#NameCollisionTestWithoutNamespace()", Justification = "Test classes must be non-static to allow fixtures")] -[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance", "CA1822:MarkMembersAsStatic", Scope = "member", Target = "Microsoft.Rest.Generator.CSharp.Tests.CSharpCodeNamingFrameworkTests.#NameCollisionTestWithNamespace()", Justification = "Test classes must be non-static to allow fixtures")] -[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance", "CA1822:MarkMembersAsStatic", Scope = "member", Target = "Microsoft.Rest.Generator.CSharp.Tests.CSharpCodeNamingFrameworkTests.#SequenceWithRenamedComplexType()", Justification = "Test classes must be non-static to allow fixtures")] -[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance", "CA1822:MarkMembersAsStatic", Scope = "member", Target = "Microsoft.Rest.Generator.CSharp.Tests.AcceptanceTests.#EnsureStatusCode`1(System.Net.HttpStatusCode,System.Func`1>>)", Justification = "Test classes must be non-static to allow fixtures")] -[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance", "CA1822:MarkMembersAsStatic", Scope = "member", Target = "Microsoft.Rest.Generator.CSharp.Tests.MirrorTests.#CanRoundTripSequences()", Justification = "Test classes must be non-static to allow fixtures")] -[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance", "CA1822:MarkMembersAsStatic", Scope = "member", Target = "Microsoft.Rest.Generator.CSharp.Tests.MirrorTests.#CanRoundtripPolymorphicTypes()", Justification = "Test classes must be non-static to allow fixtures")] -[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance", "CA1822:MarkMembersAsStatic", Scope = "member", Target = "Microsoft.Rest.Generator.CSharp.Tests.MirrorTests.#CanRoundtripFilledOutNestedTypesWithoutRecursion()", Justification = "Test classes must be non-static to allow fixtures")] -[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance", "CA1822:MarkMembersAsStatic", Scope = "member", Target = "Microsoft.Rest.Generator.CSharp.Tests.MirrorTests.#CanRoundtripFilledOutNestedTypesWithoutRecursion2()", Justification = "Test classes must be non-static to allow fixtures")] -[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance", "CA1822:MarkMembersAsStatic", Scope = "member", Target = "Microsoft.Rest.Generator.CSharp.Tests.ProcessOutputListener.#ScrubAndWriteValue(System.String,System.String)", Justification = "Test classes must be non-static to allow fixtures")] -[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance", "CA1822:MarkMembersAsStatic", Scope = "member", Target = "Microsoft.Rest.Generator.CSharp.Tests.MirrorTests.#CanSerializeAndDeserializePrimitiveTypes()", Justification = "Test classes must be non-static to allow fixtures")] -[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance", "CA1822:MarkMembersAsStatic", Scope = "member", Target = "Microsoft.Rest.Generator.CSharp.Tests.MirrorTests.#UrlIsCorrectWhenBaseUriContainsSegment()", Justification = "Test classes must be non-static to allow fixtures")] -[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance", "CA1822:MarkMembersAsStatic", Scope = "member", Target = "Microsoft.Rest.Generator.CSharp.Tests.CSharpCodeNamingFrameworkTests.#VerifyInputMappingsForFlattening()", Justification = "Test classes must be non-static to allow fixtures")] -[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance", "CA1822:MarkMembersAsStatic", Scope = "member", Target = "Microsoft.Rest.Generator.CSharp.Tests.CSharpCodeNamingFrameworkTests.#VerifyInputMappingsForGrouping()", Justification = "Test classes must be non-static to allow fixtures")] -[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance", "CA1822:MarkMembersAsStatic", Scope = "member", Target = "Microsoft.Rest.Generator.CSharp.Tests.CSharpCodeNamingFrameworkTests.#VerifyInputMappingsForResources()", Justification = "Test classes must be non-static to allow fixtures")] [assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2208:InstantiateArgumentExceptionsCorrectly", Scope = "member", Target = "Fixtures.AcceptanceTestsRequiredOptional.Models.ArrayWrapper.#Validate()", Justification="Validation exceptions types are being changed")] [assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2208:InstantiateArgumentExceptionsCorrectly", Scope = "member", Target = "Fixtures.AcceptanceTestsRequiredOptional.Models.ClassWrapper.#Validate()", Justification="Validation exceptions types are being changed")] [assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2208:InstantiateArgumentExceptionsCorrectly", Scope = "member", Target = "Fixtures.MirrorSequences.Models.ErrorModel.#Validate()", Justification="Validation exceptions types are being changed")] @@ -50,4 +33,3 @@ [assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA2204:Literals should be spelled correctly", MessageId = "npm", Scope = "member", Target = "Microsoft.Rest.Generator.CSharp.Tests.ServiceController.#StartServiceProcess()")] [assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1057:StringUriOverloadsCallSystemUriOverloads", Scope = "member", Target = "Fixtures.AcceptanceTestsUrl.AutoRestUrlTestService.#.ctor(System.String,System.Net.Http.DelegatingHandler[])", Justification = "Invalid in the current context.")] [assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance", "CA1809:AvoidExcessiveLocals", Scope = "member", Target = "Microsoft.Rest.Generator.CSharp.Tests.AcceptanceTests.#TestDictionaryPrimitiveTypes(Fixtures.AcceptanceTestsBodyDictionary.AutoRestSwaggerBATdictionaryService)")] -[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance", "CA1822:MarkMembersAsStatic", Scope = "member", Target = "Microsoft.Rest.Generator.CSharp.Tests.AcceptanceTests.#EnsureStatusCode`2(System.Net.HttpStatusCode,System.Func`1>>)")] diff --git a/AutoRest/Generators/Extensions/Azure.Extensions.Tests/GlobalSuppressions.cs b/AutoRest/Generators/Extensions/Azure.Extensions.Tests/GlobalSuppressions.cs index 314fda5322cc..91b9c621e2bc 100644 --- a/AutoRest/Generators/Extensions/Azure.Extensions.Tests/GlobalSuppressions.cs +++ b/AutoRest/Generators/Extensions/Azure.Extensions.Tests/GlobalSuppressions.cs @@ -8,31 +8,5 @@ // "In Suppression File". // You do not need to add suppressions to this file manually. -[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance", "CA1822:MarkMembersAsStatic", Scope = "member", - Target = "Microsoft.Rest.Generator.Azure.Extensions.Tests.AzureServiceClientNormalizerTests.#ResourceIsFlattenedForSimpleResource()", - Justification = "Test methods must not be static to allow suite-level fixtures")] -[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance", "CA1822:MarkMembersAsStatic", Scope = "member", - Target = "Microsoft.Rest.Generator.Azure.Extensions.Tests.AzureServiceClientNormalizerTests.#ResourceIsFlattenedForComplexResource()", - Justification = "Test methods must not be static to allow suite-level fixtures")] -[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance", "CA1822:MarkMembersAsStatic", Scope = "member", - Target = "Microsoft.Rest.Generator.Azure.Extensions.Tests.AzureServiceClientNormalizerTests.#SwaggerODataSpecParsingTest()", - Justification = "Test methods must not be static to allow suite-level fixtures")] -[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance", "CA1822:MarkMembersAsStatic", Scope = "member", - Target = "Microsoft.Rest.Generator.Azure.Extensions.Tests.AzureServiceClientNormalizerTests.#SwaggerResourceExternalFalseTest()", - Justification = "Test methods must not be static to allow suite-level fixtures")] -[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance", "CA1822:MarkMembersAsStatic", Scope = "member", - Target = "Microsoft.Rest.Generator.Azure.Extensions.Tests.AzureServiceClientNormalizerTests.#AzureParameterTest()", - Justification = "Test methods must not be static to allow suite-level fixtures")] -[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance", "CA1822:MarkMembersAsStatic", Scope = "member", - Target = "Microsoft.Rest.Generator.Azure.Extensions.Tests.AzureServiceClientNormalizerTests.#PageableTest()", - Justification = "Test methods must not be static to allow suite-level fixtures")] -[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance", "CA1822:MarkMembersAsStatic", Scope = "member", - Target = "Microsoft.Rest.Generator.Azure.Extensions.Tests.AzureServiceClientNormalizerTests.#ExternalResourceTypeIsNullSafe()", - Justification = "Test methods must not be static to allow suite-level fixtures")] -[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance", "CA1822:MarkMembersAsStatic", Scope = "member", - Target = "Microsoft.Rest.Generator.Azure.Extensions.Tests.AzureServiceClientNormalizerTests.#ResourceIsFlattenedForConflictingResource()", - Justification = "Test methods must not be static to allow suite-level fixtures")] -[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance", "CA1822:MarkMembersAsStatic", Scope = "member", Target = "Microsoft.Rest.Generator.Azure.Extensions.Tests.AzureServiceClientNormalizerTests.#FlatteningTest()")] -[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance", "CA1822:MarkMembersAsStatic", Scope = "member", Target = "Microsoft.Rest.Generator.CSharp.Azure.Tests.CSharpAzureCodeNamingFrameworkTests.#ConvertsPageResultsToPageTypeTest()")] [assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Globalization", "CA1308:NormalizeStringsToUppercase", Scope = "member", Target = "Microsoft.Rest.Generator.CSharp.Azure.Tests.CSharpAzureCodeNamingFrameworkTests.#ConvertsPageResultsToPageTypeTest()")] diff --git a/AutoRest/Generators/Extensions/Extensions.Tests/GlobalSuppressions.cs b/AutoRest/Generators/Extensions/Extensions.Tests/GlobalSuppressions.cs index a628d38cbf3b..46ddf026866e 100644 --- a/AutoRest/Generators/Extensions/Extensions.Tests/GlobalSuppressions.cs +++ b/AutoRest/Generators/Extensions/Extensions.Tests/GlobalSuppressions.cs @@ -1,14 +1,4 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. See License.txt in the project root for license information. -[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance", "CA1822:MarkMembersAsStatic", Scope = "member", Target = "Microsoft.Rest.Generator.Tests.ExtensionsTests.#TestClientModelWithPayloadFlattening()")] -[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance", "CA1822:MarkMembersAsStatic", Scope = "member", Target = "Microsoft.Rest.Generator.Tests.MappingExtensionsTests.#TestInputMapping()")] [assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Maintainability", "CA1502:AvoidExcessiveComplexity", Scope = "member", Target = "Microsoft.Rest.Generator.Tests.ExtensionsTests.#TestClientModelWithPayloadFlatteningViaXMSClientFlatten()")] -[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance", "CA1822:MarkMembersAsStatic", Scope = "member", Target = "Microsoft.Rest.Generator.Tests.ExtensionsTests.#TestClientModelWithPayloadFlatteningViaXMSClientFlatten()")] - -[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance", "CA1822:MarkMembersAsStatic", Scope = "member", Target = "Microsoft.Rest.Generator.Tests.ExtensionsTests.#TestClientModelClientName()")] -[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance", "CA1822:MarkMembersAsStatic", Scope = "member", Target = "Microsoft.Rest.Generator.Tests.ExtensionsTests.#TestClientNameCSharpNormalization()")] -[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance", "CA1822:MarkMembersAsStatic", Scope = "member", Target = "Microsoft.Rest.Generator.Tests.ExtensionsTests.#TestClientNameJavaNormalization()")] -[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance", "CA1822:MarkMembersAsStatic", Scope = "member", Target = "Microsoft.Rest.Generator.Tests.ExtensionsTests.#TestClientNameNodeJSNormalization()")] -[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance", "CA1822:MarkMembersAsStatic", Scope = "member", Target = "Microsoft.Rest.Generator.Tests.ExtensionsTests.#TestClientNamePythonNormalization()")] -[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance", "CA1822:MarkMembersAsStatic", Scope = "member", Target = "Microsoft.Rest.Generator.Tests.ExtensionsTests.#TestClientNameRubyNormalization()")] diff --git a/AutoRest/Modelers/CompositeSwagger.Tests/GlobalSuppressions.cs b/AutoRest/Modelers/CompositeSwagger.Tests/GlobalSuppressions.cs index fbc8ea7cbdbc..5f282702bb03 100644 --- a/AutoRest/Modelers/CompositeSwagger.Tests/GlobalSuppressions.cs +++ b/AutoRest/Modelers/CompositeSwagger.Tests/GlobalSuppressions.cs @@ -1,10 +1 @@ -[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance", "CA1822:MarkMembersAsStatic", Scope = "member", Target = "Microsoft.Rest.Modeler.CompositeSwagger.Tests.CompositeSwaggerModelerTests.#CompositeSwaggerWithTwoModels()")] -[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance", "CA1822:MarkMembersAsStatic", Scope = "member", Target = "Microsoft.Rest.Modeler.CompositeSwagger.Tests.CompositeSwaggerModelerTests.#CompositeSwaggerWithOneModel()")] -[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance", "CA1822:MarkMembersAsStatic", Scope = "member", Target = "Microsoft.Rest.Modeler.CompositeSwagger.Tests.CompositeSwaggerModelerTests.#CompositeModelWithEmptyInfo()")] -[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance", "CA1822:MarkMembersAsStatic", Scope = "member", Target = "Microsoft.Rest.Modeler.CompositeSwagger.Tests.CompositeSwaggerModelerTests.#CompositeModelWithEmptyDocuments()")] -[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance", "CA1822:MarkMembersAsStatic", Scope = "member", Target = "Microsoft.Rest.Modeler.CompositeSwagger.Tests.CompositeSwaggerModelerTests.#CompositeModelWithConflictInSettings()")] -[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance", "CA1822:MarkMembersAsStatic", Scope = "member", Target = "Microsoft.Rest.Modeler.CompositeSwagger.Tests.CompositeSwaggerModelerTests.#CompositeModelWithConflictInModel()")] -[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance", "CA1822:MarkMembersAsStatic", Scope = "member", Target = "Microsoft.Rest.Modeler.CompositeSwagger.Tests.CompositeSwaggerModelerTests.#CompositeModelWithConflictInMethod()")] -[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance", "CA1822:MarkMembersAsStatic", Scope = "member", Target = "Microsoft.Rest.Modeler.CompositeSwagger.Tests.CompositeSwaggerModelerTests.#CompositeModelWithConflictInGlobalParam()")] -[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance", "CA1822:MarkMembersAsStatic", Scope = "member", Target = "Microsoft.Rest.Modeler.CompositeSwagger.Tests.CompositeSwaggerModelerTests.#CompositeSwaggerWithSameModels()")] - + \ No newline at end of file diff --git a/AutoRest/Modelers/Swagger.Tests/AutoRest.Modeler.Swagger.Tests.csproj b/AutoRest/Modelers/Swagger.Tests/AutoRest.Modeler.Swagger.Tests.csproj index ea2b011b5341..76cdda60224f 100644 --- a/AutoRest/Modelers/Swagger.Tests/AutoRest.Modeler.Swagger.Tests.csproj +++ b/AutoRest/Modelers/Swagger.Tests/AutoRest.Modeler.Swagger.Tests.csproj @@ -39,6 +39,9 @@ + + PreserveNewest + PreserveNewest diff --git a/AutoRest/Modelers/Swagger.Tests/GlobalSuppressions.cs b/AutoRest/Modelers/Swagger.Tests/GlobalSuppressions.cs index 003d12bb4dc1..d7540fb6b412 100644 --- a/AutoRest/Modelers/Swagger.Tests/GlobalSuppressions.cs +++ b/AutoRest/Modelers/Swagger.Tests/GlobalSuppressions.cs @@ -11,28 +11,4 @@ [assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1004:GenericMethodsShouldProvideTypeParameter", Scope = "member", Target = "Microsoft.Rest.Modeler.Swagger.Tests.SwaggerSpecHelper.#RunTests`1(System.String,System.String,System.String,Microsoft.Rest.Generator.Settings)")] [assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1004:GenericMethodsShouldProvideTypeParameter", Scope = "member", Target = "Microsoft.Rest.Modeler.Swagger.Tests.SwaggerSpecHelper.#RunTests`1(Microsoft.Rest.Generator.Settings,System.String)")] [assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Maintainability", "CA1502:AvoidExcessiveComplexity", Scope = "member", Target = "Microsoft.Rest.Modeler.Swagger.Tests.SwaggerModelerTests.#TestDataTypes()")] -[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance", "CA1822:MarkMembersAsStatic", Scope = "member", Target = "Microsoft.Rest.Modeler.Swagger.Tests.SwaggerModelerTests.#TestClientModelFromSimpleSwagger()")] -[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance", "CA1822:MarkMembersAsStatic", Scope = "member", Target = "Microsoft.Rest.Modeler.Swagger.Tests.SwaggerModelerTests.#TestExternalReferences()")] -[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance", "CA1822:MarkMembersAsStatic", Scope = "member", Target = "Microsoft.Rest.Modeler.Swagger.Tests.SwaggerModelerTests.#TestExternalReferencesWithAllOf()")] -[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance", "CA1822:MarkMembersAsStatic", Scope = "member", Target = "Microsoft.Rest.Modeler.Swagger.Tests.SwaggerModelerTests.#TestExternalReferencesWithReferencesInProperties()")] -[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance", "CA1822:MarkMembersAsStatic", Scope = "member", Target = "Microsoft.Rest.Modeler.Swagger.Tests.SwaggerModelerTests.#TestExternalReferencesWithExtension()")] -[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance", "CA1822:MarkMembersAsStatic", Scope = "member", Target = "Microsoft.Rest.Modeler.Swagger.Tests.SwaggerModelerTests.#TestClientModelWithInheritance()")] -[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance", "CA1822:MarkMembersAsStatic", Scope = "member", Target = "Microsoft.Rest.Modeler.Swagger.Tests.SwaggerModelerTests.#TestClientModelPolymorhism()")] -[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance", "CA1822:MarkMembersAsStatic", Scope = "member", Target = "Microsoft.Rest.Modeler.Swagger.Tests.SwaggerModelerTests.#ClientModelWithCircularDependencyThrowsError()")] -[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance", "CA1822:MarkMembersAsStatic", Scope = "member", Target = "Microsoft.Rest.Modeler.Swagger.Tests.SwaggerModelerTests.#TestClientModelWithRecursiveTypes()")] -[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance", "CA1822:MarkMembersAsStatic", Scope = "member", Target = "Microsoft.Rest.Modeler.Swagger.Tests.SwaggerModelerTests.#TestClientModelWithNoContent()")] -[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance", "CA1822:MarkMembersAsStatic", Scope = "member", Target = "Microsoft.Rest.Modeler.Swagger.Tests.SwaggerModelerTests.#TestClientModelWithDifferentReturnsTypesBasedOnStatusCode()")] -[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance", "CA1822:MarkMembersAsStatic", Scope = "member", Target = "Microsoft.Rest.Modeler.Swagger.Tests.SwaggerModelerTests.#DefaultReturnsCorrectType()")] -[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance", "CA1822:MarkMembersAsStatic", Scope = "member", Target = "Microsoft.Rest.Modeler.Swagger.Tests.SwaggerModelerTests.#GlobalResponsesReference()")] -[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance", "CA1822:MarkMembersAsStatic", Scope = "member", Target = "Microsoft.Rest.Modeler.Swagger.Tests.SwaggerModelerTests.#TestClientModelWithStreamAndByteArray()")] -[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance", "CA1822:MarkMembersAsStatic", Scope = "member", Target = "Microsoft.Rest.Modeler.Swagger.Tests.SwaggerModelerTests.#TestClientModelWithMethodGroups()")] -[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance", "CA1822:MarkMembersAsStatic", Scope = "member", Target = "Microsoft.Rest.Modeler.Swagger.Tests.SwaggerModelerTests.#TestDataTypes()")] -[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance", "CA1822:MarkMembersAsStatic", Scope = "member", Target = "Microsoft.Rest.Modeler.Swagger.Tests.SwaggerModelerTests.#TestClientWithValidation()")] -[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance", "CA1822:MarkMembersAsStatic", Scope = "member", Target = "Microsoft.Rest.Modeler.Swagger.Tests.SwaggerModelerTests.#TestClientModelWithPayloadFlattening()")] -[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance", "CA1822:MarkMembersAsStatic", Scope = "member", Target = "Microsoft.Rest.Modeler.Swagger.Tests.SwaggerModelerTests.#TestClientModelWithResponseHeaders()")] -[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance", "CA1822:MarkMembersAsStatic", Scope = "member", Target = "Microsoft.Rest.Modeler.Swagger.Tests.SwaggerModelerTests.#TestCustomPaths()")] -[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance", "CA1822:MarkMembersAsStatic", Scope = "member", Target = "Microsoft.Rest.Modeler.Swagger.Tests.SwaggerModelerTests.#TestSettingsFromSwagger()")] [assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance", "CA1804:RemoveUnusedLocals", MessageId = "client", Scope = "member", Target = "Microsoft.Rest.Modeler.Swagger.Tests.SwaggerModelerTests.#TestSettingsFromSwagger()")] -[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance", "CA1822:MarkMembersAsStatic", Scope = "member", Target = "Microsoft.Rest.Modeler.Swagger.Tests.SwaggerModelerTests.#TestConstants()")] -[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance", "CA1822:MarkMembersAsStatic", Scope = "member", Target = "Microsoft.Rest.Modeler.Swagger.Tests.SwaggerModelerTests.#TestCompositeConstants()")] - diff --git a/AutoRest/Modelers/Swagger.Tests/Swagger/swagger-ref-allOf-inheritance.json b/AutoRest/Modelers/Swagger.Tests/Swagger/swagger-ref-allOf-inheritance.json new file mode 100644 index 000000000000..a72247c6fb38 --- /dev/null +++ b/AutoRest/Modelers/Swagger.Tests/Swagger/swagger-ref-allOf-inheritance.json @@ -0,0 +1,280 @@ +{ + "swagger": "2.0", + "info": { + "title": "RedisManagementClient", + "description": "A sample model for testing that swagger references and allOf gets understood by the modeler properly", + "version": "1.0.0" + }, + "host": "management.azure.com", + "schemes": [ + "https" + ], + "consumes": [ + "application/json", + "text/json" + ], + "produces": [ + "application/json", + "text/json" + ], + "securityDefinitions": { }, + "security": [ ], + "tags": [ ], + "paths": { + "providers/Microsoft.Cache/Redis/{name}": { + "put": { + "operationId": "Redis_CreateOrUpdate", + "description": "Create or update a redis cache", + "parameters": [ + { + "name": "name", + "in": "path", + "required": true, + "type": "string", + "description": "" + }, + { + "name": "parameters", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/RedisCreateOrUpdateParameters" + }, + "description": "Parameters supplied to the CreateOrUpdate redis operation." + } + ], + "responses": { + "201": { + "description": "", + "schema": { + "$ref": "#/definitions/Resource" + } + } + } + } + } + }, + "definitions": { + "Sku": { + "properties": { + "name": { + "type": "string", + "description": "", + "enum": [ + "Basic", + "Standard", + "Premium" + ], + "x-ms-enum": { + "name": "SkuName", + "modelAsString": true + } + }, + "family": { + "type": "string", + "description": "", + "enum": [ + "C", + "P" + ], + "x-ms-enum": { + "name": "SkuFamily", + "modelAsString": true + } + }, + "capacity": { + "type": "integer", + "format": "int32", + "description": "" + } + }, + "required": [ + "name", + "family", + "capacity" + ], + "description": "Sku parameters supplied to the create redis operation." + }, + "RedisProperties": { + "properties": { + "sku": { + "$ref": "#/definitions/Sku", + "description": "" + }, + "redisConfiguration": { + "type": "object", + "additionalProperties": { + "type": "string" + }, + "description": "" + }, + "enableNonSslPort": { + "type": "boolean", + "description": "" + }, + "tenantSettings": { + "type": "object", + "additionalProperties": { + "type": "string" + }, + "description": "" + }, + "shardCount": { + "type": "integer", + "format": "int32", + "description": "" + }, + "subnetId": { + "type": "string", + "description": "" + }, + "staticIP": { + "type": "string", + "description": "" + } + }, + "required": [ + "sku" + ], + "description": "'RedisProperties' - Parameters supplied to CreateOrUpdate redis operation." + }, + "Resource": { + "properties": { + "id": { + "readOnly": true, + "type": "string", + "description": "Resource Id" + }, + "name": { + "readOnly": true, + "type": "string", + "description": "Resource name" + }, + "type": { + "readOnly": true, + "type": "string", + "description": "Resource type" + }, + "location": { + "type": "string", + "description": "Resource location" + }, + "tags": { + "type": "object", + "additionalProperties": { + "type": "string" + }, + "description": "Resource tags" + } + }, + "description": "''Resource' - common resource information", + "required": [ + "location" + ], + "x-ms-azure-resource": true + }, + "RedisCreateOrUpdateParameters": { + "properties": { + "properties": { + "x-ms-client-flatten": true, + "$ref": "#/definitions/RedisProperties", + "description": "'RedisCreateOrUpdateParameters.properties' - Redis cache properties." + } + }, + "required": [ + "properties" + ], + "allOf": [ + { + "$ref": "#/definitions/Resource" + } + ], + "description": "'RedisCreateOrUpdateParameters' - Parameters supplied to the CreateOrUpdate Redis operation." + }, + "RedisAccessKeys": { + "properties": { + "primaryKey": { + "type": "string", + "description": "" + }, + "secondaryKey": { + "type": "string", + "description": "" + } + }, + "description": "'RedisAccessKeys' - Redis cache access keys." + }, + "RedisReadableProperties": { + "properties": { + "provisioningState": { + "type": "string", + "description": "provisioning status" + }, + "hostName": { + "type": "string", + "description": "" + }, + "port": { + "type": "integer", + "format": "int32", + "description": "" + }, + "sslPort": { + "type": "integer", + "format": "int32", + "description": "" + } + }, + "allOf": [ + { + "$ref": "#/definitions/RedisProperties" + } + ], + "description": "'RedisReadableProperties' - Parameters describing a redis instance" + }, + "RedisReadablePropertiesWithAccessKey": { + "properties": { + "accessKeys": { + "$ref": "#/definitions/RedisAccessKeys", + "description": "Redis cache access keys." + } + }, + "allOf": [ + { + "$ref": "#/definitions/RedisReadableProperties" + } + ], + "description": "'RedisReadablePropertiesWithAccessKey' - Access Keys in addition to RedisReadableProperties" + }, + "RedisResourceWithAccessKey": { + "properties": { + "properties": { + "x-ms-client-flatten": true, + "$ref": "#/definitions/RedisReadablePropertiesWithAccessKey", + "description": "'RedisResourceWithAccessKey.properties' Redis cache properties" + } + }, + "allOf": [ + { + "$ref": "#/definitions/RedisResource" + } + ], + "description": "'RedisResourceWithAccessKey' - A redis item in CreateOrUpdate Operation response." + }, + "RedisResource": { + "properties": { + "properties": { + "x-ms-client-flatten": true, + "$ref": "#/definitions/RedisReadableProperties", + "description": "'RedisResource.properties' - Redis cache properties" + } + }, + "allOf": [ + { + "$ref": "#/definitions/Resource" + } + ], + "description": "'RedisResource' - A redis resource" + } + } +} \ No newline at end of file diff --git a/AutoRest/Modelers/Swagger.Tests/SwaggerModelerTests.cs b/AutoRest/Modelers/Swagger.Tests/SwaggerModelerTests.cs index 0aac57a71e45..6083741a77c6 100644 --- a/AutoRest/Modelers/Swagger.Tests/SwaggerModelerTests.cs +++ b/AutoRest/Modelers/Swagger.Tests/SwaggerModelerTests.cs @@ -185,7 +185,9 @@ public void ClientModelWithCircularDependencyThrowsError() Namespace = "Test", Input = Path.Combine("Swagger", "swagger-allOf-circular.json") }); - Assert.Throws(() => modeler.Build()); + var ex = Assert.Throws(() => modeler.Build()); + Assert.Contains("circular", ex.Message, StringComparison.OrdinalIgnoreCase); + Assert.Contains("siamese", ex.Message, StringComparison.OrdinalIgnoreCase); } [Fact] @@ -204,6 +206,40 @@ public void TestClientModelWithRecursiveTypes() Assert.Equal("String", clientModel.ModelTypes.First(m => m.Name == "Product").Properties[0].Type.ToString()); } + [Fact] + public void TestClientModelWithManyAllOfRelationships() + { + var modeler = new SwaggerModeler(new Settings + { + Namespace = "Test", + Input = Path.Combine("Swagger", "swagger-ref-allOf-inheritance.json") + }); + var clientModel = modeler.Build(); + + // the model has a few base type relationships which should be observed: + // RedisResource is a Resource + var resourceModel = clientModel.ModelTypes.Single(x => x.Name == "Resource"); + var redisResourceModel = clientModel.ModelTypes.Single(x => x.Name == "RedisResource"); + Assert.Equal(resourceModel, redisResourceModel.BaseModelType); + + // RedisResourceWithAccessKey is a RedisResource + var redisResponseWithAccessKeyModel = clientModel.ModelTypes.Single(x => x.Name == "RedisResourceWithAccessKey"); + Assert.Equal(redisResourceModel, redisResponseWithAccessKeyModel.BaseModelType); + + // RedisCreateOrUpdateParameters is a Resource + var redisCreateUpdateParametersModel = clientModel.ModelTypes.Single(x => x.Name == "RedisCreateOrUpdateParameters"); + Assert.Equal(resourceModel, redisCreateUpdateParametersModel.BaseModelType); + + // RedisReadableProperties is a RedisProperties + var redisPropertiesModel = clientModel.ModelTypes.Single(x => x.Name == "RedisProperties"); + var redisReadablePropertieModel = clientModel.ModelTypes.Single(x => x.Name == "RedisReadableProperties"); + Assert.Equal(redisPropertiesModel, redisReadablePropertieModel.BaseModelType); + + // RedisReadablePropertiesWithAccessKey is a RedisReadableProperties + var redisReadablePropertiesWithAccessKeysModel = clientModel.ModelTypes.Single(x => x.Name == "RedisReadablePropertiesWithAccessKey"); + Assert.Equal(redisReadablePropertieModel, redisReadablePropertiesWithAccessKeysModel.BaseModelType); + } + [Fact] public void TestClientModelWithNoContent() { @@ -560,7 +596,6 @@ public void TestSettingsFromSwagger() Assert.Equal(true, codeGenerator.InternalConstructors); } - [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance", "CA1822:MarkMembersAsStatic")] [Fact] public void TestParameterizedHostFromSwagger() { diff --git a/AutoRest/Modelers/Swagger/Properties/Resources.Designer.cs b/AutoRest/Modelers/Swagger/Properties/Resources.Designer.cs index e2335bc14a76..bb600eb0be9a 100644 --- a/AutoRest/Modelers/Swagger/Properties/Resources.Designer.cs +++ b/AutoRest/Modelers/Swagger/Properties/Resources.Designer.cs @@ -60,6 +60,15 @@ internal Resources() { } } + /// + /// Looks up a localized string similar to Found a type set '{0}' which is circularly defined.. + /// + internal static string CircularBaseSchemaSet { + get { + return ResourceManager.GetString("CircularBaseSchemaSet", resourceCulture); + } + } + /// /// Looks up a localized string similar to Circular reference detected: {0}. /// diff --git a/AutoRest/Modelers/Swagger/Properties/Resources.resx b/AutoRest/Modelers/Swagger/Properties/Resources.resx index 057ff414a1b2..18588c769584 100644 --- a/AutoRest/Modelers/Swagger/Properties/Resources.resx +++ b/AutoRest/Modelers/Swagger/Properties/Resources.resx @@ -117,6 +117,9 @@ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + Found a type set '{0}' which is circularly defined. + Circular reference detected: {0} diff --git a/AutoRest/Modelers/Swagger/SchemaResolver.cs b/AutoRest/Modelers/Swagger/SchemaResolver.cs index 092a8c145f6d..7504d3314106 100644 --- a/AutoRest/Modelers/Swagger/SchemaResolver.cs +++ b/AutoRest/Modelers/Swagger/SchemaResolver.cs @@ -18,7 +18,6 @@ public class SchemaResolver : ICloneable private const int MaximumReferenceDepth = 40; private readonly SwaggerModeler _modeler; private readonly ServiceDefinition _serviceDefinition; - private readonly List _visitedReferences; /// /// Create a new schema resolver in the context of the given swagger spec @@ -33,7 +32,6 @@ public SchemaResolver(SwaggerModeler modeler) _modeler = modeler; _serviceDefinition = modeler.ServiceDefinition; - _visitedReferences = new List(); } /// @@ -44,11 +42,6 @@ public SchemaResolver(SwaggerModeler modeler) public object Clone() { var resolver = new SchemaResolver(_modeler); - foreach (string reference in _visitedReferences) - { - resolver._visitedReferences.Add(reference); - } - return resolver; } @@ -89,7 +82,9 @@ public void ExpandAllOf(Schema schema) if (schema.AllOf != null) { + CheckCircularAllOf(schema, null, null); var references = schema.AllOf.Where(s => s.Reference != null).ToList(); + if (references.Count == 1) { if (schema.Extends != null) @@ -108,6 +103,7 @@ public void ExpandAllOf(Schema schema) Properties = schema.Properties }; + var schemaList = new List().Concat(schema.AllOf) .Concat(new List {propertiesOnlySchema}); @@ -177,6 +173,34 @@ public void ExpandAllOf(Schema schema) } } + void CheckCircularAllOf(Schema schema, HashSet visited, Stack referenceChain) + { + visited = visited ?? new HashSet(); + referenceChain = referenceChain ?? new Stack(); + if (!visited.Add(schema)) // was already present in the set + { + var setDescription = "(" + String.Join(", ", referenceChain) + ")"; + throw new InvalidOperationException( + string.Format(CultureInfo.InvariantCulture, + Properties.Resources.CircularBaseSchemaSet, setDescription)); + } + + if (schema.AllOf != null) + { + foreach (var reference in schema.AllOf.Select(s => s.Reference).Where(r => r != null)) + { + referenceChain.Push(reference); + + var deref = Dereference(reference); + CheckCircularAllOf(deref, visited, referenceChain); + + Debug.Assert(reference == referenceChain.Peek()); + referenceChain.Pop(); + } + } + visited.Remove(schema); + } + /// /// Determine equivalence between the types described by two schemas. /// Limit the comparison to exclude comparison of complexe inline schemas. @@ -201,12 +225,32 @@ private bool SchemaTypesAreEquivalent(Schema parentProperty, if ((parentProperty.Type == null || parentProperty.Type == DataType.Object) && (unwrappedProperty.Type == null || unwrappedProperty.Type == DataType.Object)) { - if (!string.IsNullOrEmpty(parentProperty.Reference) || - !string.IsNullOrEmpty(unwrappedProperty.Reference)) + var parentPropertyToCompare = parentProperty; + var unwrappedPropertyToCompare = unwrappedProperty; + if (!string.IsNullOrEmpty(parentProperty.Reference)) + { + parentPropertyToCompare = Dereference(parentProperty.Reference); + } + if (!string.IsNullOrEmpty(unwrappedProperty.Reference)) + { + unwrappedPropertyToCompare = Dereference(unwrappedProperty.Reference); + } + + if (parentPropertyToCompare == unwrappedPropertyToCompare) + { + return true; // when fully dereferenced, they can refer to the same thing + } + + // or they can refer to different things... but there can be an inheritance relation... + while (unwrappedPropertyToCompare != null && unwrappedPropertyToCompare.Extends != null) { - return parentProperty.Reference == unwrappedProperty.Reference; + unwrappedPropertyToCompare = Dereference(unwrappedPropertyToCompare.Extends); + if (unwrappedPropertyToCompare == parentPropertyToCompare) + { + return true; + } } - // do not compare inline schemas + return false; } if (parentProperty.Type == DataType.Array && @@ -252,6 +296,12 @@ private Schema FindParentProperty(string parentReference, string propertyName) /// The schema reference to dereference. /// The dereferenced schema. private Schema Dereference(string referencePath) + { + var vistedReferences = new List(); + return DereferenceInner(referencePath, vistedReferences); + } + + private Schema DereferenceInner(string referencePath, List visitedReferences) { // Check if external reference string[] splitReference = referencePath.Split(new[] {'#'}, StringSplitOptions.RemoveEmptyEntries); @@ -260,17 +310,17 @@ private Schema Dereference(string referencePath) referencePath = "#" + splitReference[1]; } - if (_visitedReferences.Contains(referencePath.ToLower(CultureInfo.InvariantCulture))) + if (visitedReferences.Contains(referencePath.ToUpperInvariant())) { throw new ArgumentException(string.Format(CultureInfo.InvariantCulture, Properties.Resources.CircularReference, referencePath)); } - if (_visitedReferences.Count >= MaximumReferenceDepth) + if (visitedReferences.Count >= MaximumReferenceDepth) { throw new ArgumentException(Properties.Resources.ExceededMaximumReferenceDepth, referencePath); } - _visitedReferences.Add(referencePath.ToLower(CultureInfo.InvariantCulture)); + visitedReferences.Add(referencePath.ToUpperInvariant()); var definitions = _serviceDefinition.Definitions; if (definitions == null || !definitions.ContainsKey(referencePath.StripDefinitionPath())) { @@ -282,7 +332,7 @@ private Schema Dereference(string referencePath) var schema = _serviceDefinition.Definitions[referencePath.StripDefinitionPath()]; if (schema.Reference != null) { - schema = Dereference(schema.Reference); + schema = DereferenceInner(schema.Reference, visitedReferences); } return schema; diff --git a/Tools/TestRules.ruleset b/Tools/TestRules.ruleset index 6c0755dd13d5..15f831c090a8 100644 --- a/Tools/TestRules.ruleset +++ b/Tools/TestRules.ruleset @@ -1,4 +1,4 @@ - + @@ -35,6 +35,8 @@ + +