Skip to content

Commit

Permalink
Updated api client, Required parameters {{#required}} .. {{/required}…
Browse files Browse the repository at this point in the history
…}, are mapped to Eiffel (swagger-api#6653)

Void Safety Rules, optional parameters are translated to detachable TYPE.
Validation Rules are mapped to preconditions, at the moment maximun and minimun
validation has been added.
Improved API_CLIENT.parameter_to_tuple feature to accept a LIST [ANY] instead of LIST [STRING_32].
Improved model template to generate the model output.
  • Loading branch information
jvelilla authored and fvarose committed Oct 12, 2017
1 parent 5cdd1fc commit 1e6def8
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 6 deletions.
13 changes: 12 additions & 1 deletion modules/swagger-codegen/src/main/resources/Eiffel/api.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,25 @@ feature -- API Access

{{#operation}}

{{operationId}} {{#hasParams}}({{#allParams}}{{paramName}}: {{#required}}{{{dataType}}}{{/required}}{{^required}}detachable {{{dataType}}}{{/required}}{{#hasMore}}; {{/hasMore}}{{/allParams}}){{/hasParams}}{{#returnType}}: detachable {{{returnType}}}{{/returnType}}{{^returnType}}{{/returnType}}
{{operationId}} {{#hasParams}}({{#allParams}}{{paramName}}: {{#required}}{{{dataType}}}{{/required}}{{^required}}{{#isPrimitiveType}}{{{dataType}}}{{/isPrimitiveType}}{{^isPrimitiveType}}detachable {{{dataType}}}{{/isPrimitiveType}}{{/required}}{{#hasMore}}; {{/hasMore}}{{/allParams}}){{/hasParams}}{{#returnType}}: detachable {{{returnType}}}{{/returnType}}{{^returnType}}{{/returnType}}
-- {{summary}}
-- {{notes}}
-- {{#allParams}}
-- argument: {{paramName}} {{description}}{{#required}} (required){{/required}}{{^required}} (optional{{#defaultValue}}, default to {{{.}}}{{/defaultValue}}){{/required}}
-- {{/allParams}}
-- {{#returnType}}
-- Result {{returnType}}{{/returnType}}
require
{{#allParams}}
{{#hasValidation}}
{{#maximum}}
{{{paramName}}}_is_less_or_equal_than: {{{paramName}}} <= {{{maximum}}}
{{/maximum}}
{{#minimum}}
{{{paramName}}}_is_greater_or_equal_than: {{{paramName}}} >= {{{minimum}}}
{{/minimum}}
{{/hasValidation}}
{{/allParams}}
local
l_path: STRING
l_request: API_CLIENT_REQUEST
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ feature -- Query Parameter Helpers
l_delimiter: STRING
l_value: STRING
do
if attached {LIST [STRING_32]} a_value as a_list then
if attached {LIST [ANY]} a_value as a_list then
-- Collection
if a_list.is_empty then
-- Return an empty list
Expand All @@ -150,7 +150,7 @@ feature -- Query Parameter Helpers
end
if l_format.is_case_insensitive_equal ("multi") then
across a_list as ic loop
Result.force ([a_name, ic.item.as_string_8])
Result.force ([a_name, parameter_to_string (ic.item)])
end
else
if l_format.is_case_insensitive_equal ("csv") then
Expand All @@ -166,7 +166,7 @@ feature -- Query Parameter Helpers
end
across a_list as ic from create l_value.make_empty
loop
l_value.append (ic.item)
l_value.append (parameter_to_string (ic.item))
l_value.append (l_delimiter)
end
l_value.remove_tail (1)
Expand All @@ -185,6 +185,61 @@ feature -- Query Parameter Helpers
end


parameter_to_string (a_param: detachable ANY): STRING
-- return the string representation of the givien object `a_param'.
do
if a_param = Void then
Result := ""
else
if attached {BOOLEAN} a_param as bool then
Result := bool.out
elseif attached {NUMERIC} a_param as num then
if attached {INTEGER_64} num as i64 then
Result := i64.out
elseif attached {INTEGER_32} num as i32 then
Result := i32.out
elseif attached {INTEGER_16} num as i16 then
Result := i16.out
elseif attached {INTEGER_8} num as i8 then
Result := i8.out
elseif attached {NATURAL_64} num as n64 then
Result := n64.out
elseif attached {NATURAL_32} num as n32 then
Result := n32.out
elseif attached {NATURAL_16} num as n16 then
Result := n16.out
elseif attached {NATURAL_8} num as n8 then
Result := n8.out
elseif attached {REAL_64} num as r64 then
Result := r64.out
elseif attached {REAL_32} num as r32 then
Result := r32.out
else
check is_basic_numeric_type: False end
end
Result := num.out
elseif attached {CHARACTER_8} a_param as ch8 then
Result := ch8.out
elseif attached {CHARACTER_32} a_param as ch32 then
Result := ch32.out
elseif attached {POINTER} a_param as ptr then
Result := ptr.to_integer_32.out
elseif attached {DATE} a_param as date then
--TODO improve to support
-- date string As defined by full-date - RFC3339
Result := date.debug_output
elseif attached {DATE_TIME} a_param as date_time then
-- TODO improve to support
-- dateTime string date-time As defined by date-time - RFC3339
Result := date_time.date.debug_output
else
-- Unsupported Object type.
Result := ""
end
end
end


feature -- Status Report

is_valid_uri (a_uri: STRING): BOOLEAN
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,14 +74,15 @@ feature -- Change Element
{{#isListContainer}}
if attached {{name}} as l_{{name}} then
across l_{{name}} as ic loop
Result.append ("%N")
Result.append ("%N {{name}}:")
Result.append (ic.item.out)
Result.append ("%N")
end
end
{{/isListContainer}}
{{#isMapContainer}}
if attached {{name}} as l_{{name}} then
Result.append ("%N{{name}}:")
across l_{{name}} as ic loop
Result.append ("%N")
Result.append ("key:")
Expand All @@ -95,7 +96,7 @@ feature -- Change Element
{{/isMapContainer}}
{{^isContainer}}
if attached {{name}} as l_{{name}} then
Result.append ("%N")
Result.append ("%N{{name}}:")
Result.append (l_{{name}}.out)
Result.append ("%N")
end
Expand Down

0 comments on commit 1e6def8

Please sign in to comment.