Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 29 additions & 21 deletions modules/swagger-codegen/src/main/resources/php/model.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ use \ArrayAccess;
* @license http://www.apache.org/licenses/LICENSE-2.0 Apache Licene v2
* @link https://github.com/swagger-api/swagger-codegen
*/
class {{classname}} {{#parent}}extends {{{parent}}} {{/parent}}implements ArrayAccess
class {{classname}} {{#parentSchema}}extends {{{parent}}} {{/parentSchema}}implements ArrayAccess
{
/**
* The original name of the model.
Expand All @@ -64,7 +64,7 @@ class {{classname}} {{#parent}}extends {{{parent}}} {{/parent}}implements ArrayA
);

static function swaggerTypes() {
return self::$swaggerTypes{{#parent}} + parent::swaggerTypes(){{/parent}};
return self::$swaggerTypes{{#parentSchema}} + parent::swaggerTypes(){{/parentSchema}};
}

/**
Expand All @@ -77,7 +77,7 @@ class {{classname}} {{#parent}}extends {{{parent}}} {{/parent}}implements ArrayA
);

static function attributeMap() {
return {{#parent}}parent::attributeMap() + {{/parent}}self::$attributeMap;
return {{#parentSchema}}parent::attributeMap() + {{/parentSchema}}self::$attributeMap;
}

/**
Expand All @@ -90,7 +90,7 @@ class {{classname}} {{#parent}}extends {{{parent}}} {{/parent}}implements ArrayA
);

static function setters() {
return {{#parent}}parent::setters() + {{/parent}}self::$setters;
return {{#parentSchema}}parent::setters() + {{/parentSchema}}self::$setters;
}

/**
Expand All @@ -103,31 +103,35 @@ class {{classname}} {{#parent}}extends {{{parent}}} {{/parent}}implements ArrayA
);

static function getters() {
return {{#parent}}parent::getters() + {{/parent}}self::$getters;
return {{#parentSchema}}parent::getters() + {{/parentSchema}}self::$getters;
}

{{#vars}}
/**
* ${{name}} {{#description}}{{{description}}}{{/description}}
* @var {{datatype}}
*/
protected ${{name}}{{#defaultValue}} = {{{defaultValue}}}{{/defaultValue}};
{{/vars}}
* Associative array for storing property values
* @var mixed[]
*/
protected $container = array({{#vars}}
/**
* $container['{{{name}}}']{{#description}} {{{description}}}{{/description}}
* @var {{datatype}}
*/
'{{{name}}}' => {{#defaultValue}}{{{defaultValue}}}{{/defaultValue}}{{^defaultValue}}null{{/defaultValue}},
{{/vars}});

/**
* Constructor
* @param mixed[] $data Associated array of property value initalizing the model
*/
public function __construct(array $data = null)
{
{{#parent}}parent::__construct($data);{{/parent}}
{{#parentSchema}}parent::__construct($data);{{/parentSchema}}
{{#discriminator}}// Initialize discriminator property with the model name.
$discrimintor = array_search('{{discriminator}}', self::$attributeMap);
$this->{$discrimintor} = static::$swaggerModelName;
$this->container[$discrimintor] = static::$swaggerModelName;
{{/discriminator}}

if ($data != null) {
{{#vars}}$this->{{name}} = $data["{{name}}"];{{#hasMore}}
{{#vars}}$this->container['{{name}}'] = $data['{{name}}'];{{#hasMore}}
{{/hasMore}}{{/vars}}
}
}
Expand All @@ -138,7 +142,7 @@ class {{classname}} {{#parent}}extends {{{parent}}} {{/parent}}implements ArrayA
*/
public function {{getter}}()
{
return $this->{{name}};
return $this->container['{{name}}'];
}

/**
Expand All @@ -148,11 +152,11 @@ class {{classname}} {{#parent}}extends {{{parent}}} {{/parent}}implements ArrayA
*/
public function {{setter}}(${{name}})
{
{{#isEnum}}$allowed_values = array({{#allowableValues}}{{#values}}"{{{this}}}"{{^-last}}, {{/-last}}{{/values}}{{/allowableValues}});
{{#isEnum}}$allowed_values = array({{#allowableValues}}{{#values}}'{{{this}}}'{{^-last}}, {{/-last}}{{/values}}{{/allowableValues}});
if (!in_array(${{{name}}}, $allowed_values)) {
throw new \InvalidArgumentException("Invalid value for '{{name}}', must be one of {{#allowableValues}}{{#values}}'{{{this}}}'{{^-last}}, {{/-last}}{{/values}}{{/allowableValues}}");
}{{/isEnum}}
$this->{{name}} = ${{name}};
$this->container['{{name}}'] = ${{name}};
return $this;
}
{{/vars}}
Expand All @@ -163,7 +167,7 @@ class {{classname}} {{#parent}}extends {{{parent}}} {{/parent}}implements ArrayA
*/
public function offsetExists($offset)
{
return isset($this->$offset);
return isset($this->container[$offset]);
}

/**
Expand All @@ -173,7 +177,7 @@ class {{classname}} {{#parent}}extends {{{parent}}} {{/parent}}implements ArrayA
*/
public function offsetGet($offset)
{
return $this->$offset;
return isset($this->container[$offset]) ? $this->container[$offset] : null;
}

/**
Expand All @@ -184,7 +188,11 @@ class {{classname}} {{#parent}}extends {{{parent}}} {{/parent}}implements ArrayA
*/
public function offsetSet($offset, $value)
{
$this->$offset = $value;
if (is_null($offset)) {
$this->container[] = $value;
} else {
$this->container[$offset] = $value;
}
}

/**
Expand All @@ -194,7 +202,7 @@ class {{classname}} {{#parent}}extends {{{parent}}} {{/parent}}implements ArrayA
*/
public function offsetUnset($offset)
{
unset($this->$offset);
unset($this->container[$offset]);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -842,6 +842,10 @@ definitions:
properties:
className:
type: string
AnimalFarm:
type: array
items:
$ref: '#/definitions/Animal'
format_test:
type: object
required:
Expand Down
38 changes: 24 additions & 14 deletions samples/client/petstore/php/SwaggerClient-php/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ This PHP package is automatically generated by the [Swagger Codegen](https://git

- API version: 1.0.0
- Package version: 1.0.0
- Build date: 2016-04-23T22:48:00.795+08:00
- Build date: 2016-04-27T21:03:06.377+02:00
- Build package: class io.swagger.codegen.languages.PhpClientCodegen

## Requirements
Expand Down Expand Up @@ -58,16 +58,24 @@ Please follow the [installation procedure](#installation--usage) and then run th
<?php
require_once(__DIR__ . '/vendor/autoload.php');

// Configure OAuth2 access token for authorization: petstore_auth
Swagger\Client\Configuration::getDefaultConfiguration()->setAccessToken('YOUR_ACCESS_TOKEN');

$api_instance = new Swagger\Client\Api\PetApi();
$body = new \Swagger\Client\Model\Pet(); // \Swagger\Client\Model\Pet | Pet object that needs to be added to the store
$api_instance = new Swagger\Client\Api\FakeApi();
$number = 3.4; // float | None
$double = 1.2; // double | None
$string = "string_example"; // string | None
$byte = "B"; // string | None
$integer = 56; // int | None
$int32 = 56; // int | None
$int64 = 789; // int | None
$float = 3.4; // float | None
$binary = "B"; // string | None
$date = new \DateTime(); // \DateTime | None
$date_time = new \DateTime(); // \DateTime | None
$password = "password_example"; // string | None

try {
$api_instance->addPet($body);
$api_instance->testEndpointParameters($number, $double, $string, $byte, $integer, $int32, $int64, $float, $binary, $date, $date_time, $password);
} catch (Exception $e) {
echo 'Exception when calling PetApi->addPet: ', $e->getMessage(), "\n";
echo 'Exception when calling FakeApi->testEndpointParameters: ', $e->getMessage(), "\n";
}

?>
Expand All @@ -79,6 +87,7 @@ All URIs are relative to *http://petstore.swagger.io/v2*

Class | Method | HTTP request | Description
------------ | ------------- | ------------- | -------------
*FakeApi* | [**testEndpointParameters**](docs/FakeApi.md#testendpointparameters) | **POST** /fake | Fake endpoint for testing various parameters
*PetApi* | [**addPet**](docs/PetApi.md#addpet) | **POST** /pet | Add a new pet to the store
*PetApi* | [**deletePet**](docs/PetApi.md#deletepet) | **DELETE** /pet/{petId} | Deletes a pet
*PetApi* | [**findPetsByStatus**](docs/PetApi.md#findpetsbystatus) | **GET** /pet/findByStatus | Finds Pets by status
Expand All @@ -104,6 +113,7 @@ Class | Method | HTTP request | Description
## Documentation For Models

- [Animal](docs/Animal.md)
- [AnimalFarm](docs/AnimalFarm.md)
- [ApiResponse](docs/ApiResponse.md)
- [Cat](docs/Cat.md)
- [Category](docs/Category.md)
Expand All @@ -122,12 +132,6 @@ Class | Method | HTTP request | Description
## Documentation For Authorization


## api_key

- **Type**: API key
- **API key parameter name**: api_key
- **Location**: HTTP header

## petstore_auth

- **Type**: OAuth
Expand All @@ -137,6 +141,12 @@ Class | Method | HTTP request | Description
- **write:pets**: modify pets in your account
- **read:pets**: read your pets

## api_key

- **Type**: API key
- **API key parameter name**: api_key
- **Location**: HTTP header


## Author

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# AnimalFarm

## Properties
Name | Type | Description | Notes
------------ | ------------- | ------------- | -------------

[[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md)


75 changes: 75 additions & 0 deletions samples/client/petstore/php/SwaggerClient-php/docs/FakeApi.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
# Swagger\Client\FakeApi

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

Method | HTTP request | Description
------------- | ------------- | -------------
[**testEndpointParameters**](FakeApi.md#testEndpointParameters) | **POST** /fake | Fake endpoint for testing various parameters


# **testEndpointParameters**
> testEndpointParameters($number, $double, $string, $byte, $integer, $int32, $int64, $float, $binary, $date, $date_time, $password)

Fake endpoint for testing various parameters

Fake endpoint for testing various parameters

### Example
```php
<?php
require_once(__DIR__ . '/vendor/autoload.php');

$api_instance = new Swagger\Client\Api\FakeApi();
$number = 3.4; // float | None
$double = 1.2; // double | None
$string = "string_example"; // string | None
$byte = "B"; // string | None
$integer = 56; // int | None
$int32 = 56; // int | None
$int64 = 789; // int | None
$float = 3.4; // float | None
$binary = "B"; // string | None
$date = new \DateTime(); // \DateTime | None
$date_time = new \DateTime(); // \DateTime | None
$password = "password_example"; // string | None

try {
$api_instance->testEndpointParameters($number, $double, $string, $byte, $integer, $int32, $int64, $float, $binary, $date, $date_time, $password);
} catch (Exception $e) {
echo 'Exception when calling FakeApi->testEndpointParameters: ', $e->getMessage(), "\n";
}
?>
```

### Parameters

Name | Type | Description | Notes
------------- | ------------- | ------------- | -------------
**number** | **float**| None |
**double** | **double**| None |
**string** | **string**| None |
**byte** | **string**| None |
**integer** | **int**| None | [optional]
**int32** | **int**| None | [optional]
**int64** | **int**| None | [optional]
**float** | **float**| None | [optional]
**binary** | **string**| None | [optional]
**date** | **\DateTime**| None | [optional]
**date_time** | **\DateTime**| None | [optional]
**password** | **string**| None | [optional]

### Return type

void (empty response body)

### Authorization

No authorization required

### HTTP request headers

- **Content-Type**: Not defined
- **Accept**: application/xml, application/json

[[Back to top]](#) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to Model list]](../README.md#documentation-for-models) [[Back to README]](../README.md)

Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ Name | Type | Description | Notes
**binary** | **string** | | [optional]
**date** | [**\DateTime**](Date.md) | |
**date_time** | [**\DateTime**](\DateTime.md) | | [optional]
**uuid** | [**UUID**](UUID.md) | | [optional]
**password** | **string** | |

[[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md)
Expand Down
Loading