resolve conflict during rebase

This commit is contained in:
wing328 2015-04-06 18:03:15 +08:00
parent 2bb42a1147
commit 3811a5a209
21 changed files with 266 additions and 88 deletions

View File

@ -27,7 +27,14 @@ public class PhpClientCodegen extends DefaultCodegen implements CodegenConfig {
public PhpClientCodegen() {
super();
modelPackage = "models";
//TODO determine hte package name from host name
invokerPackage = camelize("SwaggerPetstore");
String packagePath = invokerPackage + "-php";
modelPackage = packagePath + "/lib/models";
apiPackage = packagePath + "/lib";
outputFolder = "generated-code/php";
modelTemplateFiles.put("model.mustache", ".php");
apiTemplateFiles.put("api.mustache", ".php");
@ -59,7 +66,10 @@ public class PhpClientCodegen extends DefaultCodegen implements CodegenConfig {
typeMapping.put("List", "array");
typeMapping.put("map", "map");
supportingFiles.add(new SupportingFile("Swagger.mustache", "", "Swagger.php"));
supportingFiles.add(new SupportingFile("composer.mustache", packagePath, "composer.json"));
supportingFiles.add(new SupportingFile("APIClient.mustache", packagePath + "/lib", "APIClient.php"));
supportingFiles.add(new SupportingFile("APIClientException.mustache", packagePath + "/lib", "APIClientException.php"));
supportingFiles.add(new SupportingFile("require.mustache", packagePath, invokerPackage + ".php"));
}
@Override

View File

@ -15,24 +15,11 @@
* limitations under the License.
*/
/* Autoload the model definition files */
/**
*
* @param string $className the class to attempt to load
*/
function swagger_autoloader($className) {
$currentDir = dirname(__FILE__);
if (file_exists($currentDir . '/' . $className . '.php')) {
include $currentDir . '/' . $className . '.php';
} elseif (file_exists($currentDir . '/models/' . $className . '.php')) {
include $currentDir . '/models/' . $className . '.php';
}
}
spl_autoload_register('swagger_autoloader');
namespace {{invokerPackage}};
class APIClient {
public static $PATCH = "PATCH";
public static $POST = "POST";
public static $GET = "GET";
public static $PUT = "PUT";
@ -199,7 +186,7 @@ class APIClient {
* @return string the serialized object
*/
public static function toPathValue($value) {
return rawurlencode(toString($value));
return rawurlencode(self::toString($value));
}
/**
@ -214,7 +201,7 @@ class APIClient {
if (is_array($object)) {
return implode(',', $object);
} else {
return toString($object);
return self::toString($object);
}
}
@ -226,7 +213,7 @@ class APIClient {
* @return string the header string
*/
public static function toHeaderValue($value) {
return toString($value);
return self::toString($value);
}
/**
@ -237,7 +224,7 @@ class APIClient {
* @return string the form string
*/
public static function toFormValue($value) {
return toString($value);
return self::toString($value);
}
/**
@ -292,6 +279,7 @@ class APIClient {
settype($data, $class);
$deserialized = $data;
} else {
$class = "{{invokerPackage}}\\models\\".$class;
$instance = new $class();
foreach ($instance::$swaggerTypes as $property => $type) {
if (isset($data->$property)) {
@ -307,20 +295,3 @@ class APIClient {
}
class APIClientException extends Exception {
protected $response, $response_info;
public function __construct($message="", $code=0, $response_info=null, $response=null) {
parent::__construct($message, $code);
$this->response_info = $response_info;
$this->response = $response;
}
public function getResponse() {
return $this->response;
}
public function getResponseInfo() {
return $this->response_info;
}
}

View File

@ -0,0 +1,38 @@
<?php
/**
* Copyright 2015 Reverb Technologies, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
namespace {{invokerPackage}};
use \Exception;
class APIClientException extends Exception {
protected $response, $response_info;
public function __construct($message="", $code=0, $response_info=null, $response=null) {
parent::__construct($message, $code);
$this->response_info = $response_info;
$this->response = $response;
}
public function getResponse() {
return $this->response;
}
public function getResponseInfo() {
return $this->response_info;
}
}

View File

@ -19,6 +19,9 @@
*
* NOTE: This class is auto generated by the swagger code generator program. Do not edit the class manually.
*/
namespace {{invokerPackage}};
{{#operations}}
class {{classname}} {

View File

@ -0,0 +1,32 @@
{
"name": "{{invokerPackage}}/{{invokerPackage}}-php",
"description": "{{description}}",
"keywords": [
"swagger",
"php",
"sdk",
"api"
],
"homepage": "http://swagger.io",
"license": "Apache v2",
"authors": [
{
"name": "Swagger and contributors",
"homepage": "https://github.com/swagger-api/swagger-codegen"
}
],
"require": {
"php": ">=5.3.3",
"ext-curl": "*",
"ext-json": "*",
"ext-mbstring": "*"
},
"require-dev": {
"phpunit/phpunit": "~4.0",
"satooshi/php-coveralls": "~0.6.1",
"squizlabs/php_codesniffer": "~2.0"
},
"autoload": {
"psr-4": { "{{invokerPackage}}\\" : "lib/" }
}
}

View File

@ -15,14 +15,18 @@
* limitations under the License.
*/
{{#models}}
{{#model}}
/**
* $model.description$
* {{description}}
*
* NOTE: This class is auto generated by the swagger code generator program. Do not edit the class manually.
*
*/
{{#models}}
{{#model}}
namespace {{invokerPackage}}\models;
use \ArrayAccess;
class {{classname}} implements ArrayAccess {
static $swaggerTypes = array(
@ -41,7 +45,7 @@ class {{classname}} implements ArrayAccess {
*/{{/description}}
public ${{name}}; /* {{{datatype}}} */{{/vars}}
public function __construct(array $data) {
public function __construct(array $data = null) {
{{#vars}}$this->{{name}} = $data["{{name}}"];{{#hasMore}}
{{/hasMore}}{{/vars}}
}

View File

@ -0,0 +1,16 @@
<?php
// source code generated by http://restunited.com
// for any feedback/issue, please send to feedback{at}restunited.com
// load models defined for endpoints
foreach (glob(dirname(__FILE__)."/lib/models/*.php") as $filename)
{
require_once $filename;
}
// load classes for accessing the endpoints
foreach (glob(dirname(__FILE__)."/lib/*.php") as $filename)
{
require_once $filename;
}
?>

View File

@ -848,6 +848,7 @@
}
},
"Category": {
"description" : "testing category description",
"properties": {
"id": {
"type": "integer",

View File

@ -0,0 +1,16 @@
<?php
// source code generated by http://restunited.com
// for any feedback/issue, please send to feedback{at}restunited.com
// load models defined for endpoints
foreach (glob(dirname(__FILE__)."/lib/models/*.php") as $filename)
{
require_once $filename;
}
// load classes for accessing the endpoints
foreach (glob(dirname(__FILE__)."/lib/*.php") as $filename)
{
require_once $filename;
}
?>

View File

@ -0,0 +1,32 @@
{
"name": "SwaggerPetstore/SwaggerPetstore-php",
"description": "",
"keywords": [
"swagger",
"php",
"sdk",
"api"
],
"homepage": "http://swagger.io",
"license": "Apache v2",
"authors": [
{
"name": "Swagger and contributors",
"homepage": "https://github.com/swagger-api/swagger-codegen"
}
],
"require": {
"php": ">=5.3.3",
"ext-curl": "*",
"ext-json": "*",
"ext-mbstring": "*"
},
"require-dev": {
"phpunit/phpunit": "~4.0",
"satooshi/php-coveralls": "~0.6.1",
"squizlabs/php_codesniffer": "~2.0"
},
"autoload": {
"psr-4": { "SwaggerPetstore\\" : "lib/" }
}
}

View File

@ -15,24 +15,11 @@
* limitations under the License.
*/
/* Autoload the model definition files */
/**
*
* @param string $className the class to attempt to load
*/
function swagger_autoloader($className) {
$currentDir = dirname(__FILE__);
if (file_exists($currentDir . '/' . $className . '.php')) {
include $currentDir . '/' . $className . '.php';
} elseif (file_exists($currentDir . '/models/' . $className . '.php')) {
include $currentDir . '/models/' . $className . '.php';
}
}
spl_autoload_register('swagger_autoloader');
namespace SwaggerPetstore;
class APIClient {
public static $PATCH = "PATCH";
public static $POST = "POST";
public static $GET = "GET";
public static $PUT = "PUT";
@ -199,7 +186,7 @@ class APIClient {
* @return string the serialized object
*/
public static function toPathValue($value) {
return rawurlencode(toString($value));
return rawurlencode(self::toString($value));
}
/**
@ -214,7 +201,7 @@ class APIClient {
if (is_array($object)) {
return implode(',', $object);
} else {
return toString($object);
return self::toString($object);
}
}
@ -226,7 +213,7 @@ class APIClient {
* @return string the header string
*/
public static function toHeaderValue($value) {
return toString($value);
return self::toString($value);
}
/**
@ -237,7 +224,7 @@ class APIClient {
* @return string the form string
*/
public static function toFormValue($value) {
return toString($value);
return self::toString($value);
}
/**
@ -292,6 +279,7 @@ class APIClient {
settype($data, $class);
$deserialized = $data;
} else {
$class = "SwaggerPetstore\\models\\".$class;
$instance = new $class();
foreach ($instance::$swaggerTypes as $property => $type) {
if (isset($data->$property)) {
@ -307,20 +295,3 @@ class APIClient {
}
class APIClientException extends Exception {
protected $response, $response_info;
public function __construct($message="", $code=0, $response_info=null, $response=null) {
parent::__construct($message, $code);
$this->response_info = $response_info;
$this->response = $response;
}
public function getResponse() {
return $this->response;
}
public function getResponseInfo() {
return $this->response_info;
}
}

View File

@ -0,0 +1,38 @@
<?php
/**
* Copyright 2015 Reverb Technologies, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
namespace SwaggerPetstore;
use \Exception;
class APIClientException extends Exception {
protected $response, $response_info;
public function __construct($message="", $code=0, $response_info=null, $response=null) {
parent::__construct($message, $code);
$this->response_info = $response_info;
$this->response = $response;
}
public function getResponse() {
return $this->response;
}
public function getResponseInfo() {
return $this->response_info;
}
}

View File

@ -19,6 +19,9 @@
*
* NOTE: This class is auto generated by the swagger code generator program. Do not edit the class manually.
*/
namespace SwaggerPetstore;
class PetApi {
function __construct($apiClient) {

View File

@ -19,6 +19,9 @@
*
* NOTE: This class is auto generated by the swagger code generator program. Do not edit the class manually.
*/
namespace SwaggerPetstore;
class StoreApi {
function __construct($apiClient) {

View File

@ -19,6 +19,9 @@
*
* NOTE: This class is auto generated by the swagger code generator program. Do not edit the class manually.
*/
namespace SwaggerPetstore;
class UserApi {
function __construct($apiClient) {

View File

@ -16,12 +16,16 @@
*/
/**
* $model.description$
* testing category description
*
* NOTE: This class is auto generated by the swagger code generator program. Do not edit the class manually.
*
*/
namespace SwaggerPetstore\models;
use \ArrayAccess;
class Category implements ArrayAccess {
static $swaggerTypes = array(
'id' => 'int',
@ -37,7 +41,7 @@ class Category implements ArrayAccess {
public $id; /* int */
public $name; /* string */
public function __construct(array $data) {
public function __construct(array $data = null) {
$this->id = $data["id"];
$this->name = $data["name"];
}

View File

@ -16,12 +16,16 @@
*/
/**
* $model.description$
*
*
* NOTE: This class is auto generated by the swagger code generator program. Do not edit the class manually.
*
*/
namespace SwaggerPetstore\models;
use \ArrayAccess;
class Order implements ArrayAccess {
static $swaggerTypes = array(
'id' => 'int',
@ -52,7 +56,7 @@ class Order implements ArrayAccess {
public $status; /* string */
public $complete; /* boolean */
public function __construct(array $data) {
public function __construct(array $data = null) {
$this->id = $data["id"];
$this->pet_id = $data["pet_id"];
$this->quantity = $data["quantity"];

View File

@ -16,12 +16,16 @@
*/
/**
* $model.description$
*
*
* NOTE: This class is auto generated by the swagger code generator program. Do not edit the class manually.
*
*/
namespace SwaggerPetstore\models;
use \ArrayAccess;
class Pet implements ArrayAccess {
static $swaggerTypes = array(
'id' => 'int',
@ -52,7 +56,7 @@ class Pet implements ArrayAccess {
*/
public $status; /* string */
public function __construct(array $data) {
public function __construct(array $data = null) {
$this->id = $data["id"];
$this->category = $data["category"];
$this->name = $data["name"];

View File

@ -16,12 +16,16 @@
*/
/**
* $model.description$
*
*
* NOTE: This class is auto generated by the swagger code generator program. Do not edit the class manually.
*
*/
namespace SwaggerPetstore\models;
use \ArrayAccess;
class Tag implements ArrayAccess {
static $swaggerTypes = array(
'id' => 'int',
@ -37,7 +41,7 @@ class Tag implements ArrayAccess {
public $id; /* int */
public $name; /* string */
public function __construct(array $data) {
public function __construct(array $data = null) {
$this->id = $data["id"];
$this->name = $data["name"];
}

View File

@ -16,12 +16,16 @@
*/
/**
* $model.description$
*
*
* NOTE: This class is auto generated by the swagger code generator program. Do not edit the class manually.
*
*/
namespace SwaggerPetstore\models;
use \ArrayAccess;
class User implements ArrayAccess {
static $swaggerTypes = array(
'id' => 'int',
@ -58,7 +62,7 @@ class User implements ArrayAccess {
*/
public $user_status; /* int */
public function __construct(array $data) {
public function __construct(array $data = null) {
$this->id = $data["id"];
$this->username = $data["username"];
$this->first_name = $data["first_name"];

View File

@ -0,0 +1,17 @@
<?php
//require_once('vendor/autoload.php');
require_once('SwaggerPetstore-php/SwaggerPetstore.php');
// initialize the API client
$api_client = new SwaggerPetstore\APIClient('http://petstore.swagger.io/v2');
$petId = 5; // ID of pet that needs to be fetched
try {
$pet_api = new SwaggerPetstore\PetAPI($api_client);
// return Pet (model)
$response = $pet_api->getPetById($petId);
var_dump($response);
} catch (Exception $e) {
echo 'Caught exception: ', $e->getMessage(), "\n";
}
?>