openapi-generator-for-spring icon indicating copy to clipboard operation
openapi-generator-for-spring copied to clipboard

Request content-type should default to application/json

Open ethlo opened this issue 3 years ago • 2 comments

Spring defaults to application/json as expected content-type, this documenter should do the same (not */*)

ethlo avatar Dec 27 '21 11:12 ethlo

@ethlo Thanks for bringing this up. I think it's in de.qaware.openapigeneratorforspring.common.paths.method.SpringWebHandlerMethodContentTypesMapper which you could override to fix it now, but I'll see if I can fix it within the library itself. Currently, it uses */* for request and response types, which is probably not right.

neiser avatar Dec 29 '21 16:12 neiser

Thanks for the hints!

I worked around it for now with:

    @Bean
    public OperationPostFilter replaceContentType()
    {
        return (operation, handlerMethod) ->
        {
            final RequestBody rb = operation.getRequestBody();
            if (rb != null)
            {
                final Content requestParams = rb.getContent();
                final Iterator<Map.Entry<String, de.qaware.openapigeneratorforspring.model.media.MediaType>> requestsIter = requestParams.entrySet().iterator();
                while (requestsIter.hasNext())
                {
                    final Map.Entry<String, de.qaware.openapigeneratorforspring.model.media.MediaType> e = requestsIter.next();
                    if (ALL_VALUE.equals(e.getKey()))
                    {
                        requestsIter.remove();
                        requestParams.put(APPLICATION_JSON_VALUE, e.getValue());
                    }
                }
            }
            
            return true;
        };
    }

ethlo avatar Jan 03 '22 11:01 ethlo