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

Add support for an another json serializer called dart_mappable #141

Merged
merged 6 commits into from
Dec 6, 2023
Merged

Add support for an another json serializer called dart_mappable #141

merged 6 commits into from
Dec 6, 2023

Conversation

dagyu
Copy link
Contributor

@dagyu dagyu commented Nov 23, 2023

With this issue I add the support for dart_mappable as json_serializer.

dart_mappable, is a library for json serialization and immutable data structures, it is like freezed but for our use case is by far better than it (I think in general but this is pretty subjective).

Edits

  • I transformed freezed boolean field with an enum called JsonSerializer that allow to understand inside the code which kind of serializer should be used. So the definition inside swagger_parser.yaml change in this way:
 - schema_path: schemas/openapi.json
    root_client_name: ApiMicroservice
-   freezed: true
+   jsonSerializer: "freezed"
    put_in_folder: true
    put_in_folder: true
    replacement_rules: []
  • Obviously, the code that allows you to generate the models using dart_mappable has been added, to do this I have not touched the pre-existing generation in any way in order to avoid introducing breaking changes.

  • Furthermore, a test case has also been added to test the generation of a class with dart_mappable.

Usage

The usage remains unchanged obviously if you want to use dart_mappable you need to:

  • add the required dependencies from the package
  • indicate in swagger.parser.yaml json_serializer: "dart_mappable"
  • add the following string to build.yaml:
  dart_mappable_builder:
    runs_before:
      - retrofit_generator
    options:
      renameMethods:
        toJson: toJsonString
        # This is because retrofit_generator expect a method Map<String,dynamic> toJson()
        toMap: toJson

Final considerations

Every changes has been made incremental without compromising and touching the other serializer in this way backward compatibility is totally granted. The only "breaking change" is the definition inside swagger_parser.yaml as explained above.

Please, I kindly request you to consider this PR and integrate it into the library. I am open to any suggestions or questions regarding my work.

@Carapacik Carapacik added the enhancement New feature or request label Nov 23, 2023
@Carapacik Carapacik self-requested a review November 25, 2023 20:12
@Carapacik
Copy link
Owner

Thanks for PR. Please fix analyze issues and add changelog to CHANGELOG.MD

@dagyu
Copy link
Contributor Author

dagyu commented Dec 1, 2023

@Carapacik I do the followings:

  • Rebased to the latest version on main
  • Fix analysis issues
  • Updated CHANGELOG and README
  • Fixed a bug related to enum generation when the enum is inside an array definition, I also added a test case. The fix is pretty simple take a look here 43a02fb

@Carapacik Carapacik self-requested a review December 1, 2023 18:15
@dagyu
Copy link
Contributor Author

dagyu commented Dec 2, 2023

I fix the failing test

@Carapacik Carapacik self-requested a review December 4, 2023 06:11
@Carapacik Carapacik merged commit 850739a into Carapacik:main Dec 6, 2023
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants