question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

allOf/anyOf support

See original GitHub issue

Please take the time to search the repository, if your question has already been asked or answered.

  • What version of the library are you using? Is it the latest version? The latest released version is Download

Springfox 2.9.1-SNAPSHOT

What kind of issue is this?

  • Question. Is this a question about how to do a certain thing?

  • Bug report. If you’ve found a bug, spend the time to write a failing test. Bugs with tests or steps to reproduce get fixed faster.

  • Feature Request. Start by telling us what problem you’re trying to solve. Often a solution already exists! Don’t send pull requests to implement new features without first getting our support. Sometimes we leave features out on purpose to keep the project small.

Is it possible to generate an oneOf/anyOf definitions described here with Springfox at the moment?

I have a REST resource that can return a serialized instance of one of two types, say A and B:

    abstract class Common {
    // Contains common fields for A and B
    }
    
    class A extends Common {
    // Adds A specific fields
    }
    
    class B extends Common {
    // Adds B specific fields
    }

And here how my API would look like:

    // Swagger documentation annotation
    @ApiOperation(
      value = "Get items",
      // Specify a parent class here instead of actual definition
      response = Common.class)
    @GetMapping
    public Common getItem(String id) {
    ...
    }

Is there any way to define that a resource can return either of two concrete types with Springfox?

Issue Analytics

  • State:open
  • Created 5 years ago
  • Reactions:1
  • Comments:8 (3 by maintainers)

github_iconTop GitHub Comments

11reactions
Ziemowitcommented, Nov 4, 2020

@scobrad this is fixed, but not entirely, could you provide your use case?

Maybe I will answer. I have a similar problem and I am not pretty sure is it solvable by springfox (by OAS3 for sure is). Later I can provide github example but more/less I have the case:

abstract class Parent {
}

class ChildA extends Parent {}
class ChildB extends Parent {}


class DTO {
   List<Parent> elements;
}

So in my case, it should be sth like that:

elements:
    type:  'array'
    items:
          oneOf:
            - $ref: '#ChildA'
            - $ref: '#ChildB'

But always I receive:

elements:
    type:  'array'
    items:
       - $ref: '#Parent'

Maybe some extra annotations need to be added? I have tried a few approaches but failed each time.

1reaction
mikehfabercommented, Jun 25, 2020

We still need this. Springfox isn’t providing much value at the moment because the UI it generates is missing most of the relevant information.

Read more comments on GitHub >

github_iconTop Results From Across the Web

oneOf, anyOf, allOf, not - Swagger
Use the anyOf keyword to validate the data against any amount of the given subschemas. That is, the data may be valid against...
Read more >
Support for oneOf, anyOf and allOf - Liferay Help Center
Support for oneOf, anyOf and allOf. OpenAPI 3.0 added several ways of using inheritance and composition to create complex schemas. Specifically, it added ......
Read more >
[Java] Add proper support for allOf anyOf oneOf #634 - GitHub
Hi folks, I've added better support of allOf, anyOf and oneOf via #1360. Please give it a try and let us know if...
Read more >
AllOf, AnyOf, OneOf - Liquid Technologies
The AllOf, AnyOf, OneOf nodes are all optional, and a schema can contain any combination of them. Example - Multiple Versions of a...
Read more >
oneOf / anyOf / allOf - react-jsonschema-form documentation
oneOf, anyOf, and allOf¶. react-jsonschema-form supports custom widgets for oneOf, anyOf, and allOf. A schema with oneOf is valid if exactly one of...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found