Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SpringAnnotationScanner doesn't manage any "framework" context classes #1824

Open
morettileo opened this issue May 6, 2024 · 1 comment
Open
Labels
enhancement New feature or request

Comments

@morettileo
Copy link
Contributor

morettileo commented May 6, 2024

In Spring, when we need to access HttpServletRequest / HttpServletResponse ) in controller we can define them as parameters in method signature, as in this example:

/**
 * Generate a PDF report...
 */
@RequestMapping(value = "/report", method = RequestMethod.POST)
@ResponseBody
public void generateReport(
        HttpServletRequest request, 
        HttpServletResponse response,
        @RequestBody ReportData sourceData) {

    // ...
    // Here you can use the request and response objects like:
    // response.setContentType("application/pdf");
    // response.getOutputStream().write(...);
}

Of course there are alternative ways to do it, but this is what I have actually in my controllers.

This generate the following OpenAPI YAML:

"/report" : {
  "post" : {
    "requestBody" : {
      "content" : {
        "*/*" : {
          "schema" : {
            "type" : "object"
          }
        }
      }
    },
    "responses" : {
      "201" : {
        "description" : "Created"
      }
    }
  }
}

while if I remove HttpServletRequest \ HttpServletResponse I get the expected YAML:

"/report" : {
  "post" : {
    "requestBody" : {
      "content" : {
        "*/*" : {
          "schema" : {
            "$ref" : "#/components/schemas/ReportData"
          }
        }
      }
    },
    "responses" : {
      "201" : {
        "description" : "Created"
      }
    }
  }
}

Maybe SpringAnnotationScanner could manage these "framework" classes as JaxRsAnnotationScanner does for javax.ws.rs.core.Request and other class of the same package.
I refer to this implementation in JaxRsAnnotationScanner:

public boolean isFrameworkContextType(Type type) {
    return JaxRsConstants.CONTEXTS.contains(type.name());
}
@MikeEdgar
Copy link
Member

Seems reasonable. @morettileo do you have any interest in doing a PR with the change? It should be simply an override of boolean isFrameworkContextType(Type type) as you mentioned, plus adjusting some of the tests to verify it.

@MikeEdgar MikeEdgar added the enhancement New feature or request label May 6, 2024
@morettileo morettileo changed the title SpringAnnotationScanner doesn't manage any "framework" context annotation SpringAnnotationScanner doesn't manage any "framework" context classes May 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants