Merge pull request #705 from wing328/fix_required_parameter

Fix required parameter validation for Java, Android, PHP and Ruby
This commit is contained in:
Tony Tam
2015-05-12 05:48:22 -04:00
16 changed files with 222 additions and 62 deletions

View File

@@ -45,12 +45,12 @@ public class {{classname}} {
*/
public {{#returnType}}{{{returnType}}} {{/returnType}}{{^returnType}}void {{/returnType}}{{nickname}} ({{#allParams}}{{{dataType}}} {{paramName}}{{#hasMore}}, {{/hasMore}}{{/allParams}}) throws ApiException {
Object postBody = {{#bodyParam}}{{paramName}}{{/bodyParam}}{{^bodyParam}}null{{/bodyParam}};
{{#requiredParamCount}}
// verify required params are set
if({{/requiredParamCount}}{{#requiredParams}} {{paramName}} == null {{#hasMore}}|| {{/hasMore}}{{/requiredParams}}{{#requiredParamCount}}) {
throw new ApiException(400, "missing required params");
{{#allParams}}{{#required}}
// verify the required parameter '{{paramName}}' is set
if ({{paramName}} == null) {
throw new ApiException(400, "Missing the required parameter '{{paramName}}' when calling {{nickname}}");
}
{{/requiredParamCount}}
{{/required}}{{/allParams}}
// create path and map variables
String path = "{{path}}".replaceAll("\\{format\\}","json"){{#pathParams}}

View File

@@ -47,13 +47,12 @@ public class {{classname}} {
*/
public {{#returnType}}{{{returnType}}} {{/returnType}}{{^returnType}}void {{/returnType}} {{nickname}} ({{#allParams}}{{{dataType}}} {{paramName}}{{#hasMore}}, {{/hasMore}}{{/allParams}}) throws ApiException {
Object postBody = {{#bodyParam}}{{paramName}}{{/bodyParam}}{{^bodyParam}}null{{/bodyParam}};
{{#requiredParamCount}}
// verify required params are set
if({{/requiredParamCount}}{{#requiredParams}} {{paramName}} == null {{#hasMore}}|| {{/hasMore}}{{/requiredParams}}{{#requiredParamCount}}) {
throw new ApiException(400, "missing required params");
{{#allParams}}{{#required}}
// verify the required parameter '{{paramName}}' is set
if ({{paramName}} == null) {
throw new ApiException(400, "Missing the required parameter '{{paramName}}' when calling {{nickname}}");
}
{{/requiredParamCount}}
{{/required}}{{/allParams}}
// create path and map variables
String path = "{{path}}".replaceAll("\\{format\\}","json"){{#pathParams}}.replaceAll("\\{" + "{{paramName}}" + "\\}", apiInvoker.escapeString({{{paramName}}}.toString())){{/pathParams}};

View File

@@ -39,6 +39,12 @@ class {{classname}} {
{{/allParams}} * @return {{#returnType}}{{{returnType}}}{{/returnType}}{{^returnType}}void{{/returnType}}
*/
public function {{nickname}}({{#allParams}}${{paramName}}{{#optional}}=null{{/optional}}{{#hasMore}}, {{/hasMore}}{{/allParams}}) {
{{#allParams}}{{#required}}
// verify the required parameter '{{paramName}}' is set
if (${{paramName}} === null) {
throw new \Exception("Missing the required parameter ${{paramName}} when calling {{nickname}}");
}
{{/required}}{{/allParams}}
// parse inputs
$resourcePath = "{{path}}";

View File

@@ -13,8 +13,10 @@ class {{classname}}
{{#allParams}}{{^required}} # @option opts [{{dataType}}] :{{paramName}} {{description}}
{{/required}}{{/allParams}} # @return {{#returnType}}{{{returnType}}}{{/returnType}}{{^returnType}}void{{/returnType}}
def self.{{nickname}}({{#allParams}}{{#required}}{{paramName}}, {{/required}}{{/allParams}}opts = {})
# verify existence of params{{#allParams}}{{#required}}
raise "{{{paramName}}} is required" if {{{paramName}}}.nil?{{/required}}{{/allParams}}
{{#allParams}}{{#required}}
# verify the required parameter '{{paramName}}' is set
raise "Missing the required parameter '{{paramName}}' when calling {{nickname}}" if {{{paramName}}}.nil?
{{/required}}{{/allParams}}
# resource path
path = "{{path}}".sub('{format}','json'){{#pathParams}}.sub('{' + '{{baseName}}' + '}', {{paramName}}.to_s){{/pathParams}}

View File

@@ -46,7 +46,6 @@ public class PetApi {
*/
public void updatePet (Pet body) throws ApiException {
Object postBody = body;
// create path and map variables
@@ -101,7 +100,6 @@ public class PetApi {
*/
public void addPet (Pet body) throws ApiException {
Object postBody = body;
// create path and map variables
@@ -156,7 +154,6 @@ public class PetApi {
*/
public List<Pet> findPetsByStatus (List<String> status) throws ApiException {
Object postBody = null;
// create path and map variables
@@ -213,7 +210,6 @@ public class PetApi {
*/
public List<Pet> findPetsByTags (List<String> tags) throws ApiException {
Object postBody = null;
// create path and map variables
@@ -270,7 +266,11 @@ public class PetApi {
*/
public Pet getPetById (Long petId) throws ApiException {
Object postBody = null;
// verify the required parameter 'petId' is set
if (petId == null) {
throw new ApiException(400, "Missing the required parameter 'petId' when calling getPetById");
}
// create path and map variables
@@ -327,7 +327,11 @@ public class PetApi {
*/
public void updatePetWithForm (String petId, String name, String status) throws ApiException {
Object postBody = null;
// verify the required parameter 'petId' is set
if (petId == null) {
throw new ApiException(400, "Missing the required parameter 'petId' when calling updatePetWithForm");
}
// create path and map variables
@@ -393,7 +397,11 @@ public class PetApi {
*/
public void deletePet (String apiKey, Long petId) throws ApiException {
Object postBody = null;
// verify the required parameter 'petId' is set
if (petId == null) {
throw new ApiException(400, "Missing the required parameter 'petId' when calling deletePet");
}
// create path and map variables
@@ -451,7 +459,11 @@ public class PetApi {
*/
public void uploadFile (Long petId, String additionalMetadata, File file) throws ApiException {
Object postBody = null;
// verify the required parameter 'petId' is set
if (petId == null) {
throw new ApiException(400, "Missing the required parameter 'petId' when calling uploadFile");
}
// create path and map variables

View File

@@ -45,7 +45,6 @@ public class StoreApi {
*/
public Map<String, Integer> getInventory () throws ApiException {
Object postBody = null;
// create path and map variables
@@ -100,7 +99,6 @@ public class StoreApi {
*/
public Order placeOrder (Order body) throws ApiException {
Object postBody = body;
// create path and map variables
@@ -155,7 +153,11 @@ public class StoreApi {
*/
public Order getOrderById (String orderId) throws ApiException {
Object postBody = null;
// verify the required parameter 'orderId' is set
if (orderId == null) {
throw new ApiException(400, "Missing the required parameter 'orderId' when calling getOrderById");
}
// create path and map variables
@@ -210,7 +212,11 @@ public class StoreApi {
*/
public void deleteOrder (String orderId) throws ApiException {
Object postBody = null;
// verify the required parameter 'orderId' is set
if (orderId == null) {
throw new ApiException(400, "Missing the required parameter 'orderId' when calling deleteOrder");
}
// create path and map variables

View File

@@ -46,7 +46,6 @@ public class UserApi {
*/
public void createUser (User body) throws ApiException {
Object postBody = body;
// create path and map variables
@@ -101,7 +100,6 @@ public class UserApi {
*/
public void createUsersWithArrayInput (List<User> body) throws ApiException {
Object postBody = body;
// create path and map variables
@@ -156,7 +154,6 @@ public class UserApi {
*/
public void createUsersWithListInput (List<User> body) throws ApiException {
Object postBody = body;
// create path and map variables
@@ -212,7 +209,6 @@ public class UserApi {
*/
public String loginUser (String username, String password) throws ApiException {
Object postBody = null;
// create path and map variables
@@ -270,7 +266,6 @@ public class UserApi {
*/
public void logoutUser () throws ApiException {
Object postBody = null;
// create path and map variables
@@ -325,7 +320,11 @@ public class UserApi {
*/
public User getUserByName (String username) throws ApiException {
Object postBody = null;
// verify the required parameter 'username' is set
if (username == null) {
throw new ApiException(400, "Missing the required parameter 'username' when calling getUserByName");
}
// create path and map variables
@@ -381,7 +380,11 @@ public class UserApi {
*/
public void updateUser (String username, User body) throws ApiException {
Object postBody = body;
// verify the required parameter 'username' is set
if (username == null) {
throw new ApiException(400, "Missing the required parameter 'username' when calling updateUser");
}
// create path and map variables
@@ -436,7 +439,11 @@ public class UserApi {
*/
public void deleteUser (String username) throws ApiException {
Object postBody = null;
// verify the required parameter 'username' is set
if (username == null) {
throw new ApiException(400, "Missing the required parameter 'username' when calling deleteUser");
}
// create path and map variables

View File

@@ -249,6 +249,11 @@ public class PetApi {
public Pet getPetById (Long petId) throws ApiException {
Object postBody = null;
// verify the required parameter 'petId' is set
if (petId == null) {
throw new ApiException(400, "Missing the required parameter 'petId' when calling getPetById");
}
// create path and map variables
String path = "/pet/{petId}".replaceAll("\\{format\\}","json")
@@ -302,6 +307,11 @@ public class PetApi {
public void updatePetWithForm (String petId, String name, String status) throws ApiException {
Object postBody = null;
// verify the required parameter 'petId' is set
if (petId == null) {
throw new ApiException(400, "Missing the required parameter 'petId' when calling updatePetWithForm");
}
// create path and map variables
String path = "/pet/{petId}".replaceAll("\\{format\\}","json")
@@ -362,6 +372,11 @@ public class PetApi {
public void deletePet (String apiKey, Long petId) throws ApiException {
Object postBody = null;
// verify the required parameter 'petId' is set
if (petId == null) {
throw new ApiException(400, "Missing the required parameter 'petId' when calling deletePet");
}
// create path and map variables
String path = "/pet/{petId}".replaceAll("\\{format\\}","json")
@@ -416,6 +431,11 @@ public class PetApi {
public void uploadFile (Long petId, String additionalMetadata, File file) throws ApiException {
Object postBody = null;
// verify the required parameter 'petId' is set
if (petId == null) {
throw new ApiException(400, "Missing the required parameter 'petId' when calling uploadFile");
}
// create path and map variables
String path = "/pet/{petId}/uploadImage".replaceAll("\\{format\\}","json")

View File

@@ -144,6 +144,11 @@ public class StoreApi {
public Order getOrderById (String orderId) throws ApiException {
Object postBody = null;
// verify the required parameter 'orderId' is set
if (orderId == null) {
throw new ApiException(400, "Missing the required parameter 'orderId' when calling getOrderById");
}
// create path and map variables
String path = "/store/order/{orderId}".replaceAll("\\{format\\}","json")
@@ -195,6 +200,11 @@ public class StoreApi {
public void deleteOrder (String orderId) throws ApiException {
Object postBody = null;
// verify the required parameter 'orderId' is set
if (orderId == null) {
throw new ApiException(400, "Missing the required parameter 'orderId' when calling deleteOrder");
}
// create path and map variables
String path = "/store/order/{orderId}".replaceAll("\\{format\\}","json")

View File

@@ -299,6 +299,11 @@ public class UserApi {
public User getUserByName (String username) throws ApiException {
Object postBody = null;
// verify the required parameter 'username' is set
if (username == null) {
throw new ApiException(400, "Missing the required parameter 'username' when calling getUserByName");
}
// create path and map variables
String path = "/user/{username}".replaceAll("\\{format\\}","json")
@@ -351,6 +356,11 @@ public class UserApi {
public void updateUser (String username, User body) throws ApiException {
Object postBody = body;
// verify the required parameter 'username' is set
if (username == null) {
throw new ApiException(400, "Missing the required parameter 'username' when calling updateUser");
}
// create path and map variables
String path = "/user/{username}".replaceAll("\\{format\\}","json")
@@ -402,6 +412,11 @@ public class UserApi {
public void deleteUser (String username) throws ApiException {
Object postBody = null;
// verify the required parameter 'username' is set
if (username == null) {
throw new ApiException(400, "Missing the required parameter 'username' when calling deleteUser");
}
// create path and map variables
String path = "/user/{username}".replaceAll("\\{format\\}","json")

View File

@@ -38,6 +38,7 @@ class PetApi {
* @return void
*/
public function updatePet($body) {
// parse inputs
$resourcePath = "/pet";
@@ -91,6 +92,7 @@ class PetApi {
* @return void
*/
public function addPet($body) {
// parse inputs
$resourcePath = "/pet";
@@ -144,6 +146,7 @@ class PetApi {
* @return array[Pet]
*/
public function findPetsByStatus($status) {
// parse inputs
$resourcePath = "/pet/findByStatus";
@@ -202,6 +205,7 @@ class PetApi {
* @return array[Pet]
*/
public function findPetsByTags($tags) {
// parse inputs
$resourcePath = "/pet/findByTags";
@@ -260,6 +264,12 @@ class PetApi {
* @return Pet
*/
public function getPetById($pet_id) {
// verify the required parameter 'pet_id' is set
if ($pet_id === null) {
throw new \Exception("Missing the required parameter $pet_id when calling getPetById");
}
// parse inputs
$resourcePath = "/pet/{petId}";
@@ -321,6 +331,12 @@ class PetApi {
* @return void
*/
public function updatePetWithForm($pet_id, $name, $status) {
// verify the required parameter 'pet_id' is set
if ($pet_id === null) {
throw new \Exception("Missing the required parameter $pet_id when calling updatePetWithForm");
}
// parse inputs
$resourcePath = "/pet/{petId}";
@@ -381,6 +397,12 @@ class PetApi {
* @return void
*/
public function deletePet($api_key, $pet_id) {
// verify the required parameter 'pet_id' is set
if ($pet_id === null) {
throw new \Exception("Missing the required parameter $pet_id when calling deletePet");
}
// parse inputs
$resourcePath = "/pet/{petId}";
@@ -439,6 +461,12 @@ class PetApi {
* @return void
*/
public function uploadFile($pet_id, $additional_metadata, $file) {
// verify the required parameter 'pet_id' is set
if ($pet_id === null) {
throw new \Exception("Missing the required parameter $pet_id when calling uploadFile");
}
// parse inputs
$resourcePath = "/pet/{petId}/uploadImage";

View File

@@ -37,6 +37,7 @@ class StoreApi {
* @return map[string,int]
*/
public function getInventory() {
// parse inputs
$resourcePath = "/store/inventory";
@@ -92,6 +93,7 @@ class StoreApi {
* @return Order
*/
public function placeOrder($body) {
// parse inputs
$resourcePath = "/store/order";
@@ -151,6 +153,12 @@ class StoreApi {
* @return Order
*/
public function getOrderById($order_id) {
// verify the required parameter 'order_id' is set
if ($order_id === null) {
throw new \Exception("Missing the required parameter $order_id when calling getOrderById");
}
// parse inputs
$resourcePath = "/store/order/{orderId}";
@@ -210,6 +218,12 @@ class StoreApi {
* @return void
*/
public function deleteOrder($order_id) {
// verify the required parameter 'order_id' is set
if ($order_id === null) {
throw new \Exception("Missing the required parameter $order_id when calling deleteOrder");
}
// parse inputs
$resourcePath = "/store/order/{orderId}";

View File

@@ -38,6 +38,7 @@ class UserApi {
* @return void
*/
public function createUser($body) {
// parse inputs
$resourcePath = "/user";
@@ -91,6 +92,7 @@ class UserApi {
* @return void
*/
public function createUsersWithArrayInput($body) {
// parse inputs
$resourcePath = "/user/createWithArray";
@@ -144,6 +146,7 @@ class UserApi {
* @return void
*/
public function createUsersWithListInput($body) {
// parse inputs
$resourcePath = "/user/createWithList";
@@ -198,6 +201,7 @@ class UserApi {
* @return string
*/
public function loginUser($username, $password) {
// parse inputs
$resourcePath = "/user/login";
@@ -258,6 +262,7 @@ class UserApi {
* @return void
*/
public function logoutUser() {
// parse inputs
$resourcePath = "/user/logout";
@@ -307,6 +312,12 @@ class UserApi {
* @return User
*/
public function getUserByName($username) {
// verify the required parameter 'username' is set
if ($username === null) {
throw new \Exception("Missing the required parameter $username when calling getUserByName");
}
// parse inputs
$resourcePath = "/user/{username}";
@@ -367,6 +378,12 @@ class UserApi {
* @return void
*/
public function updateUser($username, $body) {
// verify the required parameter 'username' is set
if ($username === null) {
throw new \Exception("Missing the required parameter $username when calling updateUser");
}
// parse inputs
$resourcePath = "/user/{username}";
@@ -424,6 +441,12 @@ class UserApi {
* @return void
*/
public function deleteUser($username) {
// verify the required parameter 'username' is set
if ($username === null) {
throw new \Exception("Missing the required parameter $username when calling deleteUser");
}
// parse inputs
$resourcePath = "/user/{username}";

View File

@@ -10,7 +10,7 @@ class PetApi
# @option opts [Pet] :body Pet object that needs to be added to the store
# @return void
def self.update_pet(opts = {})
# verify existence of params
# resource path
path = "/pet".sub('{format}','json')
@@ -62,7 +62,7 @@ class PetApi
# @option opts [Pet] :body Pet object that needs to be added to the store
# @return void
def self.add_pet(opts = {})
# verify existence of params
# resource path
path = "/pet".sub('{format}','json')
@@ -114,7 +114,7 @@ class PetApi
# @option opts [array[string]] :status Status values that need to be considered for filter
# @return array[Pet]
def self.find_pets_by_status(opts = {})
# verify existence of params
# resource path
path = "/pet/findByStatus".sub('{format}','json')
@@ -148,7 +148,7 @@ class PetApi
# @option opts [array[string]] :tags Tags to filter by
# @return array[Pet]
def self.find_pets_by_tags(opts = {})
# verify existence of params
# resource path
path = "/pet/findByTags".sub('{format}','json')
@@ -182,8 +182,10 @@ class PetApi
# @param [Hash] opts the optional parameters
# @return Pet
def self.get_pet_by_id(pet_id, opts = {})
# verify existence of params
raise "pet_id is required" if pet_id.nil?
# verify the required parameter 'pet_id' is set
raise "Missing the required parameter 'pet_id' when calling get_pet_by_id" if pet_id.nil?
# resource path
path = "/pet/{petId}".sub('{format}','json').sub('{' + 'petId' + '}', pet_id.to_s)
@@ -218,8 +220,10 @@ class PetApi
# @option opts [string] :status Updated status of the pet
# @return void
def self.update_pet_with_form(pet_id, opts = {})
# verify existence of params
raise "pet_id is required" if pet_id.nil?
# verify the required parameter 'pet_id' is set
raise "Missing the required parameter 'pet_id' when calling update_pet_with_form" if pet_id.nil?
# resource path
path = "/pet/{petId}".sub('{format}','json').sub('{' + 'petId' + '}', pet_id.to_s)
@@ -254,8 +258,10 @@ class PetApi
# @option opts [string] :api_key
# @return void
def self.delete_pet(pet_id, opts = {})
# verify existence of params
raise "pet_id is required" if pet_id.nil?
# verify the required parameter 'pet_id' is set
raise "Missing the required parameter 'pet_id' when calling delete_pet" if pet_id.nil?
# resource path
path = "/pet/{petId}".sub('{format}','json').sub('{' + 'petId' + '}', pet_id.to_s)
@@ -290,8 +296,10 @@ class PetApi
# @option opts [file] :file file to upload
# @return void
def self.upload_file(pet_id, opts = {})
# verify existence of params
raise "pet_id is required" if pet_id.nil?
# verify the required parameter 'pet_id' is set
raise "Missing the required parameter 'pet_id' when calling upload_file" if pet_id.nil?
# resource path
path = "/pet/{petId}/uploadImage".sub('{format}','json').sub('{' + 'petId' + '}', pet_id.to_s)

View File

@@ -9,7 +9,7 @@ class StoreApi
# @param [Hash] opts the optional parameters
# @return map[string,int]
def self.get_inventory(opts = {})
# verify existence of params
# resource path
path = "/store/inventory".sub('{format}','json')
@@ -42,7 +42,7 @@ class StoreApi
# @option opts [Order] :body order placed for purchasing the pet
# @return Order
def self.place_order(opts = {})
# verify existence of params
# resource path
path = "/store/order".sub('{format}','json')
@@ -95,8 +95,10 @@ class StoreApi
# @param [Hash] opts the optional parameters
# @return Order
def self.get_order_by_id(order_id, opts = {})
# verify existence of params
raise "order_id is required" if order_id.nil?
# verify the required parameter 'order_id' is set
raise "Missing the required parameter 'order_id' when calling get_order_by_id" if order_id.nil?
# resource path
path = "/store/order/{orderId}".sub('{format}','json').sub('{' + 'orderId' + '}', order_id.to_s)
@@ -129,8 +131,10 @@ class StoreApi
# @param [Hash] opts the optional parameters
# @return void
def self.delete_order(order_id, opts = {})
# verify existence of params
raise "order_id is required" if order_id.nil?
# verify the required parameter 'order_id' is set
raise "Missing the required parameter 'order_id' when calling delete_order" if order_id.nil?
# resource path
path = "/store/order/{orderId}".sub('{format}','json').sub('{' + 'orderId' + '}', order_id.to_s)

View File

@@ -10,7 +10,7 @@ class UserApi
# @option opts [User] :body Created user object
# @return void
def self.create_user(opts = {})
# verify existence of params
# resource path
path = "/user".sub('{format}','json')
@@ -62,7 +62,7 @@ class UserApi
# @option opts [array[User]] :body List of user object
# @return void
def self.create_users_with_array_input(opts = {})
# verify existence of params
# resource path
path = "/user/createWithArray".sub('{format}','json')
@@ -114,7 +114,7 @@ class UserApi
# @option opts [array[User]] :body List of user object
# @return void
def self.create_users_with_list_input(opts = {})
# verify existence of params
# resource path
path = "/user/createWithList".sub('{format}','json')
@@ -167,7 +167,7 @@ class UserApi
# @option opts [string] :password The password for login in clear text
# @return string
def self.login_user(opts = {})
# verify existence of params
# resource path
path = "/user/login".sub('{format}','json')
@@ -201,7 +201,7 @@ class UserApi
# @param [Hash] opts the optional parameters
# @return void
def self.logout_user(opts = {})
# verify existence of params
# resource path
path = "/user/logout".sub('{format}','json')
@@ -233,8 +233,10 @@ class UserApi
# @param [Hash] opts the optional parameters
# @return User
def self.get_user_by_name(username, opts = {})
# verify existence of params
raise "username is required" if username.nil?
# verify the required parameter 'username' is set
raise "Missing the required parameter 'username' when calling get_user_by_name" if username.nil?
# resource path
path = "/user/{username}".sub('{format}','json').sub('{' + 'username' + '}', username.to_s)
@@ -268,8 +270,10 @@ class UserApi
# @option opts [User] :body Updated user object
# @return void
def self.update_user(username, opts = {})
# verify existence of params
raise "username is required" if username.nil?
# verify the required parameter 'username' is set
raise "Missing the required parameter 'username' when calling update_user" if username.nil?
# resource path
path = "/user/{username}".sub('{format}','json').sub('{' + 'username' + '}', username.to_s)
@@ -321,8 +325,10 @@ class UserApi
# @param [Hash] opts the optional parameters
# @return void
def self.delete_user(username, opts = {})
# verify existence of params
raise "username is required" if username.nil?
# verify the required parameter 'username' is set
raise "Missing the required parameter 'username' when calling delete_user" if username.nil?
# resource path
path = "/user/{username}".sub('{format}','json').sub('{' + 'username' + '}', username.to_s)