ring-swagger-ui
ring-swagger-ui copied to clipboard
More informative errors
I'm currently getting an error when I access the root path of my compojure-api app:
500 : {"type":"unknown-exception","class":"java.lang.RuntimeException"} http://localhost:8080/swagger.json
Then when I visit http://localhost:8080/swagger.json, I get a more informative error message, but it's still pretty obscure.
2015-12-29 23:05:48,250[qtp974317728-29 [0m[32m[43m849b[0m] ERROR compojure.api.exception - Bad explicit key: class java.lang.String
java.lang.RuntimeException: Bad explicit key: class java.lang.String
at schema.core$explicit_schema_key.invoke(core.clj:725)
at ring.swagger.json_schema$properties$iter__14975__14979$fn__14980.invoke(json_schema.clj:240)
...
So I understand the problem is with one of my schema specified in :return. I can debug this with trial-and-error going by adding/removing one schema at at time. But I was wondering if there was a way to get much more precise error messages like which route caused the failure, etc.
https://github.com/metosin/ring-swagger/issues/77
Ok so I just used lein-git-deps to use the updated ring-swagger from github (specifically, commit 0b854b6). Now when I run the app, there are no more exceptions.
This was the schema that was causing problems:
:return {:a s/Str
:b {s/Str {:c s/Str
:d s/Int}}}
The /swagger.json endpoint is returning a JSON file, but now there's a new problem: From the main /index.html endpoint (swagger-ui), the following message is shown:
fetching resource list: http://localhost:8080/swagger.json; Please wait.
and it gets stuck there. This problem happened when I tried to remove the problematic schema (omitting the :return keyword) before adding the updated ring-swagger. After adding the new dependency, I added back the :return keyword for the problematic schema and the same behavior shows up again. Any ideas what's causing it to get stuck? There are no exceptions in the logs.
Hi. Agree on better error messages. For this case: your schema has a s/Str as a key, which is not currently allowed. s/Keyword should work. Will fix that soon.
the root cause should be fixed in [metosin/ring-swagger "0.22.2-SNAPSHOT"].
Cool. Yeah that fixes it. But I still have the "stuck" problem. The JavaScript console gave the following error:
Uncaught TypeError: Swagger 2.0 does not support null types ([object Object],). See https://github.com/swagger-api/swagger-spec/issues/229.
I have checked all my schemas and I do not have any "null" types.
UPDATE: After looking through my schemas for anything that can be "nullable" I found
(s/conditional empty? s/Str :else sc/Email)
That's probably bad API design from my end, but I take it that (s/conditional) is not supported either? Removing that conditional allowed me to see the API listing again.
So, there is no swagger-bindings for sc/Email, causing nil, which was not stripped away from s/Conditional output, causing the problem. fixed in the latest [metosin/ring-swagger "0.22.2-SNAPSHOT"].
But, Swagger has dropped support of the anyOf, so the generated spec of s/conditional is no more valid swagger spec. Might be back in the next version of the spec. There are some published workarounds, will apply the at some point.
https://github.com/metosin/ring-swagger/commit/7a94465c4db801a4f740b633c2aa168975ad4931
Currently, I use [kixi/schema-contrib "0.2.0"] for the sc/Email schema and the sc/URI which are sprinkled throughout the codebase inside of maps. What steps do I take to support these and add documentation for them so that they show up in the Swagger UI when I click on the endpoint?
See https://github.com/metosin/ring-swagger/blob/master/README.md#schema-to-swagger-json-schema-conversion.