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

Input & output validation with api-docs (swagger) #7

Open
ikitommi opened this issue Dec 20, 2016 · 17 comments
Open

Input & output validation with api-docs (swagger) #7

ikitommi opened this issue Dec 20, 2016 · 17 comments

Comments

@ikitommi
Copy link

Optional & pluggable, for handlers, maybe also for middleware. Schema is awesome and proven per today, Spec is the probable future. I could pull out a proposal for a common structure for input & output coercion with api-docs, based on our libs.

  • simple, data-driven core
  • optionally "easy" macro sugar with inferred models
  • pluggable implementation (schema, spec, other)
  • protocols for routing libs to collect routes for api-docs
  • swagger-docs (ring/spec-swagger)

what do you think?

@yogthos
Copy link
Member

yogthos commented Dec 20, 2016

Great idea, and makes sense to base it on Metosin libs as they're real world tested already. :)

@ikitommi
Copy link
Author

Hi. Finally having time for this. Just talked with @miikka, we will do first drafts of the data-model, for both schema (me) & spec (Miikka). Will integrate the spec-side into the current JVM-based libs too, starting with compojure-api. No plan yet how the code should be split into modules/repos, we'll start with separate code-base(s), let's chat on merging/re-packaging these later.

@ikitommi
Copy link
Author

@yogthos
Copy link
Member

yogthos commented Feb 11, 2017

I like your idea of leveraging the metadata for this, and it looks like using Schema or Spec would work nearly identically.

@ikitommi
Copy link
Author

ikitommi commented May 5, 2017

The validation part for specs is done'ish, with https://github.com/metosin/spec-tools, I'll write examples on schema & spec -enforced handlers and middleware next.

@yogthos
Copy link
Member

yogthos commented May 5, 2017

This is looking very nice. :)

@ikitommi
Copy link
Author

Went few steps back and tried to figure out how to handle the specs/schemas should with (nested) routing like compojure-api does. Ended up writing a small routing library, which supports route meta-data (like middleware & partial route specs/schemas) as first class citizen. Actually quite happy how the lib turned out.

Anyway, about to re-implement the spec/schema validation now, wrote these:

As the coercion is not tied to routing lib and Macchiato uses bidi, might end up spinning a another single-purpose ("just coercion") micro-lib, but will start from there. Targeting anyway Clojure(Script) so should work with Macchiato oob.

@yogthos
Copy link
Member

yogthos commented Aug 17, 2017

That looks really nice, and Macchiato should allow swapping routing easily. At some point I'm thinking of adding Luminus style profiles, it looks like it should be very easy to swap between Bidi and Reitit.

Out of curiosity, have you had a chance to use Macchiato for anything yet?

@ikitommi
Copy link
Author

Sounds great. Have just poked with the samples, no real project for yet. But a new customer project starting next month, going to give it a spin.

@yogthos
Copy link
Member

yogthos commented Aug 18, 2017

Exciting :) Definitely let me know how things go, also if you'd be interested I can add you to maintainers for the org. Oh wait nevermind, looks like you're already there. :)

@ikitommi
Copy link
Author

Coercion is done going forward in reitit, tests run on node, but not tested on actual node-based web server. There are separate modules now for: coercion, spec-coercion and schema-coercion.

Coercion can be applied by using reitit directly + there could be an example how to run this with bidi.

Swagger-docs ~next.

@yogthos
Copy link
Member

yogthos commented Nov 27, 2017

I'd be open to swapping bidi out for reitit, or adding support for profiles similarly to luminus. I think if reitit will ultimately provide validation and coercion, it would be a better default.

@ikitommi
Copy link
Author

Reitit 0.1.0 has shipped, with support for schema & spec coercion for Clojure/Script. 0.1.1-SNAPSHOT has now swagger-support ported also for Clojure/Script!

reitit-examples are for Clojure now, would be good to make a Macchiato example too.

https://github.com/metosin/reitit/blob/master/examples/ring-swagger/src/example/server.clj

Only differences between ring & macchiato at the moment:

  • ring.adapter.jetty
  • ring.middleware.params/wrap-params
  • muuntaja.middleware/wrap-format
  • serve swagger-ui somehow

TODO:

  • make a Macchiato example (anyone?)
  • abstract the differences so that identical apps could be run on both JVM & Node (a separate issue, but thinking aloud)

@yogthos
Copy link
Member

yogthos commented Apr 20, 2018

I'm definitely be interested in taking a go at using Reitit in Macchiato, but I've been a bit swamped lately. If anybody gets around to it before I do, that would be very welcome.

@nenadalm
Copy link
Contributor

I was playing wih Macchiato and Reitit a bit and and here is the result so far: https://github.com/nenadalm/spa-demo.

Swagger with spec coercion, validation works (only with json for now). I intend to do some demo of project with single page app using re-frame, api using Macchiato and server side rendering.

It might take a while with current speed (if ever), but basics with Macchiato and Reitit seems to be working. I hope to use that at work some day :)

@yogthos
Copy link
Member

yogthos commented Sep 23, 2018

Thanks, that looks great. I keep to switch Macchiato to use Reitit as the default at some point. This will be helpful as a starting point.

@ikitommi
Copy link
Author

Awesome!

Just asked about the record walking cljs issue on CLJS Jira, would like to get your spec-tools pr merged.

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

No branches or pull requests

3 participants