swagger-api / swagger-api/swagger-codegen
[PHP/Symfony] BUG Generate string insteaf of object
Nobody has claimed this yet.
- Dominant language
- Mustache
- Stars
- 17.8k
- Forks
- 6k
- PR merge metrics
- No merged PRs in 30d
Description
I defined a User with an email
definitions:
User:
type: object
properties:
email:
$ref: '#/definitions/Email'
Email:
type: string
format: email
the library generate a class Email
class SWEmail
{
public function __construct(array $data = null) { }
}
And a User (where @Type is \Email and not string)
class SWUser
{
/**
* @var App\Model\SW\Email|null
* @SerializedName("email")
* @Assert\Type("App\Model\SW\SWEmail")
* @Type("App\Model\SW\SWEmail")
*/
protected $email;
}
If I want the PHP object :
class User
{
private $email;
public function setEmail(string $email) {
$this->email = $email;
}
}
$user = new User();
$user->setEmail('foo@bar.com');
App\Model\User {
email: "foo@bar.com"
}
After using jms Serializer, The error is :
must be an object, string given
Because swagger codegen generate
@Type("App\Model\SW\SWEmail") insteaf of @Type("string")
In java there is no Email Model generated, and the User Model has an email type String
public class SWUser {
@SerializedName("email")
private String email = null;
}
Is there a way to fix it ?
Swagger-codegen version
2.4.12
Command line used for generation
java -jar swagger-codegen-cli.jar generate -i C:\swagger.yaml -l php-symfony -o C:\generationDirectory
Steps to reproduce
Symfony 5
PHP 7.4
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
Reproduce the php-symfony generation command with the supplied Swagger definition under Symfony 5 and PHP 7.4, then compare the generated SWUser annotations with the Java output shown. Trace the generator entry point and templates responsible for a string schema referenced through $ref. Done means the PHP property is generated as a string and JMS Serializer no longer expects an object.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java, openapi, php, symfony
- Domain
- backend, tooling
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100