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

  1. Name the spec file with a `.yaml`, `.yml`, or `.json` extension so the media type resolves.
  2. 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" ...`).
  3. 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

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


AI-assisted analysis of gohugoio/hugo@8a468df065 (2026-07-31). Data as JSON: /data/errors/88fa0291406e7fdc.json. Report an issue: GitHub ↗.