Skip to content

.Net: OpenAPI parameter resolution mechanism - part 1 #9668

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged

Conversation

SergeyMenshykh
Copy link
Member

Motivation and Context

Today, the SK OpenAPI plugin's functionality does not support OpenAPI operations that include parameters with the same name. For example, a parameter named "id" can be used in the operation path, payload, header, and query string, each representing the ID of a different entity in those contexts. An attempt to import an OpenAPI operation containing multiple parameters with the same name will fail with the error message: "The function has two or more parameters with the same name '{parameter name}'." Therefore, the SK OpenAPI plugin needs a way to gracefully manage operations that include parameters with identical names.

Description

This PR adds the ArgumentName property to the RestApiPayloadProperty and RestApiServerVariable classes and renames the RestApiParameter.AlternativeName property to RestApiParameter.ArgumentName to better represent its purpose, as it was used as an argument name before. The property allows associating argument names with OpenAPI parameters and is used by the RestApiOperationRunner to look up values for them in the arguments the function was invoked with.

The next PR will allow consumers to access the OpenAPI document model and provide argument names for the "clashing" parameters.

Additionally, this PR adds functionality that allows "freezing" the classes to prevent their modification after the OpenAPI document has been parsed and imported, and its operations have become available via the KernelFunction.Metadata.AdditionalProperties["operation"] item.

Contributes to: #4666

@SergeyMenshykh SergeyMenshykh added openapi Issues related to the OpenAPI function importer Ignite Features planned for next Ignite conference labels Nov 12, 2024
@SergeyMenshykh SergeyMenshykh self-assigned this Nov 12, 2024
@SergeyMenshykh SergeyMenshykh requested a review from a team as a code owner November 12, 2024 17:32
@markwallace-microsoft markwallace-microsoft added the .NET Issue or Pull requests regarding .NET code label Nov 12, 2024
@SergeyMenshykh SergeyMenshykh added this pull request to the merge queue Nov 13, 2024
Merged via the queue into microsoft:main with commit 50bc6f3 Nov 13, 2024
14 checks passed
@SergeyMenshykh SergeyMenshykh deleted the name-resolution-mechanism-part1 branch November 13, 2024 14:06
github-merge-queue bot pushed a commit that referenced this pull request Nov 14, 2024
### 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:
#4666
The first PR: #9668
github-merge-queue bot pushed a commit that referenced this pull request Jan 6, 2025
### Motivation and Context
The payload property value lookup mechanism was broken in this PR -
#9668, preventing the
resolution of payload property values by sanitized payload property
names, leading to exceptions such as - "No argument is found for the
'customerid_[[email protected]](mailto:[email protected])' payload
property."

### Description
This PR fixes the issue and adds the necessary tests to ensure that the
functionality won't break in the future.

---------

Co-authored-by: Roger Barreto <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Ignite Features planned for next Ignite conference .NET Issue or Pull requests regarding .NET code openapi Issues related to the OpenAPI function importer
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants