Unable to access the Schema file(.json) from dependent module

Issue #116 new
harinath batarayappa created an issue

Hi , i'm getting below exception when i try to access .json file from dependent module .I'm stuck up on this issue. Please help me .

Thanks in advance.

Error starting Tomcat context. Exception: org.springframework.beans.factory.BeanCreationException. Message: Error creating bean with name ‘xx.xx.xx.xx.<swaggerconfigClassName>': Bean instantiation via constructor failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [‘xx.xx.xx.xx.<ClassName>$$EnhancerBySpringCGLIB$$56cb9a53]: Constructor threw exception; nested exception is java.lang.IllegalArgumentException: Unable to load API descriptor from provided

{ "swagger":"2.0", "info":{ "description":"Api Documentation",

// here Schema file contents

              }
            }
          }
        }
      }
    }`]
    at com.atlassian.oai.validator.SwaggerRequestResponseValidator.<init>(SwaggerRequestResponseValidator.java:112)
    at com.atlassian.oai.validator.SwaggerRequestResponseValidator.<init>(SwaggerRequestResponseValidator.java:40)
    at com.atlassian.oai.validator.SwaggerRequestResponseValidator$Builder.build(SwaggerRequestResponseValidator.java:323)
    at xx.xx.xx.<Classname>.<init>(xxxx.java:42)

Comments (6)

  1. James Navin

    Can I ask what version of SRV you're using, and whether you are loading from a source file or passing the spec in as a String. Thanks.

  2. harinath batarayappa reporter

    I'm loading file from source file from classpath in sub class of WebMvcConfigurerAdapter class.same file works fine if i keep this file under /src/main/resources folder. @Autowired public xxxxxxConfig( @Value("classpath:${swaggerschemaValidationfile:xxx.json}") final Resource swaggerApi) throws IOException {

            'org.springframework:spring-webmvc',
            "com.atlassian.oai:swagger-request-validator-core:1.3.10"
    
  3. James Navin

    Its hard to tell from the output you've shown, but my guess is either the String has been loaded incorrectly (e.g. with some sort of escaping or encoding) or the schema you're loading is invalid.

    The output should include any messages that the swagger parser emits, but it might help to debug from SwaggerRequestResponseValidator.java:105 to understand exactly what is happening.

  4. harinath batarayappa reporter

    Thanks For your Reply,James.Same file works if file present under resource folder of same project but it fails when try access from dependent module.

  5. Sven Döring

    Is this really the code?
    @Autowired public xxxxxxConfig( @Value("classpath:${swaggerschemaValidationfile:xxx.json}") final Resource swaggerApi) throws IOException {

    That seems wrong.
    Try it like this - without the dollar and the curly braces:
    @Autowired public xxxxxxConfig( @Value("classpath:swaggerschemaValidationfile:xxx.json") final Resource swaggerApi) throws IOException {

  6. Log in to comment