[ 
https://issues.apache.org/jira/browse/CAMEL-22790?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Claus Ibsen resolved CAMEL-22790.
---------------------------------
    Resolution: Fixed

> RestOpenApiReader does not build an ApiResponse correctly for multiple 
> produces content types
> ---------------------------------------------------------------------------------------------
>
>                 Key: CAMEL-22790
>                 URL: https://issues.apache.org/jira/browse/CAMEL-22790
>             Project: Camel
>          Issue Type: Bug
>          Components: camel-openapi-java
>    Affects Versions: 4.16.0
>            Reporter: Darius Cooper
>            Priority: Minor
>             Fix For: 4.14.4, 4.17.0
>
>
> If we specify multiple types as "produces", using a comma-delimited string,  
> the openApi spec does not reflect that.  RestOpenApiReader does not build an 
> ApiResponse correctly for multiple produces content types
> In camel-openapi-java:
> When `produces` contains multiple media types (e.g., 
> `"application/json,application/xml"`), the RestOpenApiReader generator 
> creates a new ApiResponse in each loop iteration and overwrites the previous 
> one using the same "200" key. Only the last media type appears in the 
> generated OpenAPI spec.
> h3. Expected Behavior
> Create a single ApiResponse with one Content object containing all media 
> types.
> h3. Proposed Fix
> Move `ApiResponse` and `Content` instantiation outside the loop. Only create 
> `MediaType` objects inside the loop and add them to the shared `Content` 
> object.
> Also change description from "Output type" to "OK".  The description is 
> typically the HTTP reason description. 
> {code:java}
>             String[] parts;
>             if (produces != null) {
>                 ApiResponse response = new ApiResponse().description("OK");
>                 Content responseContent = new Content();                      
>           
>               Schema<?> model = modelTypeAsProperty(getValue(camelContext, 
> verb.getOutType()), openApi); 
>               parts = produces.split(",");
>                 for (String produce : parts) {
>                     MediaType contentType = new MediaType();
>                     contentType.setSchema(model);
>                     responseContent.addMediaType(produce, contentType);
>                 }
>                 response.setContent(responseContent);
>                 op.getResponses().addApiResponse("200", response);
>             } 
> {code}



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to