0

I have an openapi spec with multiple endpoints. I have included two in this example:

openapi: 3.0.1
info:
   ...
servers:
   ...
tags:
    - name: academic degrees
      description: academic degrees description here
paths:
    /education/academicdegrees:
        get:
            tags:
                - academic degrees
            summary: Returns all the academic degrees
            operationId: getAcademicDegrees
            responses:
                ...
    /education/academicdegrees/{id}:
        get:
            tags:
                - academic degrees
            summary: Returns the academic degree with the requested id
            operationId: getAcademicDegree
            parameters:
                ...
            responses:
                200:
                    ...

I use the Openapi generator maven plugin to generate api classes. The generator is "spring" with these config options:

<configOptions>
        <verbose>true</verbose>
        <templateDirectory>templates</templateDirectory>
        <delegatePattern>true</delegatePattern>
        <documentationProvider>springdoc</documentationProvider>
        <useSpringBoot3>true</useSpringBoot3>
        <useTags>true</useTags>
</configOptions>

This results in this Api file called AcademicDegreesApi. I have omitted the second endpoint.

Generated(value = "org.openapitools.codegen.languages.SpringCodegen", date = "2023-02-02T11:47:50.034894501+01:00[Europe/Copenhagen]")
@Validated
@Tag(name = "AcademicDegrees", description = "academic degrees description here")
public interface AcademicDegreesApi {

    ...

    @Operation(
        operationId = "getAcademicDegree",
        summary = "Returns the academic degree with the requested id",
        tags = { "academic degrees" },
        responses = {
            @ApiResponse(responseCode = "200", description = "successful operation", content = {
                @Content(mediaType = "application/json", schema = @Schema(implementation = AcademicDegreeDTO.class))
            })
        },
        security = {
            @SecurityRequirement(name = "ApiKeyAuth")
        }
    )
    @RequestMapping(
        method = RequestMethod.GET,
        value = "/uddbase/academicdegrees/{id}",
        produces = { "application/json" }
    )
    default ResponseEntity<AcademicDegreeDTO> getAcademicDegree(
        @Parameter(name = "id", description = "UUID of an academic degree", required = true) @PathVariable("id") UUID id
    ) {
        return getDelegate().getAcademicDegree(id);
    }

    ...

}

The class has the decorator Tag with name = "AcademicDegrees" while the individual endpoints are tagged with "academic degrees" as in the spec file. This causes the swagger UI to display duplicate endpoints:

duplicate swagger-ui endpoints

I would like to have both the api tag name and the controller tag name to be "academic degrees"

How can I avoid these duplicates and how can I control the tag name defined in the api decorator?

I have tried to remove the tags from the spec and this causes no tags on the individual endpoints but only on the api. The api class then takes the name "EducationApi" from the paths defined. I want to avoid this because I have many endpoints in this spec and want to group them with tags in order to have the swagger-ui nice and neat.

1 Answers1

1

Rather than using the multi-word tag "academic degrees" use a single word everywhere, eg "AcademicDegrees" or "academic_decrees".

John Williams
  • 4,252
  • 2
  • 9
  • 18