0

Short version: I want to validate a JSON model to see if it is a valid swagger model.

For example, I have:

{
  "swagger" : "2.0",
  "info" : {
    "version" : "0.0.1",
    "title" : "API"
  },
  "basePath" : "/api",
  "paths" : {
    "/{myVar}" : {
      "get" : {
        "summary" : "Summary",
        "parameters" : [],
        "responses" : {
          "200" : {
            "description" : "OK"
          }
        }
      }
    }
  }
}

If I use the online editor (editor.swagger.io), I have the following error:

Semantic error at paths./{myVar} Declared path parameter "myVar" needs to be defined as a path parameter at either the path or operation level

I would like to retrieve the same error in my java code.

I tried the following:

  • validating the json against the swagger schema (http://swagger.io/v2/schema.json)
  • parsing the json with SwaggerParser.readWithInfo then calling getMessages (= empty list)

Any idea if it is feasible with the current java librairies?

Tiller
  • 436
  • 1
  • 4
  • 22
  • I am using the simple [swagger core](https://github.com/swagger-api/swagger-core) packeage to validate them, it notice those missing parameters while parsing. – Turtle Jan 10 '18 at 14:48
  • @Nathan thanks but I fail to see what class I could use in this module. Any example? – Tiller Jan 10 '18 at 15:00
  • Possible duplicate of [Swagger 2.0 offline validation](https://stackoverflow.com/questions/35978671/swagger-2-0-offline-validation) and [Validating JSON against Swagger API schema](https://stackoverflow.com/q/39275947/113116) – Helen Jan 10 '18 at 16:51

0 Answers0