# Validation JSON schema with a Graphql response

**URL:** <https://community.postman.com/t/validation-json-schema-with-a-graphql-response/49743>\
**Category:** Help Hub\
**Created:** [July 19, 2023, 8:11pm UTC](https://community.postman.com/t/validation-json-schema-with-a-graphql-response/49743 "2023-07-19T20:11:34Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![journauxpostman](https://avatars.discourse-cdn.com/v4/letter/j/f0a364/32.png) [@journauxpostman](https://community.postman.com/u/journauxpostman)\
**Post date:** [July 19, 2023, 8:11pm UTC](https://community.postman.com/t/validation-json-schema-with-a-graphql-response/49743/1 "2023-07-19T20:11:34Z")

</div>

Hi,

I’m having a issue with validating a json response from a graphql relay endpoint.

I’m trying to put additional Properties to false. But once I add that validation the tests fails. Even if specified all fields.

Here is my body response :

```auto
{
    "data": {
        "posts": {
            "edges": [
                {
                    "node": {
                        "title": "Pénitencier de Saint-Jérôme: un gardien meurt de la COVID-19",
                        "slug": "penitencier-de-saint-jerome-un-gardien-meurt-de-la-covid-19",
                        "id": "cG9zdDo4OTQ0"
                    }
                },
                {
                    "node": {
                        "title": "Une excellente 20e position pour Cendrine Browne en skiathlon",
                        "slug": "une-excellente-20e-position-pour-cendrine-browne-en-skiathlon",
                        "id": "cG9zdDo4OTQw"
                    }
                },
                {
                    "node": {
                        "title": "Le transport collectif mis à mal par le variant Omicron",
                        "slug": "le-transport-collectif-mis-a-mal-par-le-variant-omicron",
                        "id": "cG9zdDo4OTE0"
                    }
                },
                {
                    "node": {
                        "title": "Paul Germain à la présidence : Bernard Pilon devient directeur du P’tit Train du Nord",
                        "slug": "paul-germain-a-la-presidence-bernard-pilon-devient-directeur-du-ptit-train-du-nord",
                        "id": "cG9zdDo4OTMz"
                    }
                },
                {
                    "node": {
                        "title": "Une nouvelle convention collective est signée : l’APTS souhaite « un réseau public accessible et humain »",
                        "slug": "une-nouvelle-convention-collective-est-signee-lapts-souhaite-un-reseau-public-accessible-et-humain ",
                        "id": "cG9zdDo4OTMw"
                    }
                },
                {
                    "node": {
                        "title": "Canadian Tire de Saint-Jérôme : l’heure de la retraite a sonné pour Jean-Guy Poulin",
                        "slug": "canadian-tire-de-saint-jerome-lheure-de-la-retraite-a-sonne-pour-jean-guy-poulin",
                        "id": "cG9zdDo4OTI2"
                    }
                },
                {
                    "node": {
                        "title": "Malgré la taxe spéciale : Saint-Colomban enregistre une hausse de la construction",
                        "slug": "malgre-la-taxe-speciale-saint-colomban-enregistre-une-hausse-de-la-construction",
                        "id": "cG9zdDo4OTI0"
                    }
                },
                {
                    "node": {
                        "title": "Saint-Jérôme : quel avenir pour le BIPA ?",
                        "slug": "saint-jerome-quel-avenir-pour-le-bipa",
                        "id": "cG9zdDo4OTIx"
                    }
                },
                {
                    "node": {
                        "title": "Convoi de la liberté vers Ottawa : quelques centaines de personnes répondent à l’appel",
                        "slug": "convoi-de-la-liberte-vers-ottawa-quelques-centaines-de-personnes-repondent-a-lappel",
                        "id": "cG9zdDo4OTE3"
                    }
                },
                {
                    "node": {
                        "title": "Le convoi de camions est en route pour Ottawa",
                        "slug": "le-convoi-de-camions-est-en-route-pour-ottawa",
                        "id": "cG9zdDo4OTA3"
                    }
                }
            ]
        }
    },
    "extensions": {
        "debug": [
            {
                "type": "DEBUG_LOGS_INACTIVE",
                "message": "GraphQL Debug logging is not active. To see debug logs, GRAPHQL_DEBUG must be enabled."
            }
        ]
    }
}

```

And here is my first validation test :

```auto
const schema = {
    type: 'object',
    proporties: {
        data: {
            type: 'object'
        },
        extensions: {
            type: 'object'
        }
    },
    required: ['data', 'extensions'],
    additionalProperties: false
}

pm.test('validate JSON Schema', function() {
    console.log('schema ', schema)
    // console.log('schema ', pm.response.to.have.jsonSchema(schema))
    pm.response.to.have.jsonSchema(schema);
});

```

I even tried a more complex validation but still got a error in my test:

```auto
const schema = {
    type: 'object',
    proporties: {
        data: {
            type: 'object',
            required: ['posts'],
            additionalProperties: false,
            proporties: {
                posts: {
                    type: 'object',
                    required: ['edges'],
                    additionalProperties: false,
                    proporties: {
                        edges: {
                            type: 'array',
                            "minItems": 1,
                            "items": {
                                type: 'object',
                                required: ['node'],
                                additionalProperties: false,
                                proporties: {
                                    node: {
                                        type: 'object',
                                        required: ['title', 'slug'],
                                        additionalProperties: false,
                                        proporties: {
                                            title : {
                                                type: 'string'
                                            },
                                            slug: {
                                                type: 'string'
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        },
        extensions: {
            type: 'object',
            required: ['debug'],
            additionalProperties: false,
            proporties: {
                debug: {
                    type: 'array',
                    "items": {
                        type: 'object',
                        required: ['type', 'message', 'id'],
                        additionalProperties: false,
                        proporties: {
                            type: {
                                type: 'string'
                            },
                            message: {
                                type: 'message'
                            },
                            id: {
                                type: 'string'
                            }
                        }
                    }
                }
            }
        }

    },
    required: ['data', 'extensions'],
    additionalProperties: false
}

pm.test('validate JSON Schema', function() {
    console.log('schema ', schema)
    // console.log('schema ', pm.response.to.have.jsonSchema(schema))
    pm.response.to.have.jsonSchema(schema);
});

```

When I remove the first additionalProperties . The test pass but if more fields gets applied It won’t fail.

---

<div class="post-metadata">

**Author:** ![michaelderekjones](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/michaelderekjones/32/14819_2.png) [@michaelderekjones](https://community.postman.com/u/michaelderekjones)\
**Post date:** [July 20, 2023, 12:26pm UTC](https://community.postman.com/t/validation-json-schema-with-a-graphql-response/49743/2 "2023-07-20T12:26:28Z")

</div>

Use this website to generate the schema.

[JSON Schema Tool](https://jsonschema.net/)

You can continue as a guest (you don’t have to sign up).

This will generate a large schema including examples. You can go into the settings and turn off the examples and other elements that you don’t want included.

Remove the $schema and $id that it includes as that will cause the test to fail.

From there, you can then start removing the elements you don’t want if needed (or remove them via the settings and re-generate).

---

<div class="post-metadata">

**Author:** ![michaelderekjones](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/michaelderekjones/32/14819_2.png) [@michaelderekjones](https://community.postman.com/u/michaelderekjones)\
**Post date:** [July 20, 2023, 12:51pm UTC](https://community.postman.com/t/validation-json-schema-with-a-graphql-response/49743/3 "2023-07-20T12:51:10Z")

</div>

This is what it produced for the schema. I changed the first additionalProperties to false to test it and it appear to work as intended.

```auto
const schema = {
    "type": "object",
    "required": [
        "data",
        "extensions"
    ],
    "additionalProperties": false,
    "properties": {
        "data": {
            "type": "object",
            "required": [
                "posts"
            ],
            "additionalProperties": true,
            "properties": {
                "posts": {
                    "type": "object",
                    "required": [
                        "edges"
                    ],
                    "additionalProperties": true,
                    "properties": {
                        "edges": {
                            "type": "array",
                            "additionalItems": true,
                            "items": {
                                "type": "object",
                                "required": [
                                    "node"
                                ],
                                "additionalProperties": true,
                                "properties": {
                                    "node": {
                                        "type": "object",
                                        "required": [
                                            "title",
                                            "slug",
                                            "id"
                                        ],
                                        "additionalProperties": true,
                                        "properties": {
                                            "title": {
                                                "type": "string"
                                            },
                                            "slug": {
                                                "type": "string"
                                            },
                                            "id": {
                                                "type": "string"
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        },
        "extensions": {
            "type": "object",
            "required": [
                "debug"
            ],
            "additionalProperties": true,
            "properties": {
                "debug": {
                    "type": "array",
                    "additionalItems": true,
                    "items": {
                        "type": "object",
                        "required": [
                            "type",
                            "message"
                        ],
                        "additionalProperties": true,
                        "properties": {
                            "type": {
                                "type": "string"
                            },
                            "message": {
                                "type": "string"
                            }
                        }
                    }
                }
            }
        }
    }
}

```

---

<div class="post-metadata">

**Author:** ![journauxpostman](https://avatars.discourse-cdn.com/v4/letter/j/f0a364/32.png) [@journauxpostman](https://community.postman.com/u/journauxpostman)\
**Post date:** [July 21, 2023, 1:44am UTC](https://community.postman.com/t/validation-json-schema-with-a-graphql-response/49743/4 "2023-07-21T01:44:14Z")

</div>

Thanks @michaelderekjones for the answer.

I did try it the site before. But It was not giving me the additionalProperties.

I compare your response and mine. And I found out my error. I used ‘proporties’ instead of ‘properties’.

Everything works now.

Thanks

---

<div class="post-metadata">

**Author:** ![michaelderekjones](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/michaelderekjones/32/14819_2.png) [@michaelderekjones](https://community.postman.com/u/michaelderekjones)\
**Post date:** [July 22, 2023, 10:54am UTC](https://community.postman.com/t/validation-json-schema-with-a-graphql-response/49743/5 "2023-07-22T10:54:39Z")

</div>

Glad its working. In that site, when you go into the settings on the left hand pane, it has a lot of options including turning additionalProperties on or off.

It’s pretty cool, and has saved me a lot of grief in the past.

---

<div class="post-metadata">

**Author:** ![system](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/system/32/29796_2.png) [@system](https://community.postman.com/u/system)\
**Post date:** [October 20, 2023, 10:54am UTC](https://community.postman.com/t/validation-json-schema-with-a-graphql-response/49743/6 "2023-10-20T10:54:43Z")

</div>

Closed on October 20, 2023, 10:54am UTC

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.
