OpenAPITools / OpenAPITools/openapi-generator

[BUG] [Symfony] Backslashes in namespaces passed to the Assert\Type ctor are not escaped

Open
#6,596 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Issue: Bug Server: PHP
Dominant language
Java
Stars
26.8k
Forks
7.7k
PR merge metrics
PR metrics pending

Description

Bug Report Checklist
  • Have you provided a full/minimal spec to reproduce the issue?
  • Have you validated the input using an OpenAPI validator (example)?
  • What's the version of OpenAPI Generator used?
  • Have you search for related issues/PRs?
  • What's the actual output vs expected output?
  • [Optional] Bounty to sponsor the fix ([example]
Description

Version 4.3.0

If any part of the namespace of a type starts with an escape character, the string is mangled (contains a unicode or non-printable character) when passed to the constructor to Assert\Type.

Generated code for the controller with "invokerPackage": "Api\\v1" in the configuration file:

        // Deserialize the input values that needs it
        try {
            $body = $this->deserialize($body, 'Api\v1\Model\MyType', $inputFormat);
        } catch (SerializerRuntimeException $exception) {
            return $this->createBadRequestResponse($exception->getMessage());
        }

        // Validate the input values
        $asserts = [];
>>>     $asserts[] = new Assert\Type("Api\v1\Model\MyType");
        $asserts[] = new Assert\Valid();
        $response = $this->validate($body, $asserts);

Here \v is converted to the vertical tab character.

Suggest a fix

Escape the backslashes or use single quotes for the string passed to the constructor of Assert\Type

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the Symfony generator templates or entry points responsible for emitting controller validation code, using the reported invokerPackage value "Api\v1" to reproduce the generated Assert\Type line. Verify the generated PHP preserves namespace backslashes and no longer converts sequences such as \v into control characters.

Written by the indexing model from the issue text.

Assessment

Tech stack
php, symfony
Domain
backend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.