internetarchive / iiif

The official Internet Archive IIIF service
GNU General Public License v3.0
21 stars 4 forks source link

Handle arrays for metadata['description'] in addMetadata() #14

Closed hadro closed 10 months ago

hadro commented 11 months ago

Flagged by @barmintor on the IIIF community call:

Want to flag this - working: https://iiif.archive.org/iiif/2/annualreport00carn_14/manifest.json broken: https://iiif.archive.org/iiif/3/annualreport00carn_14/manifest.json

At a quick glance, looks like it's failing because metadata['description'] is an array: https://archive.org/metadata/annualreport00carn_14

hadro commented 11 months ago

The fix here is pretty simple, we need to make another use of the existing coerce_list() function to handle complexity in description fields.

Specifically,

Line 304: item.summary = {"none": [metadata["description"]]} should be: item.summary = {"none": [coerce_list(metadata["description"])]}

and similarly Line 108: child.summary = {"none": [item['description']]} should be: child.summary = {"none": [coerce_list(item["description"])]}

@digitaldogsbody CCing you again here, if you're making changes soon feel free to incorporate but if not I can do a PR in the coming days

digitaldogsbody commented 11 months ago

For documentation purposes - I actually went with a slightly different fix here: Since summary is a language map (https://iiif.io/api/presentation/3.0/#summary), it can have an array of values, and the issue was that we were double-wrapping it so it became "summary": {"none": [["value 1", "value 2"]]}.

I've fixed it by adding a conditional that only wraps the value in a list if it isn't already, otherwise it passes it through as-is.