Comments (9)
I guess your wrap-dashed-params middleware is only editing request :params. You should edit :query-params and :body-params because those are the parts of request that Compojure-api reads.
from compojure-api.
Ah, that makes sense. AFK. I'll try it out later.
Thanks for the quick reply.
- Arnab
http://arnab-deka.com
On Aug 11, 2014 7:12 PM, "Juho Teperi" [email protected] wrote:
I guess your wrap-dashed-params middleware is only editing request
:params. You should edit :query-params and :body-params because those are
the parts of request that Compojure-api reads.—
Reply to this email directly or view it on GitHub
#40 (comment)
.
from compojure-api.
Hi @Deraen, I changed my middleware and got the transliteration done. However, compojure-api (rather swagger and prismatic-schema) fails the incoming HTTP request as invalid. That's because
- the schema specifies
per_page
as the param.- That's what I want the swagger doc and api to look like, so it's natural from JS or Rails to call from.
- The incoming HTTP request indeed sends
per_page
and that's fine. - But the middleware now changes it to
per-page
and that does not match the schema anymore.- I want my app's clojure code to work with idiomatic dasherized names.
Is there a way around this (short of calling something like this on every route):
(ok (underscorize (api/index (dasherize params))))
I could write a HOF to make the duplication less, but that's still not an ideal solution, IMO. I basically want something that allows the schema/api to have _
s and the internal of my app to deal with -
instead of _
s.
from compojure-api.
I would resolve this with overriding compojure-api restucturing dispatch functions :query
and :query-params
. Like this:
(original here):
(require '[compojure.api.meta :as meta])
(declare dasherize) ;; implement
(declare un-dasherize) ;; implement
(defmethod meta/restructure-param :query-params [_ query-params acc]
(let [schema (meta/fnk-schema query-params)
pimped (un-dasherize schema)]
(-> acc
(update-in [:parameters :parameters] conj {:type :query :model pimped})
(update-in [:letks] into [query-params `(dasherize ~(meta/src-coerce! pimped :query-params :query))]))))
with this, you can say:
(GET* "/" []
:return Long
:query-params [per-page :- Long]
(ok per-page))
... while the input models (& swagger-docs) have the per_page
.
more info at doing your own restructuring at: https://github.com/metosin/compojure-api#creating-your-own-metadata-handlers
hope this helps.
from compojure-api.
works for me, will close this. please reopen if still need help with this one.
cheers.
from compojure-api.
Thanks, I forgot to reply here. We ended up writing an HOF to do the camel-case
on the way in and underscore
on the way out.
from compojure-api.
ok, great to hear you got it working. But what is HOF?
from compojure-api.
a higher order function, found it :)
from compojure-api.
Heh. sorry :) I thought that was lingua franca in Clojure :)
from compojure-api.
Related Issues (20)
- spec coercion to int HOT 1
- OpenAPI? HOT 5
- Add {:coercion :select-schema} option
- muuntaja encoder modifying swagger.json output HOT 1
- Vulnerability issue in dependent lib
- Missing security and deprecated meta
- Memory use rises with requests HOT 3
- Can't get Swagger UI to provide interface for arbitrary query params HOT 2
- fix broken url link in docs
- Clj-kondo linting issue HOT 2
- Consider bumping to Compojure 1.7.0 or Compojure 1.6.3
- Mixing compojure.api.sweet/defapi and compojure.core/defroutes
- How do I specify an optional field when accepting multipart-params for a request?
- Compojure 2.x should be backwards compatible with 1.x HOT 3
- Automatically push `context` parameters into endpoints when safe HOT 3
- Calculate coercers/schemas outside contexts when not dependent on request
- Pull out static parts of an otherwise-dynamic context
- Compile to non-linear routing strategies
- Immutable `restructure` interface
- Potential memory leak
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from compojure-api.