Skip to content

Commit

Permalink
fix ruby parameters in documentation, fix reuqiredParams, optionalParams
Browse files Browse the repository at this point in the history
  • Loading branch information
wing328 committed Apr 9, 2018
1 parent 26f08aa commit a081645
Show file tree
Hide file tree
Showing 9 changed files with 95 additions and 83 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ public class CodegenOperation {
public List<CodegenParameter> formParams = new ArrayList<CodegenParameter>();
public List<CodegenParameter> cookieParams = new ArrayList<CodegenParameter>();
public List<CodegenParameter> requiredParams = new ArrayList<CodegenParameter>();
public List<CodegenParameter> optionalParams = new ArrayList<CodegenParameter>();
public List<CodegenSecurity> authMethods;
public List<Tag> tags;
public List<CodegenResponse> responses = new ArrayList<CodegenResponse>();
Expand Down Expand Up @@ -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
*
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2135,6 +2135,7 @@ public CodegenOperation fromOperation(String path,
List<CodegenParameter> cookieParams = new ArrayList<CodegenParameter>();
List<CodegenParameter> formParams = new ArrayList<CodegenParameter>();
List<CodegenParameter> requiredParams = new ArrayList<CodegenParameter>();
List<CodegenParameter> optionalParams = new ArrayList<CodegenParameter>();

CodegenParameter bodyParam = null;
RequestBody requestBody = operation.getRequestBody();
Expand Down Expand Up @@ -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)) {
Expand All @@ -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;
}
}
Expand Down Expand Up @@ -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;
Expand Down
22 changes: 14 additions & 8 deletions modules/openapi-generator/src/main/resources/ruby/api_doc.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -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}}

Expand All @@ -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}"
Expand Down
2 changes: 0 additions & 2 deletions samples/client/petstore/ruby/docs/AnotherFakeApi.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
57 changes: 31 additions & 26 deletions samples/client/petstore/ruby/docs/FakeApi.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ Method | HTTP request | Description


# **fake_outer_boolean_serialize**
> OuterBoolean fake_outer_boolean_serialize()
> OuterBoolean fake_outer_boolean_serialize(opts)


Expand All @@ -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}"
Expand Down Expand Up @@ -61,7 +63,7 @@ No authorization required


# **fake_outer_composite_serialize**
> OuterComposite fake_outer_composite_serialize()
> OuterComposite fake_outer_composite_serialize(opts)


Expand All @@ -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}"
Expand Down Expand Up @@ -105,7 +109,7 @@ No authorization required


# **fake_outer_number_serialize**
> OuterNumber fake_outer_number_serialize()
> OuterNumber fake_outer_number_serialize(opts)


Expand All @@ -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}"
Expand Down Expand Up @@ -149,7 +155,7 @@ No authorization required


# **fake_outer_string_serialize**
> OuterString fake_outer_string_serialize()
> OuterString fake_outer_string_serialize(opts)


Expand All @@ -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}"
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -338,7 +339,7 @@ nil (empty response body)


# **test_enum_parameters**
> test_enum_parameters()
> test_enum_parameters(opts)
To test enum parameters

Expand All @@ -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<String> | 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<String> | 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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
2 changes: 0 additions & 2 deletions samples/client/petstore/ruby/docs/FakeClassnameTags123Api.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Loading

0 comments on commit a081645

Please sign in to comment.