Access to OpenAPI specification?
I was looking through the endpoints and noticed that the endpoints are defined using OpenAPI (previously called Swagger). This specification allows people to autogenerate client code into a whole bunch of programming languages using the openapi-generator from OpenAPITools. Having client code in all sorts of languages will allow developers to more easily access your API.
A list of supported languages can be found here: https://github.com/OpenAPITools/openapi-generator#overview
Can there be a stable URL for downloading the Swagger/OpenAPI specification?
Examples: https://api.congress.gov/specification/2022-09-08/openapi.yaml
As a workaround, it looks like the specification is stored in var spec in the script tag towards the bottom of view-source:https://api.congress.gov.
It would be nice if it used the standard https://api.congress.gov/openapi.json
Also, see What is the Difference Between Swagger and OpenAPI?
Heres a bookmarklet to export the in-memory spec to a json file. Tested in firefox:
javascript: (() => { const filename = 'swagger.json'; const jsonStr = JSON.stringify(ui.getConfigs().spec); let element = document.createElement('a'); element.setAttribute('href', 'data:text/plain;charset=utf-8,' + encodeURIComponent(jsonStr)); element.setAttribute('download', filename); element.style.display = 'none'; document.body.appendChild(element); element.click(); document.body.removeChild(element); })();
Not sure how often they update their specification but I pulled it from the markup and loaded it into a ReadMe project[^1], which you can check out here: https://congress.readme.io
As part of this, I cleaned up the spec and converted it to OpenAPI 3.0: https://congress.readme.io/openapi/6320bd793750a5001222766f
Still could use some love (i.e. using properly defined response examples, as opposed to stringified code snippets in the description fields 😬), but it's a start!
[^1]: Disclaimer: I'm a ReadMe employee so I'm a bit biased, but this is my personal favorite way to interact with an API! 🦉
Right now, we're mostly concerned with refining the current offerings. But we are considering possible enhancements for future development, and we'll add this to the list.
We added our swagger file here. Let me know if you have any questions! Thanks!