Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Where is the schema for cloudflare api v4? #22

Open
johnspurlock opened this issue Oct 2, 2019 · 13 comments
Open

Where is the schema for cloudflare api v4? #22

johnspurlock opened this issue Oct 2, 2019 · 13 comments

Comments

@johnspurlock
Copy link

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

@unicomp21
Copy link

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

@johnspurlock
Copy link
Author

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
Copy link

r3h0 commented Nov 25, 2021

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?

@johnspurlock
Copy link
Author

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

😳

@alexdoesh
Copy link

@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

@johnspurlock
Copy link
Author

@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
Copy link

@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)

@johnspurlock
Copy link
Author

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

@alexdoesh
Copy link

alexdoesh commented Jun 23, 2022

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 :(

@johnspurlock
Copy link
Author

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.

@alexdoesh
Copy link

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?

@johnspurlock
Copy link
Author

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 : )

@Cherry
Copy link

Cherry commented Jun 24, 2022

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants