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.

Apis that return a generic type (Foo<T>) where T is an ENUM overrides APIs that return a T that is a String

See original GitHub issue

Hi

An issue appears to exist with Enum’s and generic types where if we have two APIs that return:

  • ResponseWrapper<String>
  • ResponseWrapper<MyEnum Then I find that the generated swagger json contains:
"ResponseWrapper«string»": {
      "properties": {
        "data": {
          "allowEmptyValue": false,
          "description": "...",
          "enum": [
            "FOO",
            "BAR"
          ],
          "type": "string"
        },
        "errorMessage": {
          "allowEmptyValue": false,
          "description": "If a error occurs a user friendly message may be placed here.",
          "type": "string"
        }
      },
      "title": "ResponseWrapper«string»",
      "type": "object"
    }

So now swagger thinks that for anything that returns a ResponseWrapper<String> it is restricted to the values of the enum. This is particularly problematic when a client is generated from the JSON. As ResponseWrapper<String> is made to return a ResponseWrapper<MyEnum> instead.

I appear to be depending on:

            <dependency>
                <groupId>io.swagger</groupId>
                <artifactId>swagger-annotations</artifactId>
                <version>1.5.19</version>
            </dependency>
            <dependency>
                <groupId>io.springfox</groupId>
                <artifactId>springfox-swagger2</artifactId>
                <version>2.8.0</version>
            </dependency>

Issue Analytics

  • State:open
  • Created 5 years ago
  • Comments:7 (2 by maintainers)

github_iconTop GitHub Comments

4reactions
rusu-robertcommented, Feb 22, 2019

A fix for this would be highly appreciated! Thank you!

1reaction
LukeButterscommented, Apr 30, 2018

I worked around the problem by extending my class e.g.

class MyEnumResponseWrapper extends ResponseWrapper<MyEnum>

the down side is each person needs to remember to actually do that.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Java enum implements interface with Class<T> return type
Here's an enum that implements an interface with a method that returns a 'raw type' which gives me a warning on the getCaste()...
Read more >
Extensions — The Swift Programming Language (Swift 5.7)
An extension can be used to extend an existing generic type, as described in Extending a Generic Type. You can also extend a...
Read more >
Monkey C Language Reference - Garmin Developers
The goal of Monkey C is to round the sharp edges of app development, ... types must be declared for each function parameter...
Read more >
Avro C - Apache Avro
Most functions in the Avro C library return a single int status code. ... the C types used to represent Avro data in...
Read more >
Sensor | Android Developers
A constant string describing an accelerometer sensor type. ... Returns true if the sensor supports sensor additional information API.
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