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

feat(dart): dart-next generator #18970

Draft
wants to merge 23 commits into
base: master
Choose a base branch
from

Conversation

ahmednfwela
Copy link
Contributor

@ahmednfwela ahmednfwela commented Jun 19, 2024

supersedes #15485

This generator is designed to replace both dart and dart-dio generators, and has the following features:

  1. NO dependency on 3rd party modelling/serialization libraries (built_value, freezed, etc...), everything is done in-house (also no need to run dart run build_runner build).
  2. Heavy use of the new Extension types to add strict static typing with no run-time cost. an example of this is:
    • UndefinedWrapper<T> which makes any non-required variable recognize undefined as a valid value, in which case, it will NOT be included during serialization.
    • Enums: an enum is just an expression of the available values a variable can have, it shouldn't replace the data type, which is a perfect use case for extension types (see this file for an example).
  3. Pluggable networking libraries, by extending NetworkingClientBase
    • Support initially will be for package:http, but package:dio can be added as well
  4. Heavy use of mustache's ability to recursively include templates (example), which minimizes java code that was used to hack around nested types.
  5. separate shared_infrastructure package that has simple base models that should NOT be changed, but the generator will also include an option to inline it. this is done so we can maintain a version of it on pub.dev which users can opt-in to use.
  6. Use package:cross_file to handle files
  7. support multiple mime types, not just json.
  8. generate reflection information for models.
  9. Support request/response streaming.

Current tasks:

  • finalize JSON model serialization
  • support discriminators when available
  • finalize XML support
  • finalize API classes
  • write tests in java
  • generate model tests (roundtrip serialization)
  • generate API tests by mocking

P.S. testing and templating for this generator is done here https://github.com/ahmednfwela/dart-next-generator-testing

PR checklist

  • Read the contribution guidelines.
  • Pull Request title clearly describes the work in the pull request and Pull Request description provides details about how to validate the work. Missing information here may result in delayed response from the community.
  • Run the following to build the project and update samples:
    ./mvnw clean package 
    ./bin/generate-samples.sh ./bin/configs/*.yaml
    ./bin/utils/export_docs_generators.sh
    
    (For Windows users, please run the script in Git BASH)
    Commit all changed files.
    This is important, as CI jobs will verify all generator outputs of your HEAD commit as it would merge with master.
    These must match the expectations made by your contribution.
    You may regenerate an individual generator by passing the relevant config(s) as an argument to the script, for example ./bin/generate-samples.sh bin/configs/java*.
    IMPORTANT: Do NOT purge/delete any folders/files (e.g. tests) when regenerating the samples as manually written tests may be removed.
  • File the PR against the correct branch: master (upcoming 7.6.0 minor release - breaking changes with fallbacks), 8.0.x (breaking changes without fallbacks)
  • If your PR is targeting a particular programming language, @mention the technical committee members, so they are more likely to review the pull request.

@ahmednfwela
Copy link
Contributor Author

cc core team: @wing328 @jimschubert @cbornet @jmini @etherealjoy

I made a non-breaking change in DefaultCodegen by adding a new method updateCodegenPropertyEnum to fix name conflicts in inner enums for languages that don't support namespaces

public void updateCodegenPropertyEnum(CodegenProperty var, CodegenModel model)

@ahmednfwela
Copy link
Contributor Author

cc dart committee for early review:
@jaumard (2018/09) @josh-burton (2019/12) @amondnet (2019/12) @sbu-WBT (2020/12) @kuhnroyal (2020/12) @agilob (2020/12) @ahmednfwela (2021/08)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant