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

camel-rest-openapi - Generated produces string is missing media types #6766

Open
calleandersson opened this issue Nov 11, 2024 · 1 comment
Assignees
Labels
area/rest-openapi bug Something isn't working

Comments

@calleandersson
Copy link

Bug description

I found a bug in camel-rest-openapi.

The following code exists in RestOpenApiProcessor.java in 4.8.0 and 4.8.1:

// the operation may have specific information what it can produce
if (o.getResponses() != null) {
    for (var a : o.getResponses().values()) {
        Content c = a.getContent();
        if (c != null) {
            produces = c.keySet().stream().sorted().collect(Collectors.joining(","));
        }
    }
}

In main, the code seems to have been refactored into OpenApiUtils.java:

public String getProduces(Operation operation) {
    // the operation may have specific information what it can produce
    if (operation.getResponses() != null) {
        for (var apiResponse : operation.getResponses().values()) {
            Content content = apiResponse.getContent();
            if (content != null) {
                return content.keySet().stream().sorted().collect(Collectors.joining(","));
            }
        }
    }
    return null;
}

In my case, I have a structure which looks like this:

operation
   ...
   responses
      {0}
         key = "200"
         value
            ...
            content
               {0}
                  key = "application/json"
                  value = ...
      {1}
         key = "400"
         value
            ...
            content
               {0}
                  key = "application/problem+json"
                  value = ...
      {2}
         key = "404"
         value
            ...
            content
               {0}
                  key = "application/problem+json"
                  value = ...
      ...

When running the code with 4.8.0, produces is set to application/problem+json. It should be set to application/json,application/problem+json instead.

The code from main also generates wrong result.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/rest-openapi bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants