Error on parsing OpeanAPI spec #7606

Closed
opened 2026-02-21 18:21:27 -05:00 by yindo · 2 comments
Owner

Originally created by @lotsik on GitHub (Jan 8, 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

Originally created by @lotsik on GitHub (Jan 8, 2025). ### Self Checks - [X] This is only for bug report, if you would like to ask a question, please head to [Discussions](https://github.com/langgenius/dify/discussions/categories/general). - [X] I have searched for existing issues [search for existing issues](https://github.com/langgenius/dify/issues), including closed ones. - [X] I confirm that I am using English to submit this report (我已阅读并同意 [Language Policy](https://github.com/langgenius/dify/issues/1542)). - [X] [FOR CHINESE USERS] 请务必使用英文提交 Issue,否则会被关闭。谢谢!:) - [X] 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
yindo added the 🐞 bug🔨 feat:tools labels 2026-02-21 18:21:27 -05:00
yindo closed this issue 2026-02-21 18:21:27 -05:00
Author
Owner

@dosubot[bot] commented on GitHub (Jan 8, 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[bot] commented on GitHub (Jan 8, 2025): <!-- Greeting --> @lotsik Hello! I'm here to help you with any bugs, questions, or contributions you may have. Let's tackle this issue together! <!-- Answer --> 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 <sup>[[1]](https://github.com/langgenius/dify/blob/main/api/core/tools/utils/parser.py)</sup>. 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. <!-- Dosu Comment Footer --> *To continue talking to [Dosu](https://dosu.dev), mention @dosu.* --- <sup>Help Dosu learn! Give it feedback: [Great Response](https://app.dosu.dev/response-feedback/c3cb1176-ebe0-40ef-a52d-1f63a3a462a1?feedback_type=great_response) | [Irrelevant Answer](https://app.dosu.dev/response-feedback/c3cb1176-ebe0-40ef-a52d-1f63a3a462a1?feedback_type=irrelevant_answer) | [Incorrect Sources](https://app.dosu.dev/response-feedback/c3cb1176-ebe0-40ef-a52d-1f63a3a462a1?feedback_type=incorrect_sources) | [Too Verbose](https://app.dosu.dev/response-feedback/c3cb1176-ebe0-40ef-a52d-1f63a3a462a1?feedback_type=too_verbose) | [Hallucination](https://app.dosu.dev/response-feedback/c3cb1176-ebe0-40ef-a52d-1f63a3a462a1?feedback_type=hallucination) | [Other](https://app.dosu.dev/response-feedback/c3cb1176-ebe0-40ef-a52d-1f63a3a462a1?feedback_type=other)</sup>
Author
Owner

@fre2d0m commented on GitHub (Jan 9, 2025):

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

@fre2d0m commented on GitHub (Jan 9, 2025): Same error, When I upgraded from v13 to v15, I couldn't save the custom tool open api schema
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: langgenius/dify#7606