You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: semantic-kernel/concepts/plugins/adding-openapi-plugins.md
+112-1Lines changed: 112 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -538,7 +538,7 @@ The base URL will be `https://api-host.com`.
538
538
539
539
In some instances, the server URL specified in the OpenAPI document or the server from which the document was loaded may not be suitable for use cases involving the OpenAPI plugin.
540
540
541
-
The Semantic Kernel allows you to override the server URL by providing a custom base URL when adding the OpenAPI plugin to the kernel:
541
+
Semantic Kernel allows you to override the server URL by providing a custom base URL when adding the OpenAPI plugin to the kernel:
For more complex authentication scenarios that require dynamic access to the details of the authentication schemas supported by an API, you can use document
597
+
and operation metadata to obtain this information. For more details, see [Document and operation metadata](./adding-openapi-plugins.md#document-and-operation-metadata).
598
+
599
+
## Response content reading customization
600
+
601
+
Semantic Kernel has a built-in mechanism for reading the content of HTTP responses from OpenAPI plugins and converting them to the appropriate .NET data types.
602
+
For example, an image response can be read as a byte array, while a JSON or XML response can be read as a string.
603
+
604
+
However, there may be cases when the built-in mechanism is insufficient for your needs. For instance, when the response is a large JSON object or image that needs
605
+
to be read as a stream in order to be supplied as input to another API. In such cases, reading the response content as a string or byte array and then converting
606
+
it back to a stream can be inefficient and may lead to performance issues. To address this, Semantic Kernel allows for response content reading customization
In this example, the `ReadHttpResponseContentAsync` method reads the HTTP response content as a stream when the content type is `application/json` or when the request
638
+
contains a custom header `x-stream`. The method returns `null` for any other content types, indicating that the default content reader should be used.
639
+
640
+
## Document and operation metadata
641
+
642
+
Semantic Kernel extracts OpenAPI document and operation metadata, including API information, security schemas, operation ID, description, parameter metadata and many more.
643
+
It provides access to this information through the `KernelFunction.Metadata.AdditionalParameters` property. This metadata can be useful in scenarios where additional
644
+
information about the API or operation is required, such as for authentication purposes:
thrownewNotSupportedException($"API key location '{scheme.In}' is not supported.");
676
+
}
677
+
}
678
+
679
+
// Handle other authentication types like Basic, Bearer, OAuth2, etc. For more information, see https://swagger.io/docs/specification/v3_0/authentication/
680
+
}
681
+
}
682
+
}
683
+
684
+
// Import the transformed OpenAPI plugin specification
In this example, the `AuthenticateRequestAsyncCallbackAsync` method reads the operation metadata from the function context and extracts the security requirements for the operation
697
+
to determine the authentication scheme. It then retrieves the API key, for the scheme and scopes, from the app identity provider and adds it to the request headers or query parameters.
698
+
699
+
The following table lists the metadata available in the `KernelFunction.Metadata.AdditionalParameters` dictionary:
0 commit comments