nickwilliamsqa
2023-04-14 13:23
Thanks both. So it was a combination of things - firstly de-referencing and then using the json-schema-resolve-allof library as described in the docs.
This however resulted in an invalid schema in our case, specifically due to the inheritance enums in the example above resolving strangely which leads to errors in PactFlow due to duplicate IDs (one of many of the same error):
`schema is invalid: data.definitions['Projects'].items.properties['props'].properties['thing'].oneOf[0].properties['primaries'].items.oneOf[1].properties['id'].enum should NOT have duplicate items (items ## 0 and 1 are identical)`
However these do not appear to actually be duplicated:
```"oneOf": [{
"description": "",
"type": "object",
"properties": {
"id": {
"type": "integer",
"enum": [3, 4, 5, 6, 7, 8, 9, 16],
"example": 3,
"nullable": false
},
"activities": {
....
}
},
"required": ["id", "activities"]
},
{
"description": "",
"type": "object",
"properties": {
"id": {
"type": "integer",
"enum": [4, 4, 5, 6, 7, 8, 9, 16],
"example": 3,
"nullable": false
},
"activities": {
....
}
},
"required": ["id", "activities"]
}
...
]```
There is definitely an issue here with the dereferencing, as the enum values have been listed incorrectly (I assume due to inheritance), but I am unsure why PactFlow is identifying those as duplicates, as `properties.id.enum` values are different between the two.
After manually fixing this (so each child contains a single enum value e.g. `properties.id.enum: [3]`), the dereferencing has fixed a bunch of errors - but unfortunately there are still a large number of `should NOT have additional properties` errors, where we have `oneOf`.
In some situations, where we only have a single reference within the `oneOf`, I was able to get this working by removing the `oneOf` array. For the example in the `schemas.category` above, this became the following which works:
```"properties": {
"project_type": {
"type": "object",
"nullable": true,
"required": ["short_name"],
"properties": {
"short_name": {
"type": "string",
"nullable": false,
"example": "test"
},
"child": {
"nullable": true,
"type": "object",
"required": ["short_name"],
"properties": {
"short_name": {
"type": "string",
"nullable": false,
"example": "test"
},
"child": {
"nullable": true
}
}
}
}
}
}```
But has meant the loss of the circular reference for the nested `child` property.
Where multiple entities exist under `oneOf` and so couldn't just be removed, I added `additionalProperties: true` wherever the keyword was used, which seems to be the nuclear option I'd much rather avoid. E.g
```"properties": {
"metrics": {
"type": "array",
"nullable": true,
"items": {
"additionalProperties": true,
"oneOf": [{
...
}, {
...
}
...
]
}
}
}```