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

Better OpenAPI spec v3 support: allOf, anyOf, oneOf #1360

Merged
merged 28 commits into from
Dec 6, 2018
Merged

Conversation

wing328
Copy link
Member

@wing328 wing328 commented Nov 1, 2018

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 and ./bin/security/{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\.
  • Filed the PR against the correct branch: master, 3.4.x, 4.0.x. Default: master.
  • Copied the technical committee to review the pull request if your PR is targeting a particular programming language.

Description of the PR

  • fix composition
  • fix inheritance support
  • add mustache tags allOf, anyOf, oneOf
  • add tests for discriminator, allOf, anyOf, etc in Rub client generator
  • update Ruby templates to support inheritance, anyOf, oneOf, etc

Related issues/PRs

cc @OpenAPITools/generator-core-team

@wing328 wing328 removed the WIP Work in Progress label Nov 2, 2018
@wing328 wing328 changed the title [WIP] Better OpenAPI spec v3 support: allOf, anyOf, oneOf Better OpenAPI spec v3 support: allOf, anyOf, oneOf Nov 2, 2018
@etherealjoy
Copy link
Contributor

also this one #537?

@wing328
Copy link
Member Author

wing328 commented Nov 2, 2018

@etherealjoy 👍 updated the list

Copy link
Contributor

@ybelenko ybelenko left a comment

Choose a reason for hiding this comment

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

Fix {{{#vars}{{{/vars}}} codegen array, please.

@mm-matthias
Copy link

FWIW, I tested with some simple specs using allOf using the python generator. It works really well so far. I ran into the limitation of "allOf"/ComposedSchemas not begin supported, but this is clearly logged.
I'm also writing my own codegen against the oas3-spec-support1 branch and things have worked out very nice as well.
Thanks for adding this sorely needed feature!

@wing328
Copy link
Member Author

wing328 commented Dec 6, 2018

@mm-matthias thanks for reviewing the change. Can you ping me via https://gitter.im (ID: wing328) or Google hangout (email address in my Github profile page) for a quick chat?

@wing328 wing328 changed the title [WIP] Better OpenAPI spec v3 support: allOf, anyOf, oneOf Better OpenAPI spec v3 support: allOf, anyOf, oneOf Dec 6, 2018
@wing328
Copy link
Member Author

wing328 commented Dec 6, 2018

Let's go with this PR to start with. If anyone encounters issues related to allOf/anyOf/oneOf, please open an issue with the details.

@wing328 wing328 merged commit 774013c into master Dec 6, 2018
@hellboy81
Copy link

Waiting for anyOf, oneOf for Java as well.

+1000

@wing328 wing328 deleted the oas3-spec-support1 branch December 10, 2018 13:45
@tomghyselinck
Copy link
Contributor

tomghyselinck commented Dec 10, 2018

I tried the latest build, but it looks like allOf is not supported for Python either yet.
We definitely need this too.

We get warnings like:

[main] INFO  o.o.codegen.DefaultCodegen - Composed schema not yet supported: class ComposedSchema {
...
}

@wing328
Copy link
Member Author

wing328 commented Dec 10, 2018

@tomghyselinck do you mind opening an issue and share the spec so that we can reproduce the issue more easily?

@tomghyselinck
Copy link
Contributor

tomghyselinck commented Dec 10, 2018

@wing328 Thank you very much for your quick response!
I stripped down my pretty huge yaml file and file BUG report #1657

@marcelstoer
Copy link
Contributor

I would love to give this a try. Is there a binary somewhere that includes this fix? Specifically I want to find out if this addresses the v2 Java multi-level hierarchy bug (not sure it was even reported) where it would not generate the correct Jackson @JsonSubTypes for

C allOf B allOf A

on A. That's the only reason I'm currently still stuck on Swagger gen 2.4; would love to migrate.

@jmini
Copy link
Member

jmini commented Dec 12, 2018

I would love to give this a try. Is there a binary somewhere that includes this fix?

We push SNAPSHOT releases on sonatype snapshot repository (sort of maven central for snapshots).
4.0.0-SNAPSHOT is available.

3 options:

  1. You can use gradle/maven to get them, indicate that you want to consume binaries for:
https://oss.sonatype.org/content/repositories/snapshots/

With gradle/maven you can download the CLI jar and then use it from the command line or directly use the gradle/maven plugin.

  1. If you want to download the all-in-one jar that we are producing manually, download the newest jar from this folder:
    https://oss.sonatype.org/content/repositories/snapshots/org/openapitools/openapi-generator-cli/4.0.0-SNAPSHOT/

  2. @jimschubert has proposed a script that do the download for you:
    https://gist.github.com/jimschubert/ce241b0c78140e364f46914ef8ec4103
    Set OPENAPI_GENERATOR_VERSION to 4.0.0-SNAPSHOT and it should work.


Specifically I want to find out if this addresses the v2 Java multi-level hierarchy bug (not sure it was even reported)

Is it this #827 ?

If not please create a separated issue with a minimal spec to reproduce your issue...

@wing328
Copy link
Member Author

wing328 commented Dec 12, 2018

@marcelstoer we only added the mustache tags for oneOf, anyOf and allOf but have not yet updated the templates for all the languages/generators to take advantage of these new features in OAS v3.

For Java client, please open a new issue with a spec and the current vs expected output for tracking.

@wing328
Copy link
Member Author

wing328 commented Dec 12, 2018

@YeTingGe are you free for a quick chat via https://gitter.im (ID: wing328) about your use case?

@smasala
Copy link
Contributor

smasala commented Dec 21, 2018

@wing328 TypeScript generator has a weird side effect in which the interface property typing is prefixed with the word AnyOf or OneOf.

import {AnyOfMyType} from '../models/anyOfMyType.ts';   // doesn't exists. Only exists without the prefix
 
interface MyInt {
     myProp:  AnyOfMyType | null;
}

We need to define anyOf | oneOf so that we can use a $ref in conjunction with nullable: true OAI/OpenAPI-Specification#1368

@strobox
Copy link

strobox commented Jan 13, 2019

I found interesting part in ReDoc petstore.yaml OpenAPI 3.0 sample:

  requestBodies:
    Pet:
      content:
        application/json:
          schema:
            allOf:
              - description: My Pet
                title: Pettie
              - $ref: '#/components/schemas/Pet'

I think it is some kind of inline overriding of default models using allOf notation

@spacether
Copy link
Contributor

spacether commented Jan 23, 2019

Fix {{{#vars}{{{/vars}}} codegen array, please.

#vars does not include inherited variables on 2019-01-23

A-Joshi pushed a commit to ihsmarkitoss/openapi-generator that referenced this pull request Feb 27, 2019
* add oneOf support to Ruby

* add anyOf support to ruby client

* add discriminator support to ruby client

* fix typo

* update samples, fix NPE

* better format in ruby generator

* fix test cases, disable mapping test

* fix update script, update samples

* add test, fix mapping

* update exit code

* reenabled discriminator test

* remove duplicated properties

* add test for duplicated properties

* update samples, add new spec

* fix ruby test cases

* fix hasMore after removing duplicates

* refactor method, comment out haskell client test

* fix hasMore and update samples

* fix parent detection

* fix discriminator check

* [haskell-http-client] need to use {{vars}}{{required}} instead of {{requiredVars}}

* remove deprecated methods in default codegen (OpenAPITools#1031)

* regenerate samples

* remove commented code
@jakzal
Copy link

jakzal commented Dec 22, 2019

Am I right to think this has only been implemented for ruby?

@epark-brex
Copy link

@jazkal According to #10010, as of Jan 2022, it does seem like this is only solved for Ruby.

@spacether
Copy link
Contributor

spacether commented Feb 3, 2022

Composition in the root level or in deeper inline levels is working in python-experimental

Here is a PR that shows composition in inline schemas working #11420

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.

None yet