Skip to content

Only emit action constraint helper types when the ontology defines Action - #229

Open
rootkiller6788 wants to merge 2 commits into
google:mainfrom
rootkiller6788:fix-action-constraints-undefined-refs
Open

rootkiller6788 wants to merge 2 commits into
google:mainfrom
rootkiller6788:fix-action-constraints-undefined-refs

Conversation

@rootkiller6788

Copy link
Copy Markdown

Since #202 the generator always appends the InputActionConstraints / OutputActionConstraints / WithActionConstraints helper types to the generated file. Those helpers reference ActionBase and PropertyValueSpecification, which only exist in the output when the ontology actually defines those classes. Running the generator against a custom ontology that has no Action class therefore produced a .ts file that does not compile:

TS2304: Cannot find name 'ActionBase'.
TS2304: Cannot find name 'PropertyValueSpecification'.

This change gates the three helper types on the ontology defining both Action and PropertyValueSpecification, following the same pattern as the existing hasRole check. The real schema.org vocabulary still defines both classes, so the published output is unchanged; only custom/minimal ontologies get a clean, compilable result.

Adds a baseline test that keeps the helpers for an ontology that does define an Action class, and updates the existing custom-ontology baselines that no longer include them.

Tested with the full schema-dts-gen suite: 41 suites, 142 tests, 43 snapshots all passing.

…tion

The InputActionConstraints / OutputActionConstraints / WithActionConstraints
helpers reference ActionBase and PropertyValueSpecification, but were
unconditionally appended to every generated file since google#202. For custom
ontologies that do not define those classes the generated .ts failed to
compile (TS2304: Cannot find name 'ActionBase').

Gate the emission on the ontology actually containing Action and
PropertyValueSpecification, mirroring the existing hasRole check, and add a
baseline test that keeps the helpers for an ontology with an Action class.
All custom test ontologies in baselines/ define no Action class, so the
generated output no longer includes the three action constraint helper
types. Refresh the inline snapshots to match.
@rootkiller6788
rootkiller6788 marked this pull request as ready for review November 10, 2026 05:15

@mangeshraut712 mangeshraut712 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.

Gating the helpers the same way as hasRole makes sense, and the new baseline with a real Action is a good positive control. One remaining case where the output still references a name that isn't emitted.

// The action-constraint helpers reference ActionBase and
// PropertyValueSpecification, so only emit them when the ontology
// actually defines those classes.
hasAction: !!(

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

hasAction checks that the Action class exists, but the helpers reference the ActionBase interface (hard-coded as ActionBaseName = 'ActionBase' in ts/action_constraints.ts). These aren't the same condition. In ts/class.ts, skipBase() returns true when a class has exactly one named parent and no own properties, and then baseDecl() returns undefined, so no ActionBase is generated. A minimal custom ontology that declares Action rdfs:subClassOf Thing without attaching any property to it (e.g. it only uses Action subclasses, or puts the properties on those) would still produce TS2304: Cannot find name 'ActionBase' with this change. The new baseline doesn't catch that because it gives Action a query property.

Two possible fixes: gate on the Action class not skipping its base (e.g. expose something like hasBaseDeclaration() on Class), or have the helpers use the Action class's actual baseName(context) instead of the hard-coded string. A second baseline with a property-less Action would pin it either way. I've reasoned from class.ts rather than running the generator on that input, so it's worth confirming with a quick snapshot.

@Eyas

Eyas commented Nov 18, 2026

Copy link
Copy Markdown
Collaborator

Thanks for the contribution, @rootkiller6788 , this looks like a good change. Can you iterate to make sure CI is happy? Then I'm happy to merge.

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.

3 participants