Skip to content

Commit

Permalink
[Clojure] Update petstore sample
Browse files Browse the repository at this point in the history
  • Loading branch information
f-f committed May 21, 2018
1 parent 8a29496 commit 2abe0c8
Show file tree
Hide file tree
Showing 16 changed files with 318 additions and 521 deletions.
32 changes: 0 additions & 32 deletions samples/client/petstore/clojure/pom.xml

This file was deleted.

9 changes: 6 additions & 3 deletions samples/client/petstore/clojure/project.clj
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
:description "This is a sample server Petstore server. For this sample, you can use the api key \"special-key\" to test the authorization filters"
:license {:name "Apache-2.0"
:url "http://www.apache.org/licenses/LICENSE-2.0.html"}
:dependencies [[org.clojure/clojure "1.7.0"]
[clj-http "3.6.0"]
[cheshire "5.5.0"]])
:dependencies [[org.clojure/clojure "1.9.0"]
[metosin/spec-tools "0.7.0"]
[clj-http "3.8.0"]
[orchestra "2017.11.12-1"]
[camel-snake-kebab "0.4.0"]
[cheshire "5.8.0"]])
1 change: 0 additions & 1 deletion samples/client/petstore/clojure/resources/hello.txt

This file was deleted.

128 changes: 85 additions & 43 deletions samples/client/petstore/clojure/src/open_api_petstore/api/pet.clj
Original file line number Diff line number Diff line change
@@ -1,11 +1,21 @@
(ns open-api-petstore.api.pet
(:require [open-api-petstore.core :refer [call-api check-required-params with-collection-format]])
(:require [open-api-petstore.core :refer [call-api check-required-params with-collection-format *api-context*]]
[clojure.spec.alpha :as s]
[spec-tools.core :as st]
[orchestra.core :refer [defn-spec]]
[open-api-petstore.specs.tag :refer :all]
[open-api-petstore.specs.category :refer :all]
[open-api-petstore.specs.user :refer :all]
[open-api-petstore.specs.pet :refer :all]
[open-api-petstore.specs.order :refer :all]
)
(:import (java.io File)))

(defn add-pet-with-http-info

(defn-spec add-pet-with-http-info any?
"Add a new pet to the store"
([] (add-pet-with-http-info nil))
([{:keys [pet ]}]
([{:keys [pet]}]
(call-api "/pet" :post
{:path-params {}
:header-params {}
Expand All @@ -16,16 +26,20 @@
:accepts []
:auth-names ["petstore_auth"]})))

(defn add-pet
(defn-spec add-pet any?
"Add a new pet to the store"
([] (add-pet nil))
([optional-params]
(:data (add-pet-with-http-info optional-params))))
(let [res (:data (add-pet-with-http-info optional-params))]
(if (:decode-models *api-context*)
(st/decode any? res st/string-transformer)
res))))


(defn delete-pet-with-http-info
(defn-spec delete-pet-with-http-info any?
"Deletes a pet"
([pet-id ] (delete-pet-with-http-info pet-id nil))
([pet-id {:keys [api-key ]}]
([pet-id int?, ] (delete-pet-with-http-info pet-id nil))
([pet-id int?, {:keys [api-key]}]
(check-required-params pet-id)
(call-api "/pet/{petId}" :delete
{:path-params {"petId" pet-id }
Expand All @@ -36,17 +50,21 @@
:accepts []
:auth-names ["petstore_auth"]})))

(defn delete-pet
(defn-spec delete-pet any?
"Deletes a pet"
([pet-id ] (delete-pet pet-id nil))
([pet-id optional-params]
(:data (delete-pet-with-http-info pet-id optional-params))))
([pet-id int?, ] (delete-pet pet-id nil))
([pet-id int?, optional-params]
(let [res (:data (delete-pet-with-http-info pet-id optional-params))]
(if (:decode-models *api-context*)
(st/decode any? res st/string-transformer)
res))))


(defn find-pets-by-status-with-http-info
(defn-spec find-pets-by-status-with-http-info any?
"Finds Pets by status
Multiple status values can be provided with comma separated strings"
([] (find-pets-by-status-with-http-info nil))
([{:keys [status ]}]
([{:keys [status]}]
(call-api "/pet/findByStatus" :get
{:path-params {}
:header-params {}
Expand All @@ -56,18 +74,22 @@
:accepts ["application/json" "application/xml"]
:auth-names ["petstore_auth"]})))

(defn find-pets-by-status
(defn-spec find-pets-by-status (s/coll-of pet-spec)
"Finds Pets by status
Multiple status values can be provided with comma separated strings"
([] (find-pets-by-status nil))
([optional-params]
(:data (find-pets-by-status-with-http-info optional-params))))
(let [res (:data (find-pets-by-status-with-http-info optional-params))]
(if (:decode-models *api-context*)
(st/decode (s/coll-of pet-spec) res st/string-transformer)
res))))

(defn find-pets-by-tags-with-http-info

(defn-spec find-pets-by-tags-with-http-info any?
"Finds Pets by tags
Multiple tags can be provided with comma separated strings. Use tag1, tag2, tag3 for testing."
([] (find-pets-by-tags-with-http-info nil))
([{:keys [tags ]}]
([{:keys [tags]}]
(call-api "/pet/findByTags" :get
{:path-params {}
:header-params {}
Expand All @@ -77,17 +99,21 @@
:accepts ["application/json" "application/xml"]
:auth-names ["petstore_auth"]})))

(defn find-pets-by-tags
(defn-spec find-pets-by-tags (s/coll-of pet-spec)
"Finds Pets by tags
Multiple tags can be provided with comma separated strings. Use tag1, tag2, tag3 for testing."
([] (find-pets-by-tags nil))
([optional-params]
(:data (find-pets-by-tags-with-http-info optional-params))))
(let [res (:data (find-pets-by-tags-with-http-info optional-params))]
(if (:decode-models *api-context*)
(st/decode (s/coll-of pet-spec) res st/string-transformer)
res))))


(defn get-pet-by-id-with-http-info
(defn-spec get-pet-by-id-with-http-info any?
"Find pet by ID
Returns a pet when ID < 10. ID > 10 or nonintegers will simulate API error conditions"
[pet-id ]
[pet-id int?]
(check-required-params pet-id)
(call-api "/pet/{petId}" :get
{:path-params {"petId" pet-id }
Expand All @@ -98,16 +124,20 @@
:accepts ["application/json" "application/xml"]
:auth-names ["api_key" "petstore_auth"]}))

(defn get-pet-by-id
(defn-spec get-pet-by-id pet-spec
"Find pet by ID
Returns a pet when ID < 10. ID > 10 or nonintegers will simulate API error conditions"
[pet-id ]
(:data (get-pet-by-id-with-http-info pet-id)))
[pet-id int?]
(let [res (:data (get-pet-by-id-with-http-info pet-id))]
(if (:decode-models *api-context*)
(st/decode pet-spec res st/string-transformer)
res)))

(defn update-pet-with-http-info

(defn-spec update-pet-with-http-info any?
"Update an existing pet"
([] (update-pet-with-http-info nil))
([{:keys [pet ]}]
([{:keys [pet]}]
(call-api "/pet" :put
{:path-params {}
:header-params {}
Expand All @@ -118,16 +148,20 @@
:accepts []
:auth-names ["petstore_auth"]})))

(defn update-pet
(defn-spec update-pet any?
"Update an existing pet"
([] (update-pet nil))
([optional-params]
(:data (update-pet-with-http-info optional-params))))
(let [res (:data (update-pet-with-http-info optional-params))]
(if (:decode-models *api-context*)
(st/decode any? res st/string-transformer)
res))))


(defn update-pet-with-form-with-http-info
(defn-spec update-pet-with-form-with-http-info any?
"Updates a pet in the store with form data"
([pet-id ] (update-pet-with-form-with-http-info pet-id nil))
([pet-id {:keys [name status ]}]
([pet-id string?, ] (update-pet-with-form-with-http-info pet-id nil))
([pet-id string?, {:keys [name status]}]
(check-required-params pet-id)
(call-api "/pet/{petId}" :post
{:path-params {"petId" pet-id }
Expand All @@ -138,16 +172,20 @@
:accepts []
:auth-names ["petstore_auth"]})))

(defn update-pet-with-form
(defn-spec update-pet-with-form any?
"Updates a pet in the store with form data"
([pet-id ] (update-pet-with-form pet-id nil))
([pet-id optional-params]
(:data (update-pet-with-form-with-http-info pet-id optional-params))))
([pet-id string?, ] (update-pet-with-form pet-id nil))
([pet-id string?, optional-params]
(let [res (:data (update-pet-with-form-with-http-info pet-id optional-params))]
(if (:decode-models *api-context*)
(st/decode any? res st/string-transformer)
res))))

(defn upload-file-with-http-info

(defn-spec upload-file-with-http-info any?
"uploads an image"
([pet-id ] (upload-file-with-http-info pet-id nil))
([pet-id {:keys [additional-metadata ^File file ]}]
([pet-id int?, ] (upload-file-with-http-info pet-id nil))
([pet-id int?, {:keys [additional-metadata ^File file]}]
(check-required-params pet-id)
(call-api "/pet/{petId}/uploadImage" :post
{:path-params {"petId" pet-id }
Expand All @@ -158,9 +196,13 @@
:accepts []
:auth-names ["petstore_auth"]})))

(defn upload-file
(defn-spec upload-file any?
"uploads an image"
([pet-id ] (upload-file pet-id nil))
([pet-id optional-params]
(:data (upload-file-with-http-info pet-id optional-params))))
([pet-id int?, ] (upload-file pet-id nil))
([pet-id int?, optional-params]
(let [res (:data (upload-file-with-http-info pet-id optional-params))]
(if (:decode-models *api-context*)
(st/decode any? res st/string-transformer)
res))))


62 changes: 44 additions & 18 deletions samples/client/petstore/clojure/src/open_api_petstore/api/store.clj
Original file line number Diff line number Diff line change
@@ -1,11 +1,21 @@
(ns open-api-petstore.api.store
(:require [open-api-petstore.core :refer [call-api check-required-params with-collection-format]])
(:require [open-api-petstore.core :refer [call-api check-required-params with-collection-format *api-context*]]
[clojure.spec.alpha :as s]
[spec-tools.core :as st]
[orchestra.core :refer [defn-spec]]
[open-api-petstore.specs.tag :refer :all]
[open-api-petstore.specs.category :refer :all]
[open-api-petstore.specs.user :refer :all]
[open-api-petstore.specs.pet :refer :all]
[open-api-petstore.specs.order :refer :all]
)
(:import (java.io File)))

(defn delete-order-with-http-info

(defn-spec delete-order-with-http-info any?
"Delete purchase order by ID
For valid response try integer IDs with value < 1000. Anything above 1000 or nonintegers will generate API errors"
[order-id ]
[order-id string?]
(check-required-params order-id)
(call-api "/store/order/{orderId}" :delete
{:path-params {"orderId" order-id }
Expand All @@ -16,13 +26,17 @@
:accepts []
:auth-names []}))

(defn delete-order
(defn-spec delete-order any?
"Delete purchase order by ID
For valid response try integer IDs with value < 1000. Anything above 1000 or nonintegers will generate API errors"
[order-id ]
(:data (delete-order-with-http-info order-id)))
[order-id string?]
(let [res (:data (delete-order-with-http-info order-id))]
(if (:decode-models *api-context*)
(st/decode any? res st/string-transformer)
res)))


(defn get-inventory-with-http-info
(defn-spec get-inventory-with-http-info any?
"Returns pet inventories by status
Returns a map of status codes to quantities"
[]
Expand All @@ -35,16 +49,20 @@
:accepts ["application/json" "application/xml"]
:auth-names ["api_key"]}))

(defn get-inventory
(defn-spec get-inventory (s/map-of string? int?)
"Returns pet inventories by status
Returns a map of status codes to quantities"
[]
(:data (get-inventory-with-http-info)))
(let [res (:data (get-inventory-with-http-info))]
(if (:decode-models *api-context*)
(st/decode (s/map-of string? int?) res st/string-transformer)
res)))


(defn get-order-by-id-with-http-info
(defn-spec get-order-by-id-with-http-info any?
"Find purchase order by ID
For valid response try integer IDs with value <= 5 or > 10. Other values will generated exceptions"
[order-id ]
[order-id string?]
(check-required-params order-id)
(call-api "/store/order/{orderId}" :get
{:path-params {"orderId" order-id }
Expand All @@ -55,16 +73,20 @@
:accepts ["application/json" "application/xml"]
:auth-names []}))

(defn get-order-by-id
(defn-spec get-order-by-id order-spec
"Find purchase order by ID
For valid response try integer IDs with value <= 5 or > 10. Other values will generated exceptions"
[order-id ]
(:data (get-order-by-id-with-http-info order-id)))
[order-id string?]
(let [res (:data (get-order-by-id-with-http-info order-id))]
(if (:decode-models *api-context*)
(st/decode order-spec res st/string-transformer)
res)))

(defn place-order-with-http-info

(defn-spec place-order-with-http-info any?
"Place an order for a pet"
([] (place-order-with-http-info nil))
([{:keys [order ]}]
([{:keys [order]}]
(call-api "/store/order" :post
{:path-params {}
:header-params {}
Expand All @@ -75,9 +97,13 @@
:accepts ["application/json" "application/xml"]
:auth-names []})))

(defn place-order
(defn-spec place-order order-spec
"Place an order for a pet"
([] (place-order nil))
([optional-params]
(:data (place-order-with-http-info optional-params))))
(let [res (:data (place-order-with-http-info optional-params))]
(if (:decode-models *api-context*)
(st/decode order-spec res st/string-transformer)
res))))


Loading

0 comments on commit 2abe0c8

Please sign in to comment.