Skip to content

Conversation

LuisTejedaS
Copy link
Contributor

@LuisTejedaS LuisTejedaS commented Jul 20, 2022

Current behavior:
When in a defined spec you happen to have a schema defined like this

            "properties": {
              "id": {
                "allOf": [
                  {
                    "type": "string",
                    "example": "3",
                    "nullable": false,
                    "description": "A numeric identifier"
                  },
                  {
                    "nullable": false
                  }
                ]
              },

the conversion process generates a message like this

"{\n  \"id\": {\n    \"value\": \"<Error: Could not resolve allOf schema\"\n  },\n  \"name\": \"Contract.pdf\"\n}"

Expected behavior:
It should generate a message like this:

'{\n  "id": "3",\n  "name": "Contract.pdf"\n}'

Issue causes:
In resolveRefs method, we are trying to identify the type of the schema whether it is Array, object, a reference, etc.
But the default behavior is considering the schema as an object

      else {
        return {
          type: SCHEMA_TYPES.object
        };
      }

When we have a schema like the one mentioned before, the generated schema for

{
  "nullable": false
}

was

{
  type: object
}

So the allOf merger was trying to merge a schema type object into a schema type string throwing an error and cached by the process adding the message in the result: Error: Could not resolve allOf schema.

The way we resolve:
If we know that we are processing a schema that comes from an allOf parent then we are returning the same schema instead of defaulting to a schema with type as object, and no other properties. So the result of the method is the same

{
  nullable: false
}

And the merger can merge the string with this sub-schema.

@LuisTejedaS LuisTejedaS self-assigned this Jul 20, 2022
@LuisTejedaS LuisTejedaS requested a review from VShingala July 21, 2022 16:13
@SahilChoudhary22 SahilChoudhary22 merged commit 70b42f9 into develop Aug 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants