cloudflare/json-schema-tools

Where is the schema for cloudflare api v4?

johnspurlock opened this issue ยท 13 comments

Assuming https://api.cloudflare.com/ is generated using this toolchain, where are the corresponding source schema definitions?

They would be useful when creating/maintaining cloudflare api clients in other languages.

Found a reference to api.cloudflare.com/schemas/v4 but it doesn't seem to be accessible.

Thanks!
- John

Ditto, this would be really nice @johnspurlock Can't believe there isn't something available.

I wonder if we could use something like:
https://www.liquid-technologies.com/online-json-to-schema-converter

Yea, it's frustrating - the source exists internally and can even be seen here! [1] Hopefully they have something in the works...

[1] https://community.cloudflare.com/t/where-is-the-source-json-schema-for-cloudflare-api-v4/119389/2

r3h0 commented

I also looked for a type-safe or machine-readable version of the API schema and didn't find anything. Most of the clients seem to be maintained manually, which is surprising.

The python client appears to use a hybrid approach of hardcoding the endpoints and generating the details by scraping api.cloudflare.com with beautifulsoup.

The Terraform provider can also dump a schema, but that's a level above the actual API and would require some tedious reverse engineering to use reliably.

IIRC the JSON schema is embedded in the page source, so I might look at that again, but if it's non-standard it'll also take some time to reverse engineer.

Anyone else have better luck finding the Cloudflare API schema?

generating the details by scraping api.cloudflare.com with beautifulsoup.

๐Ÿ˜ณ

@r3h0 @johnspurlock I figured out how to extract JSON schemas from the official documentation app, take a look https://github.com/nxpub/cloudflare-api-schemas

@alexdoesh Ooh, nice idea - are those exported objects embedded in the static app bundle source-equivalent to the https://api.cloudflare.com/schemas/v4/**/*.json source files?

I wish they just made those endpoints available!

@alexdoesh Ooh, nice idea - are those exported objects embedded in the static app bundle source-equivalent to the https://api.cloudflare.com/schemas/v4/**/*.json source files?

@johnspurlock I don't think they are exactly the same, it probably passes some transformation phases (e.g. hides some internal stuff), but still, this information is enough to build stuff on top of it (each of this objects has a direct relationship to the corresponding json schema file), and it's more reliable than parsing html docs ofc.

I also hope Cloudflare folks will release schemas properly, also looking forward for webidl stuff related to workers and the runtime itself (their promised)

They do a great job of maintaining idl for the workers runtime here: https://github.com/cloudflare/workers-types/blob/master/index.d.ts

They even have a process to generate it periodically from the source, so new production runtime additions show up there very quickly

They do a great job of maintaining idl

I'm also using this, but there are problems: it doesn't describe the entire API available within the worker, for example (like Web API's provided via their isolant). They do manipulate v8 flags and probably even codebase, some Web APIs are not available, some APIs are overriden in a weird way. You still need to merge multiple webidls together to get the full ecosystem description, and it still won't be precise enough :(

That's true, I suppose we'll have to wait until they finish their refactoring and open source the runtime itself: https://blog.cloudflare.com/workers-open-source-announcement/

Regarding the comprehensibility of the rest api docs: I'm sure you've noticed that the api surface represented in those api docs you extracted are still not up to date with even what are public-facing and available callable apis at the moment. The rest api docs are far behind.

Regarding the comprehensibility of the rest api docs: I'm sure you've noticed that the api surface represented in those api docs you extracted are still not up to date with even what are public-facing and available callable apis at the moment. The rest api docs are far behind.

@johnspurlock can you provide a few samples, please?

As far as public code, you might find some workers-related ones in my Denoflare project's cfapi client: https://github.com/skymethod/denoflare/blob/master/common/cloudflare_api.ts

For more, just open up dash.cloudflare.com and do stuff : )

https://api.cloudflare.com/schemas.json might be of interest, recently shared in the Discord.