Skip to content

Handle singleton artifact objects per FAIR spec#497

Open
kasparsd wants to merge 5 commits into
fairpm:mainfrom
kasparsd:fix-package-artifacts-types
Open

Handle singleton artifact objects per FAIR spec#497
kasparsd wants to merge 5 commits into
fairpm:mainfrom
kasparsd:fix-package-artifacts-types

Conversation

@kasparsd
Copy link
Copy Markdown
Contributor

Fixes #496.

This changeset fixes package handling when a FAIR repository returns releases[].artifacts.package as a single object instead of an array.

Per the FAIR core spec, the artifacts map allows each artifact type value to be either an object or a list of objects. The plugin was normalizing neither shape internally and some consumer paths assumed array access, which caused failures such as Cannot use object of type stdClass as array during install/update flows.

This patch normalizes release artifact values to arrays at parse time in ReleaseDocument::from_data(), so downstream code can consume a consistent internal shape regardless of how the repository serialized the artifact. Consumer paths that read package download URLs or inspect package artifacts were updated accordingly, and regression tests were added to cover both valid spec shapes.

Spec references

  • FAIR Release Document: artifacts is a JSON object whose values “MUST be objects or lists of objects”
  • FAIR Core compatibility implication: clients must accept both valid shapes for artifact values, including artifacts.package

Testing

Added parser regression tests for:

  • singleton artifact object -> normalized to array
  • artifact array -> preserved as-is

kasparsd added 5 commits May 16, 2026 12:16
Signed-off-by: Kaspars Dambis <hi@kaspars.net>
Signed-off-by: Kaspars Dambis <hi@kaspars.net>
Signed-off-by: Kaspars Dambis <hi@kaspars.net>
Signed-off-by: Kaspars Dambis <hi@kaspars.net>
@github-actions
Copy link
Copy Markdown
Contributor

// Score artifacts based on match.
$score_artifact = function ( $artifact ) use ( $langs ) {
$score = 0;
$lang = strtolower( $artifact->lang ?? '' );
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Account for missing lang property which is allowed per spec.

return false;
}
$artifact = pick_artifact_by_lang( $release->artifacts->package );
$artifact = isset( $release->artifacts->package ) ? pick_artifact_by_lang( $release->artifacts->package ) : null;
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.

Should this return false for the check below?

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