Skip to content
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

Error on parsing OpeanAPI spec #12518

Closed
5 tasks done
lotsik opened this issue Jan 9, 2025 · 2 comments · Fixed by #12530
Closed
5 tasks done

Error on parsing OpeanAPI spec #12518

lotsik opened this issue Jan 9, 2025 · 2 comments · Fixed by #12530
Labels
🐞 bug Something isn't working 🔨 feat:tools Tools for agent, function call related stuff.

Comments

@lotsik
Copy link
Contributor

lotsik commented Jan 9, 2025

Self Checks

  • This is only for bug report, if you would like to ask a question, please head to Discussions.
  • I have searched for existing issues search for existing issues, including closed ones.
  • I confirm that I am using English to submit this report (我已阅读并同意 Language Policy).
  • [FOR CHINESE USERS] 请务必使用英文提交 Issue,否则会被关闭。谢谢!:)
  • Please do not modify this template :) and fill in all the required fields.

Dify version

0.15.0

Cloud or Self Hosted

Self Hosted (Docker)

Steps to reproduce

  1. Open tool's page
  2. Select category api
  3. Open popup for creating new tool
  4. Paste in textarea OpenAPI Specification (YAML or JSON) with requestBody
    { "openapi": "3.1.0", "info": { "title": "Tool", "description": "Desc", "version": "1.0.0" }, "servers": [ { "url": "https://example.com" } ], "paths": { "/call": { "post": { "summary": "Execute", "description": "Execute", "operationId": "query", "requestBody": { "content": { "application/json": { "schema": { "type": "object", "properties": { "query": { "type": "string", "description": "query to execute" } }, "required": ["query"], "title": "Query" } } } }, "responses": { "200": { "description": "OK", "content": { "application/json": { "schema": { "type": "object", "properties": { "msg": { "type": "string", "description": "message" } } } } } } } } } }, "components": { "schemas": {}, "parameters": {} } }
  5. Got error invalid schema: invalid schema: cannot access local variable 'parameter' where it is not associated with a value

✔️ Expected Behavior

Succefully safe OpenAPI spec and create external tool

❌ Actual Behavior

Can't create external tool from OpenAPI spec with json object in request body

Copy link

dosubot bot commented Jan 9, 2025

@lotsik Hello! I'm here to help you with any bugs, questions, or contributions you may have. Let's tackle this issue together!

The error you're encountering, "invalid schema: cannot access local variable 'parameter' where it is not associated with a value," suggests that there might be an issue with how the OpenAPI schema is being parsed, particularly with the handling of parameters in the request body.

In Dify's codebase, the parsing of OpenAPI specifications involves checking for requestBody objects and processing their content. If a schema reference ($ref) is found, it resolves the reference and overwrites the content schema. The code then parses the body parameters by extracting the schema's properties and required fields, creating ToolParameter objects for each property. However, it seems there might be a missing or improperly handled variable, possibly related to the parameter variable in the parsing logic [1].

To troubleshoot this issue, you might want to:

  1. Ensure that the OpenAPI schema is correctly formatted and adheres to the expected structure, especially in the requestBody section.
  2. Check if there are any missing or incorrectly defined parameters in the schema.
  3. Review the code handling the parsing of OpenAPI schemas to ensure that all variables, such as parameter, are properly initialized and used.

If the issue persists, it might be helpful to look into the specific part of the codebase responsible for parsing the OpenAPI schema to identify any potential bugs or areas where the handling of parameters could be improved.

To continue talking to Dosu, mention @dosu.


Help Dosu learn! Give it feedback: Great Response | Irrelevant Answer | Incorrect Sources | Too Verbose | Hallucination | Other

@dosubot dosubot bot added 🐞 bug Something isn't working 🔨 feat:tools Tools for agent, function call related stuff. labels Jan 9, 2025
@lotsik lotsik mentioned this issue Jan 9, 2025
5 tasks
@fre2d0m
Copy link

fre2d0m commented Jan 9, 2025

Same error, When I upgraded from v13 to v15, I couldn't save the custom tool open api schema

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🐞 bug Something isn't working 🔨 feat:tools Tools for agent, function call related stuff.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants