Validating json payload against swagger file - json-schema-validator











up vote
0
down vote

favorite












I am trying to validate a json payload against a swagger file that contains the service agreement. I am using the json-schema-validator(2.1.7) library to achieve this, but at the moment it's not validating against the specified patterns or min/max length.



Java Code:



public void validateJsonData(final String jsonData) throws IOException, ProcessingException {

ClassLoader classLoader = getClass().getClassLoader();
File jsonSchemaFile = new File (classLoader.getResource("coachingStatusUpdate.json").getFile());

String jsonSchema = new String(Files.readAllBytes(jsonSchemaFile.toPath()));

final JsonNode dataNode = JsonLoader.fromString(jsonData);
final JsonNode schemaNode = JsonLoader.fromString(jsonSchema);

final JsonSchemaFactory factory = JsonSchemaFactory.byDefault();
JsonValidator jsonValidator = factory.getValidator();

ProcessingReport report = jsonValidator.validate(schemaNode, dataNode);
System.out.println(report);
if (!report.toString().contains("success")) {
throw new ProcessingException (
report.toString());
}
}


Message I am sending through



{
"coachingStatus": "LEAD",
"coachingStatusReason": "ABUSIVE",
"correlationID": -1,
"effectiveDate": "2018-10-30",
"externalEntityIdentifier": "string" }


The swagger definition:



    {
"swagger": "2.0",
"info": {
"version": "1.0.0",
"title": "Test",
"termsOfService": "http://www.test.co.za",
"license": {
"name": "Test"
}
},
"host": "localhost:9001",
"basePath": "/test/services",
"tags": [
{
"name": "status-update-controller",
"description": "Submission of member status updates"
}
],
"paths": {
"/statusUpdate": {
"put": {
"tags": [
"status-update-controller"
],
"summary": "statusUpdate",
"operationId": "statusUpdateUsingPUT",
"consumes": [
"application/json;charset=UTF-8"
],
"produces": [
"application/json;charset=UTF-8"
],
"parameters": [
{
"in": "body",
"name": "statusUpdateRequest",
"description": "statusUpdateRequest",
"required": true,
"schema": {
"$ref": "#/definitions/statusUpdateRequest"
}
}
],
"responses": {
"200": {
"description": "Received member status update",
"schema": {
"$ref": "#/definitions/ResponseEntity"
}
},
"400": {
"description": "Bad Request"
},
"401": {
"description": "Unauthorized"
},
"408": {
"description": "Request Timeout"
},
"500": {
"description": "Generic Error"
},
"502": {
"description": "Bad Gateway"
},
"503": {
"description": "Service Unavailable"
}
}
}
}
},
"definitions": {
"statusUpdateRequest": {
"type": "object",
"required": [
"coachingStatus",
"correlationID",
"effectiveDate",
"externalEntityIdentifier"
],
"properties": {
"coachingStatus": {
"type": "string",
"description": "Status of patient enrollment returned by Guidepost",
"enum": [
"LEAD",
"PROSPECT",
"ACTIVE_NEW",
"ACTIVE",
"MAINTENANCE",
"SUSPENDED",
"DECEASED",
"TERMINATED"
]
},
"coachingStatusReason": {
"type": "string",
"description": "Status reason of patient enrollment returned by Guidepost",
"enum": [
"ABUSIVE",
"BAD_LEAD",
"CHANGED_DOCTOR",
"DOCTOR_COMPLAINT",
"DOCTOR_WITHDREW",
"GRADUATED",
"NON_CONTACTABLE",
"NON_PARTICIPATION",
"NON_PAYMENT",
"OFF_LABEL_MEDICATION_USAGE",
"PATIENT_WITHDREW",
"MEDICAL_DISQUALIFICATION",
"PREGNANT",
"EXISTING"
]
},
"correlationID": {
"type": "integer",
"format": "int32",
"description": "Unique reference generated to uniquely identify a transaction",
"minimum": 1,
"maximum": 9999999
},
"effectiveDate": {
"type": "string",
"format": "date",
"description": "Date of when the member status update was performed"
},
"externalEntityIdentifier": {
"type": "string",
"description": "Unique reference to represent the entity",
"minLength": 1,
"maxLength": 100
}
}
},
"ResponseEntity": {
"type": "object",
"properties": {
"body": {
"type": "object"
},
"statusCode": {
"type": "string",
"enum": [
"100",
"101",
"102",
"103",
"200",
"201",
"202",
"203",
"204",
"205",
"206",
"207",
"208",
"226",
"300",
"301",
"302",
"303",
"304",
"305",
"307",
"308",
"400",
"401",
"402",
"403",
"404",
"405",
"406",
"407",
"408",
"409",
"410",
"411",
"412",
"413",
"414",
"415",
"416",
"417",
"418",
"419",
"420",
"421",
"422",
"423",
"424",
"426",
"428",
"429",
"431",
"451",
"500",
"501",
"502",
"503",
"504",
"505",
"506",
"507",
"508",
"509",
"510",
"511"
]
},
"statusCodeValue": {
"type": "integer",
"format": "int32"
}
}
}
}
}


As you can see I am sending through a correlationID of -1, which should fail validation, but at the moment is's returning as successful:



com.github.fge.jsonschema.report.ListProcessingReport: success









share|improve this question
























  • can you post the whole schema?
    – slimane
    Nov 19 at 12:53










  • @slimane I added the whole schema
    – Hendrien
    Nov 19 at 13:00










  • Are you sure this json-schema-validator supports OpenAPI/Swagger schemas? OpenAPI format differs from vanilla JSON Schema.
    – Helen
    Nov 19 at 13:49










  • @Helen I am unsure, I was unable to find any other components that can validate against schema files
    – Hendrien
    Nov 19 at 14:44















up vote
0
down vote

favorite












I am trying to validate a json payload against a swagger file that contains the service agreement. I am using the json-schema-validator(2.1.7) library to achieve this, but at the moment it's not validating against the specified patterns or min/max length.



Java Code:



public void validateJsonData(final String jsonData) throws IOException, ProcessingException {

ClassLoader classLoader = getClass().getClassLoader();
File jsonSchemaFile = new File (classLoader.getResource("coachingStatusUpdate.json").getFile());

String jsonSchema = new String(Files.readAllBytes(jsonSchemaFile.toPath()));

final JsonNode dataNode = JsonLoader.fromString(jsonData);
final JsonNode schemaNode = JsonLoader.fromString(jsonSchema);

final JsonSchemaFactory factory = JsonSchemaFactory.byDefault();
JsonValidator jsonValidator = factory.getValidator();

ProcessingReport report = jsonValidator.validate(schemaNode, dataNode);
System.out.println(report);
if (!report.toString().contains("success")) {
throw new ProcessingException (
report.toString());
}
}


Message I am sending through



{
"coachingStatus": "LEAD",
"coachingStatusReason": "ABUSIVE",
"correlationID": -1,
"effectiveDate": "2018-10-30",
"externalEntityIdentifier": "string" }


The swagger definition:



    {
"swagger": "2.0",
"info": {
"version": "1.0.0",
"title": "Test",
"termsOfService": "http://www.test.co.za",
"license": {
"name": "Test"
}
},
"host": "localhost:9001",
"basePath": "/test/services",
"tags": [
{
"name": "status-update-controller",
"description": "Submission of member status updates"
}
],
"paths": {
"/statusUpdate": {
"put": {
"tags": [
"status-update-controller"
],
"summary": "statusUpdate",
"operationId": "statusUpdateUsingPUT",
"consumes": [
"application/json;charset=UTF-8"
],
"produces": [
"application/json;charset=UTF-8"
],
"parameters": [
{
"in": "body",
"name": "statusUpdateRequest",
"description": "statusUpdateRequest",
"required": true,
"schema": {
"$ref": "#/definitions/statusUpdateRequest"
}
}
],
"responses": {
"200": {
"description": "Received member status update",
"schema": {
"$ref": "#/definitions/ResponseEntity"
}
},
"400": {
"description": "Bad Request"
},
"401": {
"description": "Unauthorized"
},
"408": {
"description": "Request Timeout"
},
"500": {
"description": "Generic Error"
},
"502": {
"description": "Bad Gateway"
},
"503": {
"description": "Service Unavailable"
}
}
}
}
},
"definitions": {
"statusUpdateRequest": {
"type": "object",
"required": [
"coachingStatus",
"correlationID",
"effectiveDate",
"externalEntityIdentifier"
],
"properties": {
"coachingStatus": {
"type": "string",
"description": "Status of patient enrollment returned by Guidepost",
"enum": [
"LEAD",
"PROSPECT",
"ACTIVE_NEW",
"ACTIVE",
"MAINTENANCE",
"SUSPENDED",
"DECEASED",
"TERMINATED"
]
},
"coachingStatusReason": {
"type": "string",
"description": "Status reason of patient enrollment returned by Guidepost",
"enum": [
"ABUSIVE",
"BAD_LEAD",
"CHANGED_DOCTOR",
"DOCTOR_COMPLAINT",
"DOCTOR_WITHDREW",
"GRADUATED",
"NON_CONTACTABLE",
"NON_PARTICIPATION",
"NON_PAYMENT",
"OFF_LABEL_MEDICATION_USAGE",
"PATIENT_WITHDREW",
"MEDICAL_DISQUALIFICATION",
"PREGNANT",
"EXISTING"
]
},
"correlationID": {
"type": "integer",
"format": "int32",
"description": "Unique reference generated to uniquely identify a transaction",
"minimum": 1,
"maximum": 9999999
},
"effectiveDate": {
"type": "string",
"format": "date",
"description": "Date of when the member status update was performed"
},
"externalEntityIdentifier": {
"type": "string",
"description": "Unique reference to represent the entity",
"minLength": 1,
"maxLength": 100
}
}
},
"ResponseEntity": {
"type": "object",
"properties": {
"body": {
"type": "object"
},
"statusCode": {
"type": "string",
"enum": [
"100",
"101",
"102",
"103",
"200",
"201",
"202",
"203",
"204",
"205",
"206",
"207",
"208",
"226",
"300",
"301",
"302",
"303",
"304",
"305",
"307",
"308",
"400",
"401",
"402",
"403",
"404",
"405",
"406",
"407",
"408",
"409",
"410",
"411",
"412",
"413",
"414",
"415",
"416",
"417",
"418",
"419",
"420",
"421",
"422",
"423",
"424",
"426",
"428",
"429",
"431",
"451",
"500",
"501",
"502",
"503",
"504",
"505",
"506",
"507",
"508",
"509",
"510",
"511"
]
},
"statusCodeValue": {
"type": "integer",
"format": "int32"
}
}
}
}
}


As you can see I am sending through a correlationID of -1, which should fail validation, but at the moment is's returning as successful:



com.github.fge.jsonschema.report.ListProcessingReport: success









share|improve this question
























  • can you post the whole schema?
    – slimane
    Nov 19 at 12:53










  • @slimane I added the whole schema
    – Hendrien
    Nov 19 at 13:00










  • Are you sure this json-schema-validator supports OpenAPI/Swagger schemas? OpenAPI format differs from vanilla JSON Schema.
    – Helen
    Nov 19 at 13:49










  • @Helen I am unsure, I was unable to find any other components that can validate against schema files
    – Hendrien
    Nov 19 at 14:44













up vote
0
down vote

favorite









up vote
0
down vote

favorite











I am trying to validate a json payload against a swagger file that contains the service agreement. I am using the json-schema-validator(2.1.7) library to achieve this, but at the moment it's not validating against the specified patterns or min/max length.



Java Code:



public void validateJsonData(final String jsonData) throws IOException, ProcessingException {

ClassLoader classLoader = getClass().getClassLoader();
File jsonSchemaFile = new File (classLoader.getResource("coachingStatusUpdate.json").getFile());

String jsonSchema = new String(Files.readAllBytes(jsonSchemaFile.toPath()));

final JsonNode dataNode = JsonLoader.fromString(jsonData);
final JsonNode schemaNode = JsonLoader.fromString(jsonSchema);

final JsonSchemaFactory factory = JsonSchemaFactory.byDefault();
JsonValidator jsonValidator = factory.getValidator();

ProcessingReport report = jsonValidator.validate(schemaNode, dataNode);
System.out.println(report);
if (!report.toString().contains("success")) {
throw new ProcessingException (
report.toString());
}
}


Message I am sending through



{
"coachingStatus": "LEAD",
"coachingStatusReason": "ABUSIVE",
"correlationID": -1,
"effectiveDate": "2018-10-30",
"externalEntityIdentifier": "string" }


The swagger definition:



    {
"swagger": "2.0",
"info": {
"version": "1.0.0",
"title": "Test",
"termsOfService": "http://www.test.co.za",
"license": {
"name": "Test"
}
},
"host": "localhost:9001",
"basePath": "/test/services",
"tags": [
{
"name": "status-update-controller",
"description": "Submission of member status updates"
}
],
"paths": {
"/statusUpdate": {
"put": {
"tags": [
"status-update-controller"
],
"summary": "statusUpdate",
"operationId": "statusUpdateUsingPUT",
"consumes": [
"application/json;charset=UTF-8"
],
"produces": [
"application/json;charset=UTF-8"
],
"parameters": [
{
"in": "body",
"name": "statusUpdateRequest",
"description": "statusUpdateRequest",
"required": true,
"schema": {
"$ref": "#/definitions/statusUpdateRequest"
}
}
],
"responses": {
"200": {
"description": "Received member status update",
"schema": {
"$ref": "#/definitions/ResponseEntity"
}
},
"400": {
"description": "Bad Request"
},
"401": {
"description": "Unauthorized"
},
"408": {
"description": "Request Timeout"
},
"500": {
"description": "Generic Error"
},
"502": {
"description": "Bad Gateway"
},
"503": {
"description": "Service Unavailable"
}
}
}
}
},
"definitions": {
"statusUpdateRequest": {
"type": "object",
"required": [
"coachingStatus",
"correlationID",
"effectiveDate",
"externalEntityIdentifier"
],
"properties": {
"coachingStatus": {
"type": "string",
"description": "Status of patient enrollment returned by Guidepost",
"enum": [
"LEAD",
"PROSPECT",
"ACTIVE_NEW",
"ACTIVE",
"MAINTENANCE",
"SUSPENDED",
"DECEASED",
"TERMINATED"
]
},
"coachingStatusReason": {
"type": "string",
"description": "Status reason of patient enrollment returned by Guidepost",
"enum": [
"ABUSIVE",
"BAD_LEAD",
"CHANGED_DOCTOR",
"DOCTOR_COMPLAINT",
"DOCTOR_WITHDREW",
"GRADUATED",
"NON_CONTACTABLE",
"NON_PARTICIPATION",
"NON_PAYMENT",
"OFF_LABEL_MEDICATION_USAGE",
"PATIENT_WITHDREW",
"MEDICAL_DISQUALIFICATION",
"PREGNANT",
"EXISTING"
]
},
"correlationID": {
"type": "integer",
"format": "int32",
"description": "Unique reference generated to uniquely identify a transaction",
"minimum": 1,
"maximum": 9999999
},
"effectiveDate": {
"type": "string",
"format": "date",
"description": "Date of when the member status update was performed"
},
"externalEntityIdentifier": {
"type": "string",
"description": "Unique reference to represent the entity",
"minLength": 1,
"maxLength": 100
}
}
},
"ResponseEntity": {
"type": "object",
"properties": {
"body": {
"type": "object"
},
"statusCode": {
"type": "string",
"enum": [
"100",
"101",
"102",
"103",
"200",
"201",
"202",
"203",
"204",
"205",
"206",
"207",
"208",
"226",
"300",
"301",
"302",
"303",
"304",
"305",
"307",
"308",
"400",
"401",
"402",
"403",
"404",
"405",
"406",
"407",
"408",
"409",
"410",
"411",
"412",
"413",
"414",
"415",
"416",
"417",
"418",
"419",
"420",
"421",
"422",
"423",
"424",
"426",
"428",
"429",
"431",
"451",
"500",
"501",
"502",
"503",
"504",
"505",
"506",
"507",
"508",
"509",
"510",
"511"
]
},
"statusCodeValue": {
"type": "integer",
"format": "int32"
}
}
}
}
}


As you can see I am sending through a correlationID of -1, which should fail validation, but at the moment is's returning as successful:



com.github.fge.jsonschema.report.ListProcessingReport: success









share|improve this question















I am trying to validate a json payload against a swagger file that contains the service agreement. I am using the json-schema-validator(2.1.7) library to achieve this, but at the moment it's not validating against the specified patterns or min/max length.



Java Code:



public void validateJsonData(final String jsonData) throws IOException, ProcessingException {

ClassLoader classLoader = getClass().getClassLoader();
File jsonSchemaFile = new File (classLoader.getResource("coachingStatusUpdate.json").getFile());

String jsonSchema = new String(Files.readAllBytes(jsonSchemaFile.toPath()));

final JsonNode dataNode = JsonLoader.fromString(jsonData);
final JsonNode schemaNode = JsonLoader.fromString(jsonSchema);

final JsonSchemaFactory factory = JsonSchemaFactory.byDefault();
JsonValidator jsonValidator = factory.getValidator();

ProcessingReport report = jsonValidator.validate(schemaNode, dataNode);
System.out.println(report);
if (!report.toString().contains("success")) {
throw new ProcessingException (
report.toString());
}
}


Message I am sending through



{
"coachingStatus": "LEAD",
"coachingStatusReason": "ABUSIVE",
"correlationID": -1,
"effectiveDate": "2018-10-30",
"externalEntityIdentifier": "string" }


The swagger definition:



    {
"swagger": "2.0",
"info": {
"version": "1.0.0",
"title": "Test",
"termsOfService": "http://www.test.co.za",
"license": {
"name": "Test"
}
},
"host": "localhost:9001",
"basePath": "/test/services",
"tags": [
{
"name": "status-update-controller",
"description": "Submission of member status updates"
}
],
"paths": {
"/statusUpdate": {
"put": {
"tags": [
"status-update-controller"
],
"summary": "statusUpdate",
"operationId": "statusUpdateUsingPUT",
"consumes": [
"application/json;charset=UTF-8"
],
"produces": [
"application/json;charset=UTF-8"
],
"parameters": [
{
"in": "body",
"name": "statusUpdateRequest",
"description": "statusUpdateRequest",
"required": true,
"schema": {
"$ref": "#/definitions/statusUpdateRequest"
}
}
],
"responses": {
"200": {
"description": "Received member status update",
"schema": {
"$ref": "#/definitions/ResponseEntity"
}
},
"400": {
"description": "Bad Request"
},
"401": {
"description": "Unauthorized"
},
"408": {
"description": "Request Timeout"
},
"500": {
"description": "Generic Error"
},
"502": {
"description": "Bad Gateway"
},
"503": {
"description": "Service Unavailable"
}
}
}
}
},
"definitions": {
"statusUpdateRequest": {
"type": "object",
"required": [
"coachingStatus",
"correlationID",
"effectiveDate",
"externalEntityIdentifier"
],
"properties": {
"coachingStatus": {
"type": "string",
"description": "Status of patient enrollment returned by Guidepost",
"enum": [
"LEAD",
"PROSPECT",
"ACTIVE_NEW",
"ACTIVE",
"MAINTENANCE",
"SUSPENDED",
"DECEASED",
"TERMINATED"
]
},
"coachingStatusReason": {
"type": "string",
"description": "Status reason of patient enrollment returned by Guidepost",
"enum": [
"ABUSIVE",
"BAD_LEAD",
"CHANGED_DOCTOR",
"DOCTOR_COMPLAINT",
"DOCTOR_WITHDREW",
"GRADUATED",
"NON_CONTACTABLE",
"NON_PARTICIPATION",
"NON_PAYMENT",
"OFF_LABEL_MEDICATION_USAGE",
"PATIENT_WITHDREW",
"MEDICAL_DISQUALIFICATION",
"PREGNANT",
"EXISTING"
]
},
"correlationID": {
"type": "integer",
"format": "int32",
"description": "Unique reference generated to uniquely identify a transaction",
"minimum": 1,
"maximum": 9999999
},
"effectiveDate": {
"type": "string",
"format": "date",
"description": "Date of when the member status update was performed"
},
"externalEntityIdentifier": {
"type": "string",
"description": "Unique reference to represent the entity",
"minLength": 1,
"maxLength": 100
}
}
},
"ResponseEntity": {
"type": "object",
"properties": {
"body": {
"type": "object"
},
"statusCode": {
"type": "string",
"enum": [
"100",
"101",
"102",
"103",
"200",
"201",
"202",
"203",
"204",
"205",
"206",
"207",
"208",
"226",
"300",
"301",
"302",
"303",
"304",
"305",
"307",
"308",
"400",
"401",
"402",
"403",
"404",
"405",
"406",
"407",
"408",
"409",
"410",
"411",
"412",
"413",
"414",
"415",
"416",
"417",
"418",
"419",
"420",
"421",
"422",
"423",
"424",
"426",
"428",
"429",
"431",
"451",
"500",
"501",
"502",
"503",
"504",
"505",
"506",
"507",
"508",
"509",
"510",
"511"
]
},
"statusCodeValue": {
"type": "integer",
"format": "int32"
}
}
}
}
}


As you can see I am sending through a correlationID of -1, which should fail validation, but at the moment is's returning as successful:



com.github.fge.jsonschema.report.ListProcessingReport: success






java json swagger jsonschema json-schema-validator






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 19 at 13:00

























asked Nov 19 at 12:36









Hendrien

31110




31110












  • can you post the whole schema?
    – slimane
    Nov 19 at 12:53










  • @slimane I added the whole schema
    – Hendrien
    Nov 19 at 13:00










  • Are you sure this json-schema-validator supports OpenAPI/Swagger schemas? OpenAPI format differs from vanilla JSON Schema.
    – Helen
    Nov 19 at 13:49










  • @Helen I am unsure, I was unable to find any other components that can validate against schema files
    – Hendrien
    Nov 19 at 14:44


















  • can you post the whole schema?
    – slimane
    Nov 19 at 12:53










  • @slimane I added the whole schema
    – Hendrien
    Nov 19 at 13:00










  • Are you sure this json-schema-validator supports OpenAPI/Swagger schemas? OpenAPI format differs from vanilla JSON Schema.
    – Helen
    Nov 19 at 13:49










  • @Helen I am unsure, I was unable to find any other components that can validate against schema files
    – Hendrien
    Nov 19 at 14:44
















can you post the whole schema?
– slimane
Nov 19 at 12:53




can you post the whole schema?
– slimane
Nov 19 at 12:53












@slimane I added the whole schema
– Hendrien
Nov 19 at 13:00




@slimane I added the whole schema
– Hendrien
Nov 19 at 13:00












Are you sure this json-schema-validator supports OpenAPI/Swagger schemas? OpenAPI format differs from vanilla JSON Schema.
– Helen
Nov 19 at 13:49




Are you sure this json-schema-validator supports OpenAPI/Swagger schemas? OpenAPI format differs from vanilla JSON Schema.
– Helen
Nov 19 at 13:49












@Helen I am unsure, I was unable to find any other components that can validate against schema files
– Hendrien
Nov 19 at 14:44




@Helen I am unsure, I was unable to find any other components that can validate against schema files
– Hendrien
Nov 19 at 14:44












1 Answer
1






active

oldest

votes

















up vote
1
down vote













json-schema-validator seems to work with pure JSON Schema only. OpenAPI Specification uses an extended subset of JSON Schema, so the schema format is different. You need a library that can validate specifically against OpenAPI/Swagger definitions. Since you use Java, try one of the following:





  • SchemaValidator class from the Swagger Inflector library

  • Atlassian's swagger-request-validator






share|improve this answer





















    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














     

    draft saved


    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53374810%2fvalidating-json-payload-against-swagger-file-json-schema-validator%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes








    up vote
    1
    down vote













    json-schema-validator seems to work with pure JSON Schema only. OpenAPI Specification uses an extended subset of JSON Schema, so the schema format is different. You need a library that can validate specifically against OpenAPI/Swagger definitions. Since you use Java, try one of the following:





    • SchemaValidator class from the Swagger Inflector library

    • Atlassian's swagger-request-validator






    share|improve this answer

























      up vote
      1
      down vote













      json-schema-validator seems to work with pure JSON Schema only. OpenAPI Specification uses an extended subset of JSON Schema, so the schema format is different. You need a library that can validate specifically against OpenAPI/Swagger definitions. Since you use Java, try one of the following:





      • SchemaValidator class from the Swagger Inflector library

      • Atlassian's swagger-request-validator






      share|improve this answer























        up vote
        1
        down vote










        up vote
        1
        down vote









        json-schema-validator seems to work with pure JSON Schema only. OpenAPI Specification uses an extended subset of JSON Schema, so the schema format is different. You need a library that can validate specifically against OpenAPI/Swagger definitions. Since you use Java, try one of the following:





        • SchemaValidator class from the Swagger Inflector library

        • Atlassian's swagger-request-validator






        share|improve this answer












        json-schema-validator seems to work with pure JSON Schema only. OpenAPI Specification uses an extended subset of JSON Schema, so the schema format is different. You need a library that can validate specifically against OpenAPI/Swagger definitions. Since you use Java, try one of the following:





        • SchemaValidator class from the Swagger Inflector library

        • Atlassian's swagger-request-validator







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 19 at 15:22









        Helen

        31.7k471126




        31.7k471126






























             

            draft saved


            draft discarded



















































             


            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53374810%2fvalidating-json-payload-against-swagger-file-json-schema-validator%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Wiesbaden

            Marschland

            Dieringhausen