Fix Workers Builds response envelope schema - #44
Conversation
|
@kristianfreeman @jacobbednarz @musa-cf @tamas-jozsa why not enable Issues or at least Discussions for this repo on GitHub to allow sharing issues regarding the Cloudflare API? |
|
Thanks for the feedback @alexminza , we've enabled Issues. Additionally, thanks for reporting this issue @nicu-chiciuc. I've created an internal ticket for this issue for investigation. |
0107e3e to
047e56e
Compare
|
@ssicard, sorry to tag you again, but I've already submitted the 5th issue yesterday #48 It seems these are not small bugs but that this is a broader problem in the schema generation or validation process. I have to catch these inconsistencies, then patch the official schemas and maintain provider-specific regression tests for things that are not part of my system. I’m surprised this has not come up more often, since I assume other users also consume the OpenAPI schema. Has anyone had a chance to look at the internal ticket you mentioned, and do you have any idea when the broader problem might be investigated? |
I couldn't figure out how to report an issue regarding this so I opened a PR.
Summary
Remove the shared
result: object | nullconstraint frombuilds_APIResponseso Workers Builds endpoints can define their own responseresultshape.Problem
I encountered this while generating runtime validators from the OpenAPI schema and validating Cloudflare API responses with Ajv.
builds_APIResponsecurrently definesresultas:and also marks
resultas required.Several Workers Builds operations compose this schema with an operation-specific schema using
allOf. For example,listTriggersByScriptcomposesbuilds_APIResponsewith a schema that defines:Under OpenAPI/JSON Schema semantics,
allOfdoes not override fields from earlier schemas. The response must validate against every schema in theallOflist.That makes the composed schema contradictory:
builds_APIResponserequiresresultto be an object or null.listTriggersByScriptrequiresresultto be an array.type: object.So a valid list response like this cannot validate against the published schema:
{ "success": true, "errors": [], "messages": [], "result": [] }Fix
This PR removes
resultfrom the sharedbuilds_APIResponseenvelope.The shared schema still defines the common envelope fields:
successerrorsmessagesresult_infoEach operation-specific schema can then define the concrete
resultshape it actually returns.References
allOfcomposition requires the instance to satisfy all composed schemas: https://spec.openapis.org/oas/v3.0.3#composition-and-inheritance-polymorphismnullable: trueonly allowsnullin addition to the specified type; it does not make the property optional or allow arrays fortype: object: https://spec.openapis.org/oas/v3.0.3#fixed-fields-20