Skip to content

Conversation

@blark
Copy link
Contributor

@blark blark commented Oct 28, 2025

The mediaType field in the Index struct was defined as a required field, but according to the OCI Image Index Specification, this field is optional.

This caused failures when loading OCI archives where the index.json omits the top-level mediaType field, which is valid per the spec. Tools like skopeo can generate such archives.

Error before fix

keyNotFound(CodingKeys(stringValue: "mediaType", intValue: nil))

Changes

  • Changed Index.mediaType from String to String?
  • Updated initializer to accept optional mediaType parameter
  • Added comment documenting that field is optional per OCI spec

Testing

Verified that OCI archives without a top-level mediaType field in index.json now load successfully.

Fixes apple/container#330

@katiewasnothere
Copy link
Contributor

Hi @blark thanks for the contribution! Could you follow a similar pattern to what was done in this PR #347 for Index.mediaType?

We're hoping to only use optionals in the spec definitions for pointer types. Other types that are defined omitempty in the oci spec, we will rely on the use of custom JSON decoders to ensure similar behavior to omitempty for non-pointer types in go.

The mediaType field in the Index struct was defined as a required field,
but according to the OCI Image Index Specification, this field is optional:
https://github.com/opencontainers/image-spec/blob/main/image-index.md

This caused failures when loading OCI archives where the index.json omits
the top-level mediaType field, which is valid per the spec. Tools like
skopeo can generate such archives.

Error before fix:
  keyNotFound(CodingKeys(stringValue: "mediaType", intValue: nil))

Changes:
- Changed Index.mediaType from String to String?
- Updated initializer to accept optional mediaType parameter
- Added comment documenting that field is optional per OCI spec

Fixes: apple/container#330
@blark blark force-pushed the fix-index-mediatype-optional branch from f26feb7 to b033f7e Compare October 28, 2025 23:35
@blark
Copy link
Contributor Author

blark commented Oct 28, 2025

Thanks for the feedback @katiewasnothere! I've updated the PR to follow the pattern from #347:

@dcantah dcantah merged commit d7814e4 into apple:main Oct 29, 2025
2 checks passed
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.

[Bug]: container image load rejects an image if the index JSON structure does not specify mediaType

3 participants