Hi!
I'm trying to return String value.
My OAS looks like this:
openapi: 3.0.0
info:
title: API
description: API
version: LATEST
tags:
- name: helloWorld
description: Hello World Api
paths:
/helloWorld:
get:
tags:
- helloWorld
responses:
'200':
description: OK
content:
'text/plain':
schema:
type: string
parameters:
- name: name
in: query
schema:
type: string
But it results in this method:
/**
* GET /helloWorld
*
* @param name (optional)
* @return OK (status code 200)
*/
@Operation(summary = "", tags={ "helloWorld", }, responses = { @ApiResponse(responseCode = "200", description = "OK", content = @Content(mediaType = "application/json", schema = @Schema(implementation = String.class))) })
@RequestMapping(
method = RequestMethod.GET,
value = "/helloWorld",
produces = { "text/plain" }
)
default ResponseEntity<String> helloWorldGet(@Parameter(name = "name", description = "") @Valid @RequestParam(value = "name", required = false) String name
) {
return getDelegate().helloWorldGet(name);
}
As you can see, @Content(mediaType = "application/json"...
Root of the problem is in this line, where mediatype is hardcoded as application/json:
|
@ApiResponse(responseCode = "{{{code}}}", description = "{{{message}}}"{{#baseType}}, content = @Content(mediaType = "application/json", schema = @Schema(implementation = {{{baseType}}}.class)){{/baseType}}){{^-last}},{{/-last}} |
As a temporary solution, it can be replaced:
mediaType = "application/json"
on
mediaType = {{#produces}}"{{{mediaType}}}"{{/produces}}{{^produces}}"application/json"{{/produces}}
But mediaType can contain multiple values, separated with comma, because it used in @RequestMapping(produces={...}).
True way to support multiple content types will be generate @Content annotation in array, I suppose, because in @ApiResponse annotation content is type of array:
/**
* An array containing descriptions of potential response payloads, for different media types.
*
* @return array of content
**/
Content[] content() default {};
Hi!
I'm trying to return String value.
My OAS looks like this:
But it results in this method:
As you can see,
@Content(mediaType = "application/json"...Root of the problem is in this line, where mediatype is hardcoded as application/json:
openapi-generator/modules/openapi-generator/src/main/resources/JavaSpring/api.mustache
Line 140 in dc1df25
As a temporary solution, it can be replaced:
mediaType = "application/json"on
mediaType = {{#produces}}"{{{mediaType}}}"{{/produces}}{{^produces}}"application/json"{{/produces}}But mediaType can contain multiple values, separated with comma, because it used in
@RequestMapping(produces={...}).True way to support multiple content types will be generate
@Contentannotation in array, I suppose, because in@ApiResponseannotation content is type of array: