gibahjoe / openapi-generator-dart

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

Generate error #113

Closed RoyZengTW closed 9 months ago

RoyZengTW commented 9 months ago

Description of the bug

I run dart run build_runner build --delete-conflicting-outputs and get this fail message.

[SEVERE] openapi_generator on lib/build_runner/openapi_generate.dart:
Failed to generate content.

Failed to check diff status. Unable to find spec file openapi.yaml  #0      loadSpec (package:openapi_generator/src/gen_on_spec_changes.dart:111:32)
#1      OpenapiGenerator.hasDiff (package:openapi_generator/src/openapi_generator_runner.dart:288:32)
<asynchronous suspension>
#2      OpenapiGenerator.generatorV2 (package:openapi_generator/src/openapi_generator_runner.dart:194:12)
<asynchronous suspension>

Steps to reproduce

  1. Setup the OpenapiGeneratorConfig
  2. Run command dart run build_runner build --delete-conflicting-outputs

Expected behavior

Generate the openapi package

Logs

No response

Screenshots

No response

Platform

macOS

Library version

4.13.0

Flutter version

3.10.6

Flutter channel

stable

Additional context

dart version: 3.0.6
Excds commented 9 months ago

I'm commenting here to say I have the same problem when I have useNextGen: true.

gibahjoe commented 9 months ago

Please post your @Openapi annotation code. Also confirm your spec file is correctly named and in the root of your project.

gibahjoe commented 9 months ago

Hi, upon further investigation, looks like the inputSpecFile parameter is not being handled for nextGen.

To resolve this issue, kindly specify a remote spec like below

@Openapi(
  additionalProperties:
      DioProperties(pubName: 'petstore_api', pubAuthor: 'Johnny dep..'),
  inputSpecFile: 'https://petstore3.swagger.io/api/v3/openapi.json',
  inputSpec: RemoteSpec(path: 'https://petstore3.swagger.io/api/v3/openapi.json'), // Include this in your annotation
  typeMappings: {'Pet': 'ExamplePet'},
  generatorName: Generator.dio,
  runSourceGenOnOutput: true,
  useNextGen: true,
  outputDirectory: 'api/petstore_api',
)

I will push up a fix in the next few days.

Feel free to reopen this if this does not solve your problem

TamasBarta commented 6 months ago

Hi, this still is an issue (using 4.13.1). I'm not using a remote spec, and I don't have an URL for our spec. My workaround for now was to rename it to "openapi.yaml", but that's not a solution. It now has to be in our project root, and that's not ideal at all.