Skip to content

Accept header forces application/json type even if server #10337

Merged
wing328 merged 2 commits intoOpenAPITools:masterfrom
wtrocki:patch-1
Sep 21, 2021
Merged

Accept header forces application/json type even if server #10337
wing328 merged 2 commits intoOpenAPITools:masterfrom
wtrocki:patch-1

Conversation

@wtrocki
Copy link
Contributor

@wtrocki wtrocki commented Sep 6, 2021

#10340

When API returns mixed content - 200 returns File/Binary and 500 returns JSON which is typical for error handling.
Generated code will include two accept headers. Problem is that selectHeaderAccept function that builds headers always forces accept headers to be JSON. This will crash as the server only knows how to return zip content type.

Example:
https://github.com/redhat-developer/app-services-sdk-go/blob/main/registryinstance/apiv1internal/client/api_admin.go#L1004-L1007

Request is mixed with zip and json on 500:

 ],
        "responses": {
          "200": {
            "content": {
              "application/zip": {
                "schema": {
                  "$ref": "#/components/schemas/FileContent"
                }
              }
            },
            "description": "Response when the export is successful."
          },
          "500": {
            "$ref": "#/components/responses/ServerError"
          }
        },

Headers are generated properly but request is later made with "application/json"

HTTPHeaderAccepts := []string{"application/zip", "application/json"}

@wtrocki wtrocki changed the title fix!: accept should not force application JSON Accept should not force application JSON Sep 7, 2021
@wtrocki wtrocki changed the title Accept should not force application JSON Accept header forces application/json type even if server Sep 7, 2021
@wing328
Copy link
Member

wing328 commented Sep 16, 2021

Can you please follow step 3 in the PR checklist to update the samples so that the CI can verify the change?

https://github.com/OpenAPITools/openapi-generator/blob/master/.github/PULL_REQUEST_TEMPLATE.md

cc @antihax (2017/11) @grokify (2018/07) @kemokemo (2018/09) @jirikuncar (2021/01) @ph4r5h4d (2021/04)

Generated code offen provides range of accept methods.
This method improperly takes JSON as preferred

Example:
	localVarHTTPHeaderAccepts := []string{"application/zip", "application/json"}
@wtrocki
Copy link
Contributor Author

wtrocki commented Sep 16, 2021

Rebased. Updated samples. Verified.

@wing328 wing328 added this to the 5.3.0 milestone Sep 21, 2021
@wing328 wing328 merged commit 18301d0 into OpenAPITools:master Sep 21, 2021
@wtrocki wtrocki deleted the patch-1 branch September 21, 2021 04:14
wing328 added a commit that referenced this pull request Sep 21, 2021
@wing328
Copy link
Member

wing328 commented Sep 21, 2021

Looks like this breaks the CI so I've to revert the change via #10440

For the error log, please refer to https://app.circleci.com/pipelines/github/OpenAPITools/openapi-generator/12853/workflows/ae655d09-315f-43ae-9669-ac2379d0a964/jobs/26495

To run the Go Petstore tests, please refer to https://github.com/OpenAPITools/openapi-generator/wiki/Integration-Tests#how-to-add-integration-tests-for-new-petstore-samples on how to run the test server locally.

wing328 added a commit that referenced this pull request Sep 21, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants