Skip to content

[Dart] Set type of OneOf to dynamic#6914

Open
sbu-WBT wants to merge 3 commits intoOpenAPITools:masterfrom
wbt-solutions:oneof-dart-dynamic
Open

[Dart] Set type of OneOf to dynamic#6914
sbu-WBT wants to merge 3 commits intoOpenAPITools:masterfrom
wbt-solutions:oneof-dart-dynamic

Conversation

@sbu-WBT
Copy link
Contributor

@sbu-WBT sbu-WBT commented Jul 12, 2020

OneOf is currently not supported by dart. Thus it makes no sense to generate code with it. So I replaced it with a dynamic type. We loose with this case the typing, but the code does compile and should work with all primitives. I'm unsure if serialization with generated data classes will work.
So it fixes #3884.

PR checklist

  • Read the contribution guidelines.
  • If contributing template-only or documentation-only changes which will change sample output, build the project beforehand.
  • Run the shell script ./bin/generate-samples.shto update all Petstore samples related to your fix. 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/config/java*. For Windows users, please run the script in Git BASH.
  • File the PR against the correct branch: master
  • Copy 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) @athornz (2019/12) @amondnet (2019/12)

@wing328
Copy link
Member

wing328 commented Aug 23, 2020

@agilob
Copy link
Contributor

agilob commented Nov 14, 2020

@wing328 @sbu-WBT any progress on this?

@SimonIT
Copy link
Contributor

SimonIT commented Nov 14, 2020

@NANASHI0X74
Copy link
Contributor

maybe this can be done using sum types from this package but in that case using the dart code would require another codegen step via the dart build system.
Also, there are proposals to add this sort of functionality to the dart languge natively: dart-lang/language#83 dart-lang/language#349 though there's no telling if and when those make it to the language I guess, but maybe the dart team will work on that next after the work on nun-nullable types has completed

@passsy
Copy link

passsy commented Feb 23, 2021

I vote for landing this. dynamic is the correct type in Dart when the type system is too limited.

Waiting for sum types or unions to land will take years.

@yfer
Copy link

yfer commented Apr 9, 2021

The problem is that oneOf is used now for nullable objects.
try this in https://editor.swagger.io/

openapi: 3.0.0
components:
  schemas:
    Example:
      title: Example
      properties:
        objectField:
          nullable: true
          oneOf:
            - $ref: '#/components/schemas/ObjectField'
      type: object
    ObjectField: 

in spec 3.1 there would be 'null' keyword for such cases, but even then this case is not of the list. So we at least should handle these cases with care. This is not dynamic, it is nullable ObjectField? objectField

Oh, I've should read the commit before. You already handle this case.

sbu-WBT added 2 commits April 13, 2021 19:04
# Conflicts:
#	modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/DartClientCodegen.java
@jgoyvaerts
Copy link

Any update on this? oneOf is causing troubles for our project

@agilob
Copy link
Contributor

agilob commented Jul 14, 2021

@jgoyvaerts would you be interested in testing and updating this PR against your project?

@jgoyvaerts
Copy link

I tested this branch locally, while it does get rid of the generated properties OneOfType which cause compile errors and replaces these with dynamic? , it still isn't completely correct in handling the case described by @yfer , where those dynamic? should actually be generated as nullable types, so Type?.

I'll see if I can write a fix for this case

@kuhnroyal
Copy link
Contributor

Well, NNBD is not implemented at all in the Dart generator I believe.

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.

Error in generated Dart client code: Undefined name 'OneOf'.

9 participants