Swagger formatting error - missed comma between flow collection entries

Hi,

Trying to put together a simple REST API on a new server app and hitting a strange problem with one function.

I’ve defined it thus in the server:

[ROServiceMethod]
[ROCustom(‘HttpApiPath’,‘management/findcustomers/{searchname}’)]
[ROCustom(‘HttpApiMethod’,‘GET’)]
function FindCustomers(searchname : string) : Customers;

All compiles fine, however when I copy the generated Swagger API into editor.swagger.io, I get the above error, specifically on the first line of this block:

/management/findcustomers/{searchname}: {
get: {
parameters: [
{
name: “searchname”,
in: “path”,
required: true,
type: “string”
}
],
responses: {
200: {
description: “The method call completed successfully”,
schema: {
type: “array”,
items: {
$ref: “#/definitions/Customer”
}
}
},
400: {
description: “Bad Request”
},
401: {
description: “Unauthorized”
},
500: {
description: “Internal Server Error”
}
},
security: [
{
Bearer:
}
]
}
},

Any ideas what I’m doing wrong here? Seems not to like something about the parameter (as removing it solves the problem).

Hi,

weird.
this json:

{"swagger":"2.0","info":{"title":"NewProjectLibrary","version":"1.0.0"},"host":"localhost:8099","basePath":"\/api","schemes":["http"],"consumes":["application\/json"],"produces":["application\/json"],"paths":{"\/management\/findcustomers\/{searchname}":{"get":{"parameters":[{"name":"searchname","in":"path","required":true,"type":"string"}],"responses":{"200":{"description":"The method call completed successfully","schema":{"type":"array","items":{"$ref":"#\/definitions\/Customer"}}},"400":{"description":"Bad Request"},"500":{"description":"Internal Server Error"}}}}},"definitions":{"Customer":{"type":"object","properties":{}}}}

works as expected:

Interesting.

If I compare your JSON to mine, what immediately jumps out is that every ‘name’ is surrounded by double-quotes in your file, i.e.

"swagger": "2.0",
"info": {
	"title": "NewProjectLibrary",
	"version": "1.0.0"
},

and so on, whereas in mine these double-quotes are missing, like this:

swagger: "2.0",
info: {
	title: "NewProjectLibrary",
	version: "1.0.0"
},

This also applies to the specific line that the Swagger editor is complaining about:

/management/findcustomers/{searchname}: {

If I change just this line to put the double-quotes around it, so it reads:

“/management/findcustomers/{searchname}”: {

Then it parses fine in the editor and it correctly prompts me to convert it to YAML.

The question is thus why does your JSON have these double-quotes whereas mine doesn’t. Is this an option somewhere or something that has been changed in an updated release? I’m on 1521.

Thanks.

Ah, it looks like it’s actually Chrome formatting the JSON and removing the double-quotes when I view the /api URL.

How do I stop it doing that?

EDIT: Figured it out, I had a plugin I’d long forgotten about, disabled it and now getting the raw JSON which works fine.

1 Like