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

[Question] how to mix and match Compojure Routes and static resources in defapi #48

Closed
priyatam opened this issue Sep 16, 2014 · 4 comments

Comments

@priyatam
Copy link

How do you change the default context of swagger-ui (default is "/") and include a static resource handler under the same?

The following, for example, doesn't work:

(defroutes static
    (route/resources "/public"))

(defapi router
  ;;(static) => wrong number of routes passed in core/routes/fn--1828
  (swagger-ui "swagger") ;; doesn't serve under /swagger, 404-not found
  (swagger-docs :title "Longitude api")
  (swaggered "api" :description "Longitude User who is an Organization (not a Person)"
    (context "/api" []
       (GET* "/org" []  (ok  {}))))

I also tried to include compojure.api.middleware.public-resource-routes under defapi, but no success.

@ikitommi
Copy link
Member

Hi.

You need a leading / in the path of swagger-ui. Also, you are calling (static) as a function, although it's just a value. So this should work ok:

(defapi router
  static
  (swagger-ui "/swagger")
  (swagger-docs :title "Longitude api")
  (swaggered "api" :description "Longitude User who is an Organization (not a Person)"
    (context "/api" []
       (GET* "/org" []  (ok  {}))))

@priyatam
Copy link
Author

That fixed the resource handler, but now I get a new error:

(defapi router
  static
  (swagger-ui "/swagger")
  (swagger-docs :title "Longitude api" )
  (swaggered "api" :description "Longitude User"
    (context "/api" []      
      (GET* "/org" []
        :summary "Dummy lookup"
        :return [{:created Boolean}]       
        (ok {:created true}))

Error:
json { "errors": "(not (sequential? {:created true}))" }

Thoughts?

@ikitommi
Copy link
Member

The return values are also validated against the :return schema and internal-server-error is thrown if the return value does not match the schema. Your :return [{:created Boolean}] indicates your route returns a Vector (of Maps). To return just one, you should have :return {:created Boolean}.

There is a good set of samples at https://github.com/metosin/compojure-api/blob/master/examples/src/examples/thingie.clj.

@priyatam
Copy link
Author

Thanks for your inputs. I've reverted my code to plain Compojure/Liberator for now and will revisit Schema in the future.

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

2 participants