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

Code-generating NGPVAN API client. #751

Open
alxmrs opened this issue Sep 19, 2022 · 2 comments
Open

Code-generating NGPVAN API client. #751

alxmrs opened this issue Sep 19, 2022 · 2 comments
Labels
enhancement Impact - something should be added to or changed about Parsons that isn't causing a current breakage low priority Priority - this is a nice-to-have, is non-urgent, and/or has a minor overall imapact on Parsons

Comments

@alxmrs
Copy link
Contributor

alxmrs commented Sep 19, 2022

NGPVAN appears to use the Swaggar / OpenAPI spec to generate their documentation with readme.com. This means that if we could find access to the swaggar.json (e.g. the spec for their docs), we could use code generation tools (1, 2, 3) to automatically produce a Python API client for NGPVAN.

Detailed Description

I spent some time seeing if there was some way that I could scrape the NGPVAN API from the website. Using Chome Devtools, I was able to find snippets of JSON of the API spec per each endpoint. Due to a cross-site-origin header, I was unable to script out a way to get the specs en mass.

However, I noticed a strange pattern in their readme generated docs – namely this code:

const sdk = require('api')('@ngpvan/v1.0#5r6sg7sl74xoc30');

Looking further, I found that api is an npm library that makes use of the swagger api spec for the node SDK. By reverse engineering this library, I could probably get access to the swagger spec that NGPVAN has not made available.

Indeed, this line of code reveals what that junk is at the end of the string above:

https://github.com/readmeio/api/blob/a9c6ce28b3bcb6981e2135180c19f39ef6f025af/packages/api/src/fetcher.ts#L24

Thus, the URL for the swagger spec for NGPVAN is: https://dash.readme.com/api/v1/api-registry/5r6sg7sl74xoc30

Context

Code-generating an Python API Client has several benefits:

  • Saves on manually having to write a connector for every endpoint of the NGPVAN API
  • If the API changes, all we have to do is re-run the code generation system to get the latest API client.

It's worth saying, code-generation comes with tradeoffs, too:

  • Short of writing your own tool, using a generic code-generator often leaves you with opinions / cruft that you don't need or want.
  • Extra work would be required to bridge between Parson's tables and the code-generated output. It's likely that extra coding would be needed to adapt between the two paradigms, meaning more work beyond "just regeneration".

Possible Implementation

  1. https://swagger.io/tools/swagger-codegen/
  2. https://github.com/swagger-api/swagger-codegen
  3. https://github.com/OpenAPITools/openapi-generator

Priority

low priority -- this is more of an R&D project :)

@alxmrs alxmrs added the enhancement Impact - something should be added to or changed about Parsons that isn't causing a current breakage label Sep 19, 2022
@alxmrs
Copy link
Contributor Author

alxmrs commented Sep 19, 2022

This project will require more work than I anticipated; here's why:

The current pathway forward here seems to be to experiment with not-yet-release code generators (or, maybe writing my own), or to wait until there's official 3.1 support.

@alxmrs
Copy link
Contributor Author

alxmrs commented Sep 19, 2022

Here's a prototype client API that I've made with this generator:

https://github.com/alxmrs/ngpvan-api-client

YMMV.

@shaunagm shaunagm added the low priority Priority - this is a nice-to-have, is non-urgent, and/or has a minor overall imapact on Parsons label Nov 17, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Impact - something should be added to or changed about Parsons that isn't causing a current breakage low priority Priority - this is a nice-to-have, is non-urgent, and/or has a minor overall imapact on Parsons
Projects
None yet
Development

No branches or pull requests

2 participants