metosin / metosin/schema-tools
Support for `ring.swagger.json-schema/describe`
- Dominant language
- Clojure
- Stars
- 110
- Forks
- 15
- Avg merge
- 6m
- Merged PRs (30d)
- 1
Description
Hello,
In my project I have used `ring.swagger.json-schema/describe` to annotate some types
```clojure
(require '[ring.swagger.json-schema :refer [describe]] '[schema.core :as s])
(s/defschema Foo (describe s/Str "Not very bar"))
```
However the `schema-tools.swagger.core/transform` failed on this
```clojure
(require '[schema-tools.swagger.core])
(schema-tools.swagger.core/transform Foo nil)
;; Execution error (ExceptionInfo) at schema-tools.swagger.core/not-supported! (core.cljc:56).
;; don't know how to convert ring.swagger.json_schema.FieldSchema@8d6443 into a Swagger Schema.
```
I have had to do the following
```clojure
(import ring.swagger.json_schema.FieldSchema)
(extend-protocol schema-tools.swagger.core/SwaggerSchema
FieldSchema
(-transform [this opts]
(schema-tools.swagger.core/transform (.schema this) opts)))
```
to get it working.
I am not sure if there should be support for this module in schema-tools, but at least it gave me some headache while trying to move from compojure-api to Reitit, so maybe it should be supported somewhere in the toolchain if I am not alone using that function !
Contributor guide
Research direction
Start by reproducing the failure at schema-tools.swagger.core/transform with ring.swagger.json-schema/describe and inspect the FieldSchema value from ring.swagger.json_schema. Read the SwaggerSchema protocol and the not-supported! path in schema-tools.swagger.core. Done means FieldSchema is transformed without the consumer defining an extension protocol.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- clojure
- Domain
- api
- Issue type
- Feature
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100