Skip to content

[BUG] [Dart] Recent addition of copy_with_extension breaks code generation due to wrong SDK version constraint #21815

@MichaelMarner

Description

@MichaelMarner

Bug Report Checklist

  • Have you provided a full/minimal spec to reproduce the issue?
  • Have you validated the input using an OpenAPI validator?
  • Have you tested with the latest master to confirm the issue still exists?
  • Have you searched for related issues/PRs?
  • What's the actual output vs expected output?
  • [Optional] Sponsorship to speed up the bug fix or feature request (example)
Description

The recent addition of copy_with_extension has caused code generation to fail. This is because copy_with_extension requires Dart 3.8, but the version constraint in the templated pubspec.yaml is 3.5.0.

Example error:

log output for json_serializable on lib/src/model/additional_properties_class.dart
W The language version (3.5.0) of this package (openapi) does not match the required range `^3.8.0`.
  Edit pubspec.yaml to include an SDK constraint of at least ^3.8.0.
  environment:
    sdk: ^3.8.0
E An error `FormatterException` occurred while formatting the generated source for
    `package:openapi/src/model/additional_properties_class.dart`
  which was output to
    `lib/src/model/additional_properties_class.json_serializable.g.part`.
  This may indicate an issue in the generator, the input source code, or in the
  source formatter.
  Could not format because the source could not be parsed:
  line 19, column 25 of .: This requires the 'null-aware-elements' language feature to be enabled.
     ╷
  19 │         'map_property': ?instance.mapProperty,
     │                         ^
     ╵
openapi-generator version

7.15.0, and this issue exists on master branch,

OpenAPI declaration file content or url

N/A - this issue can be verified with the petstore example in the repo.

Steps to reproduce

This issue can be verified using the petstore sample

  1. Checkout OpenAPI Generator on master
  2. cd samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake-json_serializable
  3. dart pub get
  4. dart run build_runner build --delete-conflicting-outputs

See the errors

Related issues/PRs

#21667
#21665

Suggest a fix

Requiring a minimum of Dart 3.8.0 fixes the issue for us. Unfortunately it looks like the petstore example still has other build issues. eg:

pubspec.mustache

environment:
  sdk: '>={{^useJsonSerializable}}2.18.0{{/useJsonSerializable}}{{#useJsonSerializable}}3.8.0{{/useJsonSerializable}} <4.0.0'

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions