Skip to content

Conversation

Cih2001
Copy link

@Cih2001 Cih2001 commented Dec 18, 2024

On behalf of the https://github.com/arabesque-sray:

This PR does two things:

Updating go dependancies

A lot of dependancies on this repo are obsolete and contain critical security issues. An example is the dependancy on golang.org/x/net which is totally removed after updating go.mod. This will dismiss #21

Fix: Correct Logic for File-Type Response Indexing in Code Generation

Summary

We address a logic bug in the code generation process specifically for handling file responses. The logic flaw was causing a test (TestDownloadImage) within upstream/master to fail. After this fix, it runs successfully.

Problem Description

Consider an OpenAPI specifications that returns multiple responses which at least one of them is a file operation:

'/download/{image}':
  get:
    produces:
    - image/png
    summary: Retrieve an image
    description: Retrieve an image
    operationId: DownloadImage
    responses:
      '200':
        description: Image to download
        schema:
          type: file
        headers:
          Content-Type:
            type: "string"
      '500':
        description: Malfunction (internal requirements not fulfilled)

In this example, two responses are defined:

  1. 200, which is of type file.
  2. 500, meant for handling errors.

Although the 200 response is listed first, when using the walkResponses method, it is walked second. This is due to walkResponses deliberately processing file-type responses last to accommodate certain code generation requirements, such as adding defer httpResponse.Body.Close() after generating code for that response.

However, the existing client generator incorrectly calculates the response index. In fact the code there effectively counts the number of file-type responses rather than their index.

Solution

Since walkResponses has a custom ordrering logic, it's best if the index is passed to the handler function as a parameter, which is the approach for this PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant