Fork me on GitHub
#ring-swagger
<
2016-05-12
>
josh.freckleton15:05:41

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"?

juhoteperi15:05:32

@josh.freckleton: I'm not sure if Swagger spec/JSON Schema allows describing that kind of information

juhoteperi15:05:38

At least you can add a comment using ring.swagger.json-schema/describe (or field)

juhoteperi15:05:23

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

juhoteperi15:05:45

But I'm not sure if Swagger-ui shows patten property

josh.freckleton16:05:55

@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?

juhoteperi16:05:55

hmm interesting

juhoteperi16:05:10

that exception is probably caused by defschema trying to add name to the pattern object

juhoteperi16:05:26

which fails because Pattern object can't have clojure meta-data

juhoteperi16:05:54

I'm not sayng it is impossible but I'm not sure it is possible either

juhoteperi16:05:18

the interesting fields are default and pattern

juhoteperi16:05:34

pattern should be automatically set when using Pattern as a Schema

juhoteperi16:05:59

You could manually set default field using ring.swagger.json-schema/field, but I'm not sure how Swagger-UI uses that

ikitommi16:05:22

defaults should work with the ui.

ikitommi16:05:06

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.

josh.freckleton16:05:54

@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))))

juhoteperi16:05:46

(field (s/constrained ...) {:default "123.12345, 123.12345"})

ikitommi16:05:58

Great! Would be good to write good docs for both libs. Just need... volunteers.

josh.freckleton16:05:53

@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 🙂

juhoteperi16:05:25

ClojureDocs is unfortunately only for Clojure Core

juhoteperi16:05:16

And yes, even parts of documentation would be useful

josh.freckleton16:05:08

Ya know, I've been more of an open-source user than contributor, how would i get started contributing to the documentation?

ikitommi16:05:31

I guess the github wiki pages would be a place for docs

juhoteperi16:05:38

Currently ring-swagger and compojure-api docs live in Github wiki

ikitommi16:05:25

there is a page! ;)

ikitommi16:05:32

1) figure out a page structure for the wiki 2) start writing pages

josh.freckleton16:05:08

cool, I'll take a look, I gotta learn this stuff before the wiki, so let's keep in touch 🙂 Thanks for your help!

ikitommi16:05:06

Writing there doesn't require any extra permissions, so if you have time and have an idea, feel free to write stuff. README can be simplified when things have been rewritten to wiki.