This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2016-05-12
Channels
- # admin-announcements (1)
- # aleph (1)
- # arachne (10)
- # beginners (6)
- # boot (81)
- # braveandtrue (3)
- # cider (42)
- # cljs-dev (1)
- # cljs-edn (52)
- # cljsjs (9)
- # cljsrn (9)
- # clojure (62)
- # clojure-austin (1)
- # clojure-belgium (11)
- # clojure-berlin (2)
- # clojure-gamedev (2)
- # clojure-greece (1)
- # clojure-russia (73)
- # clojure-uk (98)
- # clojurescript (156)
- # community-development (4)
- # component (3)
- # cursive (30)
- # datascript (10)
- # datomic (17)
- # emacs (5)
- # events (1)
- # hoplon (315)
- # jobs (1)
- # jobs-discuss (3)
- # lein-figwheel (6)
- # luminus (18)
- # off-topic (13)
- # om (130)
- # other-languages (122)
- # re-frame (32)
- # reagent (27)
- # rethinkdb (6)
- # ring (2)
- # ring-swagger (31)
- # spacemacs (4)
- # untangled (6)
- # yada (30)
I have a GPSType
defined like this:
(s/defschema GPSType (s/constrained s/Str
(fn gps-type? [x] (re-matches #"\d{3}\.\d{5}, ?\d{3}\.\d{5}" x))))
How can I get swagger to automatically generate something that matches that schema, even just something hard coded such as "123.45678, 123.45678"
?@josh.freckleton: I'm not sure if Swagger spec/JSON Schema allows describing that kind of information
At least you can add a comment using ring.swagger.json-schema/describe
(or field
)
Ah, and Schema infact supports Regex as a type: (s/defschema GPSType #"\d{3}\.\d{5}, ?\d{3}\.\d{5}")
should properly set JSON Schema pattern
property, which is impossible to automatically detect from constrained+fn
But I'm not sure if Swagger-ui shows patten property
@juhoteperi: ya, I like how swagger-ui
aufomatically populates sample requests, and was hoping I could populate a gpstype with even something hardcoded... hmmm...
and your suggested regex type throws an error: java.util.regex.Pattern cannot be cast to clojure.lang.IObj
you think what I'm asking for is impossible?
hmm interesting
that exception is probably caused by defschema trying to add name to the pattern object
which fails because Pattern object can't have clojure meta-data
I'm not sayng it is impossible but I'm not sure it is possible either
https://github.com/OAI/OpenAPI-Specification/blob/master/versions/2.0.md#parameter-object
the interesting fields are default
and pattern
pattern
should be automatically set when using Pattern as a Schema
You could manually set default
field using ring.swagger.json-schema/field
, but I'm not sure how Swagger-UI uses that
there is btw the schema-tools.core/default
nowadays, could be integrated into ring-swagger. Also can be used to actually coerce the default value in.
@juhoteperi: @ikitommi thanks, so I'm looking through source code and sparse documentation, and trying to learn how to apply a default... Any suggestions with how I'd do that to something like:
(s/defschema GPSType (s/constrained s/Str
(fn gps-type? [x] (re-matches #"\d{3}\.\d{5}, ?\d{3}\.\d{5}" x))))
(field (s/constrained ...) {:default "123.12345, 123.12345"})
@juhoteperi: awesome, thanks!
@juhoteperi: ps, just tried that, works great in swagger-ui @ikitommi: Would I be useful helping write parts of it, without taking on the whole doc-writing project? Or would there be a way to integrate with clojure-docs? I haven't used better documentation that that site 🙂
ClojureDocs is unfortunately only for Clojure Core
And yes, even parts of documentation would be useful
Ya know, I've been more of an open-source user than contributor, how would i get started contributing to the documentation?
Currently ring-swagger and compojure-api docs live in Github wiki
cool, I'll take a look, I gotta learn this stuff before the wiki, so let's keep in touch 🙂 Thanks for your help!