Puneet Akhouri
Puneet Akhouri

Reputation: 41

Swagger Error Expected type string but found type integer

I started working recently on swagger to generate documentation for our RESTful apis. I use the yamlbeans-1.09.jar to convert my Java DTOs to a yaml file. Everything works fine and the yaml is even validated properly on the http://www.yamllint.com/ but still while testing it with the Swagger interface, it gives an error "Expected type string but found type integer" and "No enum match for: 2" wherever I mention the swagger : 2.0 in the file.

My sample yml file is:

basePath: /employment
host: api.xxxx.com
schemes: 
    - https
swagger: 2.0
info: 
    title: API Doc
    description: Description for the info goes here
    version: 1.0.0

It always tends to give an error just a line number before the swagger version. Any help will be appreciated.

Edit: I have defined the swagger version as string in the java code and written as described below:

HashMap<String, Object> rootElementsForYml = new HashMap<String, Object>();
rootElementsForYml.put(SWAGGER, "2.0");
rootElementsForYml.put(HOST, "api.xxxx.com");
rootElementsForYml.put(BASEPATH, basePath);
rootElementsForYml.put(SCHEMES, new String[]{"https"});

But still it gives no result and the same error.

Upvotes: 0

Views: 4321

Answers (1)

Ron
Ron

Reputation: 14830

That's because the version value is a string and not a number. Just specifying 2.0 is interpreted as a number. Wrap it with quotes like "2.0" and it would work fine.

Upvotes: 1

Related Questions