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

Support for schemas as map values #53

Closed
acrao opened this issue Oct 3, 2014 · 4 comments
Closed

Support for schemas as map values #53

acrao opened this issue Oct 3, 2014 · 4 comments
Assignees

Comments

@acrao
Copy link

acrao commented Oct 3, 2014

I'm having some difficulty integrating a schema map using maybe in the map value. Here is the schema definition for the data that my API returns :

(def Boundary
  {:type (enum "MultiPolygon" "Polygon" "MultiPoint" "Point")
   :coordinates [Any]}) 

(def ReturnValue
  {:boundary (maybe Boundary) ;; can be of type Boundary or nil. In either case, 
                                                   ;; the key should always exist
   .....}

Here is the exception I'm running into when starting my server :

java.lang.IllegalArgumentException: error converting to json schema [:boundary (maybe {:type (enum "Point" "Polygon" "MultiPolygon" "MultiPoint"), :coordinates [Any]})]
    at ring.swagger.json_schema$properties$iter__10215__10219$fn__10220$fn__10228.invoke(json_schema.clj:117)
    at ring.swagger.json_schema$properties$iter__10215__10219$fn__10220.invoke(json_schema.clj:113)
    at clojure.lang.LazySeq.sval(LazySeq.java:40)
    at clojure.lang.LazySeq.seq(LazySeq.java:49)
    at clojure.lang.Cons.next(Cons.java:39)
    at clojure.lang.RT.next(RT.java:598)
......

Caused by: java.lang.IllegalArgumentException: don't know how to create json-type of: {:type (enum "Point" "Polygon" "MultiPolygon" "MultiPoint"), :coordinates [Any]}
    at ring.swagger.json_schema$eval10210$fn__10211.invoke(json_schema.clj:95)
    at clojure.lang.MultiFn.invoke(MultiFn.java:227)
    at ring.swagger.json_schema$__GT_json.doInvoke(json_schema.clj:47)
    at clojure.lang.RestFn.invoke(RestFn.java:410)
    at ring.swagger.json_schema$eval10190$fn__10191.invoke(json_schema.clj:86)
    at clojure.lang.MultiFn.invoke(MultiFn.java:227)
    at ring.swagger.json_schema$__GT_json.doInvoke(json_schema.clj:47)
    at clojure.lang.RestFn.invoke(RestFn.java:410)
    at ring.swagger.json_schema$properties$iter__10215__10219$fn__10220$fn__10228.invoke(json_schema.clj:113)
    ... 94 more

I'm using [metosin/compojure-api "0.16.2"]. I'm not quite sure what I'm missing here. Any pointers as to how I can get around this? Do I need to define a custom json-schema?

@Deraen
Copy link
Member

Deraen commented Oct 3, 2014

Define the schemas using schema.core/defschema. It attaches meta-data (name) to the maps which we need to generate the json-schema.

@Deraen
Copy link
Member

Deraen commented Oct 3, 2014

Though I think this should still work with the plain defs, ring-swagger should just use generated names for the schemas instead.

Looking at the code, I think there might be problem with handing non-named schemas with predicates like s/Maybe.

@ikitommi
Copy link
Member

ikitommi commented Dec 8, 2014

Sorry it took so long to fix, should work now with named schemas (in 0.16.6):

(defschema Boundary
  {:type (enum "MultiPolygon" "Polygon" "MultiPoint" "Point")
   :coordinates [Any]}) 

(defschema ReturnValue
  {:boundary (maybe Boundary)})

tests here https://github.com/metosin/ring-swagger/blob/master/test/ring/swagger/core_test.clj#L171

does not work with anonymous schemas (https://github.com/metosin/ring-swagger/blob/master/test/ring/swagger/core_test.clj#L341), will try to fix that later

cheers,

Tommi

@ikitommi
Copy link
Member

Fixed now, by @Deraen.

See https://github.com/metosin/compojure-api/blob/master/test/compojure/api/core_integration_test.clj#L535-L566

Will wrap the sub-walker as a separate lib so that it can be extended easier.

ikitommi added a commit that referenced this issue Mar 28, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants