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

Request header "Content-Type" is not being sent with request #1361

Closed
manish2aug opened this issue Jun 26, 2016 · 6 comments
Labels
Milestone

Comments

@manish2aug
Copy link

@manish2aug manish2aug commented Jun 26, 2016

Hi,

I am using content type versioning but from swagger-ui, the content-Type is never sent and couldn't find any annotation for that as well.

Rest controller method annotations:-

@RequestMapping(method = RequestMethod.GET, consumes = {application/vnd.market-scan.v1+json },produces={"application/json"})
@ApiOperation(response = Product.class, responseContainer = "List")
@ApiResponses(value = {
            @ApiResponse(code = 200, message = "JSON representation of collection of products including other accessible application states",   responseHeaders = @ResponseHeader(name = "Content-Type", description = "application/vnd.market-scan.v1+json", response = String.class)), 
            @ApiResponse(code = 404, message = "No product found"), 
            @ApiResponse(code = 500, message = "Something went wrong!"),
            @ApiResponse(code = 415, message = "Unsupported media type")
        }
    )

Swagger configuration:

@Bean
public Docket api() {
        return new Docket(DocumentationType.SWAGGER_2)
            .groupName("market-scan")
            .select()
        .apis(RequestHandlerSelectors.basePackage("in.co.trish.marketscan.web.controllers"))
                .paths(PathSelectors.any())
                .build()
                .consumes(getAllConsumeContentTypes())
                .produces(getAllProduceContentTypes())
                .apiInfo(apiInfo());
    }

    private Set<String> getAllConsumeContentTypes() {
        Set<String> consumes = new HashSet<>();
        // Add other media types if required in future
        consumes.add("application/vnd.market-scan.v1+json");
        return consumes;
    }

    private Set<String> getAllProduceContentTypes() {
        Set<String> produces = new HashSet<>();
        // Add other media types if required in future
        produces.add("application/json");
        return produces;
    }

Class level annotation:

@Api(tags = {"Available products in a city"}, 
                produces="application/json", 
                consumes="application/vnd.market-scan.v1+json", 
                protocols="http")
public class ProductRestController {

Swagger ui screen shot
image

@dilipkrish

This comment has been minimized.

Copy link
Member

@dilipkrish dilipkrish commented Jun 26, 2016

Please report this issue in the swagger-ui project

@dilipkrish dilipkrish added the question label Jun 26, 2016
@dilipkrish dilipkrish added this to the 2.6.0 milestone Jun 26, 2016
@dilipkrish dilipkrish added bug wontfix and removed question labels Jun 26, 2016
@manish2aug

This comment has been minimized.

Copy link
Author

@manish2aug manish2aug commented Jun 27, 2016

Thanks!

@JLLeitschuh

This comment has been minimized.

Copy link

@JLLeitschuh JLLeitschuh commented Jan 27, 2017

I'm getting the same problem as this but with version 2.6.1

@daibertdiego

This comment has been minimized.

Copy link

@daibertdiego daibertdiego commented Oct 19, 2018

I'm getting the same problem too in version 2.9.2

@geromy123

This comment has been minimized.

Copy link

@geromy123 geromy123 commented Mar 14, 2019

I'm also getting this problem, is there any solution?

@seregasheypak

This comment has been minimized.

Copy link

@seregasheypak seregasheypak commented Oct 15, 2019

Same thing v 2.9.2

  • springfox-swagger-ui
  • springfox-swagger2

SwaggerConfig

@Configuration
@EnableSwagger2
public class SwaggerConfig extends WebMvcConfigurerAdapter {


    public static final String DEFAULT_INCLUDE_PATTERN = "/public/api/v2/.*";

    @Bean
    public Docket api() {
        return new Docket(DocumentationType.SWAGGER_2)
                .consumes(Set.of(MediaType.APPLICATION_JSON_UTF8_VALUE))
                .produces(Set.of(MediaType.APPLICATION_JSON_UTF8_VALUE))
                .select()
                .apis(RequestHandlerSelectors.basePackage("com.best.controller"))
                .paths(PathSelectors.any())
                .build()
                .securityContexts(Lists.newArrayList(securityContext()))
                .securitySchemes(Lists.newArrayList(apiKey()))
                .apiInfo(apiInfo());
    }

method def

@GetMapping("/my/api")
    @ApiOperation(
            value = "Returns stuff",
            tags = "Stuff",
            consumes = MediaType.APPLICATION_JSON_UTF8_VALUE,
            produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    @ApiResponses(value = {
            @ApiResponse(code = 200, message = "Stuff", response = Stuff.class),
            @ApiResponse(code = 400, message = "Wrong stuff", response = ErrorResponse.class),
            @ApiResponse(code = 401, message = "Authorization failed", response = ErrorResponse.class)
    })
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
6 participants
You can’t perform that action at this time.