OpenAPITools / openapi-generator

OpenAPI Generator allows generation of API client libraries (SDK generation), server stubs, documentation and configuration automatically given an OpenAPI Spec (v2, v3)
https://openapi-generator.tech
Apache License 2.0
21.82k stars 6.58k forks source link

[BUG][DART] The language version override has to be the same in the library and its part(s). #16117

Open deeeznuds opened 1 year ago

deeeznuds commented 1 year ago

I ran into a dart versioning problem. My project has sdk: '>=2.17.0 <3.0.0', and openapi-cli generated API has sdk: '>=2.14.0 <3.0.0'. I can not downgrade my project SDK version, but when I manually change SDK version in "generated_api/pubscpec.yaml", the project builds without errors. I search possibilities to set up a custom SDK version for openapi-generator-cli before generating API, but found nothing. Is there any solution for manually or automatically determining the SDK version to avoid such a problem?

openapi-generator version // https://mvnrepository.com/artifact/org.openapitools/openapi-generator-cli compileOnly 'org.openapitools:openapi-generator-cli:6.3.0'

OpenAPI declaration file content or url My declaration JSON file without errors, I can't share it due to my company's policy.

Generation Details java -jar C:\Users\DEV\Documents\openapi-generator-cli.jar generate -i https://test-example.com/api/v2/api-docs -g dart-dio -o C:\Users\DEV\Documents\Projects\mobile\lib\api -p pubLibrary=mobile.api,pubName=mobile_api,serializationLibrary=json_serializable

Steps to reproduce Set up in project's pubspec.yaml file SDK version like this: environment: sdk: '>=2.17.0 <3.0.0'

Then generate API via openapi-generator-cli. flutter pub get flutter pub run build_runner build --delete-conflicting-outputs

Build app, then in the debug logs you will see "The language version override has to be the same in the library and its part(s)." error.

Suggest a fix Add the ability to manually or automatically determine the SDK version.

dexterlakin commented 1 year ago

did you ever fix this? I have the same issue

affansk commented 1 year ago

same issue

hungnm1908 commented 1 year ago

same issue

hungnm1908 commented 1 year ago

I have the same issue

felix0324324 commented 1 year ago

Same bug

affansk commented 1 year ago

I have solved by adding 1) pubspec.yaml in .openapi-generator-ignore 2) then changed this :environment: sdk: '>=3.0.6 <4.0.0' 3) dependency_overrides: analyzer: 6.2.0

felix0324324 commented 1 year ago

I have solved by adding

  1. pubspec.yaml in .openapi-generator-ignore
  2. then changed this :environment: sdk: '>=3.0.6 <4.0.0'
  3. dependency_overrides: analyzer: 6.2.0

Great try!!! But I got another method I just moved my folder. Before

affansk commented 1 year ago

@felix0324324 it a saying. if it works don't touch it

davide-bontempelli-zupit commented 11 months ago

The problem is that dart-dio still requires sdk<3 See here: https://github.com/OpenAPITools/openapi-generator/blob/b7f31ddda4d52f450748349404016f5041f5495f/modules/openapi-generator/src/main/resources/dart/libraries/dio/pubspec.mustache#L13

The real solution would be to update the templates and code generation stuff...

davide-bontempelli-zupit commented 11 months ago

Duplicate of https://github.com/OpenAPITools/openapi-generator/issues/14863 There you can find an alternative solution