MonicaA
MonicaA

Reputation: 66

JAVA: Parsing OPEN API with swagger.v3.parser.OpenAPI

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?

Upvotes: 3

Views: 11228

Answers (2)

Vishwas Shenoy Alevoor
Vishwas Shenoy Alevoor

Reputation: 567

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

Upvotes: 2

ismaildawud96
ismaildawud96

Reputation: 39

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

Upvotes: 1

Related Questions