microsoft / kiota

OpenAPI based HTTP Client code generator
https://aka.ms/kiota/docs
MIT License
3.02k stars 210 forks source link

Error when generating an API plugin #4715

Closed maisarissi closed 6 months ago

maisarissi commented 6 months ago

What are you generating using Kiota, clients or plugins?

Kiota plugin

In what context or format are you using Kiota?

Windows executable

Client library/SDK language

None

Describe the bug

I'm able to search and find the GitHub OpenAPI description and select the endpoints I care about, which are:

When trying to generate an "API Plugin" for the above endpoints, I got the following error: image

In the output folder, both generated files (plugin and sliced openapi) are wrong. Plugin file has no functions nor runtimes objects.

{
  "schema_version": "v2",
  "name_for_human": "GitHub v3 REST API",
  "description_for_human": "GitHub\u0026apos;s v3 REST API.",
  "description_for_model": "GitHub\u0026apos;s v3 REST API.",
  "logo_url": "https://api.apis.guru/v2/cache/logo/https_twitter.com_github_profile_image.jpeg",
  "namespace": "githubrepo",
  "capabilities": {
    "localization": {}
  }
}

The sliced OpenAPI description has no "paths".

openapi: 3.0.1
info:
  title: GitHub v3 REST API
  description: GitHub's v3 REST API.
  termsOfService: https://docs.github.com/articles/github-terms-of-service
  contact:
    name: Support
    url: https://support.github.com/contact?tags=dotcom-rest-api
  license:
    name: MIT
    url: https://spdx.org/licenses/MIT
  version: '1.1.4'
  x-apisguru-categories:
    - collaboration
    - developer_tools
  x-github-plan: api.github.com
  x-logo:
    url: https://api.apis.guru/v2/cache/logo/https_twitter.com_github_profile_image.jpeg
  x-origin:
    - format: openapi
      url: https://raw.githubusercontent.com/github/rest-api-description/main/descriptions/api.github.com/api.github.com.json
      version: '3.0'
  x-providerName: github.com
  x-serviceName: api.github.com
servers:
  - url: https://api.github.com
paths: { }
components: ...

Using the same extension version I'm able to correctly generate an API Plugin for other GitHub endpoints, like /search node. Also, after getting the above error, I'm not able to load a new OpenAPI description. For that, I need to close and reopen VS Code.

Expected behavior

I should be able to generate an API plugin with functions and runtime for the selected endpoints as well as have a sliced OpenAPI description with only the selected endpoints in the paths

How to reproduce

Just try to generate a plugin for all the following endpoints:

Open API description file

No response

Kiota Version

plugin feature

Latest Kiota version known to work for scenario above?(Not required)

No response

Known Workarounds

No response

Configuration

No response

Debug output

Click to expand log ``` ```

Other information

No response

andrueastman commented 6 months ago

Looks like the extension shows/sends /repos/{org-id}/{repo-id}#GET as the include pattern while the openapi description has the path as /repos/{owner}/{repo}#GET(this is due to the path deduplication logic by kiota).

Authored https://github.com/microsoft/kiota/pull/4722 to resolve the issue with the indexer cleanup logic that doesn't add a wildcard for the last indexer.

maisarissi commented 6 months ago

@andrueastman will this fix the extension showing the wrong path? image

FYI @ElinorW

andrueastman commented 6 months ago

The extension will show the deduplicated paths /repos/{org-id}/{repo-id} this is because the document has some paths as /repos/{owner}/{repo} and others as /repos/{template_owner}/{template_repo}. So Kiota will deduplicate them to avoid having multiple branches as that is ambiguous from an openaApi standpoint.

This is similar to the scenario to the test at https://github.com/microsoft/kiota/blob/96a9bef79fffc8c5b54132999b7e6851dedef093/tests/Kiota.Builder.Tests/Extensions/OpenApiUrlTreeNodeExtensionsTests.cs#L911