-
Notifications
You must be signed in to change notification settings - Fork 94
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
Add option to create references for models #274
base: master
Are you sure you want to change the base?
Conversation
4bbb46c
to
8ac2798
Compare
Codecov Report
@@ Coverage Diff @@
## master #274 +/- ##
==========================================
+ Coverage 88.01% 88.15% +0.13%
==========================================
Files 16 16
Lines 2052 2110 +58
Branches 183 185 +2
==========================================
+ Hits 1806 1860 +54
- Misses 63 65 +2
- Partials 183 185 +2
|
This is related to metosin/reitit#558 |
- Update Clojure to 1.11.1 so we can access `update-vals` - Add an option to swagger/transform to allow users to specify that they want to create references - When references are to be created create Swagger $refs and return the definitions under a ::swagger/definitions key in the top level map
3702f2a
to
98ffa58
Compare
Sorry @opqdonut, I've been away for the last month. This has now been updated, tested and ready for review. |
Thanks for the ping! I've got a lot on my plate right now but I'll try to have a look at this and remember the context. Feel free to ping me again if you don't hear back. |
Hi @opqdonut, just following up on this. Thanks, Hugh. |
Thanks for the ping! The code looks good in general (I'll have to do a careful reread though), but I have some doubts about how this interacts with some bugs & future developments we have on the reitit side. I'll try to get a small cabal together and think about these things. Have you tested this change with reitit? Or are you using some other routing library? |
Some notes:
|
:description "", | ||
:required true, | ||
:schema {:$ref "#/definitions/RefSpec"}}], | ||
:definitions {"RefSpec" {:type "object", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note: this :definitions
is then lifted to the very top level of the swagger doc by
We could add a test that documents this feature end-to-end on the reitit side.
Yes, this has (only) been tested with Reitit. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My apologies for the delay. I'm coming out of hibernation re: reitit stuff. I reread this PR and it looks good to go, I just have two new questions.
(reduce into (sorted-set)) | ||
(into []))}) | ||
(let [children' (map #(if (contains? % :$ref) | ||
(first (vals (::definitions %))) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should this actually look up the value of the ref instead of assuming that ::definitions
is a singleton?
(walk/postwalk | ||
(fn [x] | ||
(if (map? x) | ||
(reduce-kv | ||
(fn [acc k v] | ||
(if (accept? k) | ||
(-> acc (dissoc k) (merge (expand k v acc options))) | ||
(merge-with merge-only-maps (dissoc acc k) (expand k v acc options)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why was this change needed?
When users use Swagger to automatically generate clients inline models create can create multiple classes for the logically same model.
Add and option (
:refs?
) to create references and a high leveldefinitions
key to hold references.