OpenAPITools / openapi-generator

OpenAPI Generator allows generation of API client libraries (SDK generation), server stubs, documentation and configuration automatically given an OpenAPI Spec (v2, v3)
https://openapi-generator.tech
Apache License 2.0
21.99k stars 6.59k forks source link

[REQ] Add support of @ResponseStatus for spring-http-interface library #20068

Open alfet81 opened 2 weeks ago

alfet81 commented 2 weeks ago

Is your feature request related to a problem? Please describe.

The spring-http-interface library doesn't allow to use @ResponseStatus when option useResponseEntity is disabled.

Describe the solution you'd like

When useResponseEntity is set to false the generator should add @ResponseStatus similar it does for default spring generator.

Additional context

Here is what api.mustache should look like after the change:

`/**

{{#imports}}import {{import}}; {{/imports}} {{^useResponseEntity}} import org.springframework.http.HttpStatus; {{/useResponseEntity}} import org.springframework.http.ResponseEntity; {{#useResponseEntity}} import org.springframework.http.ResponseEntity; {{/useResponseEntity}} import org.springframework.web.bind.annotation.; import org.springframework.web.service.annotation.; import org.springframework.web.multipart.MultipartFile; {{#reactive}}

import org.springframework.http.codec.multipart.Part; import reactor.core.publisher.Flux; import reactor.core.publisher.Mono; {{/reactive}}

import java.util.List; import java.util.Map; import java.util.Optional; import {{javaxPackage}}.annotation.Generated;

{{>generatedAnnotation}} {{#operations}} public interface {{classname}} { {{#operation}}

/**
 * {{httpMethod}} {{{path}}}{{#summary}} : {{.}}{{/summary}}
{{#notes}}
 * {{.}}
{{/notes}}
 *
{{#allParams}}
 * @param {{paramName}} {{description}}{{#required}} (required){{/required}}{{^required}} (optional{{#defaultValue}}, default to {{.}}{{/defaultValue}}){{/required}}
{{/allParams}}
 * @return {{#responses}}{{message}} (status code {{code}}){{^-last}}
 *         or {{/-last}}{{/responses}}
{{#isDeprecated}}
 * @deprecated
{{/isDeprecated}}
{{#externalDocs}}
 * {{description}}
 * @see <a href="{{url}}">{{summary}} Documentation</a>
{{/externalDocs}}
 */
{{#isDeprecated}}
@Deprecated
{{/isDeprecated}}
{{^useResponseEntity}}
@ResponseStatus({{#springHttpStatus}}{{#responses.0}}{{{code}}}{{/responses.0}}{{/springHttpStatus}})
{{/useResponseEntity}}
@HttpExchange(
    method = "{{{httpMethod}}}",
    value = "{{{path}}}",
    accept = { {{#vendorExtensions.x-accepts}}"{{{.}}}"{{^-last}}, {{/-last}}{{/vendorExtensions.x-accepts}} }{{#vendorExtensions.x-content-type}},
    contentType = "{{{vendorExtensions.x-content-type}}}"{{/vendorExtensions.x-content-type}}
)
{{>responseType}} {{operationId}}(
    {{#allParams}}{{>queryParams}}{{>pathParams}}{{>headerParams}}{{>bodyParams}}{{>formParams}}{{>cookieParams}}{{^-last}},
    {{/-last}}{{/allParams}}
){{#unhandledException}} throws Exception{{/unhandledException}};

{{/operation}} } {{/operations}}`

alfet81 commented 2 weeks ago

PR is ready: https://github.com/OpenAPITools/openapi-generator/pull/20071