{"record":{"id":"c299ca071579291d","repo":"microsoft/semantic-kernel","slug":"neither-of-the-media-types-of-operationid-is-sup","errorCode":null,"errorMessage":"Neither of the media types of {operationId} is supported.","messagePattern":"Neither of the media types of (.+?) is supported\\.","errorType":"exception","errorClass":"KernelException","httpStatus":null,"severity":"error","filePath":"dotnet/src/Functions/Functions.OpenApi/OpenApi/OpenApiDocumentParser.cs","lineNumber":473,"sourceCode":"        }\n\n        return result;\n    }\n\n    /// <summary>\n    /// Creates REST API payload.\n    /// </summary>\n    /// <param name=\"operationId\">The operation id.</param>\n    /// <param name=\"requestBody\">The OpenAPI request body.</param>\n    /// <returns>The REST API payload.</returns>\n    private static RestApiPayload? CreateRestApiOperationPayload(string operationId, OpenApiRequestBody requestBody)\n    {\n        if (requestBody?.Content is null)\n        {\n            return null;\n        }\n\n        var mediaType = GetMediaType(requestBody.Content) ?? throw new KernelException($\"Neither of the media types of {operationId} is supported.\");\n        var mediaTypeMetadata = requestBody.Content[mediaType];\n\n        var payloadProperties = GetPayloadProperties(operationId, mediaTypeMetadata.Schema);\n\n        return new RestApiPayload(mediaType, payloadProperties, requestBody.Description, mediaTypeMetadata?.Schema?.ToJsonSchema());\n    }\n\n    /// <summary>\n    /// Returns the first supported media type. If none of the media types are supported, an exception is thrown.\n    /// </summary>\n    /// <remarks>\n    /// Handles the case when the media type contains additional parameters e.g. application/json; x-api-version=2.0.\n    /// </remarks>\n    /// <param name=\"content\">The OpenAPI request body content.</param>\n    /// <returns>The first support ed media type.</returns>\n    /// <exception cref=\"KernelException\"></exception>\n    private static string? GetMediaType(IDictionary<string, OpenApiMediaType> content)\n    {","sourceCodeStart":455,"sourceCodeEnd":491,"githubUrl":"https://github.com/microsoft/semantic-kernel/blob/c028a0c7dc4f0814cdcbaba9d998f187a41197bf/dotnet/src/Functions/Functions.OpenApi/OpenApi/OpenApiDocumentParser.cs#L455-L491","documentation":"Thrown by the Semantic Kernel OpenAPI document parser when an operation's requestBody only declares media types the parser does not handle. GetMediaType() iterates s_supportedMediaTypes, which is hard-coded to exactly 'application/json' and 'text/plain'; if no request-body content key matches (ignoring trailing parameters after ';'), it returns null and CreateRestApiOperationPayload raises KernelException. This is a parser coverage limit, not a malformed-spec error.","triggerScenarios":"Calling KernelPluginFactory.CreateFromOpenApiAsync (or OpenApiKernelPluginFactory) against an OpenAPI spec whose POST/PUT/PATCH operation declares a requestBody.content with only unsupported media types, e.g. 'application/xml', 'application/octet-stream', 'multipart/form-data', 'application/x-www-form-urlencoded', or 'application/problem+json' without a base 'application/json' entry.","commonSituations":"Importing a spec that only advertises XML (older SOAP-style REST or Java/Spring defaults), specs that use multipart/form-data for file uploads, specs that list vendor media types like 'application/vnd.api+json', or a spec authored with content-type keys whose primary segment is not exactly 'application/json'/'text/plain'. Also happens after a partial refactor that dropped the JSON content-type.","solutions":["Edit the OpenAPI spec to add an 'application/json' (or 'text/plain') entry under requestBody.content for the failing operationId, mirroring the existing schema.","If the operation genuinely only supports a non-JSON type (e.g. file upload), exclude that operation via OpenApiFunctionExecutionParameters.OperationsToExclude so the parser never builds its payload.","Fork/extend the parser: s_supportedMediaTypes is a private static list, so a local subclass of the document parser is required to register additional types (no public API exists).","Confirm the failing operationId from the exception message and inspect requestBody.content keys in the source spec to confirm none match json/plain."],"exampleFix":"// before (spec excerpt) - only XML declared\n//  requestBody:\n//    content:\n//      application/xml:\n//        schema: { $ref: '#/components/schemas/Pet' }\n// after - add an application/json entry\n//  requestBody:\n//    content:\n//      application/json:\n//        schema: { $ref: '#/components/schemas/Pet' }\n//      application/xml:\n//        schema: { $ref: '#/components/schemas/Pet' }","handlingStrategy":"validation","validationCode":"// Pre-flight: confirm each operation has a supported media type before importing.\n// supported = application/json | text/plain (case-insensitive, ignores ';...' params)\nstatic bool HasSupportedRequestBodyMediaType(OpenApiDocument doc)\n{\n    var supported = new[] { \"application/json\", \"text/plain\" };\n    bool ok = true;\n    foreach (var (path, item) in doc.Paths)\n        foreach (var op in item.Operations.Values.Where(o => o.RequestBody is not null))\n        {\n            var keys = op.RequestBody.Content.Keys\n                .Select(k => k.Split(';')[0].ToLowerInvariant()).ToList();\n            if (!keys.Any(k => supported.Contains(k)))\n            {\n                Console.WriteLine($\"{op.OperationId}: no supported media type (has {string.Join(\",\", keys)})\");\n                ok = false;\n            }\n        }\n    return ok;\n}","typeGuard":"static bool IsSupportedMediaType(string? contentType) =>\n    contentType is not null &&\n    new[] { \"application/json\", \"text/plain\" }\n        .Contains(contentType.Split(';')[0].Trim(), StringComparer.OrdinalIgnoreCase);","tryCatchPattern":"try\n{\n    var plugin = await kernel.CreatePluginFromOpenApiAsync(\"api\", specStream, execParams);\n}\ncatch (KernelException ex) when (ex.Message.Contains(\"Neither of the media types\"))\n{\n    // log the operationId from the message, fix the spec's requestBody.content, retry\n    logger.LogWarning(\"OpenAPI import failed on unsupported media type: {Msg}\", ex.Message);\n}","preventionTips":["Author specs so every writable operation advertises application/json.","Run a lint step (spectral/shinsou) that flags request bodies lacking application/json or text/plain before import.","Exclude operations that legitimately only support non-JSON media types via OperationsToExclude."],"tags":["openapi","dotnet","media-type","configuration"],"backgroundTag":null,"analyzedSha":"c028a0c7dc4f0814cdcbaba9d998f187a41197bf","analyzedAt":"2026-08-13T13:48:05.040Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}