question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Aggregation of allOf combined with additionalProperties false not working - Response validation

See original GitHub issue

I am getting the following error when validating response for a /route endpoint (see schema and the response example below)

Error: .response should NOT have additional properties, .response should NOT have additional properties
    at ResponseValidator._validate (C:\Code\automation\node_modules\express-openapi-validator\dist\middlewares\openapi.response.validator.js:83:32)
    at C:\Code\automation\node_modules\express-openapi-validator\dist\middlewares\openapi.response.validator.js:27:29
    at ServerResponse.json_hook (C:\Code\automation\node_modules\express-openapi-validator\dist\framework\modded.express.mung.js:35:24)
    at ServerResponse.send (C:\Code\automation\node_modules\express\lib\response.js:158:21)
    at c:\Code\automation\src\dataserver\Server.ts:268:25
    at Layer.handle [as handle_request] (C:\Code\automation\node_modules\express\lib\router\layer.js:95:5)
    at next (C:\Code\automation\node_modules\express\lib\router\route.js:137:13)
    at Route.dispatch (C:\Code\automation\node_modules\express\lib\router\route.js:112:3)

Expected result: The validation should pass

Example 1 - Demonstrates the issue

Having the following schema, the below response causes validation error - no additional properties Schema:

---
  openapi: "3.0.0"
  info:
    title: "Test for allOf"
    version: "1"
  paths:
    /route:
      get:
        responses:
          200:
            description: ""
            content:
              application/json:
                schema:
                  $ref: "#/components/schemas/RouteType"
  components:
    schemas:
      RouteType:
        allOf:
          -
            $ref: "#/components/schemas/Type1"
          -
            $ref: "#/components/schemas/Type2"
      Type1:
        type: "object"
        additionalProperties: false
        properties:
          property1:
            type: "integer"
      Type2:
        type: "object"
        additionalProperties: false
        properties:
          property2:
            type: "string"

Response:

---
  property1: 1
  property2: SomeString

Example 2 - No issue

If there is just one item in allOf collection, it validates correctly:

Schema:

---
  openapi: "3.0.0"
  info:
    title: "Test for allOf"
    version: "1"
  paths:
    /route:
      get:
        responses:
          200:
            description: ""
            content:
              application/json:
                schema:
                  $ref: "#/components/schemas/RouteType"
  components:
    schemas:
      RouteType:
        allOf:
          -
            $ref: "#/components/schemas/Type1"
      Type1:
        type: "object"
        additionalProperties: false
        properties:
          property1:
            type: "integer"

Response:

---
  property1: 1

Issue Analytics

  • State:open
  • Created 4 years ago
  • Reactions:2
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

4reactions
asafMasacommented, Sep 21, 2022

@cdimascio is there any progress with this issue?

4reactions
cdimasciocommented, Mar 8, 2020

FYI, i saw this today, json-schema-merge-all-of. I will plan to look into it. Im curious if it might help this situation. If so, perhaps, we can leverage it within the validator.

It seems to tackle this issue as well

Option to override common impossibility like adding properties when using additionalProperties: false

Read more comments on GitHub >

github_iconTop Results From Across the Web

JSON schema : "allof" with "additionalProperties"
Your definition should not have "additionalProperties": false if you want to combine his properties with other ones. Share.
Read more >
Extend the Kubernetes API with CustomResourceDefinitions
This page shows how to install a custom resource into the Kubernetes API by creating a CustomResourceDefinition. Before you begin You need ...
Read more >
JSON Schema: A Media Type for Describing JSON Documents
JSON Schema: A Media Type for Describing JSON Documents (Internet-Draft, 2022)
Read more >
Understanding JSON Schema
Earlier versions of JSON Schema are not completely ... You can use additionalProperties with a combination of properties and ...
Read more >
C# serialization with JsonSchema and System.Text.Json
Text.Json -based APIs that shred, map, merge, filter, compose, and otherwise process and validate JSON data from various sources, using ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found