Skip to content

Allow direct access to Bioschemas JSON-LD - #1167

Merged
fbacall merged 2 commits into
masterfrom
bioschemas-api
Nov 21, 2025
Merged

Allow direct access to Bioschemas JSON-LD#1167
fbacall merged 2 commits into
masterfrom
bioschemas-api

Conversation

@fbacall

@fbacall fbacall commented Nov 5, 2025

Copy link
Copy Markdown
Member

Summary of changes

  • Adds a jsonld format to events/materials which returns the Bioschemas JSON-LD that would be embedded on the page.

Motivation and context

Allows direct access to the JSON-LD without having to parse the HTML.

Checklist

  • I have read and followed the CONTRIBUTING guide.
  • I confirm that I have the authority necessary to make this contribution on behalf of its copyright owner and agree
    to license it to the TeSS codebase under the
    BSD license.

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

This PR adds direct access to Bioschemas JSON-LD data for events and materials by introducing a new jsonld format endpoint. This allows consumers to retrieve the structured data without parsing HTML, making it easier to integrate with external systems and tools.

Key changes:

  • Registers application/ld+json MIME type for the new :jsonld format
  • Adds JSON-LD response handlers to events and materials controllers
  • Improves Bioschemas generator by using compact_blank to remove empty address fields and implementing provider deduplication

Reviewed changes

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

Show a summary per file
File Description
config/initializers/mime_types.rb Registers application/ld+json MIME type with alias for Schema.org JSON-LD
app/controllers/events_controller.rb Adds jsonld format response that renders Bioschemas JSON directly
app/controllers/materials_controller.rb Adds jsonld format response that renders Bioschemas JSON directly
lib/bioschemas/generator.rb Replaces compact with compact_blank to remove empty strings; reorders and deduplicates provider list
test/controllers/events_controller_test.rb Adds test coverage for JSON-LD endpoint, verifying response structure and content
test/controllers/materials_controller_test.rb Adds test coverage for JSON-LD endpoint, verifying response structure and content
test/models/event_test.rb Adds tests for blank address field removal and provider deduplication in Bioschemas output

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

format.json
format.json_api { render json: @event }
format.ics { send_data @event.to_ical, type: 'text/calendar', disposition: 'attachment', filename: "#{@event.slug}.ics" }
format.jsonld { render plain: @bioschemas.first.to_json }

Copilot AI Nov 21, 2025

Copy link

Choose a reason for hiding this comment

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

[nitpick] Consider using render json: @bioschemas.first.generate instead of render plain: @bioschemas.first.to_json. This would allow Rails to handle JSON serialization consistently and automatically set proper headers. The generate method returns a hash which Rails can serialize, avoiding the need for manual to_json conversion and plain rendering.

Suggested change
format.jsonld { render plain: @bioschemas.first.to_json }
format.jsonld { render json: @bioschemas.first.generate }

Copilot uses AI. Check for mistakes.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I used to_json because it pretty generates it with nice formatting.

format.html
format.json
format.json_api { render json: @material }
format.jsonld { render plain: @bioschemas.first.to_json }

Copilot AI Nov 21, 2025

Copy link

Choose a reason for hiding this comment

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

[nitpick] Consider using render json: @bioschemas.first.generate instead of render plain: @bioschemas.first.to_json. This would allow Rails to handle JSON serialization consistently and automatically set proper headers. The generate method returns a hash which Rails can serialize, avoiding the need for manual to_json conversion and plain rendering.

Suggested change
format.jsonld { render plain: @bioschemas.first.to_json }
format.jsonld { render json: @bioschemas.first.generate }

Copilot uses AI. Check for mistakes.
@fbacall
fbacall merged commit 333ebf2 into master Nov 21, 2025
17 checks passed
@fbacall
fbacall deleted the bioschemas-api branch November 21, 2025 17:50
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