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

[QUESTION] Can Object properties should mapped into Map<>? #296

Closed
fncap opened this issue Jan 5, 2022 · 6 comments · Fixed by #315
Closed

[QUESTION] Can Object properties should mapped into Map<>? #296

fncap opened this issue Jan 5, 2022 · 6 comments · Fixed by #315
Assignees
Labels
question Further information is requested waiting customer response

Comments

@fncap
Copy link

fncap commented Jan 5, 2022

Please describe a problem.
Cannot retrieve values from Dictionary like properties, as per generated Object? type instead
Describe the solution you'd like
Some times, data returned from WebApi, has form of Dictionary like structures.
Swagger recognise them as a generic object type, and your tool do the same, generating Object? typed properties.
Instead of that, should be better if tool treats those properties as a Map<string,string> or something like that, in that way programmer should free to read values from Map as he want!

--- Detailed explanation ---
Look at following DTO

public class FooDto {
  public Dictionary<string,string> Metadata {get; set;}
}

which is translated into following swagger spec file:

{
  "components" : {
    "schemas" : {
      "FooDto": {
        "type": "object",
        "properties": {
          "metadata": {
            "type": "object",
            "additionalProperties": {
              "type": "string"
            },
            "nullable": true
          }
        },
        "additionalProperties": false
      },
    }
  }
}

and then is generated into following Dart class:

class FooDto {
  Object? metadata;
}

metadata property should be of type Map<string,string>? instead of Object?!

@fncap fncap added the question Further information is requested label Jan 5, 2022
@fryette
Copy link
Contributor

fryette commented Jan 6, 2022

But why you cannot transform Object? to Map<String, dynamic> ?

Also I think it's related to the #295

@fncap
Copy link
Author

fncap commented Jan 7, 2022

Yes! And this is exactly what I did!
But, for me that I'm new with Dart, it was not clear that could safely cast an Object to a Map<string, dynamic> type!
Thanks for your time!

@fryette
Copy link
Contributor

fryette commented Jan 7, 2022

@fncap anyway we will try to fix it(check related issue) to provide the best experience with the library.

Thanks and have a good weekend!

@Vovanella95
Copy link
Collaborator

Hi @fncap

We investigated this issue. We can't map Object properties to Map<String, String>, because metadata can has properties + additional properties. So mapping to Map<String, any concrete type> is not possible.

The only one way is to map it to Map<String, dynamic>. Is it fine?

@fncap
Copy link
Author

fncap commented Jan 14, 2022

Yes you are right, generating a 'Map<string,dynamic>' should be fine!

Vovanella95 pushed a commit that referenced this issue Jan 14, 2022
@Vovanella95
Copy link
Collaborator

Hi @fncap

Added generation of Map<String, dynamic>? for such fields

Vovanella95 added a commit that referenced this issue Jan 14, 2022
* Fixed some issues

* Added fix for Field annotations. Updatec changelog and pubspec

* Fixed lot of issues with AllOf support

* Updated changelog and pubspec

* Added requestbodies generation from requests

* Add windows support (#273)

* Run CI on windows too

* chore: Fix a number of path joins

* fix: Revert change to getFileNameWithoutExtension

* fix: Normalize paths used for extensions

* Fixed errors with requestBodies generation

* Added possibility to use operationId for request name

* Format code

* Updated pubspec and changelog

* Fix tests

* Fix analyser issues

* Updated example readme

* Removed converter generator

* Fix cases when refs are overriden

* Fixed enum generation
Changed int64 parsing to double

* Released 2.2.8

* Added support int64

* Updated changelog and pubspec

* Fix for models int64

* Updated changelog and pubspec

* Removed not needed file

* Fixed responses array of int

* Reverted analysis options

* Updated changelog

* Updated version

* Fixed tests

* Fixed analyser issues

* Fixed issue #291

* updated changelog and pubcpec

* Added parsing of security for requests

* Fixed num parsing as Num

* Implemented security keys definition

* Removed not needed prints

* Updated changelog and pubspec

* Removed use_inheritance field

* Removed outdated tests

* Implemented integer enums support

* Updated changelog and pubspec

* Fixed fromJson for integer enum fields

* Updated changelog and pubspec

* Formatted code

* Updated changelog

* Fixed issue 263

* Fixed test

* Fixed issue #311

* Updated pubspec and changelog

* Fixed list enums generation in requests

* Updated pubspec and changelog

* Fixed issue #296

* Updated pubspec and changelog

* Fixed conflicts

Co-authored-by: uladzimir_paliukhovich <>
Co-authored-by: Elliana May <me@mause.me>
Vovanella95 added a commit that referenced this issue Jan 19, 2022
* Fixed some issues

* Added fix for Field annotations. Updatec changelog and pubspec

* Fixed lot of issues with AllOf support

* Updated changelog and pubspec

* Added requestbodies generation from requests

* Add windows support (#273)

* Run CI on windows too

* chore: Fix a number of path joins

* fix: Revert change to getFileNameWithoutExtension

* fix: Normalize paths used for extensions

* Fixed errors with requestBodies generation

* Added possibility to use operationId for request name

* Format code

* Updated pubspec and changelog

* Fix tests

* Fix analyser issues

* Updated example readme

* Removed converter generator

* Fix cases when refs are overriden

* Fixed enum generation
Changed int64 parsing to double

* Released 2.2.8

* Added support int64

* Updated changelog and pubspec

* Fix for models int64

* Updated changelog and pubspec

* Removed not needed file

* Fixed responses array of int

* Reverted analysis options

* Updated changelog

* Updated version

* Fixed tests

* Fixed analyser issues

* Fixed issue #291

* updated changelog and pubcpec

* Added parsing of security for requests

* Fixed num parsing as Num

* Implemented security keys definition

* Removed not needed prints

* Updated changelog and pubspec

* Removed use_inheritance field

* Removed outdated tests

* Implemented integer enums support

* Updated changelog and pubspec

* Fixed fromJson for integer enum fields

* Updated changelog and pubspec

* Formatted code

* Updated changelog

* Fixed issue 263

* Fixed test

* Fixed issue #311

* Updated pubspec and changelog

* Fixed list enums generation in requests

* Updated pubspec and changelog

* Fixed issue #296

* Updated pubspec and changelog

* Fixed conflicts

* [BUB] Array in spec is not being generated as expected

* Updated pubspec and changelog

Co-authored-by: uladzimir_paliukhovich <>
Co-authored-by: Elliana May <me@mause.me>
Vovanella95 added a commit that referenced this issue Jan 27, 2022
* Fixed some issues

* Added fix for Field annotations. Updatec changelog and pubspec

* Fixed lot of issues with AllOf support

* Updated changelog and pubspec

* Added requestbodies generation from requests

* Add windows support (#273)

* Run CI on windows too

* chore: Fix a number of path joins

* fix: Revert change to getFileNameWithoutExtension

* fix: Normalize paths used for extensions

* Fixed errors with requestBodies generation

* Added possibility to use operationId for request name

* Format code

* Updated pubspec and changelog

* Fix tests

* Fix analyser issues

* Updated example readme

* Removed converter generator

* Fix cases when refs are overriden

* Fixed enum generation
Changed int64 parsing to double

* Released 2.2.8

* Added support int64

* Updated changelog and pubspec

* Fix for models int64

* Updated changelog and pubspec

* Removed not needed file

* Fixed responses array of int

* Reverted analysis options

* Updated changelog

* Updated version

* Fixed tests

* Fixed analyser issues

* Fixed issue #291

* updated changelog and pubcpec

* Added parsing of security for requests

* Fixed num parsing as Num

* Implemented security keys definition

* Removed not needed prints

* Updated changelog and pubspec

* Removed use_inheritance field

* Removed outdated tests

* Implemented integer enums support

* Updated changelog and pubspec

* Fixed fromJson for integer enum fields

* Updated changelog and pubspec

* Formatted code

* Updated changelog

* Fixed issue 263

* Fixed test

* Fixed issue #311

* Updated pubspec and changelog

* Fixed list enums generation in requests

* Updated pubspec and changelog

* Fixed issue #296

* Updated pubspec and changelog

* Fixed conflicts

* [BUB] Array in spec is not being generated as expected

* Updated pubspec and changelog

* Fixed responses returns Stream<Something>
Fixed cases when we have List<List<...<List<SomeClass> in model parameter

* Updated changelog and pubspec

Co-authored-by: uladzimir_paliukhovich <>
Co-authored-by: Elliana May <me@mause.me>
Vovanella95 added a commit that referenced this issue Jan 31, 2022
* Fixed some issues

* Added fix for Field annotations. Updatec changelog and pubspec

* Fixed lot of issues with AllOf support

* Updated changelog and pubspec

* Added requestbodies generation from requests

* Add windows support (#273)

* Run CI on windows too

* chore: Fix a number of path joins

* fix: Revert change to getFileNameWithoutExtension

* fix: Normalize paths used for extensions

* Fixed errors with requestBodies generation

* Added possibility to use operationId for request name

* Format code

* Updated pubspec and changelog

* Fix tests

* Fix analyser issues

* Updated example readme

* Removed converter generator

* Fix cases when refs are overriden

* Fixed enum generation
Changed int64 parsing to double

* Released 2.2.8

* Added support int64

* Updated changelog and pubspec

* Fix for models int64

* Updated changelog and pubspec

* Removed not needed file

* Fixed responses array of int

* Reverted analysis options

* Updated changelog

* Updated version

* Fixed tests

* Fixed analyser issues

* Fixed issue #291

* updated changelog and pubcpec

* Added parsing of security for requests

* Fixed num parsing as Num

* Implemented security keys definition

* Removed not needed prints

* Updated changelog and pubspec

* Removed use_inheritance field

* Removed outdated tests

* Implemented integer enums support

* Updated changelog and pubspec

* Fixed fromJson for integer enum fields

* Updated changelog and pubspec

* Formatted code

* Updated changelog

* Fixed issue 263

* Fixed test

* Fixed issue #311

* Updated pubspec and changelog

* Fixed list enums generation in requests

* Updated pubspec and changelog

* Fixed issue #296

* Updated pubspec and changelog

* Fixed conflicts

* [BUB] Array in spec is not being generated as expected

* Updated pubspec and changelog

* Fixed responses returns Stream<Something>
Fixed cases when we have List<List<...<List<SomeClass> in model parameter

* Updated changelog and pubspec

* Fixed issue 328: Error when swagger has models with name "Type"

* Updated changelog and pubspec

* Fixed enums naming

Co-authored-by: uladzimir_paliukhovich <>
Co-authored-by: Elliana May <me@mause.me>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested waiting customer response
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants