wso2 / api-manager

All issues, tasks, improvements and new features of WSO2 API Manager
Apache License 2.0
34 stars 8 forks source link

Error while generating samples in API chat #2739

Open RakhithaRR opened 3 months ago

RakhithaRR commented 3 months ago

Description

The following error is observed after creating an API using a valid OpenAPI 3.0.1 definition

Screenshot 2024-03-28 at 22 01 03

Steps to Reproduce

  1. Create and publish an API using https://raw.githubusercontent.com/OAI/OpenAPI-Specification/main/examples/v3.0/uspto.json
  2. Navigate to API chat section in devportal

Affected Component

APIM

Version

4.3.0

Environment Details (with versions)

No response

Relevant Log Output

No response

Related Issues

No response

Suggested Labels

No response

ashera96 commented 3 months ago

Initial Analysis:

This is occurring due to a limitation in the ballerina agent side. The error getting logged at that level is as follows:

"The OpenAPI specification includes non-JSON input types, which are not currently supported." error={"causes":[],"message":"Only json, xml or text content is supported.","detail":{"availableContentTypes":["application/x-www-form-urlencoded"]},"stackTrace":[{"callableName":"visitContent","moduleName":"wso2.ai.agent.0.OpenApiSpecVisitor","fileName":"openapi_utils.bal","lineNumber":213},{"callableName":"visitRequestBody","moduleName":"wso2.ai.agent.0.OpenApiSpecVisitor","fileName":"openapi_utils.bal","lineNumber":220},{"callableName":"visitOperation","moduleName":"wso2.ai.agent.0.OpenApiSpecVisitor","fileName":"openapi_utils.bal","lineNumber":190},{"callableName":"visitPathItem","moduleName":"wso2.ai.agent.0.OpenApiSpecVisitor","fileName":"openapi_utils.bal","lineNumber":166},{"callableName":"visitPaths","moduleName":"wso2.ai.agent.0.OpenApiSpecVisitor","fileName":"openapi_utils.bal","lineNumber":150},{"callableName":"visit","moduleName":"wso2.ai.agent.0.OpenApiSpecVisitor","fileName":"openapi_utils.bal","lineNumber":104},{"callableName":"extractToolsFromOpenApiJsonSpec","moduleName":"wso2.ai.agent.0","fileName":"openapi_utils.bal","lineNumber":66},{"callableName":"$post$prepare","moduleName":"choreo.testgpt.2.$anonType$_24","fileName":"service.bal","lineNumber":124}]} id="1"

Ballerina agent returns a 500 Internal Server Error with the following error response:

{
    "level": "WARN",
    "message": "The OpenAPI specification includes non-JSON input types, which are not currently supported.",
    "code": "UNSUPPORTED_MEDIA_TYPE"
}

In summary, API Chat page gives this error as we are unable to parse the API specification at the ballerina agent level. Error is occurring due to the following content under the API specification.

        "requestBody": {
          "content": {
            "application/x-www-form-urlencoded": {
              "schema": {
                "type": "object",
                "properties": {
                  "criteria": {
                    "description": "Uses Lucene Query Syntax in the format of propertyName:value, propertyName:[num1 TO num2] and date range format: propertyName:[yyyyMMdd TO yyyyMMdd]. In the response please see the 'docs' element which has the list of record objects. Each record structure would consist of all the fields and their corresponding values.",
                    "type": "string",
                    "default": "*:*"
                  },
                  "start": {
                    "description": "Starting record number. Default value is 0.",
                    "type": "integer",
                    "default": 0
                  },
                  "rows": {
                    "description": "Specify number of rows to be returned. If you run the search with default values, in the response you will see 'numFound' attribute which will tell the number of records available in the dataset.",
                    "type": "integer",
                    "default": 100
                  }
                },
                "required": [
                  "criteria"
                ]
              }
            }
          }
        }