79170508

Date: 2024-11-08 14:57:01
Score: 0.5
Natty:
Report link

It seems that there is no inherent way to do this with configs or standard OpenAPI conventions. What I found is that creating a vendor extension that holds a boolean as to whether to use that class response or not in each operation then using it in template files is a way to override this. Specifically, using JavaJaxRS, customize the returnTypes.mustache template.

YAML Example:

openapi: 3.0.1
info:
servers:
paths:
    /sample:
        get:
            x-response: true

returnTypes.mustache changes:

{{#vendorExtensions.x-response}}Response{{/vendorExtensions.x-response}}{{! non-generic response:}}
{{^vendorExtensions.x-response}}{{!
}}{{{returnType}}}{{!
}}{{/vendorExtensions.x-response}}

One thing to consider is that doing this will override the useGenericResponse flag. If you want to continue having that option available, you'll have to account for that being set or not in the template.

Reasons:
  • Long answer (-0.5):
  • Has code block (-0.5):
  • Self-answer (0.5):
  • Low reputation (1):
Posted by: Michael Rudd