getSchemaByDefinition example

SimpleDefinition::class,
                ComplexDefinition::class,
                SimpleExtendedDefinition::class,
            ],
            $this->createMock(ValidatorInterface::class),
            $this->createMock(EntityWriteGatewayInterface::class)
        );
    }

    public function testEntityNameConversion(): void
    {
        $schema = $this->schemaBuilder->getSchemaByDefinition(
            $this->definitionRegistry->get(SimpleDefinition::class),
            '/simple',
            false
        );
        static::assertArrayHasKey('Simple', $schema);
        static::assertArrayHasKey('SimpleJsonApi', $schema);
    }

    public function testAssociationSchemas(): void
    {
        $schema = $this->schemaBuilder->getSchemaByDefinition(
            
private $service;

    protected function setUp(): void
    {
        $this->service = $this->getContainer()->get(OpenApiDefinitionSchemaBuilder::class);
    }

    public function testFieldIsMarkedAsNew(): void
    {
        $definition = $this->registerDefinition(SimpleDefinition::class);

        $build = json_decode(json_encode($this->service->getSchemaByDefinition($definition, '', false), \JSON_THROW_ON_ERROR), true, 512, \JSON_THROW_ON_ERROR);

        static::assertSame('Added since version: 6.0.0.0', $build['SimpleJsonApi']['description']);
        static::assertSame('Added since version: 6.3.9.9.', $build['SimpleJsonApi']['allOf'][1]['properties']['i_am_a_new_field']['description']);
    }

    public function testFieldIsMarkedAsNewWithJsonType(): void
    {
        $definition = $this->registerDefinition(SimpleDefinition::class);

        $build = json_decode(json_encode(
            $this->service->getSchemaByDefinition(
                
foreach ($definitions as $definition) {
            if (!$definition instanceof EntityDefinition) {
                continue;
            }

            if (!$this->shouldDefinitionBeIncluded($definition)) {
                continue;
            }

            $onlyReference = $this->shouldIncludeReferenceOnly($definition$forSalesChannel);

            $schema = $this->definitionSchemaBuilder->getSchemaByDefinition($definition$this->getResourceUri($definition)$forSalesChannel$onlyReference);

            $openApi->components->merge($schema);
        }

        $this->addGeneralInformation($openApi);
        $this->addContentTypeParameter($openApi);

        $data = json_decode($openApi->toJson(), true, 512, \JSON_THROW_ON_ERROR);
        $data['paths'] ??= [];

        $schemaPaths = [$this->schemaPath];

        
foreach ($definitions as $definition) {
            if (!$this->shouldDefinitionBeIncluded($definition)) {
                continue;
            }

            $onlyFlat = match ($apiType) {
                DefinitionService::TYPE_JSON => true,
                default => $this->shouldIncludeReferenceOnly($definition$forSalesChannel),
            };

            $schema = $this->definitionSchemaBuilder->getSchemaByDefinition(
                $definition,
                $this->getResourceUri($definition),
                $forSalesChannel,
                $onlyFlat,
                $apiType
            );

            $openApi->components->merge($schema);

            if ($onlyFlat) {
                continue;
            }
Home | Imprint | This part of the site doesn't use cookies.