dify icon indicating copy to clipboard operation
dify copied to clipboard

Provide OpenAPI Spec JSON for Import into Postman

Open ChiayenGu opened this issue 1 year ago • 6 comments

Self Checks

  • [X] I have searched for existing issues search for existing issues, including closed ones.
  • [X] I confirm that I am using English to submit this report (我已阅读并同意 Language Policy).
  • [X] Pleas do not modify this template :) and fill in all the required fields.

1. Is this request related to a challenge you're experiencing?

We are currently utilizing the dify backend APIs, including but not limited to the database APIs, for our development work. To enhance our development efficiency and ensure proper use of APIs, we typically use API platforms like Postman for testing and debugging.

2. Describe the feature you'd like to see

To address the issue mentioned above, we are requesting the following support from the developers:

  1. Provide an OpenAPI specification format JSON file for the dify backend APIs (such as the database APIs).
  2. Offer a link or button on the official documentation or web pages that allows for direct import into Postman.

3. How will this feature improve your workflow or experience?

With the provision of an OpenAPI spec JSON, we would be able to more efficiently import your APIs into Postman for automated testing, thus improving our workflow efficiency and the accuracy of API usage.

4. Additional context or comments

Thank you for considering this request, and we look forward to your response.

5. Can you help us with this feature?

  • [ ] I am interested in contributing to this feature.

ChiayenGu avatar Mar 04 '24 00:03 ChiayenGu

Hey there @ChiayenGu! Great to see you back around here. Hope you've been doing well since our last chat!

Thank you for your detailed request. I understand the need for an OpenAPI specification in JSON format to improve your workflow with Postman.

Currently, the OpenAPI specification for the dify backend APIs is in YAML format and is located at api/core/tools/provider/builtin/github/github.yaml within the repository. You can view it here.

To convert this YAML file to JSON for use with Postman, you can use online tools such as YAML to JSON or YAML to JSON Converter. After conversion, you should be able to import the JSON file into Postman.

As for the second part of your request, adding a link or button for direct import into Postman on the official documentation or web pages, this would require changes to the repository or the website, which I, as a technical support rep, am unable to do. However, I will pass on your suggestion to the relevant team for consideration.

I hope this helps! If you have any further questions or need additional assistance, please don't hesitate to ask.

Sources

About Dosu

This response is meant to be useful and save you time. It is not meant to be a precise solution, but rather a starting point for your own research.

Help me be more useful! Please leave a 👍 if this is helpful and 👎 if it is irrelevant.

If you want to continue the conversation, start your reply with @dosu-bot.

dosubot[bot] avatar Mar 04 '24 00:03 dosubot[bot]

@dosu-bot Thank you very much for the solution provided. I noticed that what has been provided is a YAML file for defining a plugin interface specification. However, my current need is to obtain the OpenAPI format JSON file for the DIFY API service. If you could provide a link to that JSON file or guide me on how to generate it, I would greatly appreciate it. Looking forward to your further guidance, thank you!

ChiayenGu avatar Mar 04 '24 01:03 ChiayenGu

Based on the information available in the repository, it appears that there isn't a direct OpenAPI JSON specification for the DIFY API service. However, the repository does contain tools that can parse and work with OpenAPI specifications in both YAML and JSON formats.

The ApiBasedToolSchemaParser class in api/core/tools/utils/parser.py provides methods for parsing both OpenAPI and Swagger YAML files into a tool bundle format, which is then used to work with the OpenAPI JSON format. Although these methods primarily aim to parse the YAML into a tool bundle rather than directly converting YAML to JSON, the process involves working with OpenAPI JSON format internally.

Unfortunately, there isn't a specific method or function in the ApiBasedToolSchemaParser class that directly converts an OpenAPI YAML file to an OpenAPI JSON file. The conversion between YAML and JSON formats of OpenAPI specifications is implicitly supported by the tool's architecture, but not explicitly provided as a standalone functionality.

If you're comfortable with Python, you could potentially use the existing methods in the ApiBasedToolSchemaParser class as a starting point to write a script that converts the OpenAPI YAML file to JSON. You would need to parse the YAML file into a tool bundle using parse_openapi_yaml_to_tool_bundle or parse_swagger_yaml_to_tool_bundle, then serialize the resulting tool bundle back into JSON format.

Here's a rough example of how you might do this:

from api.core.tools.utils.parser import ApiBasedToolSchemaParser

# Initialize the parser
parser = ApiBasedToolSchemaParser()

# Parse the YAML file into a tool bundle
with open('api/core/tools/provider/builtin/github/github.yaml', 'r') as yaml_file:
    tool_bundle = parser.parse_openapi_yaml_to_tool_bundle(yaml_file.read())

# Serialize the tool bundle back into JSON format
openapi_json = json.dumps(tool_bundle, indent=4)

# Write the JSON to a file
with open('openapi.json', 'w') as json_file:
    json_file.write(openapi_json)

Please note that this is a simplified example and may not work as-is. You might need to adjust it based on the actual structure and requirements of your project.

I hope this helps! If you have any further questions or need more clarification, feel free to ask.

Sources

About Dosu

This response is meant to be useful and save you time. It is not meant to be a precise solution, but rather a starting point for your own research.

Help me be more useful! Please leave a 👍 if this is helpful and 👎 if it is irrelevant.

If you want to continue the conversation, start your reply with @dosu-bot.

dosubot[bot] avatar Mar 04 '24 01:03 dosubot[bot]

Thanks for your suggestion! Currently, this is not on our roadmap. If you're interested, you can contribute to it.

takatost avatar Mar 04 '24 06:03 takatost

dify-datasets.openapi.json Hello, I have converted a portion of the dataset API into an OpenAPI-formatted JSON file. Now it can be directly imported into debugging tools like Postman!

ChiayenGu avatar Mar 14 '24 06:03 ChiayenGu

Hi, @ChiayenGu,

I'm helping the team manage their backlog and am marking this issue as stale. From what I understand, you requested an OpenAPI specification format JSON file for the dify backend APIs, and there was a detailed response from Dosubot regarding the availability of the OpenAPI specification in YAML format, along with suggestions for conversion tools. You later shared a converted portion of the dataset API into an OpenAPI-formatted JSON file, and Takatost mentioned that the request is not on their roadmap, suggesting contributing to it as a potential path forward.

Could you please confirm if this issue is still relevant to the latest version of the repository? If it is, please let the team know by commenting on the issue. Otherwise, feel free to close the issue yourself, or it will be automatically closed in 7 days. Thank you!

dosubot[bot] avatar Apr 14 '24 16:04 dosubot[bot]