Best practice for loading OpenAPI definitions for code generation?

Hi there!
I am trying to generate cURL snippets for making REST API calls based on an OpenAPI file. Trying to achieve something similar to HTTPie AI — a new way to interact with APIs. It works well for scenarios that involve a particular endpoint combined with documentation & examples. However, I am trying to see if I can fit an entire YAML file so that I can translate a natural language to several cURL snippets in one call.

I was experimenting with the Codex model for code generation based on OpenAPI specification files and it seemed very promising. Now that it is no longer available, I am experimenting with the gpt-3.5-turbo model.

The challenge I have though is that the OpenAPI specification file is really big to fit in a prompt. I tried the following approaches and would like to know if there’s a better / proper way to achieve it.

Approach 1: Extract the operationID / endpoint name and the description from the YAML file. Use that as context along with the question to identify the list of endpoitns relevant to the question. For instance
the following question will yield:

“Get all open support tickets. Update them as closed” → “getTickets, updateTicket”

Based on this, I will pass the API definitions for getTickets and updateTicket to generate the cURL snippets with the necessary parameters (that can also be potentially chained)

Approach 2: Store a list of example questions with a mapping to operations. This way it doesn’t have to know the entire list of operations but only the ones necessary for performing the common use-cases.

2 Likes