Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does the "Unrecognized token openapi" error mean when using OpenAPI Generator with OpenAPI 3.0?

I have written an API definition in the OpenAPI 3.0 format (https://swagger.io/docs/specification/basic-structure/). Now I'm trying to generate Java Spring objects as I was previously doing with a Swagger 2.0 definition and its associated Maven plugin.

So far, I have a basic API definition that begins with:

openapi: 3.0.0 info: title: Demo API description: This is a basic REST API implementing the [Open API Specification](https://en.wikipedia.org/wiki/OpenAPI_Specification). version: 0.0.1

In my pom.xml file I have added:

<dependency>
  <groupId>org.openapitools</groupId>
  <artifactId>openapi-generator-cli</artifactId>
  <version>3.3.3</version>
</dependency>

But when executing mvn install, I get this error:

com.fasterxml.jackson.core.JsonParseException: Unrecognized
     token 'openapi': was expecting ('true', 'false' or 'null')
     at [Source: definition\DEFINITION.yml; line: 1, column: 9]

Does anyone know where the problem is?

like image 672
vpa Avatar asked Nov 19 '18 06:11

vpa


1 Answers

After a lot for hit and try I found that issue was with my Swagger file. In that url was not a correct URL. It was something like /api (url without host domain).

OpenAPI generator could have given a better error message. Anyways placing some valid url, allowed me to generate the code.

like image 102
Gaurav Jeswani Avatar answered Nov 08 '22 04:11

Gaurav Jeswani