Skip to content

Commit 09ddbfb

Browse files
rajcspsgRajkumar Natarajan
andauthored
fix reflection and update readme (#152)
* fix reflection and update readme * Incorporate the review comments --------- Co-authored-by: Rajkumar Natarajan <[email protected]>
1 parent d4a5cba commit 09ddbfb

File tree

2 files changed

+88
-4
lines changed

2 files changed

+88
-4
lines changed

README.md

Lines changed: 87 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Ring-Swagger [![Build Status](https://travis-ci.org/metosin/ring-swagger.svg?branch=master)](https://travis-ci.org/metosin/ring-swagger) [![Downloads](https://versions.deps.co/metosin/ring-swagger/downloads.svg)](https://versions.deps.co/metosin/ring-swagger)
22

3-
[Swagger](http://swagger.io/) 2.0 implementation for Clojure/Ring using [Plumatic Schema](https://github.com/Plumatic/schema) (support for [clojure.spec](http://clojure.org/about/spec) via [spec-tools](https://github.com/metosin/spec-tools)).
3+
[Swagger](http://swagger.io/) 2.0/[OpenApi](https://spec.openapis.org/oas/v3.0.3.html) 3.0 implementation for Clojure/Ring using [Plumatic Schema](https://github.com/Plumatic/schema) (support for [clojure.spec](http://clojure.org/about/spec) via [spec-tools](https://github.com/metosin/spec-tools)).
44

55
- Transforms deeply nested Schemas into Swagger JSON Schema definitions
66
- Extended & symmetric JSON & String serialization & coercion
@@ -37,7 +37,7 @@ The Schema allows mostly any extra keys as ring-swagger tries not to be on your
3737

3838
[API Docs](http://metosin.github.io/ring-swagger/doc/).
3939

40-
### Simplest possible example
40+
### Simplest possible example for swagger 2.0
4141

4242
```clojure
4343
(require '[ring.swagger.swagger2 :as rs])
@@ -51,8 +51,34 @@ The Schema allows mostly any extra keys as ring-swagger tries not to be on your
5151
; :paths {},
5252
; :definitions {}}
5353
```
54+
### Simplest possible example for openapi 3.0
5455

55-
### More complete example
56+
```clojure
57+
(require '[ring.swagger.openapi3 :as rs])
58+
(rs/openapi-json {:info {:version "version"
59+
:title "title"
60+
:description "description"
61+
:termsOfService "jeah"
62+
:contact {:name "name"
63+
:url "http://someurl.com"
64+
65+
:license {:name "name"
66+
:url "http://someurl.com"}}
67+
:paths {}})
68+
;{:openapi "3.0.3"
69+
; :info {:title "title"
70+
; :version "version"
71+
; :description "description"
72+
; :termsOfService "jeah"
73+
; :contact {:name "name" :url "http://someurl.com" :email "[email protected]"}
74+
; :license {:name "name" :url "http://someurl.com"}}
75+
; :paths {}
76+
; :components {:schemas {}
77+
; :securitySchemes {}
78+
; :responses {}
79+
; :requestBodies {}}}
80+
```
81+
### More complete example for swagger 2.0
5682

5783
Info, tags, routes and anonymous nested schemas.
5884

@@ -130,6 +156,64 @@ Info, tags, routes and anonymous nested schemas.
130156
; :additionalProperties false,
131157
; :required (:street :city)}}}
132158
```
159+
### More complete example for openapi 3.x
160+
```clojure
161+
(require '[schema.core :as s])
162+
(require '[ring.swagger.openapi3 :as rs])
163+
164+
(s/defschema User {:id s/Str,
165+
:name s/Str
166+
:address {:street s/Str
167+
:city (s/enum :tre :hki)}})
168+
169+
170+
(rs/openapi-json {:info {:version "version"
171+
:title "title"
172+
:description "description"
173+
:termsOfService "jeah"
174+
:contact {:name "name"
175+
:url "http://someurl.com"
176+
177+
:license {:name "name"
178+
:url "http://someurl.com"}}
179+
:paths {"/api"
180+
{:post
181+
{:requestBody {:content {"application/json" User}}
182+
:responses {200 {:description "ok"
183+
:content {"application/json" {:schema User}}}}}}}})
184+
;{:openapi "3.0.3",
185+
; :info {:title "title",
186+
; :version "version",
187+
; :description "description",
188+
; :termsOfService "jeah",
189+
; :contact {:name "name", :url "http://someurl.com", :email "[email protected]"},
190+
; :license {:name "name", :url "http://someurl.com"}},
191+
; :paths {"/api" {:post {:requestBody {:$ref "#/components/requestBodies/User"},
192+
; :responses {200 {:$ref "#/components/responses/Response7944"}}}}},
193+
; :components {:schemas {"Response7944" {:type "object",
194+
; :properties {:schema {:$ref "#/components/schemas/User"}},
195+
; :additionalProperties false,
196+
; :required [:schema]},
197+
; "Response7944SchemaAddress" {:type "object",
198+
; :properties {:street {:type "string"},
199+
; :city {:type "string", :enum (:tre :hki)}},
200+
; :additionalProperties false,
201+
; :required [:street :city]},
202+
; "User" {:type "object",
203+
; :properties {:id {:type "string"},
204+
; :name {:type "string"},
205+
; :address {:$ref "#/components/schemas/UserAddress"}},
206+
; :additionalProperties false,
207+
; :required [:id :name :address]},
208+
; "UserAddress" {:type "object",
209+
; :properties {:street {:type "string"}, :city {:type "string", :enum (:tre :hki)}},
210+
; :additionalProperties false,
211+
; :required [:street :city]}},
212+
; :securitySchemes {},
213+
; :responses {:Response7944 {:description "ok",
214+
; :content {"application/json" {:schema {:$ref "#/components/schemas/Response7944"}}}}},
215+
; :requestBodies {:User {:content {"application/json" {:schema {:$ref "#/components/schemas/User"}}}}}}}
216+
```
133217

134218
producing the following ui:
135219

src/ring/swagger/openapi3.clj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@
148148
transformed)
149149
route))
150150

151-
(defn get-response-ref [v]
151+
(defn get-response-ref ^String [v]
152152
(some-> (-> v
153153
:content
154154
vals

0 commit comments

Comments
 (0)