From 40ae002677b4123de047ed55fed53a18ee89bc28 Mon Sep 17 00:00:00 2001 From: Andre Bossard Date: Tue, 4 Feb 2025 23:25:28 +0100 Subject: [PATCH 1/3] Enhance WsdlDocument to handle namespace declarations and add example WSDL and XSD files --- .../WsdlDocument.cs | 50 +++++++++++-------- examples/includeExample/additional.xsd | 5 ++ examples/includeExample/common.xsd | 5 ++ examples/includeExample/example.wsdl | 41 +++++++++++++++ examples/includeExample/schema1.xsd | 11 ++++ examples/includeExample/schema2.xsd | 12 +++++ 6 files changed, 103 insertions(+), 21 deletions(-) create mode 100644 examples/includeExample/additional.xsd create mode 100644 examples/includeExample/common.xsd create mode 100644 examples/includeExample/example.wsdl create mode 100644 examples/includeExample/schema1.xsd create mode 100644 examples/includeExample/schema2.xsd diff --git a/ApiManagementSchemaImport/Microsoft.Azure.ApiManagement.WsdlProcessor.Common/WsdlDocument.cs b/ApiManagementSchemaImport/Microsoft.Azure.ApiManagement.WsdlProcessor.Common/WsdlDocument.cs index 1c6e39c..79c9325 100644 --- a/ApiManagementSchemaImport/Microsoft.Azure.ApiManagement.WsdlProcessor.Common/WsdlDocument.cs +++ b/ApiManagementSchemaImport/Microsoft.Azure.ApiManagement.WsdlProcessor.Common/WsdlDocument.cs @@ -518,41 +518,49 @@ private static void AddXmlnsAndChangePrefixReferenced( IEnumerable newElements, Dictionary namespaces) { + // Capture all declared xmlns attributes var parentNamespaces = documentElement - .Attributes() - .Where(a => a.ToString() - .Contains("xmlns:")) - .Select(a => new - { - Prefix = a.Name.LocalName, - Namespace = a.Value - }).ToDictionary(a => a.Namespace, a => a.Prefix); + .Attributes() + .Where(a => a.IsNamespaceDeclaration) + .Select(a => new { Prefix = a.Name.LocalName, Namespace = a.Value }) + .ToDictionary(a => a.Namespace + "_" + a.Prefix, a => a.Prefix); // composite key foreach (var item in namespaces) { - //string prefix = string.Empty; - parentNamespaces.TryGetValue(item.Key, out string prefix); - - if (prefix == null) + string desiredPrefix = item.Value; + string prefix = null; + var attr = documentElement.Attribute(XNamespace.Xmlns + desiredPrefix); + if (attr != null) { - prefix = GenerateNewNamespace(documentElement, parentNamespaces, item); + if (attr.Value == item.Key) + { + prefix = desiredPrefix; + } + else + { + prefix = GenerateNewNamespace(documentElement, parentNamespaces, item); + } + } + else + { + documentElement.Add(new XAttribute(XNamespace.Xmlns + desiredPrefix, item.Key)); + parentNamespaces.Add(item.Key + "_" + desiredPrefix, desiredPrefix); + prefix = desiredPrefix; } - //Modify attributes from elements with the same prefix + // Modify attributes from elements that reference the old prefix var prefixValue = item.Value + ":"; - foreach (var element in newElements.DescendantsAndSelf()) { - //Go through all attributes and modify if they have the prefix + // Go through all attributes and modify if they have the prefix var attributes = element - .Attributes() - .Where(e => e.Value.Contains(prefixValue)); - + .Attributes() + .Where(e => e.Value.Contains(prefixValue)); foreach (var attribute in attributes) { if (attribute.Value.Count(i => i == ':') == 1 - && !(Uri.TryCreate(attribute.Value, UriKind.Absolute, out var uriResult) - && (uriResult.Scheme == Uri.UriSchemeHttp || uriResult.Scheme == Uri.UriSchemeHttps))) + && !(Uri.TryCreate(attribute.Value, UriKind.Absolute, out var uriResult) + && (uriResult.Scheme == Uri.UriSchemeHttp || uriResult.Scheme == Uri.UriSchemeHttps))) { var splitValue = attribute.Value.Split(':'); attribute.Value = prefix + ":" + splitValue[1]; diff --git a/examples/includeExample/additional.xsd b/examples/includeExample/additional.xsd new file mode 100644 index 0000000..a324428 --- /dev/null +++ b/examples/includeExample/additional.xsd @@ -0,0 +1,5 @@ + + + diff --git a/examples/includeExample/common.xsd b/examples/includeExample/common.xsd new file mode 100644 index 0000000..83aace1 --- /dev/null +++ b/examples/includeExample/common.xsd @@ -0,0 +1,5 @@ + + + diff --git a/examples/includeExample/example.wsdl b/examples/includeExample/example.wsdl new file mode 100644 index 0000000..ae42a9e --- /dev/null +++ b/examples/includeExample/example.wsdl @@ -0,0 +1,41 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/examples/includeExample/schema1.xsd b/examples/includeExample/schema1.xsd new file mode 100644 index 0000000..a8caceb --- /dev/null +++ b/examples/includeExample/schema1.xsd @@ -0,0 +1,11 @@ + + + + + + + + + diff --git a/examples/includeExample/schema2.xsd b/examples/includeExample/schema2.xsd new file mode 100644 index 0000000..3b871c4 --- /dev/null +++ b/examples/includeExample/schema2.xsd @@ -0,0 +1,12 @@ + + + + + + + + + + From cc647e525f732e3ea4f238d5e3a8a585ec8ad675 Mon Sep 17 00:00:00 2001 From: Andre Bossard Date: Tue, 4 Feb 2025 23:25:41 +0100 Subject: [PATCH 2/3] Fix namespace conflict in WsdlDocument --- .../.idea/.gitignore | 13 +++++++++++++ .../.idea/encodings.xml | 4 ++++ .../.idea/indexLayout.xml | 10 ++++++++++ .../.idea.ApiManagementSchemaImport/.idea/vcs.xml | 7 +++++++ 4 files changed, 34 insertions(+) create mode 100644 ApiManagementSchemaImport/.idea/.idea.ApiManagementSchemaImport/.idea/.gitignore create mode 100644 ApiManagementSchemaImport/.idea/.idea.ApiManagementSchemaImport/.idea/encodings.xml create mode 100644 ApiManagementSchemaImport/.idea/.idea.ApiManagementSchemaImport/.idea/indexLayout.xml create mode 100644 ApiManagementSchemaImport/.idea/.idea.ApiManagementSchemaImport/.idea/vcs.xml diff --git a/ApiManagementSchemaImport/.idea/.idea.ApiManagementSchemaImport/.idea/.gitignore b/ApiManagementSchemaImport/.idea/.idea.ApiManagementSchemaImport/.idea/.gitignore new file mode 100644 index 0000000..705a85e --- /dev/null +++ b/ApiManagementSchemaImport/.idea/.idea.ApiManagementSchemaImport/.idea/.gitignore @@ -0,0 +1,13 @@ +# Default ignored files +/shelf/ +/workspace.xml +# Rider ignored files +/.idea.ApiManagementSchemaImport.iml +/modules.xml +/contentModel.xml +/projectSettingsUpdater.xml +# Editor-based HTTP Client requests +/httpRequests/ +# Datasource local storage ignored files +/dataSources/ +/dataSources.local.xml \ No newline at end of file diff --git a/ApiManagementSchemaImport/.idea/.idea.ApiManagementSchemaImport/.idea/encodings.xml b/ApiManagementSchemaImport/.idea/.idea.ApiManagementSchemaImport/.idea/encodings.xml new file mode 100644 index 0000000..df87cf9 --- /dev/null +++ b/ApiManagementSchemaImport/.idea/.idea.ApiManagementSchemaImport/.idea/encodings.xml @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/ApiManagementSchemaImport/.idea/.idea.ApiManagementSchemaImport/.idea/indexLayout.xml b/ApiManagementSchemaImport/.idea/.idea.ApiManagementSchemaImport/.idea/indexLayout.xml new file mode 100644 index 0000000..7076fb0 --- /dev/null +++ b/ApiManagementSchemaImport/.idea/.idea.ApiManagementSchemaImport/.idea/indexLayout.xml @@ -0,0 +1,10 @@ + + + + + ../../api-management-schema-import + + + + + \ No newline at end of file diff --git a/ApiManagementSchemaImport/.idea/.idea.ApiManagementSchemaImport/.idea/vcs.xml b/ApiManagementSchemaImport/.idea/.idea.ApiManagementSchemaImport/.idea/vcs.xml new file mode 100644 index 0000000..62bd7a0 --- /dev/null +++ b/ApiManagementSchemaImport/.idea/.idea.ApiManagementSchemaImport/.idea/vcs.xml @@ -0,0 +1,7 @@ + + + + + + + \ No newline at end of file From 2ab5630726d424a8063dc84596bff90bb25e1c0b Mon Sep 17 00:00:00 2001 From: Andre Bossard Date: Tue, 4 Feb 2025 23:27:41 +0100 Subject: [PATCH 3/3] Remove unnecessary .idea configuration files and update .gitignore to exclude .idea directory --- .gitignore | 1 + .../.idea/.gitignore | 13 ------------- .../.idea/encodings.xml | 4 ---- .../.idea/indexLayout.xml | 10 ---------- .../.idea.ApiManagementSchemaImport/.idea/vcs.xml | 7 ------- 5 files changed, 1 insertion(+), 34 deletions(-) delete mode 100644 ApiManagementSchemaImport/.idea/.idea.ApiManagementSchemaImport/.idea/.gitignore delete mode 100644 ApiManagementSchemaImport/.idea/.idea.ApiManagementSchemaImport/.idea/encodings.xml delete mode 100644 ApiManagementSchemaImport/.idea/.idea.ApiManagementSchemaImport/.idea/indexLayout.xml delete mode 100644 ApiManagementSchemaImport/.idea/.idea.ApiManagementSchemaImport/.idea/vcs.xml diff --git a/.gitignore b/.gitignore index dfcfd56..1623ab0 100644 --- a/.gitignore +++ b/.gitignore @@ -348,3 +348,4 @@ MigrationBackup/ # Ionide (cross platform F# VS Code tools) working folder .ionide/ +.idea/ \ No newline at end of file diff --git a/ApiManagementSchemaImport/.idea/.idea.ApiManagementSchemaImport/.idea/.gitignore b/ApiManagementSchemaImport/.idea/.idea.ApiManagementSchemaImport/.idea/.gitignore deleted file mode 100644 index 705a85e..0000000 --- a/ApiManagementSchemaImport/.idea/.idea.ApiManagementSchemaImport/.idea/.gitignore +++ /dev/null @@ -1,13 +0,0 @@ -# Default ignored files -/shelf/ -/workspace.xml -# Rider ignored files -/.idea.ApiManagementSchemaImport.iml -/modules.xml -/contentModel.xml -/projectSettingsUpdater.xml -# Editor-based HTTP Client requests -/httpRequests/ -# Datasource local storage ignored files -/dataSources/ -/dataSources.local.xml \ No newline at end of file diff --git a/ApiManagementSchemaImport/.idea/.idea.ApiManagementSchemaImport/.idea/encodings.xml b/ApiManagementSchemaImport/.idea/.idea.ApiManagementSchemaImport/.idea/encodings.xml deleted file mode 100644 index df87cf9..0000000 --- a/ApiManagementSchemaImport/.idea/.idea.ApiManagementSchemaImport/.idea/encodings.xml +++ /dev/null @@ -1,4 +0,0 @@ - - - - \ No newline at end of file diff --git a/ApiManagementSchemaImport/.idea/.idea.ApiManagementSchemaImport/.idea/indexLayout.xml b/ApiManagementSchemaImport/.idea/.idea.ApiManagementSchemaImport/.idea/indexLayout.xml deleted file mode 100644 index 7076fb0..0000000 --- a/ApiManagementSchemaImport/.idea/.idea.ApiManagementSchemaImport/.idea/indexLayout.xml +++ /dev/null @@ -1,10 +0,0 @@ - - - - - ../../api-management-schema-import - - - - - \ No newline at end of file diff --git a/ApiManagementSchemaImport/.idea/.idea.ApiManagementSchemaImport/.idea/vcs.xml b/ApiManagementSchemaImport/.idea/.idea.ApiManagementSchemaImport/.idea/vcs.xml deleted file mode 100644 index 62bd7a0..0000000 --- a/ApiManagementSchemaImport/.idea/.idea.ApiManagementSchemaImport/.idea/vcs.xml +++ /dev/null @@ -1,7 +0,0 @@ - - - - - - - \ No newline at end of file