From a08164592aeaf8ca04aee46b10ba3221a0ecd5e3 Mon Sep 17 00:00:00 2001 From: wing328 Date: Mon, 9 Apr 2018 10:48:45 +0800 Subject: [PATCH] fix ruby parameters in documentation, fix reuqiredParams, optionalParams --- .../codegen/CodegenOperation.java | 25 ++++++++ .../openapitools/codegen/DefaultCodegen.java | 9 ++- .../src/main/resources/ruby/api_doc.mustache | 22 ++++--- .../petstore/ruby/docs/AnotherFakeApi.md | 2 - samples/client/petstore/ruby/docs/FakeApi.md | 57 ++++++++++--------- .../ruby/docs/FakeClassnameTags123Api.md | 2 - samples/client/petstore/ruby/docs/PetApi.md | 39 ++++++------- samples/client/petstore/ruby/docs/StoreApi.md | 6 -- samples/client/petstore/ruby/docs/UserApi.md | 16 ------ 9 files changed, 95 insertions(+), 83 deletions(-) diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/CodegenOperation.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/CodegenOperation.java index 3aecd85248b8..4b9a7abed8b8 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/CodegenOperation.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/CodegenOperation.java @@ -34,6 +34,7 @@ public class CodegenOperation { public List formParams = new ArrayList(); public List cookieParams = new ArrayList(); public List requiredParams = new ArrayList(); + public List optionalParams = new ArrayList(); public List authMethods; public List tags; public List responses = new ArrayList(); @@ -111,6 +112,24 @@ public boolean getHasCookieParams() { return nonempty(cookieParams); } + /** + * Check if there's at least one optional parameter + * + * @return true if any optional parameter exists, false otherwise + */ + public boolean getHasOptionalParams() { + return nonempty(optionalParams); + } + + /** + * Check if there's at least one required parameter + * + * @return true if any optional parameter exists, false otherwise + */ + public boolean getHasRequiredParams() { + return nonempty(requiredParams); + } + /** * Check if there's at least one example parameter * @@ -293,6 +312,10 @@ public boolean equals(Object o) { return false; if (cookieParams != null ? !cookieParams.equals(that.cookieParams) : that.cookieParams != null) return false; + if (requiredParams != null ? !requiredParams.equals(that.requiredParams) : that.requiredParams!= null) + return false; + if (optionalParams != null ? !optionalParams.equals(that.optionalParams) : that.optionalParams!= null) + return false; if (authMethods != null ? !authMethods.equals(that.authMethods) : that.authMethods != null) return false; if (tags != null ? !tags.equals(that.tags) : that.tags != null) @@ -360,6 +383,8 @@ public int hashCode() { result = 31 * result + (headerParams != null ? headerParams.hashCode() : 0); result = 31 * result + (formParams != null ? formParams.hashCode() : 0); result = 31 * result + (cookieParams != null ? cookieParams.hashCode() : 0); + result = 31 * result + (requiredParams!= null ? requiredParams.hashCode() : 0); + result = 31 * result + (optionalParams != null ? optionalParams.hashCode() : 0); result = 31 * result + (authMethods != null ? authMethods.hashCode() : 0); result = 31 * result + (tags != null ? tags.hashCode() : 0); result = 31 * result + (responses != null ? responses.hashCode() : 0); diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/DefaultCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/DefaultCodegen.java index 2c734796c3db..fe2a07932f97 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/DefaultCodegen.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/DefaultCodegen.java @@ -2135,6 +2135,7 @@ public CodegenOperation fromOperation(String path, List cookieParams = new ArrayList(); List formParams = new ArrayList(); List requiredParams = new ArrayList(); + List optionalParams = new ArrayList(); CodegenParameter bodyParam = null; RequestBody requestBody = operation.getRequestBody(); @@ -2202,9 +2203,9 @@ public CodegenOperation fromOperation(String path, for (CodegenParameter cp : bodyParams) { allParams.add(cp.copy()); } - } + // ensure unique parameter name for (CodegenParameter cp : allParams) { if (ensureUniqueParams) { if (isParameterNameUnique(cp, allParams)) { @@ -2213,9 +2214,14 @@ public CodegenOperation fromOperation(String path, cp.paramName = generateNextName(cp.paramName); } } + } + + // create optional, required parameters + for (CodegenParameter cp : allParams) { if (cp.required) { //required parameters requiredParams.add(cp.copy()); } else { // optional parameters + optionalParams.add(cp.copy()); op.hasOptionalParams = true; } } @@ -2250,6 +2256,7 @@ public int compare(CodegenParameter one, CodegenParameter another) { op.cookieParams = addHasMore(cookieParams); op.formParams = addHasMore(formParams); op.requiredParams = addHasMore(requiredParams); + op.optionalParams = addHasMore(optionalParams); op.externalDocs = operation.getExternalDocs(); // legacy support op.nickname = op.operationId; diff --git a/modules/openapi-generator/src/main/resources/ruby/api_doc.mustache b/modules/openapi-generator/src/main/resources/ruby/api_doc.mustache index 02fd5f7f5474..5f6f5bb5a5a9 100644 --- a/modules/openapi-generator/src/main/resources/ruby/api_doc.mustache +++ b/modules/openapi-generator/src/main/resources/ruby/api_doc.mustache @@ -11,7 +11,7 @@ Method | HTTP request | Description {{#operations}} {{#operation}} # **{{operationId}}** -> {{#returnType}}{{returnType}} {{/returnType}}{{operationId}}{{#hasParams}}({{#allParams}}{{#required}}{{{paramName}}}{{#vendorExtensions.x-codegen-hasMoreRequired}}, {{/vendorExtensions.x-codegen-hasMoreRequired}}{{/required}}{{/allParams}}{{#hasOptionalParams}}{{#vendorExtensions.x-codegen-hasRequiredParams}}, {{/vendorExtensions.x-codegen-hasRequiredParams}}opts{{/hasOptionalParams}}){{/hasParams}} +> {{#returnType}}{{returnType}} {{/returnType}}{{operationId}}{{#hasParams}}({{#requiredParams}}{{{paramName}}}{{^-last}}, {{/-last}}{{/requiredParams}}{{#optionalParams}}{{#-last}}{{#hasRequiredParams}}, {{/hasRequiredParams}}opts{{/-last}}{{/optionalParams}}){{/hasParams}} {{{summary}}}{{#notes}} @@ -36,17 +36,23 @@ require '{{{gemName}}}' {{/authMethods}}end {{/hasAuthMethods}} -api_instance = {{{moduleName}}}::{{{classname}}}.new{{#hasParams}} -{{#vendorExtensions.x-codegen-hasRequiredParams}}{{#allParams}}{{#required}} +api_instance = {{{moduleName}}}::{{{classname}}}.new +{{#requiredParams}} {{{paramName}}} = {{{example}}} # {{{dataType}}} | {{{description}}} -{{/required}}{{/allParams}}{{/vendorExtensions.x-codegen-hasRequiredParams}}{{#hasOptionalParams}} -opts = { {{#allParams}}{{^required}} - {{{paramName}}}: {{{example}}}{{#vendorExtensions.x-codegen-hasMoreOptional}},{{/vendorExtensions.x-codegen-hasMoreOptional}} # {{{dataType}}} | {{{description}}}{{/required}}{{/allParams}} -}{{/hasOptionalParams}}{{/hasParams}} +{{/requiredParams}} +{{#optionalParams}} +{{#-first}} +opts = { +{{/-first}} + {{{paramName}}}: {{{example}}}{{^-last}},{{/-last}} # {{{dataType}}} | {{{description}}} +{{#-last}} +} +{{/-last}} +{{/optionalParams}} begin {{#summary}} #{{{.}}} -{{/summary}} {{#returnType}}result = {{/returnType}}api_instance.{{{operationId}}}{{#hasParams}}({{#allParams}}{{#required}}{{{paramName}}}{{#vendorExtensions.x-codegen-hasMoreRequired}}, {{/vendorExtensions.x-codegen-hasMoreRequired}}{{/required}}{{/allParams}}{{#hasOptionalParams}}{{#vendorExtensions.x-codegen-hasRequiredParams}}, {{/vendorExtensions.x-codegen-hasRequiredParams}}opts{{/hasOptionalParams}}){{/hasParams}}{{#returnType}} +{{/summary}} {{#returnType}}result = {{/returnType}}api_instance.{{{operationId}}}{{#hasParams}}({{#requiredParams}}{{{paramName}}}{{^-last}}, {{/-last}}{{/requiredParams}}{{#optionalParams}}{{#-last}}{{#hasRequiredParams}}, {{/hasRequiredParams}}opts{{/-last}}{{/optionalParams}}){{/hasParams}}{{#returnType}} p result{{/returnType}} rescue {{{moduleName}}}::ApiError => e puts "Exception when calling {{classname}}->{{{operationId}}}: #{e}" diff --git a/samples/client/petstore/ruby/docs/AnotherFakeApi.md b/samples/client/petstore/ruby/docs/AnotherFakeApi.md index bb5de8285ab0..da2d5ff0b19d 100644 --- a/samples/client/petstore/ruby/docs/AnotherFakeApi.md +++ b/samples/client/petstore/ruby/docs/AnotherFakeApi.md @@ -20,10 +20,8 @@ To test special tags require 'petstore' api_instance = Petstore::AnotherFakeApi.new - client = Petstore::Client.new # Client | client model - begin #To test special tags result = api_instance.test_special_tags(client) diff --git a/samples/client/petstore/ruby/docs/FakeApi.md b/samples/client/petstore/ruby/docs/FakeApi.md index 7842f6f681fa..27eca3835dda 100644 --- a/samples/client/petstore/ruby/docs/FakeApi.md +++ b/samples/client/petstore/ruby/docs/FakeApi.md @@ -17,7 +17,7 @@ Method | HTTP request | Description # **fake_outer_boolean_serialize** -> OuterBoolean fake_outer_boolean_serialize() +> OuterBoolean fake_outer_boolean_serialize(opts) @@ -29,10 +29,12 @@ Test serialization of outer boolean types require 'petstore' api_instance = Petstore::FakeApi.new - +opts = { + UNKNOWN_PARAM_NAME: Petstore::null.new # | Input boolean as post body +} begin - result = api_instance.fake_outer_boolean_serialize() + result = api_instance.fake_outer_boolean_serialize(opts) p result rescue Petstore::ApiError => e puts "Exception when calling FakeApi->fake_outer_boolean_serialize: #{e}" @@ -61,7 +63,7 @@ No authorization required # **fake_outer_composite_serialize** -> OuterComposite fake_outer_composite_serialize() +> OuterComposite fake_outer_composite_serialize(opts) @@ -73,10 +75,12 @@ Test serialization of object with outer number type require 'petstore' api_instance = Petstore::FakeApi.new - +opts = { + outer_composite: Petstore::OuterComposite.new # OuterComposite | Input composite as post body +} begin - result = api_instance.fake_outer_composite_serialize() + result = api_instance.fake_outer_composite_serialize(opts) p result rescue Petstore::ApiError => e puts "Exception when calling FakeApi->fake_outer_composite_serialize: #{e}" @@ -105,7 +109,7 @@ No authorization required # **fake_outer_number_serialize** -> OuterNumber fake_outer_number_serialize() +> OuterNumber fake_outer_number_serialize(opts) @@ -117,10 +121,12 @@ Test serialization of outer number types require 'petstore' api_instance = Petstore::FakeApi.new - +opts = { + UNKNOWN_PARAM_NAME: Petstore::null.new # | Input number as post body +} begin - result = api_instance.fake_outer_number_serialize() + result = api_instance.fake_outer_number_serialize(opts) p result rescue Petstore::ApiError => e puts "Exception when calling FakeApi->fake_outer_number_serialize: #{e}" @@ -149,7 +155,7 @@ No authorization required # **fake_outer_string_serialize** -> OuterString fake_outer_string_serialize() +> OuterString fake_outer_string_serialize(opts) @@ -161,10 +167,12 @@ Test serialization of outer string types require 'petstore' api_instance = Petstore::FakeApi.new - +opts = { + UNKNOWN_PARAM_NAME: Petstore::null.new # | Input string as post body +} begin - result = api_instance.fake_outer_string_serialize() + result = api_instance.fake_outer_string_serialize(opts) p result rescue Petstore::ApiError => e puts "Exception when calling FakeApi->fake_outer_string_serialize: #{e}" @@ -203,12 +211,9 @@ No authorization required require 'petstore' api_instance = Petstore::FakeApi.new - query = 'query_example' # String | - user = Petstore::User.new # User | - begin api_instance.test_body_with_query_params(query, user) rescue Petstore::ApiError => e @@ -251,10 +256,8 @@ To test \"client\" model require 'petstore' api_instance = Petstore::FakeApi.new - client = Petstore::Client.new # Client | client model - begin #To test \"client\" model result = api_instance.test_client_model(client) @@ -304,10 +307,8 @@ Petstore.configure do |config| end api_instance = Petstore::FakeApi.new - UNKNOWN_PARAM_NAME = Petstore::null.new # | - begin #Fake endpoint for testing various parameters 假端點 偽のエンドポイント 가짜 엔드 포인트 api_instance.test_endpoint_parameters(UNKNOWN_PARAM_NAME) @@ -338,7 +339,7 @@ nil (empty response body) # **test_enum_parameters** -> test_enum_parameters() +> test_enum_parameters(opts) To test enum parameters @@ -350,11 +351,19 @@ To test enum parameters require 'petstore' api_instance = Petstore::FakeApi.new - +opts = { + enum_header_string_array: ['enum_header_string_array_example'], # Array | Header parameter enum test (string array) + enum_header_string: 'enum_header_string_example', # String | Header parameter enum test (string) + enum_query_string_array: ['enum_query_string_array_example'], # Array | Query parameter enum test (string array) + enum_query_string: 'enum_query_string_example', # String | Query parameter enum test (string) + enum_query_integer: 56, # Integer | Query parameter enum test (double) + enum_query_double: 1.2, # Float | Query parameter enum test (double) + UNKNOWN_PARAM_NAME: Petstore::null.new # | +} begin #To test enum parameters - api_instance.test_enum_parameters() + api_instance.test_enum_parameters(opts) rescue Petstore::ApiError => e puts "Exception when calling FakeApi->test_enum_parameters: #{e}" end @@ -398,10 +407,8 @@ test inline additionalProperties require 'petstore' api_instance = Petstore::FakeApi.new - UNKNOWN_PARAM_NAME = Petstore::null.new # | request body - begin #test inline additionalProperties api_instance.test_inline_additional_properties(UNKNOWN_PARAM_NAME) @@ -442,10 +449,8 @@ test json serialization of form data require 'petstore' api_instance = Petstore::FakeApi.new - UNKNOWN_PARAM_NAME = Petstore::null.new # | - begin #test json serialization of form data api_instance.test_json_form_data(UNKNOWN_PARAM_NAME) diff --git a/samples/client/petstore/ruby/docs/FakeClassnameTags123Api.md b/samples/client/petstore/ruby/docs/FakeClassnameTags123Api.md index f4eee7c462ec..a6153f02926a 100644 --- a/samples/client/petstore/ruby/docs/FakeClassnameTags123Api.md +++ b/samples/client/petstore/ruby/docs/FakeClassnameTags123Api.md @@ -27,10 +27,8 @@ Petstore.configure do |config| end api_instance = Petstore::FakeClassnameTags123Api.new - client = Petstore::Client.new # Client | client model - begin #To test class name in snake case result = api_instance.test_classname(client) diff --git a/samples/client/petstore/ruby/docs/PetApi.md b/samples/client/petstore/ruby/docs/PetApi.md index a87699455524..fe7425859160 100644 --- a/samples/client/petstore/ruby/docs/PetApi.md +++ b/samples/client/petstore/ruby/docs/PetApi.md @@ -30,10 +30,8 @@ Petstore.configure do |config| end api_instance = Petstore::PetApi.new - pet = Petstore::Pet.new # Pet | Pet object that needs to be added to the store - begin #Add a new pet to the store api_instance.add_pet(pet) @@ -64,7 +62,7 @@ nil (empty response body) # **delete_pet** -> delete_pet(pet_id) +> delete_pet(pet_id, opts) Deletes a pet @@ -79,13 +77,14 @@ Petstore.configure do |config| end api_instance = Petstore::PetApi.new - pet_id = 789 # Integer | Pet id to delete - +opts = { + api_key: 'api_key_example' # String | +} begin #Deletes a pet - api_instance.delete_pet(pet_id) + api_instance.delete_pet(pet_id, opts) rescue Petstore::ApiError => e puts "Exception when calling PetApi->delete_pet: #{e}" end @@ -131,10 +130,8 @@ Petstore.configure do |config| end api_instance = Petstore::PetApi.new - status = ['status_example'] # Array | Status values that need to be considered for filter - begin #Finds Pets by status result = api_instance.find_pets_by_status(status) @@ -183,10 +180,8 @@ Petstore.configure do |config| end api_instance = Petstore::PetApi.new - tags = ['tags_example'] # Array | Tags to filter by - begin #Finds Pets by tags result = api_instance.find_pets_by_tags(tags) @@ -237,10 +232,8 @@ Petstore.configure do |config| end api_instance = Petstore::PetApi.new - pet_id = 789 # Integer | ID of pet to return - begin #Find pet by ID result = api_instance.get_pet_by_id(pet_id) @@ -287,10 +280,8 @@ Petstore.configure do |config| end api_instance = Petstore::PetApi.new - pet = Petstore::Pet.new # Pet | Pet object that needs to be added to the store - begin #Update an existing pet api_instance.update_pet(pet) @@ -321,7 +312,7 @@ nil (empty response body) # **update_pet_with_form** -> update_pet_with_form(pet_id) +> update_pet_with_form(pet_id, opts) Updates a pet in the store with form data @@ -336,13 +327,15 @@ Petstore.configure do |config| end api_instance = Petstore::PetApi.new - pet_id = 789 # Integer | ID of pet that needs to be updated - +opts = { + name: 'name_example', # String | Updated name of the pet + status: 'status_example' # String | Updated status of the pet +} begin #Updates a pet in the store with form data - api_instance.update_pet_with_form(pet_id) + api_instance.update_pet_with_form(pet_id, opts) rescue Petstore::ApiError => e puts "Exception when calling PetApi->update_pet_with_form: #{e}" end @@ -372,7 +365,7 @@ nil (empty response body) # **upload_file** -> ApiResponse upload_file(pet_id) +> ApiResponse upload_file(pet_id, opts) uploads an image @@ -387,13 +380,15 @@ Petstore.configure do |config| end api_instance = Petstore::PetApi.new - pet_id = 789 # Integer | ID of pet to update - +opts = { + additional_metadata: 'additional_metadata_example', # String | Additional data to pass to server + file: File.new('/path/to/file') # File | file to upload +} begin #uploads an image - result = api_instance.upload_file(pet_id) + result = api_instance.upload_file(pet_id, opts) p result rescue Petstore::ApiError => e puts "Exception when calling PetApi->upload_file: #{e}" diff --git a/samples/client/petstore/ruby/docs/StoreApi.md b/samples/client/petstore/ruby/docs/StoreApi.md index d24d9fcc4ebb..4badb903ea43 100644 --- a/samples/client/petstore/ruby/docs/StoreApi.md +++ b/samples/client/petstore/ruby/docs/StoreApi.md @@ -23,10 +23,8 @@ For valid response try integer IDs with value < 1000. Anything above 1000 or non require 'petstore' api_instance = Petstore::StoreApi.new - order_id = 'order_id_example' # String | ID of the order that needs to be deleted - begin #Delete purchase order by ID api_instance.delete_order(order_id) @@ -117,10 +115,8 @@ For valid response try integer IDs with value <= 5 or > 10. Other values will ge require 'petstore' api_instance = Petstore::StoreApi.new - order_id = 789 # Integer | ID of pet that needs to be fetched - begin #Find purchase order by ID result = api_instance.get_order_by_id(order_id) @@ -162,10 +158,8 @@ Place an order for a pet require 'petstore' api_instance = Petstore::StoreApi.new - order = Petstore::Order.new # Order | order placed for purchasing the pet - begin #Place an order for a pet result = api_instance.place_order(order) diff --git a/samples/client/petstore/ruby/docs/UserApi.md b/samples/client/petstore/ruby/docs/UserApi.md index c4c2f9d700a1..1b6deedb1150 100644 --- a/samples/client/petstore/ruby/docs/UserApi.md +++ b/samples/client/petstore/ruby/docs/UserApi.md @@ -27,10 +27,8 @@ This can only be done by the logged in user. require 'petstore' api_instance = Petstore::UserApi.new - user = Petstore::User.new # User | Created user object - begin #Create user api_instance.create_user(user) @@ -71,10 +69,8 @@ Creates list of users with given input array require 'petstore' api_instance = Petstore::UserApi.new - user = [Petstore::User.new] # Array | List of user object - begin #Creates list of users with given input array api_instance.create_users_with_array_input(user) @@ -115,10 +111,8 @@ Creates list of users with given input array require 'petstore' api_instance = Petstore::UserApi.new - user = [Petstore::User.new] # Array | List of user object - begin #Creates list of users with given input array api_instance.create_users_with_list_input(user) @@ -161,10 +155,8 @@ This can only be done by the logged in user. require 'petstore' api_instance = Petstore::UserApi.new - username = 'username_example' # String | The name that needs to be deleted - begin #Delete user api_instance.delete_user(username) @@ -205,10 +197,8 @@ Get user by user name require 'petstore' api_instance = Petstore::UserApi.new - username = 'username_example' # String | The name that needs to be fetched. Use user1 for testing. - begin #Get user by user name result = api_instance.get_user_by_name(username) @@ -250,12 +240,9 @@ Logs user into the system require 'petstore' api_instance = Petstore::UserApi.new - username = 'username_example' # String | The user name for login - password = 'password_example' # String | The password for login in clear text - begin #Logs user into the system result = api_instance.login_user(username, password) @@ -338,12 +325,9 @@ This can only be done by the logged in user. require 'petstore' api_instance = Petstore::UserApi.new - username = 'username_example' # String | name that need to be deleted - user = Petstore::User.new # User | Updated user object - begin #Updated user api_instance.update_user(username, user)