Skip to content

[Swagger] @id gets generated as int, but exported as string #758

@dkarlovi

Description

@dkarlovi

I'm using 2.0.0-RC1 and have an entity called Ingredient with declaration as so

/**
 * Ingredient.
 *
 * @ORM\Table(name="ingredient")
 * @ORM\Entity(repositoryClass="AppBundle\Repository\IngredientRepository")
 * @ApiResource(iri="http://schema.org/Ingredient")
 */
class Ingredient
{
    /**
     * @var int
     *
     * @ORM\Column(name="id", type="integer")
     * @ORM\Id
     * @ORM\GeneratedValue(strategy="AUTO")
     */
    private $id;
}

Swagger definition in apidoc.json says

definitions: {
    Ingredient: {
        type: "object",
        xml: {
            name: "response"
        },
        properties: {
            id: {
                type: "integer"
            },

so it expects it to be an int. But, when accessing the API, ID is set as:

"@id": "/api/ingredients/4",

which makes it a string. This means that using swagger-codegen creates the API client which will cast all ID's to 0, as it's using (in PHP language mode)

// $data = /api/ingredients/4
// $class = int
settype($data, $class);

which reproduces as:

$ php70 -r '$s = "/api/ingredients/4"; settype($s, "int"); var_dump($s);'
int(0)

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions