swagger-api / swagger-api/swagger-codegen
[PHP] Doesn't generate attributes, getters, setters etc.for Model child classes
Nobody has claimed this yet.
- Dominant language
- Mustache
- Stars
- 17.8k
- Forks
- 6k
- PR merge metrics
- No merged PRs in 30d
Description
Description
It seems that Codegen doesn't process and generate attributes, setters and getters for child Model classes.
On the example below as you can see class User is a child class of Profile (extends class Profile) and contains extra attributes.
Parent class (Profile) seems to be processed and generated correctly, but child class (User) has not been processed correctly. Please look at the code examples below.
Swagger-codegen version
3.0.11
Swagger declaration file content or url
Here is a relevant API docs extraction from Swagger@OAS3
components:
schemas:
Profile:
type: object
properties:
id:
type: string
format: uuid
example: d290f1ee-6c54-4b01-90e6-d701748f0851
firstName:
type: string
example: John
lastName:
type: string
example: Smith
email:
type: string
format: email
example: john.smith@example.com
phone:
type: string
format: phone
nullable: true
example: "+44 1260 1234567"
avatar:
type: string
format: url
nullable: true
example: "https://example.com/john_smith.png"
User:
type: object
allOf:
- $ref: '#/components/schemas/Profile'
properties:
password:
type: string
example: SL3ZHkBnt8GmDWIxyD8O
emailVerifiedAt:
type: string
format: date-time
nullable: true
example: "2019-06-23 11:47:23"
rememberToken:
type: string
minLength: 64
maxLength: 64
nullable: true
example: "0mdCVQ4ozf3nNRpoeCoZRtGULXNx6Bb6gOxit9NWU1e8FPcglV3jLmXpDHh5njHc"
blocked:
type: boolean
default: false
example: false
tcAccepted:
type: boolean
default: true
example: true
role:
type: string
example: admin.account
permissions:
type: array
items:
type: string
example: accounts.own.read
createdAt:
$ref: '#/components/schemas/DateTime'
updatedAt:
$ref: '#/components/schemas/DateTime'
Here is an extraction from PHP generated classes:
Profileclass:
<?php
/**
* Swagger Codegen version: 3.0.11
*/
/**
* 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 MsAccounts\Client\Model;
use \ArrayAccess;
use \MsAccounts\Client\ObjectSerializer;
/**
* Profile Class Doc Comment
*
* @category Class
* @package MsAccounts\Client
* @author Swagger Codegen team
* @link https://github.com/swagger-api/swagger-codegen
*/
class Profile implements ModelInterface, ArrayAccess
{
const DISCRIMINATOR = null;
/**
* The original name of the model.
*
* @var string
*/
protected static $swaggerModelName = 'Profile';
/**
* Array of property to type mappings. Used for (de)serialization
*
* @var string[]
*/
protected static $swaggerTypes = [
'id' => 'string',
'firstName' => 'string',
'lastName' => 'string',
'email' => 'string',
'phone' => 'string',
'avatar' => 'string' ];
/**
* Array of property to format mappings. Used for (de)serialization
*
* @var string[]
*/
protected static $swaggerFormats = [
'id' => 'uuid',
'firstName' => null,
'lastName' => null,
'email' => 'email',
'phone' => 'phone',
'avatar' => 'url' ];
/**
* Array of property to type mappings. Used for (de)serialization
*
* @return array
*/
public static function swaggerTypes()
{
return self::$swaggerTypes;
}
/**
* Array of property to format mappings. Used for (de)serialization
*
* @return array
*/
public static function swaggerFormats()
{
return self::$swaggerFormats;
}
/**
* Array of attributes where the key is the local name,
* and the value is the original name
*
* @var string[]
*/
protected static $attributeMap = [
'id' => 'id',
'firstName' => 'firstName',
'lastName' => 'lastName',
'email' => 'email',
'phone' => 'phone',
'avatar' => 'avatar' ];
/**
* Array of attributes to setter functions (for deserialization of responses)
*
* @var string[]
*/
protected static $setters = [
'id' => 'setId',
'firstName' => 'setFirstName',
'lastName' => 'setLastName',
'email' => 'setEmail',
'phone' => 'setPhone',
'avatar' => 'setAvatar' ];
/**
* Array of attributes to getter functions (for serialization of requests)
*
* @var string[]
*/
protected static $getters = [
'id' => 'getId',
'firstName' => 'getFirstName',
'lastName' => 'getLastName',
'email' => 'getEmail',
'phone' => 'getPhone',
'avatar' => 'getAvatar' ];
/**
* Array of attributes where the key is the local name,
* and the value is the original name
*
* @return array
*/
public static function attributeMap()
{
return self::$attributeMap;
}
/**
* Array of attributes to setter functions (for deserialization of responses)
*
* @return array
*/
public static function setters()
{
return self::$setters;
}
/**
* Array of attributes to getter functions (for serialization of requests)
*
* @return array
*/
public static function getters()
{
return self::$getters;
}
/**
* The original name of the model.
*
* @return string
*/
public function getModelName()
{
return self::$swaggerModelName;
}
/**
* Associative array for storing property values
*
* @var mixed[]
*/
protected $container = [];
/**
* Constructor
*
* @param mixed[] $data Associated array of property values
* initializing the model
*/
public function __construct(array $data = null)
{
$this->container['id'] = isset($data['id']) ? $data['id'] : null;
$this->container['firstName'] = isset($data['firstName']) ? $data['firstName'] : null;
$this->container['lastName'] = isset($data['lastName']) ? $data['lastName'] : null;
$this->container['email'] = isset($data['email']) ? $data['email'] : null;
$this->container['phone'] = isset($data['phone']) ? $data['phone'] : null;
$this->container['avatar'] = isset($data['avatar']) ? $data['avatar'] : null;
}
// Cutting code here as the essence is shown above
Userclass:
<?php
/**
* Generated by: https://github.com/swagger-api/swagger-codegen.git
* Swagger Codegen version: 3.0.11
*/
/**
* 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 MsAccounts\Client\Model;
use \MsAccounts\Client\ObjectSerializer;
/**
* User Class Doc Comment
*
* @category Class
* @package MsAccounts\Client
* @author Swagger Codegen team
* @link https://github.com/swagger-api/swagger-codegen
*/
class User extends Profile
{
const DISCRIMINATOR = null;
/**
* The original name of the model.
*
* @var string
*/
protected static $swaggerModelName = 'User';
/**
* Array of property to type mappings. Used for (de)serialization
*
* @var string[]
*/
protected static $swaggerTypes = [
];
/**
* Array of property to format mappings. Used for (de)serialization
*
* @var string[]
*/
protected static $swaggerFormats = [
];
/**
* Array of property to type mappings. Used for (de)serialization
*
* @return array
*/
public static function swaggerTypes()
{
return self::$swaggerTypes + parent::swaggerTypes();
}
/**
* Array of property to format mappings. Used for (de)serialization
*
* @return array
*/
public static function swaggerFormats()
{
return self::$swaggerFormats + parent::swaggerFormats();
}
/**
* Array of attributes where the key is the local name,
* and the value is the original name
*
* @var string[]
*/
protected static $attributeMap = [
];
/**
* Array of attributes to setter functions (for deserialization of responses)
*
* @var string[]
*/
protected static $setters = [
];
/**
* Array of attributes to getter functions (for serialization of requests)
*
* @var string[]
*/
protected static $getters = [
];
/**
* Array of attributes where the key is the local name,
* and the value is the original name
*
* @return array
*/
public static function attributeMap()
{
return parent::attributeMap() + self::$attributeMap;
}
/**
* Array of attributes to setter functions (for deserialization of responses)
*
* @return array
*/
public static function setters()
{
return parent::setters() + self::$setters;
}
/**
* Array of attributes to getter functions (for serialization of requests)
*
* @return array
*/
public static function getters()
{
return parent::getters() + self::$getters;
}
/**
* The original name of the model.
*
* @return string
*/
public function getModelName()
{
return self::$swaggerModelName;
}
/**
* Constructor
*
* @param mixed[] $data Associated array of property values
* initializing the model
*/
public function __construct(array $data = null)
{
parent::__construct($data);
}
// Cutting code here as the essence is shown above
As you can see all User model related attributes, setters, geters etc. are missing.
Command line used for generation
Generated directly from SwaggerHub panel: EXPORT -> Client SDK -> php
Steps to reproduce
Simply, try to generate SDK library for any scenario which includes classes extending (referencing) parent class.
Related issues/PRs
Couldn't find any.
Suggest a fix/enhancement
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reproducing the SwaggerHub PHP SDK export with the supplied Profile/User OpenAPI schema and compare the generated classes. Trace how the PHP generator handles allOf inheritance, then verify that User includes its declared properties, attribute mappings, getters, setters, and constructor initialization.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- php
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100