Skip to content

Commit

Permalink
Swagger eiffel:fix (#6674)
Browse files Browse the repository at this point in the history
* 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.
  • Loading branch information
jvelilla authored and wing328 committed Oct 16, 2017
1 parent 3f7f6b8 commit 3067da2
Show file tree
Hide file tree
Showing 30 changed files with 198 additions and 126 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,10 @@ feature -- Query Parameter Helpers
-- TODO improve to support
-- dateTime string date-time As defined by date-time - RFC3339
Result := date_time.date.debug_output
elseif attached {STRING_32} a_param as str_32 then
Result := str_32
elseif attached {STRING_8} a_param as str_8 then
Result := str_8
else
-- Unsupported Object type.
Result := ""
Expand Down
50 changes: 4 additions & 46 deletions samples/client/petstore/eiffel/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Eiffel API client for swagger

This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\
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.

## Overview
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.
Expand All @@ -17,19 +17,10 @@ Add the library into your Eiffel configuration file.

## Documentation for API Endpoints

All URIs are relative to *http://petstore.swagger.io:80/v2*
All URIs are relative to *http://petstore.swagger.io/v2*

Class | Method | HTTP request | Description
------------ | ------------- | ------------- | -------------
*FAKE_API* | [**fake_outer_boolean_serialize**](docs/FAKE_API.md#fake_outer_boolean_serialize) | **Post** /fake/outer/boolean |
*FAKE_API* | [**fake_outer_composite_serialize**](docs/FAKE_API.md#fake_outer_composite_serialize) | **Post** /fake/outer/composite |
*FAKE_API* | [**fake_outer_number_serialize**](docs/FAKE_API.md#fake_outer_number_serialize) | **Post** /fake/outer/number |
*FAKE_API* | [**fake_outer_string_serialize**](docs/FAKE_API.md#fake_outer_string_serialize) | **Post** /fake/outer/string |
*FAKE_API* | [**test_client_model**](docs/FAKE_API.md#test_client_model) | **Patch** /fake | To test \"client\" model
*FAKE_API* | [**test_endpoint_parameters**](docs/FAKE_API.md#test_endpoint_parameters) | **Post** /fake | Fake endpoint for testing various parameters 假端點 偽のエンドポイント 가짜 엔드 포인트
*FAKE_API* | [**test_enum_parameters**](docs/FAKE_API.md#test_enum_parameters) | **Get** /fake | To test enum parameters
*FAKE_API* | [**test_json_form_data**](docs/FAKE_API.md#test_json_form_data) | **Get** /fake/jsonFormData | test json serialization of form data
*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
*PET_API* | [**add_pet**](docs/PET_API.md#add_pet) | **Post** /pet | Add a new pet to the store
*PET_API* | [**delete_pet**](docs/PET_API.md#delete_pet) | **Delete** /pet/{petId} | Deletes a pet
*PET_API* | [**find_pets_by_status**](docs/PET_API.md#find_pets_by_status) | **Get** /pet/findByStatus | Finds Pets by status
Expand All @@ -38,9 +29,9 @@ Class | Method | HTTP request | Description
*PET_API* | [**update_pet**](docs/PET_API.md#update_pet) | **Put** /pet | Update an existing pet
*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
*PET_API* | [**upload_file**](docs/PET_API.md#upload_file) | **Post** /pet/{petId}/uploadImage | uploads an image
*STORE_API* | [**delete_order**](docs/STORE_API.md#delete_order) | **Delete** /store/order/{order_id} | Delete purchase order by ID
*STORE_API* | [**delete_order**](docs/STORE_API.md#delete_order) | **Delete** /store/order/{orderId} | Delete purchase order by ID
*STORE_API* | [**inventory**](docs/STORE_API.md#inventory) | **Get** /store/inventory | Returns pet inventories by status
*STORE_API* | [**order_by_id**](docs/STORE_API.md#order_by_id) | **Get** /store/order/{order_id} | Find purchase order by ID
*STORE_API* | [**order_by_id**](docs/STORE_API.md#order_by_id) | **Get** /store/order/{orderId} | Find purchase order by ID
*STORE_API* | [**place_order**](docs/STORE_API.md#place_order) | **Post** /store/order | Place an order for a pet
*USER_API* | [**create_user**](docs/USER_API.md#create_user) | **Post** /user | Create user
*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
Expand All @@ -54,41 +45,12 @@ Class | Method | HTTP request | Description

## Documentation For Models

- [ADDITIONAL_PROPERTIES_CLASS](docs/ADDITIONAL_PROPERTIES_CLASS.md)
- [ANIMAL](docs/ANIMAL.md)
- [ANIMAL_FARM](docs/ANIMAL_FARM.md)
- [API_RESPONSE](docs/API_RESPONSE.md)
- [ARRAY_OF_ARRAY_OF_NUMBER_ONLY](docs/ARRAY_OF_ARRAY_OF_NUMBER_ONLY.md)
- [ARRAY_OF_NUMBER_ONLY](docs/ARRAY_OF_NUMBER_ONLY.md)
- [ARRAY_TEST](docs/ARRAY_TEST.md)
- [CAPITALIZATION](docs/CAPITALIZATION.md)
- [CATEGORY](docs/CATEGORY.md)
- [CLASS_MODEL](docs/CLASS_MODEL.md)
- [CLIENT](docs/CLIENT.md)
- [ENUM_ARRAYS](docs/ENUM_ARRAYS.md)
- [ENUM_CLASS](docs/ENUM_CLASS.md)
- [ENUM_TEST](docs/ENUM_TEST.md)
- [FORMAT_TEST](docs/FORMAT_TEST.md)
- [HAS_ONLY_READ_ONLY](docs/HAS_ONLY_READ_ONLY.md)
- [MAP_TEST](docs/MAP_TEST.md)
- [MIXED_PROPERTIES_AND_ADDITIONAL_PROPERTIES_CLASS](docs/MIXED_PROPERTIES_AND_ADDITIONAL_PROPERTIES_CLASS.md)
- [MODEL_200_RESPONSE](docs/MODEL_200_RESPONSE.md)
- [NAME](docs/NAME.md)
- [NUMBER_ONLY](docs/NUMBER_ONLY.md)
- [ORDER](docs/ORDER.md)
- [OUTER_BOOLEAN](docs/OUTER_BOOLEAN.md)
- [OUTER_COMPOSITE](docs/OUTER_COMPOSITE.md)
- [OUTER_ENUM](docs/OUTER_ENUM.md)
- [OUTER_NUMBER](docs/OUTER_NUMBER.md)
- [OUTER_STRING](docs/OUTER_STRING.md)
- [PET](docs/PET.md)
- [READ_ONLY_FIRST](docs/READ_ONLY_FIRST.md)
- [RETURN](docs/RETURN.md)
- [SPECIAL_MODEL_NAME](docs/SPECIAL_MODEL_NAME.md)
- [TAG](docs/TAG.md)
- [USER](docs/USER.md)
- [CAT](docs/CAT.md)
- [DOG](docs/DOG.md)


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

## http_basic_test

- **Type**: HTTP basic authentication

## petstore_auth

- **Type**: OAuth
Expand Down
2 changes: 1 addition & 1 deletion samples/client/petstore/eiffel/api_client.ecf
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="ISO-8859-1"?>
<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">
<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">
<target name="swagger_eiffel_client">
<root all_classes="true"/>
<file_rule>
Expand Down
2 changes: 1 addition & 1 deletion samples/client/petstore/eiffel/docs/PET_API.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# PET_API

All URIs are relative to *http://petstore.swagger.io:80/v2*
All URIs are relative to *http://petstore.swagger.io/v2*

Feature | HTTP request | Description
------------- | ------------- | -------------
Expand Down
8 changes: 4 additions & 4 deletions samples/client/petstore/eiffel/docs/STORE_API.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
# STORE_API

All URIs are relative to *http://petstore.swagger.io:80/v2*
All URIs are relative to *http://petstore.swagger.io/v2*

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


Expand Down Expand Up @@ -54,7 +54,7 @@ This endpoint does not need any parameter.

### Return type

[**STRING_TABLE[INTEGER_32]**](STRING_TABLE.md)
**STRING_TABLE[INTEGER_32]**

### Authorization

Expand Down
2 changes: 1 addition & 1 deletion samples/client/petstore/eiffel/docs/USER_API.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# USER_API

All URIs are relative to *http://petstore.swagger.io:80/v2*
All URIs are relative to *http://petstore.swagger.io/v2*

Feature | HTTP request | Description
------------- | ------------- | -------------
Expand Down
24 changes: 20 additions & 4 deletions samples/client/petstore/eiffel/src/api/pet_api.e
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
note
description:"[
Swagger Petstore
This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\
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.
OpenAPI spec version: 1.0.0
Contact: [email protected]
Expand Down Expand Up @@ -31,6 +31,7 @@ feature -- API Access
-- argument: body Pet object that needs to be added to the store (required)
--
--
require
local
l_path: STRING
l_request: API_CLIENT_REQUEST
Expand All @@ -41,6 +42,7 @@ feature -- API Access
l_request.set_body(body)
l_path := "/pet"


if attached {STRING} api_client.select_header_accept (<<"application/xml", "application/json">>) as l_accept then
l_request.add_header(l_accept,"Accept");
end
Expand All @@ -52,7 +54,7 @@ feature -- API Access
end
end

delete_pet (pet_id: INTEGER_64; api_key: detachable STRING_32)
delete_pet (pet_id: INTEGER_64; api_key: STRING_32)
-- Deletes a pet
--
--
Expand All @@ -61,6 +63,7 @@ feature -- API Access
-- argument: api_key (optional)
--
--
require
local
l_path: STRING
l_request: API_CLIENT_REQUEST
Expand All @@ -71,6 +74,7 @@ feature -- API Access

l_path := "/pet/{petId}"
l_path.replace_substring_all ("{"+"petId"+"}", api_client.url_encode (pet_id.out))

if attached api_key as l_api_key then
l_request.add_header(l_api_key.out,"api_key");
end
Expand All @@ -94,6 +98,7 @@ feature -- API Access
--
--
-- Result LIST [PET]
require
local
l_path: STRING
l_request: API_CLIENT_REQUEST
Expand All @@ -105,6 +110,7 @@ feature -- API Access
l_path := "/pet/findByStatus"
l_request.fill_query_params(api_client.parameter_to_tuple("csv", "status", status));


if attached {STRING} api_client.select_header_accept (<<"application/xml", "application/json">>) as l_accept then
l_request.add_header(l_accept,"Accept");
end
Expand All @@ -128,6 +134,7 @@ feature -- API Access
--
--
-- Result LIST [PET]
require
local
l_path: STRING
l_request: API_CLIENT_REQUEST
Expand All @@ -139,6 +146,7 @@ feature -- API Access
l_path := "/pet/findByTags"
l_request.fill_query_params(api_client.parameter_to_tuple("csv", "tags", tags));


if attached {STRING} api_client.select_header_accept (<<"application/xml", "application/json">>) as l_accept then
l_request.add_header(l_accept,"Accept");
end
Expand All @@ -162,6 +170,7 @@ feature -- API Access
--
--
-- Result PET
require
local
l_path: STRING
l_request: API_CLIENT_REQUEST
Expand All @@ -173,6 +182,7 @@ feature -- API Access
l_path := "/pet/{petId}"
l_path.replace_substring_all ("{"+"petId"+"}", api_client.url_encode (pet_id.out))


if attached {STRING} api_client.select_header_accept (<<"application/xml", "application/json">>) as l_accept then
l_request.add_header(l_accept,"Accept");
end
Expand All @@ -195,6 +205,7 @@ feature -- API Access
-- argument: body Pet object that needs to be added to the store (required)
--
--
require
local
l_path: STRING
l_request: API_CLIENT_REQUEST
Expand All @@ -205,6 +216,7 @@ feature -- API Access
l_request.set_body(body)
l_path := "/pet"


if attached {STRING} api_client.select_header_accept (<<"application/xml", "application/json">>) as l_accept then
l_request.add_header(l_accept,"Accept");
end
Expand All @@ -216,7 +228,7 @@ feature -- API Access
end
end

update_pet_with_form (pet_id: INTEGER_64; name: detachable STRING_32; status: detachable STRING_32)
update_pet_with_form (pet_id: INTEGER_64; name: STRING_32; status: STRING_32)
-- Updates a pet in the store with form data
--
--
Expand All @@ -227,6 +239,7 @@ feature -- API Access
-- argument: status Updated status of the pet (optional)
--
--
require
local
l_path: STRING
l_request: API_CLIENT_REQUEST
Expand All @@ -237,6 +250,7 @@ feature -- API Access

l_path := "/pet/{petId}"
l_path.replace_substring_all ("{"+"petId"+"}", api_client.url_encode (pet_id.out))

if attached name as l_name then
l_request.add_form(l_name,"name");
end
Expand All @@ -255,7 +269,7 @@ feature -- API Access
end
end

upload_file (pet_id: INTEGER_64; additional_metadata: detachable STRING_32; file: detachable FILE): detachable API_RESPONSE
upload_file (pet_id: INTEGER_64; additional_metadata: STRING_32; file: detachable FILE): detachable API_RESPONSE
-- uploads an image
--
--
Expand All @@ -267,6 +281,7 @@ feature -- API Access
--
--
-- Result API_RESPONSE
require
local
l_path: STRING
l_request: API_CLIENT_REQUEST
Expand All @@ -277,6 +292,7 @@ feature -- API Access

l_path := "/pet/{petId}/uploadImage"
l_path.replace_substring_all ("{"+"petId"+"}", api_client.url_encode (pet_id.out))

if attached additional_metadata as l_additional_metadata then
l_request.add_form(l_additional_metadata,"additionalMetadata");
end
Expand Down
20 changes: 15 additions & 5 deletions samples/client/petstore/eiffel/src/api/store_api.e
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
note
description:"[
Swagger Petstore
This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\
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.
OpenAPI spec version: 1.0.0
Contact: [email protected]
Expand Down Expand Up @@ -31,6 +31,7 @@ feature -- API Access
-- argument: order_id ID of the order that needs to be deleted (required)
--
--
require
local
l_path: STRING
l_request: API_CLIENT_REQUEST
Expand All @@ -39,8 +40,9 @@ feature -- API Access
reset_error
create l_request

l_path := "/store/order/{order_id}"
l_path.replace_substring_all ("{"+"order_id"+"}", api_client.url_encode (order_id.out))
l_path := "/store/order/{orderId}"
l_path.replace_substring_all ("{"+"orderId"+"}", api_client.url_encode (order_id.out))


if attached {STRING} api_client.select_header_accept (<<"application/xml", "application/json">>) as l_accept then
l_request.add_header(l_accept,"Accept");
Expand All @@ -59,6 +61,7 @@ feature -- API Access
--
--
-- Result STRING_TABLE[INTEGER_32]
require
local
l_path: STRING
l_request: API_CLIENT_REQUEST
Expand All @@ -69,6 +72,7 @@ feature -- API Access

l_path := "/store/inventory"


if attached {STRING} api_client.select_header_accept (<<"application/json">>) as l_accept then
l_request.add_header(l_accept,"Accept");
end
Expand All @@ -92,6 +96,9 @@ feature -- API Access
--
--
-- Result ORDER
require
order_id_is_less_or_equal_than: order_id <= 5
order_id_is_greater_or_equal_than: order_id >= 1
local
l_path: STRING
l_request: API_CLIENT_REQUEST
Expand All @@ -100,8 +107,9 @@ feature -- API Access
reset_error
create l_request

l_path := "/store/order/{order_id}"
l_path.replace_substring_all ("{"+"order_id"+"}", api_client.url_encode (order_id.out))
l_path := "/store/order/{orderId}"
l_path.replace_substring_all ("{"+"orderId"+"}", api_client.url_encode (order_id.out))


if attached {STRING} api_client.select_header_accept (<<"application/xml", "application/json">>) as l_accept then
l_request.add_header(l_accept,"Accept");
Expand All @@ -126,6 +134,7 @@ feature -- API Access
--
--
-- Result ORDER
require
local
l_path: STRING
l_request: API_CLIENT_REQUEST
Expand All @@ -136,6 +145,7 @@ feature -- API Access
l_request.set_body(body)
l_path := "/store/order"


if attached {STRING} api_client.select_header_accept (<<"application/xml", "application/json">>) as l_accept then
l_request.add_header(l_accept,"Accept");
end
Expand Down
Loading

0 comments on commit 3067da2

Please sign in to comment.