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

populating swagger description from schema docstring #76

Open
murtaza52 opened this issue Dec 1, 2015 · 4 comments
Open

populating swagger description from schema docstring #76

murtaza52 opened this issue Dec 1, 2015 · 4 comments

Comments

@murtaza52
Copy link

Hi,

I have defined my schemas using defschema and have given them docstrings. When generating the swagger json, I dont see the docstring being extracted.

The swagger spec provides a :description key, is it possible to populate that key using the docstring for a given schema ?

Thanks,
Murtaza

@ikitommi
Copy link
Member

ikitommi commented Dec 1, 2015

Hi,

Yes, we should use that. There is already support for it in schema-tools (https://github.com/metosin/schema-tools/blob/master/src/schema_tools/core.cljc#L246-L255), but ring-swagger doesn't use that yet. Would you like to integrate that in?

@murtaza52
Copy link
Author

Sure would like to give it a shot. Which function should I look at in
ring-swagger to begin with ?

On Tue, Dec 1, 2015 at 8:38 PM, Tommi Reiman [email protected]
wrote:

Hi,

Yes, we should use that. There is already support for it in schema-tools (
https://github.com/metosin/schema-tools/blob/master/src/schema_tools/core.cljc#L246-L255),
but ring-swagger doesn't use that yet. Would you like to integrate that in?


Reply to this email directly or view it on GitHub
#76 (comment)
.

@lyderichti59
Copy link

Hi,
I've written my own wrapper of schema.core/defschema to have the same feature.
Sharing here just in case it inspires someone :)

(defmacro defschema
  "Same as `s/defschema` but adds docstring as swagger's schema description"
  [name docstring form]
  `(s/defschema ~name ~(str docstring)
     (vary-meta ~form assoc-in [:json-schema :description] ~docstring)))

@kevinkrouse
Copy link

kevinkrouse commented Jun 20, 2024

I think this is possible, if not a little awkward:

(s/defschema PhoneRecord
  (rsjs/describe
    {:phone (rsjs/describe s/Str "The phone number")
     (s/optional-key :label) (rsjs/describe s/Str "An optional label")}
    "Contact phone record"
    :example {:phone "555-1212" :label "Mobile"}))

generates:

    "PhoneRecord" : {
      "description" : "Contact phone number",
      "example" : {
        "phone" : "555-1212",
        "label" : "Mobile"
      },
      "type" : "object",
      "properties" : {
        "phone" : {
          "description" : "The phone number",
          "type" : "string"
        },
        "label" : {
          "description" : "An optional label",
          "type" : "string"
        }
      },
      "additionalProperties" : false,
      "required" : [ "phone" ]
    }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants