forked from loafle/openapi-generator-original
Added ModelInterface for PHP Models (#6331)
All Model classes include a set of methods - it makes sense to align them to a concrete interface to improve strict typing when referencing these models.
This commit is contained in:
@@ -303,6 +303,7 @@ public class PhpClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
supportingFiles.add(new SupportingFile("ApiException.mustache", toPackagePath(invokerPackage, srcBasePath), "ApiException.php"));
|
||||
supportingFiles.add(new SupportingFile("Configuration.mustache", toPackagePath(invokerPackage, srcBasePath), "Configuration.php"));
|
||||
supportingFiles.add(new SupportingFile("ObjectSerializer.mustache", toPackagePath(invokerPackage, srcBasePath), "ObjectSerializer.php"));
|
||||
supportingFiles.add(new SupportingFile("ModelInterface.mustache", toPackagePath(modelPackage, srcBasePath), "ModelInterface.php"));
|
||||
supportingFiles.add(new SupportingFile("HeaderSelector.mustache", toPackagePath(invokerPackage, srcBasePath), "HeaderSelector.php"));
|
||||
supportingFiles.add(new SupportingFile("composer.mustache", getPackagePath(), "composer.json"));
|
||||
supportingFiles.add(new SupportingFile("README.mustache", getPackagePath(), "README.md"));
|
||||
|
||||
@@ -0,0 +1,86 @@
|
||||
<?php
|
||||
/**
|
||||
* ModelInterface
|
||||
*
|
||||
* PHP version 5
|
||||
*
|
||||
* @category Class
|
||||
* @package {{modelPackage}}
|
||||
* @author Swagger Codegen team
|
||||
* @link https://github.com/swagger-api/swagger-codegen
|
||||
*/
|
||||
|
||||
{{>partial_header}}
|
||||
/**
|
||||
* NOTE: This class is auto generated by the swagger code generator program.
|
||||
* https://github.com/swagger-api/swagger-codegen
|
||||
* Do not edit the class manually.
|
||||
*/
|
||||
|
||||
namespace {{modelPackage}};
|
||||
|
||||
/**
|
||||
* Interface abstracting model access.
|
||||
*
|
||||
* @package {{modelPackage}}
|
||||
* @author Swagger Codegen team
|
||||
*/
|
||||
interface ModelInterface
|
||||
{
|
||||
/**
|
||||
* The original name of the model.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getModelName();
|
||||
|
||||
/**
|
||||
* Array of property to type mappings. Used for (de)serialization
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function swaggerTypes();
|
||||
|
||||
/**
|
||||
* Array of property to format mappings. Used for (de)serialization
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function swaggerFormats();
|
||||
|
||||
/**
|
||||
* Array of attributes where the key is the local name, and the value is the original name
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function attributeMap();
|
||||
|
||||
/**
|
||||
* Array of attributes to setter functions (for deserialization of responses)
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function setters();
|
||||
|
||||
/**
|
||||
* Array of attributes to getter functions (for serialization of requests)
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function getters();
|
||||
|
||||
/**
|
||||
* Show all the invalid properties with reasons.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function listInvalidProperties();
|
||||
|
||||
/**
|
||||
* Validate all the properties in the model
|
||||
* return true if all passed
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function valid();
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
class {{classname}} {{#parentSchema}}extends {{{parent}}} {{/parentSchema}}implements ArrayAccess
|
||||
class {{classname}} {{#parentSchema}}extends {{{parent}}} {{/parentSchema}}implements ModelInterface, ArrayAccess
|
||||
{
|
||||
const DISCRIMINATOR = {{#discriminator}}'{{discriminator}}'{{/discriminator}}{{^discriminator}}null{{/discriminator}};
|
||||
|
||||
@@ -26,11 +26,21 @@ class {{classname}} {{#parentSchema}}extends {{{parent}}} {{/parentSchema}}imple
|
||||
{{/hasMore}}{{/vars}}
|
||||
];
|
||||
|
||||
/**
|
||||
* Array of property to type mappings. Used for (de)serialization
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function swaggerTypes()
|
||||
{
|
||||
return self::$swaggerTypes{{#parentSchema}} + parent::swaggerTypes(){{/parentSchema}};
|
||||
}
|
||||
|
||||
/**
|
||||
* Array of property to format mappings. Used for (de)serialization
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function swaggerFormats()
|
||||
{
|
||||
return self::$swaggerFormats{{#parentSchema}} + parent::swaggerFormats(){{/parentSchema}};
|
||||
@@ -45,7 +55,6 @@ class {{classname}} {{#parentSchema}}extends {{{parent}}} {{/parentSchema}}imple
|
||||
{{/hasMore}}{{/vars}}
|
||||
];
|
||||
|
||||
|
||||
/**
|
||||
* Array of attributes to setter functions (for deserialization of responses)
|
||||
* @var string[]
|
||||
@@ -55,7 +64,6 @@ class {{classname}} {{#parentSchema}}extends {{{parent}}} {{/parentSchema}}imple
|
||||
{{/hasMore}}{{/vars}}
|
||||
];
|
||||
|
||||
|
||||
/**
|
||||
* Array of attributes to getter functions (for serialization of requests)
|
||||
* @var string[]
|
||||
@@ -65,21 +73,46 @@ class {{classname}} {{#parentSchema}}extends {{{parent}}} {{/parentSchema}}imple
|
||||
{{/hasMore}}{{/vars}}
|
||||
];
|
||||
|
||||
/**
|
||||
* Array of attributes where the key is the local name, and the value is the original name
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function attributeMap()
|
||||
{
|
||||
return {{#parentSchema}}parent::attributeMap() + {{/parentSchema}}self::$attributeMap;
|
||||
}
|
||||
|
||||
/**
|
||||
* Array of attributes to setter functions (for deserialization of responses)
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function setters()
|
||||
{
|
||||
return {{#parentSchema}}parent::setters() + {{/parentSchema}}self::$setters;
|
||||
}
|
||||
|
||||
/**
|
||||
* Array of attributes to getter functions (for serialization of requests)
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function getters()
|
||||
{
|
||||
return {{#parentSchema}}parent::getters() + {{/parentSchema}}self::$getters;
|
||||
}
|
||||
|
||||
/**
|
||||
* The original name of the model.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getModelName()
|
||||
{
|
||||
return self::$swaggerModelName;
|
||||
}
|
||||
|
||||
{{#vars}}{{#isEnum}}{{#allowableValues}}{{#enumVars}}const {{enumName}}_{{{name}}} = {{{value}}};
|
||||
{{/enumVars}}{{/allowableValues}}{{/isEnum}}{{/vars}}
|
||||
|
||||
@@ -125,7 +158,7 @@ class {{classname}} {{#parentSchema}}extends {{{parent}}} {{/parentSchema}}imple
|
||||
}
|
||||
|
||||
/**
|
||||
* show all the invalid properties with reasons.
|
||||
* Show all the invalid properties with reasons.
|
||||
*
|
||||
* @return array invalid properties with reasons
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user