Skip to content

fix(xmlschema): declare map types so map references resolve - #308

Merged
mttrbrts merged 3 commits into
accordproject:mainfrom
NopeCharon:nopecharon/i305/xmlschema-map-types
Nov 11, 2026
Merged

mttrbrts merged 3 commits into
accordproject:mainfrom
NopeCharon:nopecharon/i305/xmlschema-map-types

Conversation

@NopeCharon

Copy link
Copy Markdown
Contributor

Closes #305

Generated XML Schema for models with maps now compiles. Before this change, the map references didn't resolve and xmllint refused to compile the schema.

Changes

  • Write a map declaration as a named xs:complexType plus an xs:element of that type, the same way concepts are written. Fields of a map type already refer to ns:MapName, and that type now exists.
  • Qualify the <Map>EntryType reference with the map's namespace, both in the map declaration and in the inline type written for map fields with a size validator (which may refer to an imported map).
  • Resolve class and enum key/value types to their fully qualified name, so imported types use the namespace that declares them. This replaces the special case for the system types (Concept, Asset, ...), and toXsType no longer needs its mapElement argument.
  • Update the map unit tests and the hr snapshot, and add a test with a real model that uses imported map value types and imported maps.

Flags

  • On main, xmllint --schema fails to compile org.acme.hr.base@1.0.0.xsd and org.acme.hr@1.0.0.xsd (References from this schema to components in no namespace are not allowed). With this change both compile, and an instance with map entries validates, including an imported concept value and an imported enum value. The XML Schema verification in test/verification only checks the files against the W3C schema for schemas, so it didn't catch this.
  • bug(xmlschema): optional properties are generated as required elements #304 also changes the map-field branch of visitField, a few lines from this change. Whichever PR is merged second will need a small rebase.

Screenshots or Video

N/A

Related Issues

Author Checklist

  • Ensure you provide a DCO sign-off for your commits using the --signoff option of git commit.
  • Vital features and changes captured in unit and/or integration tests
  • Commits messages follow AP format
  • Extend the documentation, if necessary
  • Merging to main from fork:branchname

Any model with a map declaration produced an XML Schema that did not
compile:

- the entry element of a map referred to <Map>EntryType without a
  namespace prefix, which resolves to no namespace because the schema
  has a targetNamespace and no default namespace
- a map was written as an element with an anonymous type, while fields
  of that map type refer to a type named after the map, which did not
  exist
- class and enum map values were prefixed with the namespace of the map
  instead of the namespace that declares them, so imported types did
  not resolve

Write a map declaration the same way a concept is written: a named
xs:complexType, then an xs:element of that type. Qualify the entry type
reference in the declaration and in the inline type written for map
fields with a size validator, and resolve class and enum key and value
types to their fully qualified name. This also covers the system types
(Concept, Asset, ...), which were special-cased before. Drop the now
unused mapElement argument of toXsType.

Closes accordproject#305

Signed-off-by: NopeCharon <115794254+NopeCharon@users.noreply.github.com>
@mira-accord-project

Copy link
Copy Markdown

Thanks for your contribution, and for opening #305 with the details alongside this PR. The CI workflows have been approved and are passing. The PR now waits for review from the Concerto maintainers. If you push more changes, the checks will run again, and it helps if the commits are signed off (DCO).

Drafted by an Accord Project agent, reviewed by a maintainer.

@mira-accord-project mira-accord-project Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Thank you for this fix, and for the careful tests. Map declarations now emit a named complexType plus a global element (the same pattern concepts and enums use), so fields that refer to a map now resolve. Imported maps and imported concept, enum and scalar values resolve to the namespace that declares them. The updated snapshot and the new test with imported types in test/codegen/fromcto/xmlschema/xmlschemavisitor.js cover this well. Nothing blocks the merge. The only point is a heads-up about an overlapping PR; once a maintainer has reviewed it and the order with that PR is settled, this looks ready.

Nothing blocking; some suggestions below. Findings: 1 nit.


Automated review by Mira, an Accord Project agent, at d97fa38. Findings are labelled blocking, should-fix or nit; a maintainer makes the final call.

maxOccurs = String(sizeValidator.getMaxSize());
}
const mapName = field.getType();
const mapType = this.toXsType(field.getFullyQualifiedTypeName());

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

nit · hygiene

PR #307 changes the map branch of visitField on the adjacent line (the <xs:element name=...> line that follows the mapType line here), and also edits the same visitField tests in test/codegen/fromcto/xmlschema/xmlschemavisitor.js. Whichever PR merges second will probably need a rebase. It would help to agree an order with #307 and rebase the other one afterwards.

Signed-off-by: Matt Roberts <7544022+mttrbrts@users.noreply.github.com>
@mttrbrts
mttrbrts enabled auto-merge (squash) November 11, 2026 12:13
Signed-off-by: Matt Roberts <7544022+mttrbrts@users.noreply.github.com>
@mttrbrts
mttrbrts merged commit 5f0bc86 into accordproject:main Nov 11, 2026
27 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bug(xmlschema): schemas for models with maps fail to compile

2 participants