Fork me on GitHub
#ring-swagger
<
2024-03-13
>
Leena Hyvönen10:03:13

Hi, we are using ring-swagger and to make references to our schema objects work, we had to change coercion to reitit.coercion.malli/coercion (The repository where the schema objects are validates objects using malli). Now swagger builds the swagger page nicely and the objects are visible, but when making requests there is this exception:

2024-03-13 12:32:23.058 ERROR [vcm.api.exception] - HTTP handler failed due to unhandled exception at endpoint 'POST /v1/agent'
clojure.lang.ExceptionInfo: Request coercion failed
	at reitit.coercion$request_coercion_failed_BANG_.invokeStatic(coercion.cljc:47)
	at reitit.coercion$request_coercion_failed_BANG_.invoke(coercion.cljc:45)
	at reitit.coercion$request_coercer$fn__5046.invoke(coercion.cljc:95)
	at reitit.coercion$coerce_request$fn__5059.invoke(coercion.cljc:122)
	at clojure.lang.PersistentArrayMap.kvreduce(PersistentArrayMap.java:429)
	at clojure.core$fn__8525.invokeStatic(core.clj:6908)
	at clojure.core$fn__8525.invoke(core.clj:6888)
	at clojure.core.protocols$fn__8257$G__8252__8266.invoke(protocols.clj:175)
	at clojure.core$reduce_kv.invokeStatic(core.clj:6919)
	at clojure.core$reduce_kv.invoke(core.clj:6910)
	at reitit.coercion$coerce_request.invokeStatic(coercion.cljc:120)
	at reitit.coercion$coerce_request.invoke(coercion.cljc:119)
	at reitit.ring.coercion$fn__5528$fn__5530$fn__5531.invoke(coercion.cljc:39)
	at muuntaja.middleware$wrap_format_request$fn__8988.invoke(middleware.clj:114)
	at reitit.ring.middleware.exception$wrap$fn__33923$fn__33924.invoke(exception.clj:49)
	at muuntaja.middleware$wrap_format_response$fn__8992.invoke(middleware.clj:132)
	at muuntaja.middleware$wrap_format_negotiate$fn__8985.invoke(middleware.clj:96)
	at ring.middleware.params$wrap_params$fn__10433.invoke(params.clj:75)
	at reitit.ring$ring_handler$fn__4822.invoke(ring.cljc:328)
How could we make both swagger and the requests to our api work?

Leena Hyvönen10:03:11

Hmm, it seems that if the object to be POSTed (for example agent) has correct data and format, then everything works. If the object is somehow faulty, the errors telling where the object fails to meet the requirements go into :data like [:fn {:error/message "value should be a valid kebab-case string"}