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

[REQ] Support for extra annotations on path parameters #18224

Closed
EstebanMendez opened this issue Mar 25, 2024 · 1 comment · Fixed by #18967
Closed

[REQ] Support for extra annotations on path parameters #18224

EstebanMendez opened this issue Mar 25, 2024 · 1 comment · Fixed by #18967

Comments

@EstebanMendez
Copy link

EstebanMendez commented Mar 25, 2024

Is your feature request related to a problem?

I utilize annotations to validate payloads for DTOs, like so:

someField:
  type: string
  x-field-extra-annotation: >
    @my.project.validation.annotations.Somefield

This allows for me to validate the incoming DTOs across my projects, reusing the annotations in combination with the vendor extension.
I want to be able to do something similar for path parameters, with the Spring generator

Describe the solution you'd like

I would like to be able to utilize the vendor-extension pattern for my path parameters, to be able to validate path parameters in a similar fashion as I do with my DTOs.

openapi: 3.0.1
info:
  title: headers
  version: 0.0.1
paths: { }
components:
  parameters:
    PARAMETER:
      in: path
      name: parameter
      schema:
        type: string
      required: true
      x-parameter-extra-annotation: >
        @my.project.validation.annotations.SomeAnnotation

would generate:

interface MyController
{
   @RequestMapping(
         method = RequestMethod.GET,
         value = "/some/path/{parameter}/end",
         produces = { "application/json;charset=utf-8" }
   )
   ResponseEntity<SomeDTO> someMethod(
         @Parameter(name = "parameter", description = "", required = true, in = ParameterIn.PATH) @PathVariable("parameter") @my.project.validation.annotations.SomeAnnotation String parameter, 
         HttpServletRequest httpServletRequest
   );
}

Describe alternatives you've considered

I looked into this issue: #16054 which comes quite close to what I want, but it does unfortunately not cover my use case.

Updating the template on my end is obviously one way to go, but I believe that others might find this functionality of value.

Additional context

I am not sure if this is an apropriate feature request as I find the x-vendor-extensions quite flexible, as it opens up a lot of possibilities. If this is considered to be a good feature request, then it might be possible to add the functionality to the query parameters as well.

@jpfinne
Copy link
Contributor

jpfinne commented Mar 25, 2024

for Spring, it can be implemented with a custom beanValidationQueryParams.mustache

{{#vendorExtensions.x-parameter-extra-annotation}}{{{vendorExtensions.x-parameter-extra-annotation}}} {{/vendorExtensions.x-parameter-extra-annotation}}{{#required}}@NotNull {{/required}}{{^useOptional}}{{>beanValidationCore}}{{/useOptional}}{{#useOptional}}{{#required}}{{>beanValidationCore}}{{/required}}{{/useOptional}}

and a custom beanValidationPathParams.mustache

{{! PathParam is always required, no @NotNull necessary }}{{#vendorExtensions.x-parameter-extra-annotation}}{{{vendorExtensions.x-parameter-extra-annotation}}} {{/vendorExtensions.x-parameter-extra-annotation}}{{>beanValidationCore}}

It would be nice to include that feature in the default templates

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