Skip to content

fix: valid XSD generation with model-driven namespaces#718

Open
suleman-uzair wants to merge 7 commits into
mainfrom
fix/717-xsd-xs-namespace
Open

fix: valid XSD generation with model-driven namespaces#718
suleman-uzair wants to merge 7 commits into
mainfrom
fix/717-xsd-xs-namespace

Conversation

@suleman-uzair

@suleman-uzair suleman-uzair commented Jul 2, 2026

Copy link
Copy Markdown
Member

This PR fixes the invalid XSD produced by Model.to_xsd, which referenced the
xs: prefix without ever binding it, so no XSD processor could load the
output. It binds the XML Schema vocabulary to xmlns:xs and derives all
namespace handling from the models' XmlNamespace classes, so schemas spanning
multiple namespaces are generated correctly.

What this changes

  • binds the XSD vocabulary to xmlns:xs and emits xs:-prefixed structure elements
  • collects every namespace in the model tree from the XmlNamespace classes and declares xmlns:<prefix> for each
  • sets targetNamespace from the root model and qualifies named-type references by their owning namespace
  • emits deduplicated xs:import for foreign namespaces instead of folding their types into the root schema
  • synthesizes a tns prefix when the target namespace declares none
  • raises clear errors on prefix collisions and foreign namespaces without a usable prefix
  • guards recursive models (A -> B -> A) against infinite recursion in validation and type generation
  • adds specs covering the above, including schema-load checks

Type::Value type-namespace prefixing is left as a follow-up (documented in-code).

closes #717

@suleman-uzair suleman-uzair changed the title [WIP] fix: valid XSD generation with model-driven namespaces (#717) [WIP] fix: valid XSD generation with model-driven namespaces Jul 2, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Fixes invalid XSD output from to_xsd by explicitly binding the W3C XML Schema vocabulary to xmlns:xs and consistently emitting xs:-prefixed schema structure elements, while improving namespace qualification/import behavior for named types under target namespaces (regression coverage for #717).

Changes:

  • Bind XSD vocabulary as xmlns:xs and prefix emitted schema structure elements (xs:schema, xs:element, xs:complexType, etc.).
  • Qualify named-type QName references with the appropriate namespace prefix (target namespace or referenced model namespace), including collection cases, with cycle guards for recursive models.
  • Add/adjust Nokogiri-load regression tests and update existing spec expectations to the new xs:-prefixed structure output.

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
lib/lutaml/xml/schema/xsd_schema.rb Implements xs:-prefixed schema element emission, namespace declaration/collection, QName qualification, import logic, and recursion guards.
spec/lutaml/model/schema/xsd_schema_spec.rb Adds Nokogiri schema-load regression coverage for #717 and additional namespace edge cases.
spec/lutaml/model/xsd_type_validation_spec.rb Updates expectations to reflect xs:schema + xmlns:xs binding.
spec/lutaml/model/xsd_patterns_spec.rb Updates pattern-based XSD string expectations for xs:-prefixed structure elements.
spec/lutaml/model/xsd_form_default_patterns_spec.rb Updates expectations for xs:-prefixed structure elements in generated schemas.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread spec/lutaml/model/xsd_form_default_patterns_spec.rb Outdated
Comment thread spec/lutaml/model/xsd_type_validation_spec.rb Outdated
@suleman-uzair suleman-uzair changed the title [WIP] fix: valid XSD generation with model-driven namespaces fix: valid XSD generation with model-driven namespaces Jul 6, 2026
@suleman-uzair suleman-uzair requested a review from Copilot July 6, 2026 16:19

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 5 out of 5 changed files in this pull request and generated 3 comments.

Comment thread lib/lutaml/xml/schema/xsd_schema.rb
Comment thread lib/lutaml/xml/schema/xsd_schema.rb
Comment thread lib/lutaml/xml/schema/xsd_schema.rb Outdated

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 5 out of 5 changed files in this pull request and generated 7 comments.

Comment thread lib/lutaml/xml/schema/xsd_schema.rb Outdated
Comment thread lib/lutaml/xml/schema/xsd_schema.rb Outdated
Comment thread lib/lutaml/xml/schema/xsd_schema.rb Outdated
Comment thread lib/lutaml/xml/schema/xsd_schema.rb Outdated
Comment thread lib/lutaml/xml/schema/xsd_schema.rb Outdated
Comment thread lib/lutaml/xml/schema/xsd_schema.rb
Comment thread lib/lutaml/xml/schema/xsd_schema.rb Outdated

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 5 out of 5 changed files in this pull request and generated no new comments.

@suleman-uzair suleman-uzair marked this pull request as ready for review July 7, 2026 15:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

to_xsd generates invalid XSD — xs: prefix used but xmlns:xs never declared

2 participants