Skip to content

[BUG] Invalid accept header PHP #5163

Description

@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);
        }
    }

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions