colouring-cities / colouring-core

The Core Platform for the Colouring Cities Research Programme (CCRP)
https://colouringcities.org
GNU General Public License v3.0
48 stars 43 forks source link

API: swagger doc and definition for GET buildings #1308

Open tomalrussell opened 5 years ago

tomalrussell commented 5 years ago

Initial setup and documentation for the core buildings API call:

Resources

@mz8i do you have a link for the typescript-swagger tool you mentioned earlier?

mz8i commented 5 years ago

@tomalrussell the libraries are https://www.npmjs.com/package/typescript-rest and https://www.npmjs.com/package/typescript-rest-swagger - they aren't hugely popular right now so might be something to consider. I have used them in a couple projects

tomalrussell commented 5 years ago

Thanks @mz8i - looks like https://www.npmjs.com/package/tsoa is in the space and may be worth evaluating too.

Can you evaluate options and put together a proof of concept?

By default, I'd be cautious about adding dependencies and might prefer just using the swagger codegen to stub out methods and generate static HTML UI. I'm happy to look at what's available, though, and keen to see some running code that we can test out,

The key goals as far as I see it are:

  1. Consistent API for core data operations (to be used by web app, any future apps, programmatic upload/download tools)
  2. Neat swagger documentation site for technical users
  3. Refactor for maintainability
mz8i commented 5 years ago

tsoa looks good too. I don't have experience with it but it seems to be slightly more popular.

So far the differences I can see are:

It is worth noting that using any of the above relies on colouring-cities/colouring-core#348 (switching to TypeScript) - so that needs discussing and potentially implementing first.

The alternatives would be:

tomalrussell commented 5 years ago

I do like the sound of swagger-jsdoc: seems pretty pragmatic, relatively quick win option.

I think the API should never grow too big, so not too too worried about keeping it consistent - the main thing will be keeping on top of building attributes as we fill out the remaining sections.

So, suggest:

[1] http://www.catb.org/~esr/jargon/html/Y/yak-shaving.html

mz8i commented 5 years ago

I started out with moving out the buildings API code into a routes file and a controller file to decrease the size of server.js a bit: https://github.com/mz8i/colouring-london/commit/330642c89761e59f6d9d73d9d55d70655d8aac49

I also manually created an initial openapi.yml (Swagger is now called OpenAPI) file with the specification of some of the endpoints: https://github.com/mz8i/colouring-london/commit/bd1645c34c60da9fcaa7ea725434cdb2fd9c0ced

Some thoughts:

Any comments welcome, otherwise I will continue describing the other endpoints and possibly refactoring.

polly64 commented 8 months ago

@matkoniecz can you close?

matkoniecz commented 8 months ago

Depends on whether we want to have documentation of API and plan to spend time on that.

Good documentation would be useful for more automated edits.

polly64 commented 8 months ago

@matkoniecz shall I move to core then for discussion with international group?

matkoniecz commented 8 months ago

yes