RepreZen / KaiZen-OpenApi-Parser

High-performance Parser, Validator, and Java Object Model for OpenAPI 3.x
130 stars 31 forks source link

Validation tries to match path with parameters placed in components section #228

Closed tlewowski closed 5 years ago

tlewowski commented 5 years ago

When running a validation on a YAML file that has path parameters in components/parameters section, a warning is returned that path for the parameter cannot be located.

I looked briefly at the code and this seems to come from com.reprezen.kaizen.oasparser.val3.ParameterValidator class - checkPathParam method calls getPathString for a parameter which (I suppose) is in components section. getPathString fetches the name from parent (?) object, which is components/parameters section, which obviously does not have the path field (and should not have it, I think).

This check should probably be run only for inline parameters - for referenced ones it would be cool to expand and check in the target location, but at least there should be no warning for path parameters in components. Removing the parameter clears warnings, change of path matcher does not cause new ones to appear, so I guess validation is only done on definition site, not in the places where the parameter is actually referenced.

Reproduction data:

library: "com.reprezen.kaizen" % "openapi-parser" % "4.0.1-201809050415"

YAML file (abc.yaml):

openapi: 3.0.1
info:
  title: ABC
  version: '1'
paths:
  /end/{abc}:
    parameters:
    - $ref: '#/components/parameters/abc'

components:
  parameters:
    abc:
      in: path
      required: true
      name: abc
      schema:
        type: string

Java class (Swagger.java):

import com.reprezen.kaizen.oasparser.OpenApiParser;
import com.reprezen.kaizen.oasparser.model3.OpenApi3;
import com.reprezen.kaizen.oasparser.val.ValidationResults;

public class Swagger {
    private void run() throws Exception {
        OpenApi3 model = (OpenApi3) new OpenApiParser().parse(getClass().getClassLoader().getResource("abc.yaml").toURI(), true);

        for(ValidationResults.ValidationItem t: model.getValidationResults().getItems()) {
            System.out.println(t.getMsg());
        }
    }

    public static void main(String[] args) throws Exception {
        new Swagger().run();
    }
}

actual output: Could not locate path for parameter 'abc' expected output: `` (empty)

tedepstein commented 5 years ago

@tlewowski , thanks for submitting the issue. We are working heads-down on a related project right now, so most likely will not be able to respond until next week. Just wanted to let you know we saw this, and will respond properly ASAP.

tedepstein commented 5 years ago

Fixed in #237.