Skip to content

Commit 432b358

Browse files
mewawing328
authored andcommitted
[Clojure] Default */* MIME to application/json (#8096)
* [Clojure] Default */* MIME to application/json * [Clojure] Updated sample petstore
1 parent 415edb8 commit 432b358

File tree

7 files changed

+27
-4
lines changed

7 files changed

+27
-4
lines changed

modules/swagger-codegen/src/main/resources/clojure/core.mustache

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,13 @@
169169
(map (fn [[k v]] [k (normalize-param v)]))
170170
(into {})))
171171

172+
(defn default-to-json-mime
173+
"Default to JSON MIME if given */* MIME"
174+
[mime]
175+
(if (= mime "*/*")
176+
"application/json"
177+
mime))
178+
172179
(defn json-mime?
173180
"Check if the given MIME is a standard JSON MIME or :json."
174181
[mime]
@@ -182,7 +189,7 @@
182189
[mimes]
183190
(-> (filter json-mime? mimes)
184191
first
185-
(or (first mimes))))
192+
(or (default-to-json-mime (first mimes)))))
186193

187194
(defn serialize
188195
"Serialize the given data according to content-type.

samples/client/petstore/clojure/git_push.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ git_remote=`git remote`
3636
if [ "$git_remote" = "" ]; then # git remote not defined
3737

3838
if [ "$GIT_TOKEN" = "" ]; then
39-
echo "[INFO] \$GIT_TOKEN (environment variable) is not set. Using the git crediential in your environment."
39+
echo "[INFO] \$GIT_TOKEN (environment variable) is not set. Using the git credential in your environment."
4040
git remote add origin https://github.com/${git_user_id}/${git_repo_id}.git
4141
else
4242
git remote add origin https://${git_user_id}:${GIT_TOKEN}@github.com/${git_user_id}/${git_repo_id}.git

samples/client/petstore/clojure/project.clj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
(defproject swagger-petstore "1.0.0"
22
:description "This is a sample server Petstore server. You can find out more about Swagger at <a href=\"http://swagger.io\">http://swagger.io</a> or on irc.freenode.net, #swagger. For this sample, you can use the api key \"special-key\" to test the authorization filters"
3-
:license {:name "Apache 2.0"
3+
:license {:name "Apache-2.0"
44
:url "http://www.apache.org/licenses/LICENSE-2.0.html"}
55
:dependencies [[org.clojure/clojure "1.7.0"]
66
[clj-http "3.6.0"]

samples/client/petstore/clojure/src/swagger_petstore/api/pet.clj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
"
3030
([pet-id ] (delete-pet-with-http-info pet-id nil))
3131
([pet-id {:keys [api-key ]}]
32+
(check-required-params pet-id)
3233
(call-api "/pet/{petId}" :delete
3334
{:path-params {"petId" pet-id }
3435
:header-params {"api_key" api-key }
@@ -91,6 +92,7 @@
9192
"Find pet by ID
9293
Returns a pet when ID < 10. ID > 10 or nonintegers will simulate API error conditions"
9394
[pet-id ]
95+
(check-required-params pet-id)
9496
(call-api "/pet/{petId}" :get
9597
{:path-params {"petId" pet-id }
9698
:header-params {}
@@ -133,6 +135,7 @@
133135
"
134136
([pet-id ] (update-pet-with-form-with-http-info pet-id nil))
135137
([pet-id {:keys [name status ]}]
138+
(check-required-params pet-id)
136139
(call-api "/pet/{petId}" :post
137140
{:path-params {"petId" pet-id }
138141
:header-params {}
@@ -154,6 +157,7 @@
154157
"
155158
([pet-id ] (upload-file-with-http-info pet-id nil))
156159
([pet-id {:keys [additional-metadata ^File file ]}]
160+
(check-required-params pet-id)
157161
(call-api "/pet/{petId}/uploadImage" :post
158162
{:path-params {"petId" pet-id }
159163
:header-params {}

samples/client/petstore/clojure/src/swagger_petstore/api/store.clj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
"Delete purchase order by ID
77
For valid response try integer IDs with value < 1000. Anything above 1000 or nonintegers will generate API errors"
88
[order-id ]
9+
(check-required-params order-id)
910
(call-api "/store/order/{orderId}" :delete
1011
{:path-params {"orderId" order-id }
1112
:header-params {}
@@ -44,6 +45,7 @@
4445
"Find purchase order by ID
4546
For valid response try integer IDs with value <= 5 or > 10. Other values will generated exceptions"
4647
[order-id ]
48+
(check-required-params order-id)
4749
(call-api "/store/order/{orderId}" :get
4850
{:path-params {"orderId" order-id }
4951
:header-params {}

samples/client/petstore/clojure/src/swagger_petstore/api/user.clj

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@
7272
"Delete user
7373
This can only be done by the logged in user."
7474
[username ]
75+
(check-required-params username)
7576
(call-api "/user/{username}" :delete
7677
{:path-params {"username" username }
7778
:header-params {}
@@ -91,6 +92,7 @@
9192
"Get user by user name
9293
"
9394
[username ]
95+
(check-required-params username)
9496
(call-api "/user/{username}" :get
9597
{:path-params {"username" username }
9698
:header-params {}
@@ -151,6 +153,7 @@
151153
This can only be done by the logged in user."
152154
([username ] (update-user-with-http-info username nil))
153155
([username {:keys [body ]}]
156+
(check-required-params username)
154157
(call-api "/user/{username}" :put
155158
{:path-params {"username" username }
156159
:header-params {}

samples/client/petstore/clojure/src/swagger_petstore/core.clj

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,13 @@
169169
(map (fn [[k v]] [k (normalize-param v)]))
170170
(into {})))
171171

172+
(defn default-to-json-mime
173+
"Default to JSON MIME if given */* MIME"
174+
[mime]
175+
(if (= mime "*/*")
176+
"application/json"
177+
mime))
178+
172179
(defn json-mime?
173180
"Check if the given MIME is a standard JSON MIME or :json."
174181
[mime]
@@ -182,7 +189,7 @@
182189
[mimes]
183190
(-> (filter json-mime? mimes)
184191
first
185-
(or (first mimes))))
192+
(or (default-to-json-mime (first mimes)))))
186193

187194
(defn serialize
188195
"Serialize the given data according to content-type.

0 commit comments

Comments
 (0)