Question: This example doesn't run for me. @ikitommi if you add a :description to a Spec Record it doesn't show up in the description in swagger if its a body param but it does if its a path param. I take it st is the spec-tools ns?

Asked By
drewverlee
Asked At
2017-12-12 00:40:28

Found 15 possible answers.

User Answered At Possible Answer
ikitommi 2017-12-12 08:58:02 oh, that’s not intended. The code seems to retain the :description ( https://github.com/metosin/spec-tools/blob/master/src/spec_tools/json_schema.cljc#L264-L276 ), but we might need to lift it so some other field for the swagger body-params. The test for the swagger params is here: https://github.com/metosin/spec-tools/blob/master/test/cljc/spec_tools/swagger/core_test.cljc#L188-L240 . PR welcome to fix that.
mgrbyte 2017-12-18 14:10:07 If I have a spec that defines a user with some roles, which is a set, .e.g: (s/def ::availble-roles #{:admin :view :edit}) , and user post JSON data that's supposed to contain e.g new users: {"new": [{"emai": "blah@blah.com mailto:blah@blah.com ", "roles": ["admin"]}]} - wondering how's best to go about doing this w/compojure-api + spec. Two sets of specs, one for the expected JSON payload (defining roles as a vector of strings) and another for the application (what I want in the application - a set of keywords)?
ikitommi 2017-12-19 05:56:31 @mgrbyte good question. Currently, spec-tools doesn’t try to quess the type from sets, e.g. #{:admin :view :edit} doesn’t have a type. So we have to hint it to be a ´:keyword`. Like this: https://github.com/metosin/spec-tools/issues/96 It seems there is as issue of this, waiting for a friendly PR: https://github.com/metosin/spec-tools/issues/60 @ikitommi uploaded a file: type hinting sets https://clojurians.slack.com/files/U055NJ5CC/F8FVDBNLQ/type_hinting_sets.clj
ashaeron 2017-12-21 10:43:32 Hello, I've been trying out compojure-api 2 and wondering if I can disable response encoding/coercion if my response Content-Type header is for instance text/csv or application/pdf ? I guess I have to first create a format ? https://github.com/metosin/muuntaja/wiki/Creating-new-formats https://github.com/metosin/compojure-api/wiki/2.0.0-Content-Negotiation-(with-Muuntaja )
wontheone1 2017-12-24 16:51:30 hi, is there a way to generate swagger.json file from ring-swagger? Like output json as a static asset and serve it? specifying no-body responses supported in compojure-api? how do you do that ? thank you. (sorry for massive amounts of messages) @wontheone1 uploaded a file: Untitled https://clojurians.slack.com/files/U354VUKQA/F8KP4U7PE/-.clj {:status 201} for example. I don't want to return any bodies. I tried the following things but they broke Swagger UI. So for now I am just putting there a dummy schema that's not really necessary for me One thing I cannot find any example is ... specifying responses that has no body Hi I got the multiple responses thing working the problem was elsewhere ! sorry about that. I am not sure if I am doing something wrong or there s bug :) Could I please show an example of having multiple response model with json response ? @wontheone1 uploaded a file: Untitled https://clojurians.slack.com/files/U354VUKQA/F8KF5FW75/-.clj @wontheone1 uploaded a file: Untitled https://clojurians.slack.com/files/U354VUKQA/F8K24FJF3/-.clj I found one example with multiple responses definitions, https://github.com/metosin/compojure-api/blob/master/examples/thingie/src/examples/thingie.clj#L105 . But would there be a way to have same status codes but different schema ? (I know it's not the best thing to do but just wondering) about inputstream in body, I forgot that I had to slurp (because with techstack I use in my company, the body is already string without slurp, so I never had to slurp the body in tests). Now that I slurp and parse-string the body is as expected. but still I wonder what's the purpose of :compojure.api.meta/serializable? true I would like to know how do you test endpoints by compojure-api in real world applications... Here I am expecting JSON in :body but I am getting inputstream. Also :compojure.api.meta/serializable? true part is not something I am expecting... Though when I make http calls with POSTMAN(curl substitute) then I get expected response. Is this expected behavior? @wontheone1 uploaded a file: Untitled https://clojurians.slack.com/files/U354VUKQA/F8JSZPTGR/-.clj Hi, I was testing a Get endpoint made with compojure-api with Midje & Ring mock. I found something weird. I found how to add paths in data-driven way :slightly_smiling_face: they had to be nested in context as in https://github.com/metosin/compojure-api/blob/master/examples/resources/src/example/handler.clj Thank you in advance! I assumed these are interchangeable alternatives. I want to use the data-driven approach (the first one). but there is no "path" (like "/hello-async") in the second example. I'd like an example with data-driven approach where a path is included, if possible please :slightly_smiling_face: @wontheone1 uploaded a file: Untitled https://clojurians.slack.com/files/U354VUKQA/F8L795EKG/-.clj @wontheone1 uploaded a file: Untitled https://clojurians.slack.com/files/U354VUKQA/F8JRHR9CH/-.clj Hello, while trying to use compojure-api, I have a question about exactly how to use this. In readme there is some examples, that 's really good :slightly_smiling_face: but I would like to know if there is similar convenient way in ring-swagger as well {:ui "/" At least I found that if I use composure-api, then I can just pass swagger schema as handler to jetty then the UI is served on :swagger Or do you use some kind of json generating library (cheshire) to manually generate json file and serve it as UI? what is the best way to generate swagger ui when using ring-swagger ? Helps are much appreciated! thanks! happy holidays!
hawari.rahman17 2017-12-28 03:01:12 Hi @wontheone1 , since compojure-api built on top compojure , and with that, ring , any valid ring response map will suffice.
{:status 204
You might want to learn more about it here https://github.com/ring-clojure/ring/wiki/Concepts :body ""} :headers {}
ikitommi 2017-12-28 08:37:41 hi @wontheone1 , back from the holidays, good that you have mostly resolved all the issues. Does it work if you just use empty map as the response schema? eg. {http-status/created {} the :compojure.api.meta/serializable? true is internal stuff, marking that the response should be encoded (to support encoding of primitives). I think the encoder should remove it as it’s not useful info outside of c-api. But, you can ignore it. and you can use s/Any as the Schema, for “anything”. Not exactly what you want, but works.
wontheone1 2017-12-28 14:53:59 @hawari.rahman17 Yes; I know how to construct ring response with map but my question was about how do you define schema for response with no body for Swagger. Thank you. I see @ikitommi suggested workaround for my problem below !
ikitommi 2017-12-28 14:55:17 … and meant {http-status/created {:schema s/Any}}
wontheone1 2017-12-28 14:58:28 @ikitommi Thanks s/Any or {} works ! I am confused, I could swear I tried the empty map and it didn't work yesterday but it's working now @ikitommi I can easily find out how to generate swagger.json, and expose it with compojure-api but found nothing about it from https://github.com/metosin/ring-swagger . Is similar thing supported? (I mean if you have Swagger definition in clojure map then of course you can generate json/yaml with some library and write using io and stuff but I just assumed this is common case and ring-swagger might as well do all the chores for us) I think for the new users, this kind of cases might be not so obvious, so some examples might help... If you agree I might submit PR for some examples or README improvement I proly did something wrong yesterday elsewhere
ikitommi 2017-12-28 15:13:50 Just expose the result of ring.swagger.swagger2/swagger2 function. If you need JSON String, run cheshire.core/generate-string to it.
wontheone1 2017-12-28 15:19:26 @ikitommi you mean the swagger-json function? result is plain clojure map I think. So putting that in JSON and exposing it as Swagger UI is the work of library user? I got it thanks Using existing function here, https://github.com/metosin/compojure-api/blob/4b5e2f8e59ddb915f70b5e75f70a25ea20f142b0/test/compojure/api/test_utils.clj#L131 to core library, might be enough. If you think this would help, I could try to submit a PR too. I think we can include this function as one of core library function so that compojure-api user can also easily test the validity of their definitions as in https://github.com/metosin/compojure-api/blob/4b5e2f8e59ddb915f70b5e75f70a25ea20f142b0/test/compojure/api/sweet_test.clj#L211 I have a few points about compojure-api library, please consider when you have time. I see there is get-spec function used in tests. https://github.com/metosin/compojure-api/blob/4b5e2f8e59ddb915f70b5e75f70a25ea20f142b0/test/compojure/api/sweet_test.clj#L104 I just thought (similar to compojure-api) there would be automagical way to exposing it to Swagger UI. but nevermind
ikitommi 2017-12-28 15:48:03 @wontheone1 have you checked https://github.com/metosin/compojure-api/blob/master/src/compojure/api/validator.clj ?
wontheone1 2017-12-28 15:50:49 @ikitommi no Thanks for pointing out !! after seeing test-util get-spec is used I thought there was no way :smile: ... Documentation could be improved on this one too
ikitommi 2017-12-28 15:51:20 doc PRs would be most welcome :) (a whole new static doc site would be super)

Related Questions