swagger-api / swagger-api/swagger-codegen

[PHP] Quotes in enum values are not escaped

Open
#8,599 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Mustache
Stars
17.8k
Forks
6k
PR merge metrics
No merged PRs in 30d

Description

Description

If enum values contain single quotes the codegen generates not valid PHP code.

Swagger-codegen version

2.4.0

Swagger declaration file content or url
{
  "swagger":"2.0",
  "info": {
    "title": "Foo",
    "version": "1.0.0"
  },
  "paths": {
  },
  "definitions": {
    "Foo": {
      "type": "object",
      "properties": {
        "type": {
          "type": "string",
          "enum": [
            "Foo 'bar'"
          ]
        }
      }
    }
  }
}
Command line used for generation
docker run --rm --volume=$PWD:/app --workdir=/app swaggerapi/swagger-codegen-cli generate \
    --input-spec ./swagger.json \
    --lang php
Generated PHP-file contains syntax error
<?php

namespace Swagger\Client\Model;

class Foo implements ModelInterface, ArrayAccess
{
    ...

    const TYPE_FOO_BAR = 'Foo 'bar''; // unescaped quotes

    ...
}

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 by running the documented Docker generation command with the provided Swagger definition and PHP output. Trace the PHP generator entry point and the template that emits enum constants, then verify that the generated Foo class contains valid escaping for the quoted enum value and can be parsed as PHP.

Written by the indexing model from the issue text.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.