Conversation
When generating Go types from multi-namespace WSDLs, type name collisions occur because different XML schemas can define types with the same name. This adds a --namespace-prefixes flag that accepts a JSON file mapping namespace URIs to short prefixes. With namespace prefixes enabled, every generated Go type is prefixed with its schema's namespace abbreviation (e.g., CBE_FlexAttr, COM_ProductOrder). This eliminates collisions while keeping type names readable. The implementation: - Captures xmlns:* declarations from schema elements via ExtraAttrs - Resolves cross-namespace type references using the xmlns prefix map to determine which namespace a type belongs to - Prefixes type declarations, inline anonymous types, enum types, wrapper types, and client method signatures - Skips XSD builtin types (xs:string, xs:int, etc.) - No behavioral change when the flag is not provided Also fixes RawXML type being emitted multiple times in multi-schema WSDLs.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
When a WSDL contains multiple XML schemas (common in enterprise SOAP services), different schemas can define types with the same name in different namespaces. XSD handles this through namespace scoping, but since soap-go generates all types into a single Go package, these produce compile-time name collisions.
The natural solution would be to generate each namespace into its own Go package. However, XSD namespaces commonly have circular import dependencies (namespace A imports types from B, B imports types from A). This is valid in XSD and handled natively by Java/C#, but Go's package system forbids circular imports, making per-namespace packages impossible for most real-world WSDLs.
Solution
This PR adds a
--namespace-prefixesflag that accepts a JSON file mapping namespace URIs to short prefixes:{ "http://example.com/core/types/v1": "Core", "http://example.com/billing/types/v1": "CB", "http://example.com/orders/types/v1": "COM" }When provided, every generated Go type is prefixed with its schema's namespace abbreviation:
How it works
xmlns capture: The
Schemastruct now capturesxmlns:*declarations via anExtraAttrsfield, with aNamespacePrefixMap()helper to extract the prefix-to-URI mapping.Type declarations: When generating struct, enum, and inline anonymous types, the generator prepends the namespace prefix from the user-provided map.
Type references: When a field references a type from another namespace (e.g.,
type="ns3:FlexAttr"), the generator resolvesns3→ namespace URI (via xmlns map) → short prefix (via user map) →Core_FlexAttr.XSD builtins excluded: References to
xs:string,xs:int, etc. are never prefixed — only user-defined types get namespace scoping.Client code: Operation wrapper types in the generated client are prefixed using the WSDL's own target namespace.
What doesn't change
When
--namespace-prefixesis not provided, behavior is identical to before. All existing tests pass unchanged.Why not per-namespace packages?
I explored generating each namespace into its own Go package with proper cross-package imports. The prototype worked for WSDLs without circular namespace dependencies. However, enterprise WSDLs commonly have bidirectional namespace imports (e.g., a "common entities" schema imports from "billing", and "billing" imports from "common entities"). Go's prohibition on circular package imports makes this approach fundamentally incompatible with real-world XSD namespace graphs.
The namespace-prefix approach keeps everything in a single package while eliminating collisions through deterministic, user-controlled naming.
Usage
The JSON file must map every namespace URI that appears as a
targetNamespacein the WSDL's schemas. Namespaces not in the map will generate types without a prefix.Also included
RawXMLtype declaration is now emitted only once per package (was duplicated in multi-schema WSDLs)