swagger-api / swagger-api/swagger-codegen
Using the Dart Generator for an api - how to set the headers
Open
Nobody has claimed this yet.
- Dominant language
- Mustache
- Stars
- 17.8k
- Forks
- 6k
- PR merge metrics
- No merged PRs in 30d
Description
After downloading the generated client for Dart and setting up in my flutter application
ApiClient client = ApiClient(basePath: "https://api.openai.com/v1");
var api = OpenAIApi(client);
How do I set the authentication headers?
calling the following createCompletion, there is no place to set headerParams
api.createCompletion(body);
Future<CreateCompletionResponse> createCompletion(CreateCompletionRequest body) async {
Object postBody = body;
// verify required params are set
if(body == null) {
throw new ApiException(400, "Missing required param: body");
}
// create path and map variables
String path = "/completions".replaceAll("{format}","json");
// query params
List<QueryParam> queryParams = [];
Map<String, String> headerParams = {}; // <<<<<<<<<<<<<<<<<<< here you can see they are always empty
Map<String, String> formParams = {};
List<String> contentTypes = ["application/json"];
String contentType = contentTypes.length > 0 ? contentTypes[0] : "application/json";
List<String> authNames = [];
if(contentType.startsWith("multipart/form-data")) {
bool hasFields = false;
MultipartRequest mp = new MultipartRequest(null, null);
if(hasFields)
postBody = mp;
}
else {
}
var response = await apiClient.invokeAPI(path,
'POST',
queryParams,
postBody,
headerParams,
formParams,
contentType,
authNames);
if(response.statusCode >= 400) {
throw new ApiException(response.statusCode, response.body);
} else if(response.body != null) {
return
apiClient.deserialize(response.body, 'CreateCompletionResponse') as CreateCompletionResponse ;
} else {
return null;
}
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Trace the generated Dart client from ApiClient and OpenAIApi.createCompletion to ApiClient.invokeAPI, focusing on headerParams and authNames. Reproduce the call with the shown OpenAI base path and verify that the authentication header reaches the request and that createCompletion still succeeds.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- dart, flutter
- Domain
- api, authentication, mobile
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100