swagger-api / swagger-api/swagger-parser

SwaggerCompatConverter does not parse local file correctly

Open
#542 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Java
Stars
867
Forks
560
Avg merge
2d 21h
Merged PRs (30d)
7

Description

For some reason, I am using swagger 1.2 to specify my api. And when I use swagger-parser to parse my resource list file in the local machine, I get the following error:

[main] ERROR io.swagger.parser.SwaggerCompatConverter - failed to read api declaration         
java.io.FileNotFoundException: null/https:/github.com/openalto/alto-swagger/raw/spec/api/ext/1.2/query.json (No such file or directory)                                                       
        at java.io.FileInputStream.open0(Native Method)                                        
        at java.io.FileInputStream.open(FileInputStream.java:195)                              
        at java.io.FileInputStream.<init>(FileInputStream.java:138)                            
        at com.fasterxml.jackson.core.JsonFactory.createParser(JsonFactory.java:756)           
        at com.fasterxml.jackson.databind.ObjectMapper.readTree(ObjectMapper.java:2447)        
        at io.swagger.parser.SwaggerCompatConverter.readDeclaration(SwaggerCompatConverter.java:490)                                                                                          
        at io.swagger.parser.SwaggerCompatConverter.read(SwaggerCompatConverter.java:169)      
        at io.swagger.parser.SwaggerCompatConverter.readWithInfo(SwaggerCompatConverter.java:87)                                                                                              
        at io.swagger.parser.SwaggerParser.readWithInfo(SwaggerParser.java:41)                 
        at io.swagger.codegen.cmd.Validate.run(Validate.java:25)                               
        at io.swagger.codegen.SwaggerCodegen.main(SwaggerCodegen.java:35)

My resource list file is like following:

{
  "swaggerVersion": "1.2",
  "apiVersion": "0.1.1-oas1.2",
  "info": {
    "title": "Unicorn API",
    "description": "Cross-domain path and resource discovery"
  },
  "apis": [
    {
      "path": "https://github.com/openalto/alto-swagger/raw/spec/api/ext/1.2/query.json",
      "description": "Operations about path query and resource query"
    }
  ]
}

I think here (SwaggerCompatConverter.java#L139) is the reason. The legacy swagger parser will parse api path as the remote url only when the input resource list file is also a remote url. I think it is not the right way.

Can we fix this issue?

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in modules/swagger-compat-spec-parser/src/main/java/io/swagger/parser/SwaggerCompatConverter.java, especially the logic around line 139 and readDeclaration at line 490. Reproduce the failure with a local Swagger 1.2 resource list whose API path is the remote URL. Done means the local file correctly resolves that remote API declaration without producing a null-prefixed path.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
api
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.