Skip to content

Project stops working when using YAML config #6110

@aruku

Description

@aruku

API Platform version(s) affected: 2.7.16

Description
I have a small project with two entities and a few fields on each, and that works fine both through the generated UI and integration tests. But when I change it from using annotations to yaml configuration, I get the following error when creating a single item:

Failed asserting that Array &0 (
    '@context' => '/api/contexts/Plant'
    '@id' => '/api/plants/6'
    '@type' => 'Plant'
    'name' => 'Poochy World'
    'timezone' => 'America/New_York'
    'dbConfig' => Array &1 ()
    'migrateDbConfig' => Array &2 ()
    'e1000Structure' => Array &3 ()
    'transformCenters' => Array &4 ()
    'featuresST' => Array &5 ()
    'enabled' => false
    'ready' => false
    'typePvet' => false
    'typeEdust' => false
    'typeE1000' => false
    'generateDailyReport' => false
    'realTime' => true
    'offsetDays' => 0
    'edustConfig' => 0
    'dashboardFeature' => false
    'curvesFeature' => false
    'devicesFeature' => false
    'faultsFeature' => false
    'advancedFeature' => false
    'downloadsFeature' => false
    'analysisFeature' => false
    'reportsFeature' => false
    'eventsFeature' => false
    'dustFeature' => false
    'inverterQuartileFeature' => 0
    'trackerQuartileFeature' => 0
    'timeGraphics' => 15
    'weekType' => false
    'issueTypeChecking' => false
    'issueTypePreventive' => false
    'issueTypeCorrective' => false
    'issueTypeOperative' => false
    'issueTypeOther' => false
    'issueTypeEdustClean' => false
    'eventTypeVisit' => false
    'eventTypeIncidence' => false
    'eventTypeOM' => false
    'eventTypeCampaign' => false
    'eventTypeOther' => false
    'eventTypeEdustNote' => false
    'eventTypeEdustClean' => false
    'eventTypeUnavailability' => false
    'devicesGL' => false
    'devicesCX' => false
    'devicesSS' => false
    'devicesCT' => false
    'devicesDI' => false
    'devicesIN' => false
    'devicesTR' => false
    'devicesSB' => false
    'devicesST' => false
    'devicesMS' => false
    'devicesRM' => false
    'devicesEDust' => 0
    'devicesOC' => false
    'devicesSL' => false
    'devicesSC' => false
    'dashboardLevel1' => false
    'dashboardLevel2' => false
    'dashboardLevel3' => false
    'mapLevel1' => false
    'mapLevel2' => 0
    'mapLevel3' => false
    'dailyDateRange' => true
    'weeklyDateRange' => false
    'monthlyDateRange' => false
    'yearlyDateRange' => false
    'chartVariables' => Array &6 ()
    'dataFaults' => false
    'productionFaults' => false
    'predictiveFaults' => false
    'alarmFaults' => false
    'annexReport' => false
    'hasRM' => false
    'processingIVReports' => false
    'id' => 6
    'createdAt' => '2024-01-16T16:22:25+00:00'
    'updatedAt' => '2024-01-16T16:22:25+00:00'
    'key' => '65a6ad41d0544'
    'preview' => true
    'mapLevelShow' => false
    'downloadChartVariables' => Array &7 ()
    'advancedChartVariables' => Array &8 ()
) matches the provided JSON Schema.
dbConfig: Array value found, but an object is required
migrateDbConfig: Array value found, but an object is required
e1000Structure: Array value found, but an object is required

How to reproduce
These are the relevant pieces of code:

# Config\resources.yaml
resources:
    App\Entity\Plant:
        normalizationContext:
            groups: ['plant:read']
        denormalizationContext:
            groups: ['plant:write']

properties:
    App\Entity\Plant:
        client:
            readableLink: false
            writableLink: false
# Config\Serialization\Plant.yaml
App\Entity\Plant:
    attributes:
        name:
            groups: ['plant:read', 'plant:write']
        client:
            groups: ['plant:read', 'plant:write']
        timezone:
            groups: ['plant:read', 'plant:write']

The entity, with the original annotations:

/**
 * [...]
 *
 * @ApiResource(
 *     normalizationContext={"groups"={"plant:read"}},
 *     denormalizationContext={"groups"={"plant:write"}},
 * )
 */
class Plant
{
    [...]
    /**
     * @ORM\Column(type="string", nullable=true)
     * @Assert\NotBlank()
     *
     * @Groups({"plant:read", "plant:write"})
     */
    protected ?string $name = null;

    /**
     * @ORM\ManyToOne(targetEntity="Client", inversedBy="plants")
     * @ORM\JoinColumn(name="client_id", referencedColumnName="id", onDelete="CASCADE")
     *
     * @Groups({"plant:read", "plant:write"})
     * @ApiProperty(readableLink=false, writableLink=false)
     */
    protected ?Client $client = null;

    /**
     * @ORM\Column(type="string", nullable=false, length=100, options={"fixed":true})
     * @Assert\NotBlank()
     *
     * @Groups({"plant:read", "plant:write"})
     */
    protected ?string $timezone = null;
}

I tried adding this to resources.yaml.properties, but didn't help:

        dbConfig:
            attributes:
                jsonschema_context:
                    type: object

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions