openai-openapi icon indicating copy to clipboard operation
openai-openapi copied to clipboard

some constraints seem to be unintentional no-ops

Open rogpeppe opened this issue 9 months ago • 0 comments

According to the OpenAPI 3.0 specification any keywords alongside a $ref keyword should be ignored:

This object cannot be extended with additional properties and any properties added SHALL be ignored. (emphasis in the original).

The API spec here seems to have a number of occurrences of this pattern, as flagged by the tool I was using to interpret the schema:

This seems like it would be worth fixing. Even if some tools do in fact interpret keywords alongside $ref, following likely intent despite being technically incorrect, it's straightforward to fix things so the openAPI schema follows the letter of the law.

The fix is this: any time we see $ref alongside another keyword, replace the $ref field with "allOf": {"$ref": originalRefContents}. As an allOf is allowed to coexist with other properties, this fixes the issue.

Note that if a later OpenAPI schema version (v3.1 or later) was used, this would not be an issue because subsequent versions use JSON Schema 2020-12 which does allow $ref alongside other properties.

I see this repo doesn't accept PRs but I'd be happy to provide a patch on request.

rogpeppe avatar Mar 28 '25 22:03 rogpeppe