Fork me on GitHub
#ring-swagger
<
2016-11-25
>
sammikko06:11:08

if I have hyphens in my schema keys, like {:foo-tastic s/Int} is it possible to configure Ring Swagger to do some kind of property name conversion from foo-tastic to foo_tastic?

sammikko06:11:41

I'm wondering if its worth the trouble to use hyphens in schema keywords as they are causing trouble when converted to JSON.. but its the Clojure convention

ikitommi06:11:17

there is a helper function ring.swagger.swagger2/transform-operations to walk through the endpoints before passing into ring-swagger. Still, you would have to do it on three places: 1) after parsing the body 2) when returning the body c) for the docs. Did that once, was not worth it. But, could be done. Example of a ring-swagger doc transformation: https://github.com/metosin/ring-swagger#transforming-the-swagger-spec

sammikko06:11:49

thanks.. so do you just use underscores in your schemas if you're exposing some APIs ?

sammikko07:11:50

or more accurately, avoid hyphens? 🙂

ikitommi07:11:34

depends on the project, have tried ‘em all I guess 🙂 Hyphens work with javascript too btw. Or are they illegal in the JSON spec?

sammikko07:11:10

yeah it works.. but i'd prefer the users of API to be able to use it like obj.property_name instead of obj["property-name"] .. im not sure of JSON spec

sammikko08:11:05

in ring swagger spec there's the :schema map entry.. does it have to be a symbol like MySchema or can it be just inline map ? I suppose inline should work ?

sammikko09:11:41

trying a different route, transforming the schema before i pass it to ring swagger.. using this to transform the schema: https://github.com/gfredericks/schema-bijections/blob/master/README.md

sammikko09:11:29

i can transform the schema quite easily.. but for some reason :references ends up with my schemas, but there is no :properties

sammikko09:11:08

im not sure how the resolutions to :definitions works, but my transformed schema has :name in its metadata.. i suppose its required

ikitommi10:11:44

@sammikko yes, the $ref is taken from the name. Haven’t uses the bijections lib, looks cool. There is also https://github.com/metosin/schema-tools which retains the schema meta-data.

ikitommi10:11:00

with walkers you could change the key names if that’s the case.

sammikko10:11:23

cool.. i think i found my problem.. i converted the keys in my schema map from keywords to strings and that didnt work in ring swagger.. im not sure if thats even supported in schema 🙂

sammikko10:11:35

now i just rename the keywords and seems to work

sammikko10:11:21

cool, ill check out schema-tools too

ikitommi10:11:40

awesome! Schema allows String keys, ring-swagger might not be happy with those. Please write an issue if you need that.

ikitommi10:11:16

there is a lovely use-case for Schema walkers in the schema-viz lib, like https://github.com/metosin/schema-viz/blob/master/src/schema_viz/core.clj#L81-L92

ikitommi10:11:44

bookmarked the bijections, thanks for the tip.

sammikko10:11:26

oh yeah, we actually used schema-viz too 🙂 it works but we ran into trouble when running on a headless server: No X11 DISPLAY variable was set, but this program performed an operation which requires it., compiling:(rhizome/viz.clj:27:1)

sammikko10:11:40

some problem in the underlying lib