Skip to content

Resolve a tag field's namespace from a direct link to the namespace - #103

Open
raul-marquez-csa wants to merge 1 commit into
project-chip:mainfrom
raul-marquez-csa:tag-field-namespace-xref
Open

raul-marquez-csa wants to merge 1 commit into
project-chip:mainfrom
raul-marquez-csa:tag-field-namespace-xref

Conversation

@raul-marquez-csa

Copy link
Copy Markdown
Contributor

A tag field takes its namespace from a <<ref_StandardNamespaces, X Namespace>> link in its description. The spec now links the namespace itself instead (<<ref_CommonLandmarkNamespace>>), so Alchemy finds no namespace and writes enum8 for Service Area's LandmarkTag and RelativePositionTag and for LocationDescriptorStruct.AreaType. The spec errata works around AreaType with override-type: AreaTypeTag; LandmarkInfoStruct has no workaround, and an override-type naming a tag enum is an unknown custom type, which stops generation for an input document.

Changes (matter/spec)

  • A tag field whose description links an anchor in a namespace document keeps that link as its type source, and the builder resolves the namespace from it once every namespace is parsed. The ref_StandardNamespaces label and the name match still work as before.
  • A namespace is registered with its section, so a link to the namespace's anchor resolves to the namespace.
  • With this, the 3 "Tag field does not specify namespace" warnings on spec master go away.

Testing

  • go test ./..., including TestTagFieldNamespaceFromNamespaceReference, which fails when any of the three parts is removed.
  • A full zap run into the SDK, with and without this change, over spec master with the AreaType override removed from the errata: the only difference across the 144 generated files is the three fields above, which get AreaTypeTag, LandmarkTag and RelativePositionTag (the SDK's current types) instead of enum8.

Related

@raul-marquez-csa
raul-marquez-csa requested a review from a team as a code owner November 10, 2026 01:58
@mergify

mergify Bot commented Nov 10, 2026

Copy link
Copy Markdown

Tick the box to add this pull request to the merge queue (same as @mergifyio queue).

  • Queue this pull request

Comment thread matter/spec/field.go

// isNamespaceAnchor reports whether referenceID names an anchor in a namespace document, such as
// ref_CommonLandmarkNamespace.
func (library *Library) isNamespaceAnchor(referenceID string) bool {

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.

This is a little weird, since it makes any anchor in a namespace doc into an anchor to a namespace.

Might be better to change the source element for namespaces to be the section that defines them, rather than the table; this would be on line 37 in matter/spec/namespace.go. Then anchors would just resolve to the correct element, and the namespace would automatically be associated by entity finder. This would mean you don't need the special case up above.

The other benefit to this is that in #98 we start validating these references to make sure they point to a valid element, adding a spec error if it doesn't.

With this code, if I had a description of a tag field that first linked to a specific tag, and then linked to the name space, it would silently fail; the first link would match isNamespaceAnchor, the ref would get assigned to the source, but getTagNamespace would fail on the cast to namespace.

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.

2 participants