1

Is there any swagger library available for validating a swagger spec json . For eg , I have the below json as my spec , how can I validate this spec? To check if all the references are resolved along with it being a valid json .

{
    "$schema": "http://json-schema.org/draft-04/schema#",

    "definitions": {
    "address": {
      "type": "object",
      "properties": {
        "street_address": { "type": "string" },
        "city":           { "type": "string" },
        "state":          { "type": "string" }
      },
      "required": ["street_address", "city", "state"]
    }
  },

  "type": "object",

  "properties": {
    "billing_address": { "$ref": "#/definitions/address" },
    "shipping_address": { "$ref": "#/definitions/address" }
  }
}
  • Your file is a JSON Schema file but is not a valid OpenAPI / Swagger file, FYI. For example, OpenAPI does not support the `$schema` keyword and requires that all definitions live under `definitions`, e.g. you can't have `type: object` on the root level outside `definitions`. – Helen Aug 13 '18 at 12:14
  • Hi Helen , Thanks for pointing that out . I can fix that , I just picked up a random json . I am more interested in knowing how to validate a Swagger schema using any Java lib. – Srivathsan S Aug 13 '18 at 14:25
  • Possible duplicate of [Swagger Spec Validation in Java](https://stackoverflow.com/questions/47254838/swagger-spec-validation-in-java), [Validating JSON against Swagger API schema](https://stackoverflow.com/q/39275947/113116) – Helen Aug 13 '18 at 14:43

0 Answers0