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

Path level params with ref are not parsed #2066

Open
anthochristen opened this issue Mar 21, 2024 · 0 comments
Open

Path level params with ref are not parsed #2066

anthochristen opened this issue Mar 21, 2024 · 0 comments

Comments

@anthochristen
Copy link

When the path level parameters are defined as refs we seem to run into this problem.

In this case the relative file to be loaded is present inside the path_level_params_spec/sub-dir but the parser seems to be looking for it in the base path where the openapi.json file is present.

Triage:
Looks like the ExternalRefProcessor.join(String, String) is not invoked in the flow from PathsProcessor. processPaths:80
So the relative paths of the nested refs are not loaded from the current directory but instead from basePath causing this issue.

Error:

20:42:56.335 [main] WARN  i.s.v.p.OpenAPIV3Parser - Exception while resolving:
java.lang.RuntimeException: Unable to load RELATIVE ref: sub-dir2/pagination_params_1.json path: /Users/<my_name>/swagger-parse-test/target/test-classes/path_level_params_spec
	at io.swagger.v3.parser.util.RefUtils.readExternalRef(RefUtils.java:220)
	at io.swagger.v3.parser.ResolverCache.loadRef(ResolverCache.java:156)
	at io.swagger.v3.parser.processors.ExternalRefProcessor.processRefToExternalParameter(ExternalRefProcessor.java:758)
	at io.swagger.v3.parser.processors.ParameterProcessor.processParameter(ParameterProcessor.java:46)
	at io.swagger.v3.parser.processors.OperationProcessor.processOperation(OperationProcessor.java:43)
	at io.swagger.v3.parser.processors.PathsProcessor.processPaths(PathsProcessor.java:88)
	at io.swagger.v3.parser.OpenAPIResolver.resolve(OpenAPIResolver.java:72)
	at io.swagger.v3.parser.OpenAPIResolver.resolve(OpenAPIResolver.java:59)
	at io.swagger.v3.parser.OpenAPIV3Parser.resolve(OpenAPIV3Parser.java:240)
	at io.swagger.v3.parser.OpenAPIV3Parser.readContents(OpenAPIV3Parser.java:183)
	at io.swagger.v3.parser.OpenAPIV3Parser.readLocation(OpenAPIV3Parser.java:97)
	at io.swagger.v3.parser.OpenAPIV3Parser.read(OpenAPIV3Parser.java:124)
	at com.paypal.ppaas.swagger.codegen.ParametersTest.main(ParametersTest.java:146)

openapi.json

{
  "openapi": "3.0.3",
  "info": {
    "version": "1.0.0",
    "title": "OpenAPI Service",
    "description": "Sample OpenAPI generated swagger contract"
  },
  "paths": {
    "/params": {
      "$ref": "./sub-dir/params.json"
    }
  },
  "components": {
    "responses": {
      "default-string": {
        "description": "some string",
        "content": {
          "text/plain": {
            "schema": {
              "type": "string"
            }
          }
        }
      }
    }
  }
}

params.json

{
  "parameters": [
    { "$ref": "./sub-dir2/pagination_params_1.json" }
  ],
  "get": {
    "operationId": "paramsGet",
    "responses": {
      "default": {
        "$ref": "#/components/responses/default-string"
      }
    }
  }
}

pagination_params_1.json

{
  "limit": {
    "name": "limit",
    "description": "There can be only 1!",
    "in": "query",
    "schema": {
      "$ref" : "../sub-dir3/an-int.json"
    }
  }
}
 

Main.java:

ParseOptions options = new ParseOptions();
options.setResolve(true);
OpenAPI openAPI = new OpenAPIV3Parser().read("openapi.json", null, options);
System.out.println("Parameters: " + openAPI.getComponents().getParameters().keySet());
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

1 participant