Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Api generation failing No such file/directory #164

Open
L4stIdi0t opened this issue Nov 13, 2024 · 9 comments
Open

Api generation failing No such file/directory #164

L4stIdi0t opened this issue Nov 13, 2024 · 9 comments
Labels
bug Something isn't working waiting for response

Comments

@L4stIdi0t
Copy link

L4stIdi0t commented Nov 13, 2024

Description of the bug

Generating the api fails

Steps to reproduce

dart run build_runner build --delete-conflicting-outputs
# OR
flutter pub run build_runner build --delete-conflicting-outputs

Minimal openapi specification

https://petstore3.swagger.io/api/v3/openapi.json

Annotation used

@openapi(
additionalProperties:
DioProperties(pubName: 'petstore_api', pubAuthor: 'Johnny_dep'),
inputSpec:
RemoteSpec(path: 'https://petstore3.swagger.io/api/v3/openapi.json'),
typeMappings: {'Pet': 'ExamplePet'},
generatorName: Generator.dio,
runSourceGenOnOutput: true,
outputDirectory: 'api/petstore_api',
)
class Example {}

Expected behavior

a nicely generated api package

Logs

[INFO] openapi_generator on lib/main.dart:Loaded cached and current spec files.
[INFO] openapi_generator on lib/main.dart:Dirty Spec found. Running generation.
[INFO] openapi_generator on lib/main.dart:Running following command to generate openapi client - [ generate -o=api/petstore_api -i=https://petstore3.swagger.io/api/v3/openapi.json -g=dart-dio --type-mappings=Pet=ExamplePet --additional-properties=allowUnicodeIdentifiers=false,ensureUniqueParams=true,useEnumExtension=true,enumUnknownDefaultCase=false,prependFormOrBodyParameters=false,pubAuthor=Johnny_dep,pubName=petstore_api,legacyDiscriminatorBehavior=true,sortModelPropertiesByRequiredFlag=true,sortParamsByRequiredFlag=true,wrapper=none ]
[SEVERE] openapi_generator on lib/main.dart:
Failed to generate content.

ProcessException: No such file or directory
  Command: dart run openapi_generator_cli:main generate -o=api/petstore_api -i=https://petstore3.swagger.io/api/v3/openapi.json -g=dart-dio --type-mappings=Pet=ExamplePet --additional-properties=allowUnicodeIdentifiers=false,ensureUniqueParams=true,useEnumExtension=true,enumUnknownDefaultCase=false,prependFormOrBodyParameters=false,pubAuthor=Johnny_dep,pubName=petstore_api,legacyDiscriminatorBehavior=true,sortModelPropertiesByRequiredFlag=true,sortParamsByRequiredFlag=true,wrapper=none
[INFO] openapi_generator on lib/main.dart:Found generated timestamp. Updating with 2024-11-13T09:43:10.992397

Screenshots

No response

Platform

Linux

Library version

6.0.0

Flutter version

3.24.4

Flutter channel

stable

Additional context

Running the following works just fine

dart run openapi_generator_cli:main generate -o=api/petstore_api -i=https://petstore3.swagger.io/api/v3/openapi.json -g=dart-dio --type-mappings=Pet=ExamplePet --additional-properties=allowUnicodeIdentifiers=false,ensureUniqueParams=true,useEnumExtension=true,enumUnknownDefaultCase=false,prependFormOrBodyParameters=false,pubAuthor=Johnny_dep,pubName=petstore_api,legacyDiscriminatorBehavior=true,sortModelPropertiesByRequiredFlag=true,sortParamsByRequiredFlag=true,wrapper=none
@L4stIdi0t L4stIdi0t added the bug Something isn't working label Nov 13, 2024
@gibahjoe
Copy link
Owner

Hello, could you enable debug logging by setting it to true on your annotation then try again? Please post logs if possible.

@L4stIdi0t
Copy link
Author

L4stIdi0t commented Nov 18, 2024

Sorry for the delay, i do not see any debug info in the following:

l4sti@fedora:~/Projects/local/flut-front$ flutter pub run build_runner build --delete-conflicting-outputs
Deprecated. Use `dart run` instead.
Building package executable... (1.8s)
Built build_runner:build_runner.
[INFO] Generating build script completed, took 145ms
[INFO] Precompiling build script... completed, took 1.8s
[INFO] Building new asset graph completed, took 635ms
[INFO] Checking for unexpected pre-existing outputs. completed, took 0ms
[INFO] Generating SDK summary completed, took 2.2s
[INFO] openapi_generator on lib/main.dart:

:::::::::::::::::::::::::::::::::::::::::::
::      Openapi generator for dart       ::
:::::::::::::::::::::::::::::::::::::::::::

[WARNING] openapi_generator on lib/main.dart:
Using a remote specification, a cache will still be created but may be outdated.

[WARNING] openapi_generator on lib/main.dart:
loadSpec - /home/l4sti/Projects/local/flut-front/.dart_tool/openapi-generator-cache.json
[WARNING] openapi_generator on lib/main.dart:
loadSpec - https://petstore3.swagger.io/api/v3/openapi.json
[INFO] openapi_generator on lib/main.dart:Loaded cached and current spec files.
{}
{"openapi":"3.0.2","info":{"title":"Swagger Petstore - OpenAPI 3.0
removed the openapi.json
"api_key","in":"header"}}}}

[INFO] openapi_generator on lib/main.dart:Dirty Spec found. Running generation.
[INFO] openapi_generator on lib/main.dart:Running following command to generate openapi client - [ generate -o=api/petstore_api -i=https://petstore3.swagger.io/api/v3/openapi.json -g=dart-dio --type-mappings=Pet=ExamplePet --additional-properties=allowUnicodeIdentifiers=false,ensureUniqueParams=true,useEnumExtension=true,enumUnknownDefaultCase=false,prependFormOrBodyParameters=false,pubAuthor=Johnny dep..,pubName=petstore_api,legacyDiscriminatorBehavior=true,sortModelPropertiesByRequiredFlag=true,sortParamsByRequiredFlag=true,wrapper=none ]
[SEVERE] openapi_generator on lib/main.dart:
Failed to generate content.

ProcessException: No such file or directory
  Command: dart run openapi_generator_cli:main generate -o=api/petstore_api -i=https://petstore3.swagger.io/api/v3/openapi.json -g=dart-dio --type-mappings=Pet=ExamplePet --additional-properties=allowUnicodeIdentifiers=false,ensureUniqueParams=true,useEnumExtension=true,enumUnknownDefaultCase=false,prependFormOrBodyParameters=false,pubAuthor=Johnny dep..,pubName=petstore_api,legacyDiscriminatorBehavior=true,sortModelPropertiesByRequiredFlag=true,sortParamsByRequiredFlag=true,wrapper=none
[INFO] openapi_generator on lib/main.dart:Found generated timestamp. Updating with 2024-11-18T19:00:49.272190
[INFO] Running build completed, took 8.3s
[INFO] Caching finalized dependency graph completed, took 60ms
[SEVERE] Failed after 8.3s
l4sti@fedora:~/Projects/local/flut-front$ dart --version
Dart SDK version: 3.5.4 (stable) (Wed Oct 16 16:18:51 2024 +0000) on "linux_x64"

i am using dart 3 if that matters because i found some issues with dart 3
i added debugLogging: true, just to be sure

@Dreaming-Codes
Copy link

Had the same issue try with a local spec instead of a remote one

@L4stIdi0t
Copy link
Author

using inputSpec: InputSpec(path: 'test.json'), gives the same errors

@gibahjoe
Copy link
Owner

Hi, i am unable to recreate this issue however, i suspect it is due to the cache of the spec not being created yet on first run.

Please add skipIfSpecIsUnchanged option and set it to false (default is true).

@openapi(
additionalProperties:
DioProperties(pubName: 'petstore_api', pubAuthor: 'Johnny_dep'),
inputSpec:
RemoteSpec(path: 'https://petstore3.swagger.io/api/v3/openapi.json'),
typeMappings: {'Pet': 'ExamplePet'},
generatorName: Generator.dio,
runSourceGenOnOutput: true,
skipIfSpecIsUnchanged: false, // <======= add this
outputDirectory: 'api/petstore_api',
)
class Example {}

@L4stIdi0t
Copy link
Author

L4stIdi0t commented Nov 28, 2024

After adding skipIfSpecIsUnchanged : false i still get the same logs as mentioned before
i also used flutter clean but no success

after generating the files using the command which is logged dart run openapi generator ... i am missing serializers.g.dart

@jungnitz
Copy link

jungnitz commented Dec 4, 2024

If you are on Linux, make sure that your PATH is set correctly in .bashrc, not in .bash_profile. That fixed this issue for me.

@gibahjoe
Copy link
Owner

gibahjoe commented Dec 9, 2024

Thanks @jungnitz , PATH set to what exactly? is it the Java path?

@jungnitz
Copy link

jungnitz commented Dec 9, 2024

Ah, no, the path to the dart / flutter bin folder. It fails with No such file or directory because the dart executable cannot be found in the current PATH (apparently the environment variables are not inherited from the shell that you run the build command in).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working waiting for response
Projects
None yet
Development

No branches or pull requests

4 participants