question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

How can I properly display "overloaded" URL when using content negotiation

See original GitHub issue

Hi all,

We are using content negotiation (based on accept-header) for versioning the REST resources in our SpringBoot applications. How can this be properly displayed in Swagger-UI?

We’d like to have

  • either 2 separate operations be listed in the Swagger-UI (one per version)
  • or 2 groups containing one version each (grouping done by either an own annotation or by evaluating the io.swagger.v3.oas.annotations)

(?) Can we e.g. use GroupedOpenApi (for example in combination with OperationCustomizer) to define 2 groups (let’s say “Current” and “Deprecated”) to seperate the versions?

I could not figure out how to create these groups.

The annotation io.swagger.v3.oas.annotations.Operation supports the “hidden” attribute. But this is not reflected in io.swagger.v3.oas.models.Operation. Hence the “operation” can not be modified to be hidden if it does not match the corresponding group.

(?) Can the Operation be “filtered out” in a, OperationCustomizer ?

Or how could we solve this issue?

NOTE: This came up when migrating to Spring Boot 2.3 and updating to springdoc-openapi-ui. Previsouly we used an approach with api selectors in the Docket in one of our apps:

@Configuration
@EnableSwagger2
public class SwaggerConfig {
    ...
    ...
    @Bean
    public Docket swaggerSpringMvcPluginDeprecated(
        @Value("${info.app.name}") String name,
        @Value("${info.app.description}") String description,
        @Value("${info.app.version}") String version,
        @Value("${info.app.team}") String team,
        @Value("${info.app.url}") String url,
        @Value("${info.app.contact}") String contact
    ) {
        return new Docket(DocumentationType.SWAGGER_2)
            .useDefaultResponseMessages(false)
            .select()
            .apis(selector -> Objects.requireNonNull(selector).isAnnotatedWith(DeprecatedAPI.class))
            .build()
            .apiInfo(new ApiInfo(name, description, version, null, new Contact(team, url, contact), null, null, Collections.emptyList()))
            .groupName("Deprecated");
    }

I highly appreciate any help 😃.
Kind regards,
Valentin

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:12 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
maecvalcommented, Oct 1, 2020

@bnasslahsen,

Thanks ! Works perfectly with the latest version 1.4.8 !

Cheers !

0reactions
Govindmallurwarcommented, Apr 15, 2021

@bnasslahsen,

Thanks ! Works perfectly with the latest version 1.4.8 !

Cheers !

can you please provide me updated zip file of the code after it works for you?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Content Negotiation using Spring MVC
Ignore the Accept header completely. This is often the best approach if most of your clients are actually web-browsers (typically making REST ...
Read more >
Content negotiation - HTTP - MDN Web Docs
In HTTP, content negotiation is the mechanism that is used for serving different representations of a resource to the same URI to help...
Read more >
Implementing content negotiation based on URL patterns - IBM
This task describes content negotiation based on URL patterns. Content negotiation using URLs is the simplest type of content negotiation. This ...
Read more >
RFC 7231: Hypertext Transfer Protocol (HTTP/1.1)
1. GET The GET method requests transfer of a current selected representation for the target resource. · 2. HEAD The HEAD method is...
Read more >
JSON:API — Latest Specification (v1.1)
Content Negotiation. Universal Responsibilities. Clients and servers MUST send all JSON:API payloads using the JSON:API media type in the ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found