Skip to content
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

Rough edges for swagger documentation #182

Closed
piotr-yuxuan opened this issue Feb 22, 2020 · 1 comment
Closed

Rough edges for swagger documentation #182

piotr-yuxuan opened this issue Feb 22, 2020 · 1 comment
Labels
duplicate This issue or pull request already exists for discussion Discussion is main focus of PR

Comments

@piotr-yuxuan
Copy link
Contributor

piotr-yuxuan commented Feb 22, 2020

Hi, thanks for this project which definitely is awesome! I've stumbled across this behaviour which one might counter-intuitive:

One can't describe a map attribute like this:

(malli.swagger/transform
  [:map [:my-uuid {:optional true
                   :swagger/example #uuid"eb4acd14-5321-4317-82e2-5895269f18a8"
                   :swagger/description "your most awesome uuid"}
                  uuid?]])

;; =>
{:type "object", 
 :properties {:my-uuid {:type "string", :format "uuid"}}, 
 :required []}

:optional is taken into account but :swagger/* keywords are ignored. As a result one has to follow this syntax with two attribute maps:

(malli.swagger/transform
  [:map [:my-uuid {:optional true}
                  [:and {:swagger/example #uuid"eb4acd14-5321-4317-82e2-5895269f18a8"
                         :swagger/description "your most awesome uuid"}
                        uuid?]]])
;; =>
{:type "object",
 :properties {:my-uuid {:type "string",
                        :format "uuid",
                        :x-allOf [{:type "string", :format "uuid"}],
                        :example #uuid"eb4acd14-5321-4317-82e2-5895269f18a8",
                        :description "your most awesome uuid"}},
 :required []}

For the sake of completion, this following syntax doesn't produce the expected result either as :optional now is ignored:

(malli.swagger/transform
  [:map [:my-uuid [:and {:optional true
                         :swagger/example #uuid"eb4acd14-5321-4317-82e2-5895269f18a8"
                         :swagger/description "your most awesome uuid"}
                        uuid?]]])

;; =>
{:type "object",
 :properties {:my-uuid {:type "string",
                        :format "uuid",
                        :x-allOf [{:type "string", :format "uuid"}],
                        :example #uuid"eb4acd14-5321-4317-82e2-5895269f18a8",
                        :description "your most awesome uuid"}},
 :required [:my-uuid]}

Would you agree with me to qualify this as a bug? would you be interested in fixing it, or open to pull requests about that?

Using version "0.4.2"

Cheers!

@ikitommi
Copy link
Member

ikitommi commented Mar 7, 2020

Thanks for reporting, this is duplicate to #86. Need to figure out a clean solution for this, options being:

  1. implement the parent/child relationship between entry & child schema (complex?)
  2. copy all but :optional entry-defintions to child schema properties (child m/form and m/properties show the entry-derived props, a surprise)
  3. same as 2 but move those (map m/form and m/properties don't show the entry props, a surprise)
  4. distinguish props from "derived props" (dunno how to make that work)

ideas welcome how to resolve this elegantly.

@ikitommi ikitommi closed this as completed Mar 7, 2020
@ikitommi ikitommi added duplicate This issue or pull request already exists for discussion Discussion is main focus of PR labels Mar 7, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
duplicate This issue or pull request already exists for discussion Discussion is main focus of PR
Projects
None yet
Development

No branches or pull requests

2 participants