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

More informative errors #7

Open
rahulmutt opened this issue Dec 29, 2015 · 9 comments
Open

More informative errors #7

rahulmutt opened this issue Dec 29, 2015 · 9 comments

Comments

@rahulmutt
Copy link

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.

@Deraen
Copy link
Member

Deraen commented Dec 29, 2015

metosin/ring-swagger#77

@rahulmutt
Copy link
Author

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.

@ikitommi
Copy link
Member

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.

@ikitommi
Copy link
Member

the root cause should be fixed in [metosin/ring-swagger "0.22.2-SNAPSHOT"].

@rahulmutt
Copy link
Author

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.

@ikitommi
Copy link
Member

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.

@ikitommi
Copy link
Member

@rahulmutt
Copy link
Author

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?

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