Skip to content

Conversation

@joeljons
Copy link
Contributor

In int64example.yaml the example value comes out as -81224344 in an Integer.

Maybe there is a better way of checking for int64 examples, but this seems to do the job at least. I'm happy to change if there is some obvious better way this should be done in. :)

@gracekarina gracekarina self-requested a review January 22, 2018 16:01
} if (example.getNodeType().equals(JsonNodeType.NUMBER)) {
Integer integerExample = getInteger(nodeKey, node, false, location, result);
if (integerExample != null) {
JsonNode format = node.get("format");
Copy link
Contributor

@gracekarina gracekarina Jan 22, 2018

Choose a reason for hiding this comment

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

Thanks!! @joeljons, I tried to push some changes but I have not permissions on your repo, so here is where I think it should be validated:

In the method getInteger()

line: 1196 : I added a boolean validation to make sure the number is an integer, it would return null if false and all integers will be validated as well

public Integer getInteger(String key, ObjectNode node, boolean required, String location, ParseResult result) {
        Integer value = null;
        JsonNode v = node.get(key);
        if (node == null || v == null) {
            if (required) {
                result.missing(location, key);
                result.invalid();
            }
        }
        else if(v.getNodeType().equals(JsonNodeType.NUMBER)) {
            if (v.isInt()) {
                value = v.intValue();
            }
        }
        else if(!v.isValueNode()) {
            result.invalidType(location, key, "integer", node);
        }
        return value;
    }

Copy link
Contributor

@gracekarina gracekarina left a comment

Choose a reason for hiding this comment

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

please check comment

@joeljons
Copy link
Contributor Author

Your idea is much more elegant! :)
I will change my commit to implement it that way instead.

Copy link
Contributor

@gracekarina gracekarina left a comment

Choose a reason for hiding this comment

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

@joeljons thanks!

@gracekarina gracekarina merged commit e61d2ea into swagger-api:2.0 Jan 24, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants