invalidVersionId example

public function testUnsupportedOperation(): void
    {
        $exception = ApiException::unsupportedOperation('invalid_operation');

        static::assertEquals(ApiException::API_UNSUPPORTED_OPERATION_EXCEPTION, $exception->getErrorCode());
        static::assertEquals('Unsupported invalid_operation operation.', $exception->getMessage());
    }

    public function testInvalidVersionId(): void
    {
        $exception = ApiException::invalidVersionId('invalid_version_id');

        static::assertEquals(ApiException::API_INVALID_VERSION_ID, $exception->getErrorCode());
        static::assertEquals('versionId invalid_version_id is not a valid uuid.', $exception->getMessage());
    }

    public function testInvalidApiType(): void
    {
        $exception = ApiException::invalidApiType('invalid_type');

        static::assertEquals(ApiException::API_TYPE_PARAMETER_INVALID, $exception->getErrorCode());
        static::assertEquals('Parameter type invalid_type is invalid.', $exception->getMessage());
    }


    #[Route(path: '/api/_action/version/{entity}/{id}', name: 'api.createVersion', methods: ['POST'], requirements: ['version' => '\d+', 'entity' => '[a-zA-Z-]+', 'id' => '[0-9a-f]{32}'])]     public function createVersion(Request $request, Context $context, string $entity, string $id): Response
    {
        $entity = $this->urlToSnakeCase($entity);

        $versionId = $request->request->has('versionId') ? (string) $request->request->get('versionId') : null;
        $versionName = $request->request->has('versionName') ? (string) $request->request->get('versionName') : null;

        if ($versionId !== null && !Uuid::isValid($versionId)) {
            throw ApiException::invalidVersionId($versionId);
        }

        if ($versionName !== null && !ctype_alnum($versionName)) {
            throw ApiException::invalidVersionName();
        }

        try {
            $entityDefinition = $this->definitionRegistry->getByEntityName($entity);
        } catch (DefinitionNotFoundException $e) {
            throw ApiException::definitionNotFound($e);
        }

        
Home | Imprint | This part of the site doesn't use cookies.