gohugoio/hugo · error
MIME %q not supported
Error message
MIME %q not supported
What it means
Inside the cached unmarshal (tpl/openapi/openapi3/openapi3.go:97), Hugo derives the decode format from the Resource's media-type suffixes via `metadecoders.FormatFromStrings`. If no known format (JSON, YAML, TOML, etc.) matches the MIME suffix, it cannot parse the spec and errors with the media type it saw.
Source
Thrown at tpl/openapi/openapi3/openapi3.go:97
return nil, errors.New("no Key set in Resource")
}
var opts unmarshalOptions
if len(args) > 1 {
optsm, err := hmaps.ToStringMapE(args[1])
if err != nil {
return nil, err
}
if err := mapstructure.WeakDecode(optsm, &opts); err != nil {
return nil, err
}
key += "_" + hashing.HashString(optsm)
}
v, err := ns.cache.GetOrCreate(key, func(string) (*OpenAPIDocument, error) {
f := metadecoders.FormatFromStrings(r.MediaType().Suffixes()...)
if f == "" {
return nil, fmt.Errorf("MIME %q not supported", r.MediaType())
}
reader, err := r.ReadSeekCloser()
if err != nil {
return nil, err
}
defer reader.Close()
b, err := io.ReadAll(reader)
if err != nil {
return nil, err
}
s := &kopenapi3.T{}
switch f {
case metadecoders.YAML:
err = metadecoders.UnmarshalYaml(b, s)
default:View on GitHub ↗ (pinned to 8a468df065)
Solutions
- Name the spec file with a `.yaml`, `.yml`, or `.json` extension so the media type resolves.
- For remote specs, ensure the server returns a proper Content-Type, or fetch with `resources.GetRemote` and coerce the media type via the `mediaType` option (or wrap the body with `resources.FromString "api/openapi.yaml" ...`).
- Check any custom `mediaTypes` site configuration that may override suffixes for JSON/YAML.
Example fix
<!-- before: no usable extension -->
{{ $r := resources.Get "api/openapi-spec" }}
{{ $api := openapi3.Unmarshal $r }}
<!-- after -->
{{ $r := resources.Get "api/openapi.yaml" }}
{{ $api := openapi3.Unmarshal $r }} Defensive patterns
Strategy: validation
Validate before calling
{{ $spec := resources.Get "api/openapi.json" }}
{{ if in (slice "application/json" "application/yaml" "text/yaml") $spec.MediaType.Type }}
{{ $doc := openapi3.Unmarshal $spec }}
{{ end }} Prevention
- Give spec files a .json, .yaml, or .yml extension so Hugo infers a supported media type
- For remote specs, check the served Content-Type; override with the mediaType option on resources.GetRemote if the server sends a generic type
- Check $spec.MediaType before Unmarshal when the source is dynamic
When it happens
Trigger: Passing a Resource whose media type isn't a recognized structured-data format — e.g. an OpenAPI file saved without an extension, with a `.txt` extension, or fetched remotely with a generic `application/octet-stream` or `text/plain` content type.
Common situations: Remote specs served with a wrong Content-Type header, spec files named `openapi` or `spec.txt` instead of `.yaml`/`.json`, or custom mediaTypes config that strips the suffixes Hugo uses to infer the format.
Related errors
- must provide a Resource and optionally an options map
- no Key set in Resource
- MIME %q not supported
- resources in Concat must be of the same Media Type, got %q a
- failed to resolve media type for remote resource %q
AI-assisted analysis of gohugoio/hugo@8a468df065 (2026-07-31).
Data as JSON: /data/errors/88fa0291406e7fdc.json.
Report an issue: GitHub ↗.