api.congress.gov icon indicating copy to clipboard operation
api.congress.gov copied to clipboard

Access to OpenAPI specification?

Open adamdecaf opened this issue 3 years ago • 4 comments

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

adamdecaf avatar Sep 08 '22 20:09 adamdecaf

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?

matthoendorf avatar Sep 09 '22 03:09 matthoendorf

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); })();

J-Swift avatar Sep 09 '22 13:09 J-Swift

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! 🦉

kanadgupta avatar Sep 13 '22 17:09 kanadgupta

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.

mnewatloc avatar Sep 14 '22 18:09 mnewatloc

We added our swagger file here. Let me know if you have any questions! Thanks!

apreiter18 avatar Jun 13 '24 14:06 apreiter18