Last active
August 16, 2016 10:57
-
-
Save miikka/77e2b89420e1626b606c308ec232b3f3 to your computer and use it in GitHub Desktop.
clojure.spec version of ring-swagger's README example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(ns example | |
(:require [clojure.spec :as spec] | |
[ring.swagger.swagger2 :as rs] | |
[schema.core :as s])) | |
(spec/def ::id string?) | |
(spec/def ::name string?) | |
(spec/def ::street string?) | |
(spec/def ::city #{"tre" "hki"}) | |
(spec/def ::address (spec/keys :req [::street ::city])) | |
(spec/def ::user | |
(spec/keys :req [::id ::name ::address])) | |
(defn get-def [] | |
(rs/swagger-json | |
{:info {:version "1.0.0" | |
:title "Sausages" | |
:description "Sausage description" | |
:termsOfService "http://helloreverb.com/terms/" | |
:contact {:name "My API Team" | |
:email "[email protected]" | |
:url "http://www.metosin.fi"} | |
:license {:name "Eclipse Public License" | |
:url "http://www.eclipse.org/legal/epl-v10.html"}} | |
:tags [{:name "user" | |
:description "User stuff"}] | |
:paths {"/api/ping" {:get {}} | |
"/user/:id" {:post {:summary "User Api" | |
:description "User Api description" | |
:tags ["user"] | |
:parameters {:path {:id ::id} | |
:body ::user} | |
:responses {200 {:schema ::user | |
:description "Found it!"} | |
404 {:description "Ohnoes."}}}}}})) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{:swagger "2.0", | |
:info | |
{:title "Sausages", | |
:version "1.0.0", | |
:description "Sausage description", | |
:termsOfService "http://helloreverb.com/terms/", | |
:contact | |
{:name "My API Team", | |
:email "[email protected]", | |
:url "http://www.metosin.fi"}, | |
:license | |
{:name "Eclipse Public License", | |
:url "http://www.eclipse.org/legal/epl-v10.html"}}, | |
:produces ["application/json"], | |
:consumes ["application/json"], | |
:tags [{:name "user", :description "User stuff"}], | |
:paths | |
{"/api/ping" {:get {:responses {:default {:description ""}}}}, | |
"/user/{id}" | |
{:post | |
{:summary "User Api", | |
:description "User Api description", | |
:tags ["user"], | |
:parameters | |
[{:in "path", | |
:name "id", | |
:description "", | |
:required true, | |
:type "string"}], | |
:responses | |
{200 | |
{:schema | |
{:type "object", | |
:properties | |
{"id" {:type "string"}, | |
"name" {:type "string"}, | |
"address" | |
{:type "object", | |
:properties | |
{"street" {:type "string"}, "city" {:enum ["hki" "tre"]}}, | |
:required ("street" "city"), | |
:additionalProperties false}}, | |
:required ("id" "name" "address"), | |
:additionalProperties false}, | |
:description "Found it!"}, | |
404 {:description "Ohnoes."}}}}}, | |
:definitions {}} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment