Nick Williams
04/13/2023, 5:08 PMoneOf/allOf
keywords and some circular references. The comparison is failing in several places due to "x should NOT have additional properties".
I have followed the guidance given here, but even after dereferencing and inlining the same errors still occur. I have eventually been able to get this working by further manually wrangling the spec, so could potentially write a script that would take care of this for me. However, this feels a bit hacky and is not ideal.
Are these more advanced OpenAPI spec features not supported? Is there any other guidance on what steps we can take without having to resort to intervening and amending the spec this way, or does anyone have any advice on how best to tackle this?
I am using pact-python for the consumer, and pact-php for the provider. Will comment on this thread with some excerpts of the OpenAPI spec.
Thanks in advance.Nick Williams
04/13/2023, 5:08 PM"Parent": {
"description": "Parent schema",
"type": "object",
"required": ["id", "activities"],
"properties": {
"id": {
"type": "integer",
"example": 3,
"enum": [3, 4, 5, 6, 7, 8, 9, 16],
"nullable": false
},
"activities": {
"type": "array",
"nullable": false,
"minimum": 1,
"items": {
"type": "string",
"example": "6AA2A3B9-66BD-447C-90C8-A350F60D592B"
}
}
}
},
"Child": {
"description": "",
"allOf": [{
"$ref": "#/components/schemas/Parent"
}],
"type": "object",
"properties": {
"id": {
"type": "integer",
"enum": [3]
},
"activities": {
"type": "array",
"items": {
"type": "string",
"enum": [
"value",
"another value"
]
}
}
}
}
Example of keyword & circular references:
"properties": {
"project_type": {
"type": "object",
"nullable": true,
"oneOf": [{
"$ref": "#/components/schemas/Category"
}]
}
}
....
"schemas": {
"Category": {
"type": "object",
"required": ["short_name"],
"properties": {
"short_name": {
"type": "string",
"nullable": false,
"example": "test"
},
"child": {
"nullable": true,
"allOf": [{
"$ref": "#/components/schemas/Category"
}]
}
}
}
}
Matt (pactflow.io / pact-js / pact-go)
Yousaf Nabi (pactflow.io)
Nick Williams
04/14/2023, 1:23 PMschema 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": [{
...
}, {
...
}
...
]
}
}
}
Nick Williams
04/14/2023, 1:24 PMYousaf Nabi (pactflow.io)
Nick Williams
04/17/2023, 5:15 PMNick Williams
04/28/2023, 9:35 PMMatt (pactflow.io / pact-js / pact-go)