Clojure client: update Petstore sample, fix tests

This commit is contained in:
xhh 2016-02-29 19:05:10 +08:00
parent 3106cadaf7
commit a42f972dfe
4 changed files with 93 additions and 13 deletions

View File

@ -48,7 +48,7 @@
(defn find-pets-by-status-with-http-info (defn find-pets-by-status-with-http-info
"Finds Pets by status "Finds Pets by status
Multiple status values can be provided with comma seperated strings" Multiple status values can be provided with comma separated strings"
([] (find-pets-by-status-with-http-info nil)) ([] (find-pets-by-status-with-http-info nil))
([{:keys [status ]}] ([{:keys [status ]}]
(call-api "/pet/findByStatus" :get (call-api "/pet/findByStatus" :get
@ -62,7 +62,7 @@
(defn find-pets-by-status (defn find-pets-by-status
"Finds Pets by status "Finds Pets by status
Multiple status values can be provided with comma seperated strings" Multiple status values can be provided with comma separated strings"
([] (find-pets-by-status nil)) ([] (find-pets-by-status nil))
([optional-params] ([optional-params]
(:data (find-pets-by-status-with-http-info optional-params)))) (:data (find-pets-by-status-with-http-info optional-params))))
@ -99,7 +99,7 @@
:form-params {} :form-params {}
:content-types [] :content-types []
:accepts ["application/json" "application/xml"] :accepts ["application/json" "application/xml"]
:auth-names ["api_key"]})) :auth-names ["petstore_auth" "api_key"]}))
(defn get-pet-by-id (defn get-pet-by-id
"Find pet by ID "Find pet by ID
@ -169,3 +169,44 @@
([pet-id ] (upload-file pet-id nil)) ([pet-id ] (upload-file pet-id nil))
([pet-id optional-params] ([pet-id optional-params]
(:data (upload-file-with-http-info pet-id optional-params)))) (:data (upload-file-with-http-info pet-id optional-params))))
(defn pet-pet-idtesting-byte-arraytrue-get-with-http-info
"Fake endpoint to test byte array return by 'Find pet by ID'
Returns a pet when ID < 10. ID > 10 or nonintegers will simulate API error conditions"
[pet-id ]
(call-api "/pet/{petId}?testing_byte_array=true" :get
{:path-params {"petId" pet-id }
:header-params {}
:query-params {}
:form-params {}
:content-types []
:accepts ["application/json" "application/xml"]
:auth-names ["petstore_auth" "api_key"]}))
(defn pet-pet-idtesting-byte-arraytrue-get
"Fake endpoint to test byte array return by 'Find pet by ID'
Returns a pet when ID < 10. ID > 10 or nonintegers will simulate API error conditions"
[pet-id ]
(:data (pet-pet-idtesting-byte-arraytrue-get-with-http-info pet-id)))
(defn add-pet-using-byte-array-with-http-info
"Fake endpoint to test byte array in body parameter for adding a new pet to the store
"
([] (add-pet-using-byte-array-with-http-info nil))
([{:keys [body ]}]
(call-api "/pet?testing_byte_array=true" :post
{:path-params {}
:header-params {}
:query-params {}
:form-params {}
:body-param body
:content-types ["application/json" "application/xml"]
:accepts ["application/json" "application/xml"]
:auth-names ["petstore_auth"]})))
(defn add-pet-using-byte-array
"Fake endpoint to test byte array in body parameter for adding a new pet to the store
"
([] (add-pet-using-byte-array nil))
([optional-params]
(:data (add-pet-using-byte-array-with-http-info optional-params))))

View File

@ -2,6 +2,27 @@
(:require [swagger-petstore.core :refer [call-api check-required-params with-collection-format]]) (:require [swagger-petstore.core :refer [call-api check-required-params with-collection-format]])
(:import (java.io File))) (:import (java.io File)))
(defn find-orders-by-status-with-http-info
"Finds orders by status
A single status value can be provided as a string"
([] (find-orders-by-status-with-http-info nil))
([{:keys [status ]}]
(call-api "/store/findByStatus" :get
{:path-params {}
:header-params {}
:query-params {"status" status }
:form-params {}
:content-types []
:accepts ["application/json" "application/xml"]
:auth-names ["test_api_client_id" "test_api_client_secret"]})))
(defn find-orders-by-status
"Finds orders by status
A single status value can be provided as a string"
([] (find-orders-by-status nil))
([optional-params]
(:data (find-orders-by-status-with-http-info optional-params))))
(defn get-inventory-with-http-info (defn get-inventory-with-http-info
"Returns pet inventories by status "Returns pet inventories by status
Returns a map of status codes to quantities" Returns a map of status codes to quantities"
@ -34,7 +55,7 @@
:body-param body :body-param body
:content-types [] :content-types []
:accepts ["application/json" "application/xml"] :accepts ["application/json" "application/xml"]
:auth-names []}))) :auth-names ["test_api_client_id" "test_api_client_secret"]})))
(defn place-order (defn place-order
"Place an order for a pet "Place an order for a pet
@ -54,7 +75,7 @@
:form-params {} :form-params {}
:content-types [] :content-types []
:accepts ["application/json" "application/xml"] :accepts ["application/json" "application/xml"]
:auth-names []})) :auth-names ["test_api_key_query" "test_api_key_header"]}))
(defn get-order-by-id (defn get-order-by-id
"Find purchase order by ID "Find purchase order by ID

View File

@ -9,7 +9,11 @@
(def auth-definitions (def auth-definitions
{"petstore_auth" {:type :oauth2} {"petstore_auth" {:type :oauth2}
"api_key" {:type :api-key :in :header :param-name "api_key"}}) "test_api_client_id" {:type :api-key :in :header :param-name "x-test_api_client_id"}
"test_api_client_secret" {:type :api-key :in :header :param-name "x-test_api_client_secret"}
"api_key" {:type :api-key :in :header :param-name "api_key"}
"test_api_key_query" {:type :api-key :in :query :param-name "test_api_key_query"}
"test_api_key_header" {:type :api-key :in :header :param-name "test_api_key_header"}})
(def default-api-context (def default-api-context
"Default API context." "Default API context."
@ -18,7 +22,11 @@
:datetime-format "yyyy-MM-dd'T'HH:mm:ss.SSSXXX" :datetime-format "yyyy-MM-dd'T'HH:mm:ss.SSSXXX"
:debug false :debug false
:auths {"petstore_auth" nil :auths {"petstore_auth" nil
"api_key" nil}}) "test_api_client_id" nil
"test_api_client_secret" nil
"api_key" nil
"test_api_key_query" nil
"test_api_key_header" nil}})
(def ^:dynamic *api-context* (def ^:dynamic *api-context*
"Dynamic API context to be applied in API calls." "Dynamic API context to be applied in API calls."

View File

@ -11,7 +11,11 @@
:datetime-format "yyyy-MM-dd'T'HH:mm:ss.SSSXXX" :datetime-format "yyyy-MM-dd'T'HH:mm:ss.SSSXXX"
:debug false :debug false
:auths {"api_key" nil :auths {"api_key" nil
"petstore_auth" nil}} "petstore_auth" nil
"test_api_client_id" nil
"test_api_client_secret" nil
"test_api_key_query" nil
"test_api_key_header" nil}}
default-api-context default-api-context
*api-context* *api-context*
(with-api-context {} (with-api-context {}
@ -25,8 +29,9 @@
:date-format "yyyy-MM-dd" :date-format "yyyy-MM-dd"
:datetime-format "yyyy-MM-dd'T'HH:mm:ss.SSSXXX" :datetime-format "yyyy-MM-dd'T'HH:mm:ss.SSSXXX"
:debug true :debug true
:auths {"api_key" "key1" :auths (merge (:auths default-api-context)
"petstore_auth" "token1"}} {"api_key" "key1"
"petstore_auth" "token1"})}
*api-context*)) *api-context*))
;; nested with-api-context inherits values from the outer api context ;; nested with-api-context inherits values from the outer api context
(with-api-context {:datetime-format "yyyy-MM-dd HH:mm:ss" (with-api-context {:datetime-format "yyyy-MM-dd HH:mm:ss"
@ -35,8 +40,9 @@
:date-format "yyyy-MM-dd" :date-format "yyyy-MM-dd"
:datetime-format "yyyy-MM-dd HH:mm:ss" :datetime-format "yyyy-MM-dd HH:mm:ss"
:debug true :debug true
:auths {"api_key" "key2" :auths (merge (:auths default-api-context)
"petstore_auth" "token1"}} {"api_key" "key2"
"petstore_auth" "token1"})}
*api-context*)))) *api-context*))))
;; back to default api context ;; back to default api context
(is (= {:base-url "http://petstore.swagger.io/v2" (is (= {:base-url "http://petstore.swagger.io/v2"
@ -44,7 +50,11 @@
:datetime-format "yyyy-MM-dd'T'HH:mm:ss.SSSXXX" :datetime-format "yyyy-MM-dd'T'HH:mm:ss.SSSXXX"
:debug false :debug false
:auths {"api_key" nil :auths {"api_key" nil
"petstore_auth" nil}} "petstore_auth" nil
"test_api_client_id" nil
"test_api_client_secret" nil
"test_api_key_query" nil
"test_api_key_header" nil}}
default-api-context default-api-context
*api-context*)))) *api-context*))))