fix: handle description and bio as String or Map in Work/Author models#1
Open
ketanchoyal wants to merge 2 commits into
Open
fix: handle description and bio as String or Map in Work/Author models#1ketanchoyal wants to merge 2 commits into
ketanchoyal wants to merge 2 commits into
Conversation
OpenLibrary API returns description in two formats:
- String: "Simple description text"
- Map: {"type": "/type/text", "value": "Description text"}
Added _descriptionFromJson helper to handle both cases.
Same issue as description - OpenLibrary API returns bio in two formats:
- String: "Simple bio text"
- Map: {"type": "/type/text", "value": "Bio text"}
This was causing author fetches to fail silently, resulting in empty author names.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
The OpenLibrary API returns certain text fields in two different formats, but the package models only handle the simple string format.
Affected Fields
Work.description- Returns either:{ "description": "Simple text" }or:
{ "description": { "type": "/type/text", "value": "Structured text" } }Author.bio- Returns either:{ "bio": "Simple bio text" }or:
{ "bio": { "type": "/type/text", "value": "Structured bio text" } }Error
When the API returns the object format, the current code throws:
This caused:
Solution
Added custom JSON converters for both fields:
Applied via
@JsonKey(fromJson: _descriptionFromJson)annotation.Testing
flutter analyzepassesExample API Responses
Impact
work_edition.dart,author.dart+ generated files