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

[REQ] Feature Request OAS 3.0 manyOf etc. #15119

Open
tomwilhelm opened this issue Apr 4, 2023 · 5 comments
Open

[REQ] Feature Request OAS 3.0 manyOf etc. #15119

tomwilhelm opened this issue Apr 4, 2023 · 5 comments

Comments

@tomwilhelm
Copy link

This has been on your short term roadmap for quite a while - do you have any updates when you are planning to release this feature?

@Huholoman
Copy link

I need to say I would appreciate anyOf.

@wing328
Copy link
Member

wing328 commented Nov 30, 2024

@Huholoman Some generators (e.g. C#, Java, Go, Python, etc) already supports anyOf

Which one did you try?

@Huholoman
Copy link

Huholoman commented Dec 1, 2024

@wing328 Ive tried Dart. It generated weird code and then I have read anyOf is not supported, so I though it generated something just by accident.

There are my components

  "components" : {
    "schemas" : {
      "com.example.something.Location" : {
        "anyOf" : [ {
          "$ref" : "#/components/schemas/com.example.something.GeoLocation"
        }, {
          "$ref" : "#/components/schemas/com.example.something.ServiceLocation"
        } ],
        "title" : "Location"
      },
      "com.example.something.GeoLocation" : {
        "type" : "object",
        "properties" : {
          "lat" : {
            "type" : "number",
            "format" : "double",
            "title" : "Double"
          },
          "lon" : {
            "type" : "number",
            "format" : "double",
            "title" : "Double"
          }
        },
        "required" : [ "lat", "lon" ],
        "title" : "GeoLocation"
      },
      "com.example.something.ServiceLocation" : {
        "type" : "object",
        "properties" : {
          "serviceId" : {
            "type" : "string",
            "title" : "String"
          }
        },
        "required" : [ "serviceId" ],
        "title" : "ServiceLocation"
      },
      "com.example.something.SomethingWithLocation" : {
        "type" : "object",
        "properties" : {
          "location" : {
            "$ref" : "#/components/schemas/com.example.something.Location"
          },
          "title" : {
            "type" : "string",
            "title" : "String"
          }
        },
        "required" : [ "location", "title" ],
        "title" : "SomethingWithLocation"
      }
    }

I generated the openapi.json using smiley4-swagger-ui.

There is missing "type" in the "location" component in the json so far, which ill need on frontend to detect which location actually arrived. But the generated client dart code is still wrong.

Dart "Location" is class which has properties from both GeoLocation and ServiceLocation and all props are required. Geo/ServiceLocation are generated with correct props, but component SomethingWithLocation accepts only "Location".

I would expect that i can pass GeoLocation or ServiceLocation to SomethingWithLocation as Location.

Now I highly doubt current state of anyOf in generated Dart code is correct, but I can be wrong; any help or clarification is welcome.

@wing328
Copy link
Member

wing328 commented Dec 1, 2024

I saw this PR related to anyOf support in Dart: #14528

cc @jaumard (2018/09) @josh-burton (2019/12) @amondnet (2019/12) @sbu-WBT (2020/12) @kuhnroyal (2020/12) @agilob (2020/12) @ahmednfwela (2021/08) to see if they've more info.

@ahmednfwela
Copy link
Contributor

there are currently 2 flavors of oneof,anyof support

one in dart-dio generator that uses a buggy and unreliable implementation

one in dart-next #18970 that uses similar representation as protobuf

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

No branches or pull requests

4 participants