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

ExternalRefProcessor has numerous problems causing NullPointerExceptions #132

Closed
samskiter opened this issue Nov 7, 2015 · 9 comments
Closed
Milestone

Comments

@samskiter
Copy link

Line 63 of ExternalRefProcessor.java attempts to use a property map from a model which may be null:

//If this is a new model, then check it for other sub references
//Loop the properties and recursively call this method;
Map<String, Property> subProps = model.getProperties();
for(Map.Entry<String,Property> prop: subProps.entrySet()){
    if(prop.getValue() instanceof RefProperty){
        RefProperty subRef = (RefProperty)prop.getValue();
        subRef.set$ref(processRefToExternalDefinition(subRef.get$ref(),subRef.getRefFormat()));
    }               
}
swagger.addDefinition(newRef, model);

This is easy to generate with a referenced model that looks like any of the following:

{
    "type": "array",
    "items": {
        "type": "string"
    }
}

or:

{
    "$ref": "./schemas/site.schema.json"
}

I presume there's also some work to be done to make these definitions parse properly

See also: swagger-api/swagger-codegen#1530

@fehguy
Copy link
Contributor

fehguy commented Nov 7, 2015

Thanks. The 2nd example, as a model in the #/definitions section is not valid, FYI. The first issue will be addressed.

fehguy added a commit that referenced this issue Nov 7, 2015
@fehguy fehguy closed this as completed Nov 7, 2015
@samskiter
Copy link
Author

Wow. just seen your commits and trying to merge them now... PR incoming to try to address fully

@samskiter
Copy link
Author

Sorry, I don't understand how the second example isn't valid. Could you explain a little more please?

Also your current fix would process potentially invalid properties from an array. And would miss this case:

{
    "type": "array",
    "items": {
        "ref": "./schemas/site.schema.json"
    }
}

@fehguy
Copy link
Contributor

fehguy commented Nov 7, 2015

having this:

{
   "definitions" : {
      "myModel": {
        "$ref": "./schemas/site.schema.json"
      }
   }
}

is not legal, unless I'm taking your example out of context.

@samskiter
Copy link
Author

That seems really counterintuitive

This is legal:

"responses": {
      "200": {
        "description": "Health information from the server",
        "schema": {
          "$ref": "./models/health.json"
        }
      },
    }

and so is this:

"200": {
    "description": "History information for the given user",
    "schema": {
        "$ref": "#/definitions/Activities"
    }
},
[...]
"definitions": {
    "Activities": {
        "type": "object",
        "properties": {
            "offset": {
                "type": "integer",
                "format": "int32",
                "description": "Position in pagination."
            },
            "limit": {
                "type": "integer",
                "format": "int32",
                "description": "Number of items to retrieve (100 max)."
            },
            "count": {
                "type": "integer",
                "format": "int32",
                "description": "Total number of items available."
            },
            "history": {
                "type": "array",
                "items": {
                    "$ref": "#/definitions/Activity"
                }
            }
        }
    },
}

So what you're saying should be legal

@fehguy fehguy modified the milestone: v1.0.13 Nov 7, 2015
@webron
Copy link
Contributor

webron commented Nov 7, 2015

So I think what @fehguy meant is that normally that use case would not make sense as you're simply referencing something external by naming it internally and referencing that, which seems redundant. That said, after talking with @samskiter on IRC, it seems they do have a use case for that and so it should be supported.

JSON-Schema wise, that structure is valid.

@webron webron reopened this Nov 7, 2015
@fehguy
Copy link
Contributor

fehguy commented Nov 9, 2015

Thanks @webron I stand corrected :)

The parser doesn't handle this, but if it's a valid schema, it should. I'll look into getting it supported.

@fehguy fehguy modified the milestones: v1.0.13, v1.0.14 Nov 30, 2015
@fehguy fehguy modified the milestones: v1.0.14, v1.0.15 Dec 24, 2015
@fehguy fehguy modified the milestones: v1.0.15, v1.0.16, v1.0.17 Jan 6, 2016
@fehguy fehguy removed this from the v1.0.16 milestone Jan 7, 2016
@fehguy fehguy modified the milestones: v1.0.17, v1.0.18 Feb 1, 2016
@fehguy fehguy modified the milestones: v1.0.18, future Apr 11, 2016
@diegode
Copy link

diegode commented Aug 10, 2016

#278 is a duplicate of this one, right?

@fehguy
Copy link
Contributor

fehguy commented Oct 27, 2016

This should be fixed now.

@fehguy fehguy closed this as completed Oct 27, 2016
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

No branches or pull requests

4 participants