{"record":{"id":"8afb5842e2524926","repo":"gohugoio/hugo","slug":"must-provide-a-resource-and-optionally-an-options","errorCode":null,"errorMessage":"must provide a Resource and optionally an options map","messagePattern":"must provide a Resource and optionally an options map","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"tpl/openapi/openapi3/openapi3.go","lineNumber":73,"sourceCode":"// OpenAPIDocument represents an OpenAPI 3 document.\ntype OpenAPIDocument struct {\n\t*kopenapi3.T\n\tidentityGroup identity.Identity\n}\n\nfunc (o *OpenAPIDocument) GetIdentityGroup() identity.Identity {\n\treturn o.identityGroup\n}\n\ntype unmarshalOptions struct {\n\t// Options passed to resources.GetRemote when resolving remote $ref.\n\tGetRemote map[string]any\n}\n\n// Unmarshal unmarshals the given resource into an OpenAPI 3 document.\nfunc (ns *Namespace) Unmarshal(ctx context.Context, args ...any) (*OpenAPIDocument, error) {\n\tif len(args) < 1 || len(args) > 2 {\n\t\treturn nil, errors.New(\"must provide a Resource and optionally an options map\")\n\t}\n\n\tr := args[0].(resource.UnmarshableResource)\n\tkey := r.Key()\n\tif key == \"\" {\n\t\treturn nil, errors.New(\"no Key set in Resource\")\n\t}\n\n\tvar opts unmarshalOptions\n\tif len(args) > 1 {\n\t\toptsm, err := hmaps.ToStringMapE(args[1])\n\t\tif err != nil {\n\t\t\treturn nil, err\n\t\t}\n\t\tif err := mapstructure.WeakDecode(optsm, &opts); err != nil {\n\t\t\treturn nil, err\n\t\t}\n\t\tkey += \"_\" + hashing.HashString(optsm)","sourceCodeStart":55,"sourceCodeEnd":91,"githubUrl":"https://github.com/gohugoio/hugo/blob/52c9bd7908b4d02d4d0ff8f82a888834d6ee10d2/tpl/openapi/openapi3/openapi3.go#L55-L91","documentation":"Thrown by openapi3.Unmarshal when the variadic args length is not 1 or 2. The function signature is Unmarshal(ctx, args...) expecting exactly one Resource plus an optional options map. Zero args, or more than two args, triggers this.","triggerScenarios":"Calling {{ $doc := resources.Get \"api.yaml\" | openapi3.Unmarshal }} incorrectly, or calling openapi3.Unmarshal with no resource, or passing three or more arguments like {{ openapi3.Unmarshal $r $opts $extra }}.","commonSituations":"Forgetting to pipe a resource into Unmarshal; passing both a resource and a separate options map positionally in the wrong order; typos adding extra arguments.","solutions":["Pass exactly one Resource and an optional options map: {{ $r | openapi3.Unmarshal }} or {{ openapi3.Unmarshal $r $opts }}.","Ensure the first argument is the resource obtained from resources.Get / resources.GetRemote, not a string path.","Remove any extra positional arguments beyond the optional options map."],"exampleFix":"// before\n{{ openapi3.Unmarshal \"api.yaml\" }}\n// after\n{{ resources.Get \"api.yaml\" | openapi3.Unmarshal }}","handlingStrategy":"validation","validationCode":"{{ with resources.Get \"api.yaml\" }}{{ openapi3.Unmarshal . }}{{ end }}","typeGuard":"// Verify the value implements the expected resource interface before calling\nfunc isUnmarshableResource(v any) bool {\n    _, ok := v.(resource.UnmarshableResource)\n    return ok\n}","tryCatchPattern":null,"preventionTips":["Always obtain a resource via resources.Get/resources.GetRemote before calling Unmarshal.","Pass at most one Resource and one options map.","Use {{ with }} to guard nil resources."],"tags":["template","openapi","arguments","hugo"],"backgroundTag":null,"analyzedSha":"52c9bd7908b4d02d4d0ff8f82a888834d6ee10d2","analyzedAt":"2026-08-09T21:49:36.660Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}