Lack of Support for Object Type Handling in swagger Parsing #2145

Closed
opened 2026-02-21 17:42:12 -05:00 by yindo · 0 comments
Owner

Originally created by @LeePui on GitHub (Apr 12, 2024).

Self Checks

  • This is only for bug report, if you would like to ask a quesion, 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).
  • Pleas do not modify this template :) and fill in all the required fields.

Dify version

0.6.1

Cloud or Self Hosted

Self Hosted (Docker), Self Hosted (Source)

Steps to reproduce

  • The current implementation of the swagger parsing module does not support parsing properties of type 'object' correctly.
  • When these object types are expected to be handled as dictionaries, they are instead treated and processed as strings, leading to incorrect data handling and serialization issues.

Reason:

  • In the OpenAPI-Swagger specification, six data types are defined, but Dify has implemented only five of these. Notably, the 'null' type is not part of the OpenAPI specifications . See api_tool.py#_convert_body_property_type
  • If the parameter type in the Swagger document is 'object', Dify will throw a ValueError, and then it will parse it as a string type, which leads to a 400 error in the request.
  • We need to add parsing for the object type api_tool.py#_convert_body_property_type, The specific approach is to deserialize into a dictionary if it is a string, and return it if it is already a dictionary. If possible, I can submit a PR to fix this bug.
  • By the way, Dify's support for Swagger seems quite basic. For optional data types: oneOf, anyOf, allOf, not, it only supports anyOf.

✔️ Expected Behavior

here is an example :

  • swagger document demo:
{
    "openapi": "3.0.3",
    "info": {
        "title": "Api Documentation",
        "description": "Api Documentation",
        "termsOfService": "urn:tos",
        "contact": {},
        "license": {
            "name": "Apache 2.0",
            "url": "http://www.apache.org/licenses/LICENSE-2.0"
        },
        "version": "1.0"
    },
    "servers": [{"url":"http://localhost:8080"}],
    "paths": {
        "/demo": {
            "post": {
                "tags": [
                    "demo tags"
                ],
                "summary": "a object type demo",
                "operationId": "demo",
                "requestBody": {
                    "content": {
                        "application/json": {
                            "schema": {
                                "$ref": "#/components/schemas/DemoReq"
                            }
                        }
                    }
                },
                "responses": {
                    "200": {
                        "description": "OK",

                    },
                    "201": {
                        "description": "Created"
                    },
                    "401": {
                        "description": "Unauthorized"
                    },
                    "403": {
                        "description": "Forbidden"
                    },
                    "404": {
                        "description": "Not Found"
                    }
                }
            }
        },
    },
    "components": {
        "schemas": {
            "DemoReq": {
                "type": "object",
                "required": [
                    "infos",
                    "userId"
                ],
                "properties": {
                    "infos": {
                        "type": "object",
                        "description": "a map<String, Object>"
                    },
                    "userId": {
                        "type": "string",
                        "description": "user id"
                    }
                },
                "title": "DemoReq",
                "description": "DemoReq"
            }
        }
    }
}
  • dify log
    image

Theoretically, it should be parsed as: {"infos": {"user":"23232"}, "userId": "111111"}, but Dify parsed it as: {"infos": "{"user":"23232"}", "userId": "111111"}.

Actual Behavior

No response

Originally created by @LeePui on GitHub (Apr 12, 2024). ### Self Checks - [X] This is only for bug report, if you would like to ask a quesion, 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] Pleas do not modify this template :) and fill in all the required fields. ### Dify version 0.6.1 ### Cloud or Self Hosted Self Hosted (Docker), Self Hosted (Source) ### Steps to reproduce - The current implementation of the swagger parsing module does not support parsing properties of type 'object' correctly. - When these object types are expected to be handled as dictionaries, they are instead treated and processed as strings, leading to incorrect data handling and serialization issues. # Reason: - In the [OpenAPI-Swagger specification](https://swagger.io/docs/specification/data-models/data-types/#object), six data types are defined, but Dify has implemented only five of these. Notably, the 'null' type is not part of the OpenAPI specifications . See [api_tool.py#_convert_body_property_type](https://github.com/langgenius/dify/blob/main/api/core/tools/tool/api_tool.py#L272) - If the parameter type in the Swagger document is 'object', Dify will throw a ValueError, and then it will parse it as a string type, which leads to a 400 error in the request. - We need to add parsing for the object type [api_tool.py#_convert_body_property_type](https://github.com/langgenius/dify/blob/main/api/core/tools/tool/api_tool.py#L272), The specific approach is to deserialize into a dictionary if it is a string, and return it if it is already a dictionary. **If possible, I can submit a PR to fix this bug.** - By the way, Dify's support for Swagger seems quite basic. For optional data types: [oneOf, anyOf, allOf, not](https://swagger.io/docs/specification/data-models/oneof-anyof-allof-not/), it only supports anyOf. ### ✔️ Expected Behavior # here is an example : - swagger document demo: ``` { "openapi": "3.0.3", "info": { "title": "Api Documentation", "description": "Api Documentation", "termsOfService": "urn:tos", "contact": {}, "license": { "name": "Apache 2.0", "url": "http://www.apache.org/licenses/LICENSE-2.0" }, "version": "1.0" }, "servers": [{"url":"http://localhost:8080"}], "paths": { "/demo": { "post": { "tags": [ "demo tags" ], "summary": "a object type demo", "operationId": "demo", "requestBody": { "content": { "application/json": { "schema": { "$ref": "#/components/schemas/DemoReq" } } } }, "responses": { "200": { "description": "OK", }, "201": { "description": "Created" }, "401": { "description": "Unauthorized" }, "403": { "description": "Forbidden" }, "404": { "description": "Not Found" } } } }, }, "components": { "schemas": { "DemoReq": { "type": "object", "required": [ "infos", "userId" ], "properties": { "infos": { "type": "object", "description": "a map<String, Object>" }, "userId": { "type": "string", "description": "user id" } }, "title": "DemoReq", "description": "DemoReq" } } } } ``` - dify log ![image](https://github.com/langgenius/dify/assets/14257862/51b4e99b-1f45-424a-8e9f-a0524e81620a) Theoretically, it should be parsed as: `{"infos": {"user":"23232"}, "userId": "111111"}`, but Dify parsed it as: `{"infos": "{"user":"23232"}", "userId": "111111"}`. ### ❌ Actual Behavior _No response_
yindo added the 🐞 bug label 2026-02-21 17:42:12 -05:00
yindo closed this issue 2026-02-21 17:42:12 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: langgenius/dify#2145