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.

"integer" isn't seen as a valid type by ModelRef

See original GitHub issue

version 2.6.1

I’m trying to create a ModelRef to use in a Header so I can have headers in my responses.

private ModelRef integerModel = new ModelRef("integer");
private Header xRateLimitLimit = new Header("X-RateLimit-Limit", "The defined maximum number of requests available to the consumer for this API.", integerModel);

private ArrayList<ResponseMessage> responseList = newArrayList(
        new ResponseMessageBuilder()
            .code(400)
            .headersWithDescription(defaultHeaders)
            .message("Bad Request").responseModel(responseCodeModel).build());

I am making a separate ModelRef and Header because I plan on using them quite a few times, and it’s easier than creating a new one over and over.

When I do this, I expect "type":"integer","format":"int32" in my swagger doc, instead I am getting "$ref":"#/definitions/integer".

I have used "number", "long", and "string", and everything works as expected. Instead of using $ref, it uses type, as expected. This doesn’t happen with "integer". This should work according to the OpenAPI-Specification. The common name "integer" should have a type of integer and a format of int32.


example:

    private ModelRef integerModel1 = new ModelRef("integer");
    private ModelRef integerModel2 = new ModelRef("long");
    private ModelRef integerModel3 = new ModelRef("string");

A different model for each header.

    private Header xRateLimitLimit = new Header("X-RateLimit-Limit", "The defined maximum number of requests available to the consumer for this API.", integerModel1);
    private Header xRateLimitRemaining = new Header("X-RateLimit-Remaining", "The number of calls remaining before the limit is enforced and requests are bounced.", integerModel2);
    private Header xRateLimitReset = new Header("X-RateLimit-Reset", "The time, in seconds, until the limit expires and another request will be allowed in. This header will only be present if the limit is being enforced.", integerModel3);

I then put those headers into a map…

    private Map<String, Header> defaultHeaders = new HashMap<String, Header>(){{
        put("xRateLimitLimit", xRateLimitLimit);
        put("xRateLimitRemaining", xRateLimitRemaining);
        put("xRateLimitReset", xRateLimitReset);
    }};

…so that I can use it in ResponseMessageBuilder

private ArrayList<ResponseMessage> responseList = newArrayList(
        new ResponseMessageBuilder()
            .code(400)
            .headersWithDescription(defaultHeaders)
            .message("Bad Request").responseModel(responseCodeModel).build());

And this is applied to my main Docket with…

            .globalResponseMessage(RequestMethod.GET, responseList)

Output:

"headers":{
    "xRateLimitReset": {
        "type": "string",
        "description": "The time, in seconds, until the limit expires and another request will be allowed in. This header will only be present if the limit is being enforced."
    },
    "xRateLimitLimit": {
        "description": "The defined maximum number of requests available to the consumer for this API.",
        "$ref": "#/definitions/integer"
    },
    "xRateLimitRemaining": {
        "type": "integer",
        "format": "int64",
        "description": "The number of calls remaining before the limit is enforced and requests are bounced."
    }
}

It’s attempting to find a model called integer, instead of the using the integer type.

I have a feeling this is related to SpringFox since I’m using ModelRef. If this belongs somewhere else, please let me know. Thanks!

Issue Analytics

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

github_iconTop GitHub Comments

1reaction
dilipkrishcommented, Feb 14, 2017

@ahatzz11 Closing the PR wasn’t intending to be rude or any reflection of the contribution. Any and every contribution is very much appreciated. There is a ton of requests in the backlog and would love contributions. I was just tidying up before releasing 2.7.0 and the PR was closed because it was not a valid change. So thank you for you contribution and apologies if that wasn’t clearly explained. Let me try to explain…

The reason is that it was initially modeled as int is because internally this is how we represent the following types

  • 32 byte integers as int (Integer.TYPE or Integer.class)
  • 64 byte integers as long (Long.TYPE or Long.class)

Historically we have never maintained the type representation as a function of how it needs to appear in a swagger description. They are really internal representations. That is to say that the internal data structures need to have the fidelity to represent integers as (integer, format=int32) and long as (integer, format=int64), so going with just integer is lossy. FWIW, the representation we chose to go with at the time this library was created was to go with the names of the value types (int and long).

Another way to look at this is that we could project our internal models to RAML or Api Blueprint, and still be agnostic of the service description format and be able to distinguish these internal representations.

Hope that makes sense.

0reactions
ahatzz11commented, Feb 15, 2017

@dilipkrish Didn’t think it was rude, just wanted to make sure I understood the reasoning behind it all. Definitely makes sense, thanks for the explanation! Everything is working now (and as designed 😉)! I’ll close this issue out. Thanks for the help.

Also - I’m excited for some of the stuff in 2.7.0. Keep up the good work!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Developers - "integer" isn't seen as a valid type by ModelRef -
I'm trying to create a ModelRef to use in a Header so I can have headers in my responses. private ModelRef integerModel =...
Read more >
Python pydantic model passing None as int value is not a ...
I have tried a few things with the model but still receive an error of value is not a valid integer (type=type_error.integer) when...
Read more >
Not able to get line from another modelref - MicroStation ...
Hi, I am trying to collect all elementref from different modelref other than active model. And i want to redraw those in active...
Read more >
9608/23 AS&A Level Computer Science November 2018
3 An array contains 100 integer values. An algorithm will find the maximum and minimum values stored in the array. (a) A programmer...
Read more >
List[int] = Form(...) -> value is not a valid integer #2849 - GitHub
I have -d "list_int=1,2" which seems to be interpreted as a float... I get the error: "msg": "value is not a valid integer",...
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