Skip to content

Commit 3067da2

Browse files
jvelillawing328
authored andcommitted
Swagger eiffel:fix (#6674)
* Updated api client, Required parameters {{#required}} .. {{/required}}, are mapped to Eiffel 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. * Updated API_CLIENT.parameter_to_string feature, missing STRING representation. * Updating sample using the latest modifications.
1 parent 3f7f6b8 commit 3067da2

30 files changed

+198
-126
lines changed

modules/swagger-codegen/src/main/resources/Eiffel/api_client.mustache

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,10 @@ feature -- Query Parameter Helpers
232232
-- TODO improve to support
233233
-- dateTime string date-time As defined by date-time - RFC3339
234234
Result := date_time.date.debug_output
235+
elseif attached {STRING_32} a_param as str_32 then
236+
Result := str_32
237+
elseif attached {STRING_8} a_param as str_8 then
238+
Result := str_8
235239
else
236240
-- Unsupported Object type.
237241
Result := ""

samples/client/petstore/eiffel/README.md

Lines changed: 4 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Eiffel API client for swagger
22

3-
This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\
3+
This is a sample server Petstore server. You can find out more about Swagger at [http://swagger.io](http://swagger.io) or on [irc.freenode.net, #swagger](http://swagger.io/irc/). For this sample, you can use the api key `special-key` to test the authorization filters.
44

55
## Overview
66
This API client was generated by the [swagger-codegen](https://github.com/swagger-api/swagger-codegen) project. By using the [swagger-spec](https://github.com/swagger-api/swagger-spec) from a remote server, you can easily generate an API client.
@@ -17,19 +17,10 @@ Add the library into your Eiffel configuration file.
1717

1818
## Documentation for API Endpoints
1919

20-
All URIs are relative to *http://petstore.swagger.io:80/v2*
20+
All URIs are relative to *http://petstore.swagger.io/v2*
2121

2222
Class | Method | HTTP request | Description
2323
------------ | ------------- | ------------- | -------------
24-
*FAKE_API* | [**fake_outer_boolean_serialize**](docs/FAKE_API.md#fake_outer_boolean_serialize) | **Post** /fake/outer/boolean |
25-
*FAKE_API* | [**fake_outer_composite_serialize**](docs/FAKE_API.md#fake_outer_composite_serialize) | **Post** /fake/outer/composite |
26-
*FAKE_API* | [**fake_outer_number_serialize**](docs/FAKE_API.md#fake_outer_number_serialize) | **Post** /fake/outer/number |
27-
*FAKE_API* | [**fake_outer_string_serialize**](docs/FAKE_API.md#fake_outer_string_serialize) | **Post** /fake/outer/string |
28-
*FAKE_API* | [**test_client_model**](docs/FAKE_API.md#test_client_model) | **Patch** /fake | To test \"client\" model
29-
*FAKE_API* | [**test_endpoint_parameters**](docs/FAKE_API.md#test_endpoint_parameters) | **Post** /fake | Fake endpoint for testing various parameters 假端點 偽のエンドポイント 가짜 엔드 포인트
30-
*FAKE_API* | [**test_enum_parameters**](docs/FAKE_API.md#test_enum_parameters) | **Get** /fake | To test enum parameters
31-
*FAKE_API* | [**test_json_form_data**](docs/FAKE_API.md#test_json_form_data) | **Get** /fake/jsonFormData | test json serialization of form data
32-
*FAKE_CLASSNAME_TAGS123_API* | [**test_classname**](docs/FAKE_CLASSNAME_TAGS123_API.md#test_classname) | **Patch** /fake_classname_test | To test class name in snake case
3324
*PET_API* | [**add_pet**](docs/PET_API.md#add_pet) | **Post** /pet | Add a new pet to the store
3425
*PET_API* | [**delete_pet**](docs/PET_API.md#delete_pet) | **Delete** /pet/{petId} | Deletes a pet
3526
*PET_API* | [**find_pets_by_status**](docs/PET_API.md#find_pets_by_status) | **Get** /pet/findByStatus | Finds Pets by status
@@ -38,9 +29,9 @@ Class | Method | HTTP request | Description
3829
*PET_API* | [**update_pet**](docs/PET_API.md#update_pet) | **Put** /pet | Update an existing pet
3930
*PET_API* | [**update_pet_with_form**](docs/PET_API.md#update_pet_with_form) | **Post** /pet/{petId} | Updates a pet in the store with form data
4031
*PET_API* | [**upload_file**](docs/PET_API.md#upload_file) | **Post** /pet/{petId}/uploadImage | uploads an image
41-
*STORE_API* | [**delete_order**](docs/STORE_API.md#delete_order) | **Delete** /store/order/{order_id} | Delete purchase order by ID
32+
*STORE_API* | [**delete_order**](docs/STORE_API.md#delete_order) | **Delete** /store/order/{orderId} | Delete purchase order by ID
4233
*STORE_API* | [**inventory**](docs/STORE_API.md#inventory) | **Get** /store/inventory | Returns pet inventories by status
43-
*STORE_API* | [**order_by_id**](docs/STORE_API.md#order_by_id) | **Get** /store/order/{order_id} | Find purchase order by ID
34+
*STORE_API* | [**order_by_id**](docs/STORE_API.md#order_by_id) | **Get** /store/order/{orderId} | Find purchase order by ID
4435
*STORE_API* | [**place_order**](docs/STORE_API.md#place_order) | **Post** /store/order | Place an order for a pet
4536
*USER_API* | [**create_user**](docs/USER_API.md#create_user) | **Post** /user | Create user
4637
*USER_API* | [**create_users_with_array_input**](docs/USER_API.md#create_users_with_array_input) | **Post** /user/createWithArray | Creates list of users with given input array
@@ -54,41 +45,12 @@ Class | Method | HTTP request | Description
5445

5546
## Documentation For Models
5647

57-
- [ADDITIONAL_PROPERTIES_CLASS](docs/ADDITIONAL_PROPERTIES_CLASS.md)
58-
- [ANIMAL](docs/ANIMAL.md)
59-
- [ANIMAL_FARM](docs/ANIMAL_FARM.md)
6048
- [API_RESPONSE](docs/API_RESPONSE.md)
61-
- [ARRAY_OF_ARRAY_OF_NUMBER_ONLY](docs/ARRAY_OF_ARRAY_OF_NUMBER_ONLY.md)
62-
- [ARRAY_OF_NUMBER_ONLY](docs/ARRAY_OF_NUMBER_ONLY.md)
63-
- [ARRAY_TEST](docs/ARRAY_TEST.md)
64-
- [CAPITALIZATION](docs/CAPITALIZATION.md)
6549
- [CATEGORY](docs/CATEGORY.md)
66-
- [CLASS_MODEL](docs/CLASS_MODEL.md)
67-
- [CLIENT](docs/CLIENT.md)
68-
- [ENUM_ARRAYS](docs/ENUM_ARRAYS.md)
69-
- [ENUM_CLASS](docs/ENUM_CLASS.md)
70-
- [ENUM_TEST](docs/ENUM_TEST.md)
71-
- [FORMAT_TEST](docs/FORMAT_TEST.md)
72-
- [HAS_ONLY_READ_ONLY](docs/HAS_ONLY_READ_ONLY.md)
73-
- [MAP_TEST](docs/MAP_TEST.md)
74-
- [MIXED_PROPERTIES_AND_ADDITIONAL_PROPERTIES_CLASS](docs/MIXED_PROPERTIES_AND_ADDITIONAL_PROPERTIES_CLASS.md)
75-
- [MODEL_200_RESPONSE](docs/MODEL_200_RESPONSE.md)
76-
- [NAME](docs/NAME.md)
77-
- [NUMBER_ONLY](docs/NUMBER_ONLY.md)
7850
- [ORDER](docs/ORDER.md)
79-
- [OUTER_BOOLEAN](docs/OUTER_BOOLEAN.md)
80-
- [OUTER_COMPOSITE](docs/OUTER_COMPOSITE.md)
81-
- [OUTER_ENUM](docs/OUTER_ENUM.md)
82-
- [OUTER_NUMBER](docs/OUTER_NUMBER.md)
83-
- [OUTER_STRING](docs/OUTER_STRING.md)
8451
- [PET](docs/PET.md)
85-
- [READ_ONLY_FIRST](docs/READ_ONLY_FIRST.md)
86-
- [RETURN](docs/RETURN.md)
87-
- [SPECIAL_MODEL_NAME](docs/SPECIAL_MODEL_NAME.md)
8852
- [TAG](docs/TAG.md)
8953
- [USER](docs/USER.md)
90-
- [CAT](docs/CAT.md)
91-
- [DOG](docs/DOG.md)
9254

9355

9456
## Documentation For Authorization
@@ -100,10 +62,6 @@ Class | Method | HTTP request | Description
10062
- **API key parameter name**: api_key
10163
- **Location**: HTTP header
10264

103-
## http_basic_test
104-
105-
- **Type**: HTTP basic authentication
106-
10765
## petstore_auth
10866

10967
- **Type**: OAuth

samples/client/petstore/eiffel/api_client.ecf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<?xml version="1.0" encoding="ISO-8859-1"?>
2-
<system xmlns="http://www.eiffel.com/developers/xml/configuration-1-16-0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.eiffel.com/developers/xml/configuration-1-16-0 http://www.eiffel.com/developers/xml/configuration-1-16-0.xsd" name="swagger_eiffel_client" uuid="e892c29a-3caa-456b-bc97-f488bba434b9" library_target="swagger_eiffel_client">
2+
<system xmlns="http://www.eiffel.com/developers/xml/configuration-1-16-0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.eiffel.com/developers/xml/configuration-1-16-0 http://www.eiffel.com/developers/xml/configuration-1-16-0.xsd" name="swagger_eiffel_client" uuid="fb819818-bd09-421e-84e6-a6b7ce8ecb39" library_target="swagger_eiffel_client">
33
<target name="swagger_eiffel_client">
44
<root all_classes="true"/>
55
<file_rule>

samples/client/petstore/eiffel/docs/PET_API.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# PET_API
22

3-
All URIs are relative to *http://petstore.swagger.io:80/v2*
3+
All URIs are relative to *http://petstore.swagger.io/v2*
44

55
Feature | HTTP request | Description
66
------------- | ------------- | -------------

samples/client/petstore/eiffel/docs/STORE_API.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
# STORE_API
22

3-
All URIs are relative to *http://petstore.swagger.io:80/v2*
3+
All URIs are relative to *http://petstore.swagger.io/v2*
44

55
Feature | HTTP request | Description
66
------------- | ------------- | -------------
7-
[**delete_order**](STORE_API.md#delete_order) | **Delete** /store/order/{order_id} | Delete purchase order by ID
7+
[**delete_order**](STORE_API.md#delete_order) | **Delete** /store/order/{orderId} | Delete purchase order by ID
88
[**inventory**](STORE_API.md#inventory) | **Get** /store/inventory | Returns pet inventories by status
9-
[**order_by_id**](STORE_API.md#order_by_id) | **Get** /store/order/{order_id} | Find purchase order by ID
9+
[**order_by_id**](STORE_API.md#order_by_id) | **Get** /store/order/{orderId} | Find purchase order by ID
1010
[**place_order**](STORE_API.md#place_order) | **Post** /store/order | Place an order for a pet
1111

1212

@@ -54,7 +54,7 @@ This endpoint does not need any parameter.
5454

5555
### Return type
5656

57-
[**STRING_TABLE[INTEGER_32]**](STRING_TABLE.md)
57+
**STRING_TABLE[INTEGER_32]**
5858

5959
### Authorization
6060

samples/client/petstore/eiffel/docs/USER_API.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# USER_API
22

3-
All URIs are relative to *http://petstore.swagger.io:80/v2*
3+
All URIs are relative to *http://petstore.swagger.io/v2*
44

55
Feature | HTTP request | Description
66
------------- | ------------- | -------------

samples/client/petstore/eiffel/src/api/pet_api.e

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
note
22
description:"[
33
Swagger Petstore
4-
This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\
4+
This is a sample server Petstore server. You can find out more about Swagger at [http://swagger.io](http://swagger.io) or on [irc.freenode.net, #swagger](http://swagger.io/irc/). For this sample, you can use the api key `special-key` to test the authorization filters.
55
OpenAPI spec version: 1.0.0
66
Contact: apiteam@swagger.io
77
@@ -31,6 +31,7 @@ feature -- API Access
3131
-- argument: body Pet object that needs to be added to the store (required)
3232
--
3333
--
34+
require
3435
local
3536
l_path: STRING
3637
l_request: API_CLIENT_REQUEST
@@ -41,6 +42,7 @@ feature -- API Access
4142
l_request.set_body(body)
4243
l_path := "/pet"
4344

45+
4446
if attached {STRING} api_client.select_header_accept (<<"application/xml", "application/json">>) as l_accept then
4547
l_request.add_header(l_accept,"Accept");
4648
end
@@ -52,7 +54,7 @@ feature -- API Access
5254
end
5355
end
5456

55-
delete_pet (pet_id: INTEGER_64; api_key: detachable STRING_32)
57+
delete_pet (pet_id: INTEGER_64; api_key: STRING_32)
5658
-- Deletes a pet
5759
--
5860
--
@@ -61,6 +63,7 @@ feature -- API Access
6163
-- argument: api_key (optional)
6264
--
6365
--
66+
require
6467
local
6568
l_path: STRING
6669
l_request: API_CLIENT_REQUEST
@@ -71,6 +74,7 @@ feature -- API Access
7174

7275
l_path := "/pet/{petId}"
7376
l_path.replace_substring_all ("{"+"petId"+"}", api_client.url_encode (pet_id.out))
77+
7478
if attached api_key as l_api_key then
7579
l_request.add_header(l_api_key.out,"api_key");
7680
end
@@ -94,6 +98,7 @@ feature -- API Access
9498
--
9599
--
96100
-- Result LIST [PET]
101+
require
97102
local
98103
l_path: STRING
99104
l_request: API_CLIENT_REQUEST
@@ -105,6 +110,7 @@ feature -- API Access
105110
l_path := "/pet/findByStatus"
106111
l_request.fill_query_params(api_client.parameter_to_tuple("csv", "status", status));
107112

113+
108114
if attached {STRING} api_client.select_header_accept (<<"application/xml", "application/json">>) as l_accept then
109115
l_request.add_header(l_accept,"Accept");
110116
end
@@ -128,6 +134,7 @@ feature -- API Access
128134
--
129135
--
130136
-- Result LIST [PET]
137+
require
131138
local
132139
l_path: STRING
133140
l_request: API_CLIENT_REQUEST
@@ -139,6 +146,7 @@ feature -- API Access
139146
l_path := "/pet/findByTags"
140147
l_request.fill_query_params(api_client.parameter_to_tuple("csv", "tags", tags));
141148

149+
142150
if attached {STRING} api_client.select_header_accept (<<"application/xml", "application/json">>) as l_accept then
143151
l_request.add_header(l_accept,"Accept");
144152
end
@@ -162,6 +170,7 @@ feature -- API Access
162170
--
163171
--
164172
-- Result PET
173+
require
165174
local
166175
l_path: STRING
167176
l_request: API_CLIENT_REQUEST
@@ -173,6 +182,7 @@ feature -- API Access
173182
l_path := "/pet/{petId}"
174183
l_path.replace_substring_all ("{"+"petId"+"}", api_client.url_encode (pet_id.out))
175184

185+
176186
if attached {STRING} api_client.select_header_accept (<<"application/xml", "application/json">>) as l_accept then
177187
l_request.add_header(l_accept,"Accept");
178188
end
@@ -195,6 +205,7 @@ feature -- API Access
195205
-- argument: body Pet object that needs to be added to the store (required)
196206
--
197207
--
208+
require
198209
local
199210
l_path: STRING
200211
l_request: API_CLIENT_REQUEST
@@ -205,6 +216,7 @@ feature -- API Access
205216
l_request.set_body(body)
206217
l_path := "/pet"
207218

219+
208220
if attached {STRING} api_client.select_header_accept (<<"application/xml", "application/json">>) as l_accept then
209221
l_request.add_header(l_accept,"Accept");
210222
end
@@ -216,7 +228,7 @@ feature -- API Access
216228
end
217229
end
218230

219-
update_pet_with_form (pet_id: INTEGER_64; name: detachable STRING_32; status: detachable STRING_32)
231+
update_pet_with_form (pet_id: INTEGER_64; name: STRING_32; status: STRING_32)
220232
-- Updates a pet in the store with form data
221233
--
222234
--
@@ -227,6 +239,7 @@ feature -- API Access
227239
-- argument: status Updated status of the pet (optional)
228240
--
229241
--
242+
require
230243
local
231244
l_path: STRING
232245
l_request: API_CLIENT_REQUEST
@@ -237,6 +250,7 @@ feature -- API Access
237250

238251
l_path := "/pet/{petId}"
239252
l_path.replace_substring_all ("{"+"petId"+"}", api_client.url_encode (pet_id.out))
253+
240254
if attached name as l_name then
241255
l_request.add_form(l_name,"name");
242256
end
@@ -255,7 +269,7 @@ feature -- API Access
255269
end
256270
end
257271

258-
upload_file (pet_id: INTEGER_64; additional_metadata: detachable STRING_32; file: detachable FILE): detachable API_RESPONSE
272+
upload_file (pet_id: INTEGER_64; additional_metadata: STRING_32; file: detachable FILE): detachable API_RESPONSE
259273
-- uploads an image
260274
--
261275
--
@@ -267,6 +281,7 @@ feature -- API Access
267281
--
268282
--
269283
-- Result API_RESPONSE
284+
require
270285
local
271286
l_path: STRING
272287
l_request: API_CLIENT_REQUEST
@@ -277,6 +292,7 @@ feature -- API Access
277292

278293
l_path := "/pet/{petId}/uploadImage"
279294
l_path.replace_substring_all ("{"+"petId"+"}", api_client.url_encode (pet_id.out))
295+
280296
if attached additional_metadata as l_additional_metadata then
281297
l_request.add_form(l_additional_metadata,"additionalMetadata");
282298
end

samples/client/petstore/eiffel/src/api/store_api.e

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
note
22
description:"[
33
Swagger Petstore
4-
This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\
4+
This is a sample server Petstore server. You can find out more about Swagger at [http://swagger.io](http://swagger.io) or on [irc.freenode.net, #swagger](http://swagger.io/irc/). For this sample, you can use the api key `special-key` to test the authorization filters.
55
OpenAPI spec version: 1.0.0
66
Contact: apiteam@swagger.io
77
@@ -31,6 +31,7 @@ feature -- API Access
3131
-- argument: order_id ID of the order that needs to be deleted (required)
3232
--
3333
--
34+
require
3435
local
3536
l_path: STRING
3637
l_request: API_CLIENT_REQUEST
@@ -39,8 +40,9 @@ feature -- API Access
3940
reset_error
4041
create l_request
4142

42-
l_path := "/store/order/{order_id}"
43-
l_path.replace_substring_all ("{"+"order_id"+"}", api_client.url_encode (order_id.out))
43+
l_path := "/store/order/{orderId}"
44+
l_path.replace_substring_all ("{"+"orderId"+"}", api_client.url_encode (order_id.out))
45+
4446

4547
if attached {STRING} api_client.select_header_accept (<<"application/xml", "application/json">>) as l_accept then
4648
l_request.add_header(l_accept,"Accept");
@@ -59,6 +61,7 @@ feature -- API Access
5961
--
6062
--
6163
-- Result STRING_TABLE[INTEGER_32]
64+
require
6265
local
6366
l_path: STRING
6467
l_request: API_CLIENT_REQUEST
@@ -69,6 +72,7 @@ feature -- API Access
6972

7073
l_path := "/store/inventory"
7174

75+
7276
if attached {STRING} api_client.select_header_accept (<<"application/json">>) as l_accept then
7377
l_request.add_header(l_accept,"Accept");
7478
end
@@ -92,6 +96,9 @@ feature -- API Access
9296
--
9397
--
9498
-- Result ORDER
99+
require
100+
order_id_is_less_or_equal_than: order_id <= 5
101+
order_id_is_greater_or_equal_than: order_id >= 1
95102
local
96103
l_path: STRING
97104
l_request: API_CLIENT_REQUEST
@@ -100,8 +107,9 @@ feature -- API Access
100107
reset_error
101108
create l_request
102109

103-
l_path := "/store/order/{order_id}"
104-
l_path.replace_substring_all ("{"+"order_id"+"}", api_client.url_encode (order_id.out))
110+
l_path := "/store/order/{orderId}"
111+
l_path.replace_substring_all ("{"+"orderId"+"}", api_client.url_encode (order_id.out))
112+
105113

106114
if attached {STRING} api_client.select_header_accept (<<"application/xml", "application/json">>) as l_accept then
107115
l_request.add_header(l_accept,"Accept");
@@ -126,6 +134,7 @@ feature -- API Access
126134
--
127135
--
128136
-- Result ORDER
137+
require
129138
local
130139
l_path: STRING
131140
l_request: API_CLIENT_REQUEST
@@ -136,6 +145,7 @@ feature -- API Access
136145
l_request.set_body(body)
137146
l_path := "/store/order"
138147

148+
139149
if attached {STRING} api_client.select_header_accept (<<"application/xml", "application/json">>) as l_accept then
140150
l_request.add_header(l_accept,"Accept");
141151
end

0 commit comments

Comments
 (0)