Allow direct access to Bioschemas JSON-LD - #1167
Conversation
…s Bioschemas JSON-LD
…nstitution are the same org. Hide empty string address fields
There was a problem hiding this comment.
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+jsonMIME type for the new:jsonldformat - Adds JSON-LD response handlers to events and materials controllers
- Improves Bioschemas generator by using
compact_blankto 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 } |
There was a problem hiding this comment.
[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.
| format.jsonld { render plain: @bioschemas.first.to_json } | |
| format.jsonld { render json: @bioschemas.first.generate } |
There was a problem hiding this comment.
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 } |
There was a problem hiding this comment.
[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.
| format.jsonld { render plain: @bioschemas.first.to_json } | |
| format.jsonld { render json: @bioschemas.first.generate } |
Summary of changes
jsonldformat 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
to license it to the TeSS codebase under the
BSD license.