spec-tools icon indicating copy to clipboard operation
spec-tools copied to clipboard

Add option to create references for models

Open HughPowell opened this issue 2 years ago • 8 comments

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 level definitions key to hold references.

HughPowell avatar Apr 10 '23 23:04 HughPowell

Codecov Report

Merging #274 (3702f2a) into master (d15ec93) will increase coverage by 0.13%. Report is 4 commits behind head on master. The diff coverage is 94.23%.

@@            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     
Files Changed Coverage Δ
src/spec_tools/swagger/core.cljc 96.13% <94.23%> (-1.43%) :arrow_down:

... and 1 file with indirect coverage changes

codecov-commenter avatar Aug 28 '23 10:08 codecov-commenter

This is related to metosin/reitit#558

opqdonut avatar Aug 28 '23 10:08 opqdonut

Sorry @opqdonut, I've been away for the last month. This has now been updated, tested and ready for review.

HughPowell avatar Sep 20 '23 00:09 HughPowell

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.

opqdonut avatar Sep 22 '23 13:09 opqdonut

Hi @opqdonut, just following up on this. Thanks, Hugh.

HughPowell avatar Oct 04 '23 04:10 HughPowell

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?

opqdonut avatar Oct 04 '23 04:10 opqdonut

Some notes:

  • this adds :definitions for spec swagger
    • ~only inside parameters~
    • ~automatically, i.e. every parameter gets a :definition~
    • everywhere, lifted to the very top of the swagger fragment generated
      • see note https://github.com/metosin/spec-tools/pull/274#discussion_r1345199233
    • :definitions are given for swagger fragments that have a :title
  • meanwhile https://github.com/metosin/malli/pull/863 added :definitions for malli swagger
    • everywhere, lifted to the very top level of the swagger fragment
    • :definitions are based on the malli registry structure

opqdonut avatar Oct 04 '23 05:10 opqdonut

Have you tested this change with reitit? Or are you using some other routing library?

Yes, this has (only) been tested with Reitit.

HughPowell avatar Oct 06 '23 05:10 HughPowell