gibahjoe / openapi-generator-dart

Openapi Generator for Dart/Flutter
BSD 3-Clause "New" or "Revised" License
123 stars 34 forks source link

Api key in query not possible #66

Closed onurkaygisiz closed 2 years ago

onurkaygisiz commented 2 years ago

Hi, I have an api, which requires the api key in the query, it does not accept an apikey in the headers:

  securitySchemes:
    apikey:
      name: apikey
      type: apiKey
      in: query
security:
  - apikey: []

but the generator DioNext generates no code, in which I can pass the api key in the query, only in the headers:

    final _response = await _dio.request<Object>(
      _path, //This is the generated path
      options: _options, //Here are the headers and extras, the only place I can pass the apikey
      queryParameters: _queryParameters, //Here are the queries, but I cannot pass the apikey here, only the api parameters
      cancelToken: cancelToken,
      onSendProgress: onSendProgress,
      onReceiveProgress: onReceiveProgress,
    );

Here my configuration: open api generator

import 'package:openapi_generator_annotations/openapi_generator_annotations.dart';

@Openapi(
    additionalProperties: AdditionalProperties(
        pubName: 'apiconnection', pubAuthor: 'PeterParker'),
    inputSpecFile: 'packages/apiconnection.yaml',
    generatorName: Generator.dioNext,
    outputDirectory: 'packages/apiconnection')
class Example extends OpenapiGeneratorConfig {}

and my pubspec.yaml

dependencies:
  flutter:
    sdk: flutter
  cupertino_icons: ^1.0.2
  html: ^0.15.0
  apiconnection:
    path: 'packages/apiconnection'
  openapi_generator_annotations: ^3.3.0
  json_annotation: ^4.4.0
  dio: ^4.0.4
  build: ^2.2.1
  path: ^1.8.1
  source_gen: ^1.2.1
dev_dependencies:
  flutter_test:
    sdk: flutter
  flutter_lints: ^1.0.0
  openapi_generator: ^3.3.0+1
  build_runner: ^2.1.7
  analyzer: ^3.0.0
  json_serializable: ^6.1.4

Is there a solution to this problem? Thank you very much.

onurkaygisiz commented 2 years ago

All right, I solved the issue by using the generator by OpenApiTools and using the Dart generator.