Skip to content
GitLab
Projects Groups Snippets
  • /
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Sign in / Register
  • O openapi-generator
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
  • Issues 3,476
    • Issues 3,476
    • List
    • Boards
    • Service Desk
    • Milestones
  • Merge requests 402
    • Merge requests 402
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
  • Deployments
    • Deployments
    • Environments
    • Releases
  • Packages and registries
    • Packages and registries
    • Package Registry
    • Infrastructure Registry
  • Monitor
    • Monitor
    • Incidents
  • Analytics
    • Analytics
    • Value stream
    • CI/CD
    • Repository
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • OpenAPI Tools
  • openapi-generator
  • Issues
  • #5163
Closed
Open
Issue created Jan 30, 2020 by Administrator@rootContributor

[BUG] Invalid accept header PHP

Created by: dansleboby

OpenAPI Generator version: 4.2.2

Description

You should not overwrite the headers It a valid header and also define in RFC: https://tools.ietf.org/html/rfc2616#section-14.1

Here is the JSON: https://github.com/dansleboby/ubity-sdk-php/blob/master/swagger.json#L307

Suggest a fix/enhancement

The elseif for application/json overwrite the wanted headers in my YAML

I use

'application/json;version=1'

FIX: Remove elseif and content

In: HeaderSelector.php (https://www.google.com/url?q=https://github.com/OpenAPITools/openapi-generator/blob/0ffb99a48e0b669180e991031dfbe90505c3a571/modules/openapi-generator/src/main/resources/php/HeaderSelector.mustache&sa=D&source=hangouts&ust=1580443980093000&usg=AFQjCNE8Tn7jqApaid8Qt8nDJrD8nwJqDA)

     /**
     * Return the header 'Accept' based on an array of Accept provided
     *
     * @param string[] $accept Array of header
     *
     * @return string Accept (e.g. application/json)
     */
    private function selectAcceptHeader($accept)
    {
        if (count($accept) === 0 || (count($accept) === 1 && $accept[0] === '')) {
            return null;
        } elseif ($jsonAccept = preg_grep('~(?i)^(application/json|[^;/ \t]+/[^;/ \t]+[+]json)[ \t]*(;.*)?$~', $accept)) {
            return implode(',', $jsonAccept);
        } else {
            return implode(',', $accept);
        }
    }

    /**
     * Return the content type based on an array of content-type provided
     *
     * @param string[] $contentType Array fo content-type
     *
     * @return string Content-Type (e.g. application/json)
     */
    private function selectContentTypeHeader($contentType)
    {
        if (count($contentType) === 0 || (count($contentType) === 1 && $contentType[0] === '')) {
            return 'application/json';
        } elseif (preg_grep("/application\/json/i", $contentType)) {
            return 'application/json';
        } else {
            return implode(',', $contentType);
        }
    }
Assignee
Assign to
Time tracking