microsoft / semantic-kernel

Integrate cutting-edge LLM technology quickly and easily into your apps
https://aka.ms/semantic-kernel
MIT License
22.12k stars 3.3k forks source link

.Net: Mechanism for transforming OpenAPI documents - part2 #9689

Closed SergeyMenshykh closed 2 weeks ago

SergeyMenshykh commented 2 weeks ago

Motivation and Context

This is the second PR to add a mechanism to transform OpenAPI documents before creating a kernel plugin from them.

Description

This PR:

  1. Makes the OpenApiDocumentParser public, allowing for the parsing of OpenAPI documents and accessing the instance of the RestApiSpecification class representing the parsed document, which can be modified, by the consumer, if needed, before creating a plugin from it. Currently, it's only possible to modify argument name property of parameters and server variables.

  2. Adds a few kernel extension overload methods to create and import OpenAPI document represented by the RestApiSpecification model class. This is the final element of the transformation mechanism that receives the specification model class instance returned by the parser and transformed by the consumer and creates an SK plugin from it.

  3. Adds the OpenApiDocumentParserOptions class to represent existing parser options and allows adding new ones with no breaking changes.

  4. Replaces the operationsToExclude exclusion list, which is limited to filtering out operations by operation id, with the OperationSelectionPredicate callback that can filter out operations based on id, method, path, and description.

  5. Removes the internal IOpenApiDocumentParser unneeded interface that was not used all that time.

  6. Other: XML comments + OpenAPI specification transformation sample

Contributes to the issue: https://github.com/microsoft/semantic-kernel/issues/4666 The first PR: https://github.com/microsoft/semantic-kernel/pull/9668