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

Fix dart2 custom templates #3656

Merged
merged 4 commits into from
Aug 29, 2019

Conversation

alexnavratil
Copy link
Contributor

@alexnavratil alexnavratil commented Aug 15, 2019

PR checklist

  • Read the contribution guidelines.
  • Ran the shell script under ./bin/ to update Petstore sample so that CIs can verify the change. (For instance, only need to run ./bin/{LANG}-petstore.sh, ./bin/openapi3/{LANG}-petstore.sh if updating the {LANG} (e.g. php, ruby, python, etc) code generator or {LANG} client's mustache templates). Windows batch files can be found in .\bin\windows\. If contributing template-only or documentation-only changes which will change sample output, be sure to build the project first.
  • Filed the PR against the correct branch: master, 4.1.x, 5.0.x. Default: master.
  • Copied the technical committee to review the pull request if your PR is targeting a particular programming language.

@ircecho (2017/07) @swipesight (2018/09) @jaumard (2018/09)

Description of the PR

setting a custom template directory using the dart client generator didn't work for dart 2.x since the templateDir gets overwritten by "dart2". Since the dart2 templates were outdated and still based on dartson (which isn't defined as dependency and also not working anymore), I've decided to fix them too (copied and fixed formatting from #3048).

fixes #3655

UPDATE: also fixes #2830

@alexnavratil
Copy link
Contributor Author

just pushed another commit which finally fixes parsing json to dart enums. I've also fixed parsing a map property with a list as value since the complexType is List and List.mapFromJson doesn't exist. I've added a mapListFromJson to each model class which is used when the complexType is a List.
This should fix some first issues. We need to further consider maps with a list of primitive or enum values, these are still not handled.

@alexnavratil
Copy link
Contributor Author

just fixed your discussions :)

@wing328
Copy link
Member

wing328 commented Aug 24, 2019

Can you please resolve the merge conflicts when you've time as I just merged another Dart PR into master?

* fix decoding a map with a list of some objects as value since the complexType is a List and List.mapFromJson doesn't exist.
@alexnavratil alexnavratil force-pushed the fix-dart2-custom-templates branch from 32edf79 to fb80a56 Compare August 25, 2019 17:10
@alexnavratil
Copy link
Contributor Author

rebased

@wing328 wing328 modified the milestones: 4.1.1, 4.1.2 Aug 26, 2019
// check to not overwrite a custom templateDir
if (templateDir == null) {
embeddedTemplateDir = templateDir = "dart2";
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this may be causing issues. I ran ./bin/dart2-petstore.sh and got the following diff (partial):

--- a/samples/client/petstore/dart2/flutter_petstore/openapi/.travis.yml
+++ b/samples/client/petstore/dart2/flutter_petstore/openapi/.travis.yml
@@ -3,7 +3,7 @@
 language: dart
 dart:
 # Install a specific stable release
-- "2.2.0"
+- "1.24.3"
 install:
 - pub get
 
diff --git a/samples/client/petstore/dart2/flutter_petstore/openapi/README.md b/samples/client/petstore/dart2/flutter_petstore/openapi/README.md
index e78e0e3e69..8520a219f8 100644
--- a/samples/client/petstore/dart2/flutter_petstore/openapi/README.md
+++ b/samples/client/petstore/dart2/flutter_petstore/openapi/README.md
@@ -44,10 +44,10 @@ Please follow the [installation procedure](#installation--usage) and then run th
 import 'package:openapi/api.dart';
 
 // TODO Configure OAuth2 access token for authorization: petstore_auth
-//defaultApiClient.getAuthentication<OAuth>('petstore_auth').accessToken = 'YOUR_ACCESS_TOKEN';
+//openapi.api.Configuration.accessToken = 'YOUR_ACCESS_TOKEN';
 
-var api_instance = PetApi();
-var body = Pet(); // Pet | Pet object that needs to be added to the store
+var api_instance = new PetApi();
+var body = new Pet(); // Pet | Pet object that needs to be added to the store
 
 try {

so dart 2 seems to be using dart 1.x template instead.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

and undo these changes (line 205 to 208) seem to have fixed the issue.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would suggest you remove these changes so that we can merge the remaining changes into master to give us more time reviewing this particular issue.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I know what the problem is and will file another PR to fix it after merging your PR

@wing328 wing328 merged commit 1443f01 into OpenAPITools:master Aug 29, 2019
@wing328
Copy link
Member

wing328 commented Sep 12, 2019

@alexnavratil thanks for the PR, which has been included in the v4.1.2 release: https://twitter.com/oas_generator/status/1172068944355528705

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

Successfully merging this pull request may close these issues.

dart2 client not compiling and ignoring templateDir [BUG] Dart code (seems to) need dartson
2 participants