3

I'm trying to parse an OPEN API URL this is the following code for it

OpenAPI openAPI = new OpenAPIV3Parser().read("https://petstore3.swagger.io/api/v3/openapi.json");

which is giving me the following exception

org.springframework.web.util.NestedServletException: Handler dispatch failed; nested exception is java.lang.NoClassDefFoundError: com/fasterxml/jackson/core/JsonFactoryBuilder

The library which i'm using is

<dependency>
<groupId>io.swagger.parser.v3</groupId>
<artifactId>swagger-parser-v3</artifactId>
<version>2.0.19</version>

Is there any other library which i can use for parsing OPEN API 3.0?

MonicaA
  • 66
  • 1
  • 4
  • Seems like you have multiple jackson core libraries. Can you exclude one. You can check that by firing mvn:dependency:tree – Bala Jul 23 '20 at 12:39

2 Answers2

2

If you check OpenAPI.read() it accepts either

  1. (String location) or
  2. (String location, List auths, ParseOptions resolve)

But what you are trying with is "String URL", instead try giving (String "filePath") with below dependency. It will work like charm.

<dependency>
  <groupId>io.swagger.parser.v3</groupId>
  <artifactId>swagger-parser</artifactId>
  <version>2.0.26</version>
</dependency> 

Note:

 OpenAPI openAPI = new OpenAPIV3Parser().read(filePath) for OpenAPI3.0
 Swagger swagger = new SwaggerParser().read(filePath)   for Swagger2.0

Check out below read() snippet handy for your clarity.

enter image description here

You can use swagger editor to switch json file type to yaml. Swagger editor >> Edit >> Convert to YAML >> downloaded file move it to filePath

enter image description here

Dharman
  • 30,962
  • 25
  • 85
  • 135
1

Use the dependency:

<dependency>
  <groupId>io.swagger.parser.v3</groupId>
  <artifactId>swagger-parser</artifactId>
  <version>2.0.25</version>
</dependency>

This works for me parsing OpenAPI and Swagger Specifications