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.

springfox-swagger 3.0.0 - SNAPSHOT - JSON schema not being generated as it was before te update

See original GitHub issue

Please take the time to search the repository, if your question has already been asked or answered.

-3.0.0-SNAPSHOT

  • SpringBoot 2.2.7 Webflux
  • JsonView

I’m using SpringFox swagger in SpringBoot with JsonView support

My docket configuration is:

final List<ResponseMessage> globalResponses = Arrays.asList(
                new ResponseMessageBuilder().code(400)
                                            .message(ErrorMessages.INVALID_REQUEST)
                                            .responseModel(new ModelRef("InvalidDataResponse"))
                                            .build(),
                new ResponseMessageBuilder().code(401)
                                            .message(ErrorMessages.UNAUTHENTICATED)
                                            .responseModel(new ModelRef("UnauthenticatedResponse"))
                                            .build(),
                new ResponseMessageBuilder().code(403)
                                            .message(ErrorMessages.FORBIDDEN)
                                            .responseModel(new ModelRef("ForbiddenResponse"))
                                            .build(),
                new ResponseMessageBuilder().code(500)
                                            .message(ErrorMessages.INTERNAL_SERVER_ERROR)
                                            .responseModel(new ModelRef("InternalServerError"))
                                            .build()
        );

        return new Docket(DocumentationType.SWAGGER_2)
                .select()
                .apis(RequestHandlerSelectors.any())
                .paths(PathSelectors.any())
                .build()
                .globalResponseMessage(RequestMethod.GET, globalResponses)
                .globalResponseMessage(RequestMethod.POST, globalResponses)
                .globalResponseMessage(RequestMethod.DELETE, globalResponses)
                .globalResponseMessage(RequestMethod.PATCH, globalResponses)
                .globalResponseMessage(RequestMethod.PUT, globalResponses)
                .useDefaultResponseMessages(false)
                .genericModelSubstitutes(ResponseEntity.class)
                .alternateTypeRules(
                        newRule(typeResolver.resolve(
                                Mono.class,
                                typeResolver.resolve(ResponseEntity.class, WildcardType.class)),
                                typeResolver.resolve(WildcardType.class))
                )
                .additionalModels(
                        typeResolver.resolve(InvalidDataResponse.class),
                        typeResolver.resolve(UnauthenticatedResponse.class),
                        typeResolver.resolve(ForbiddenResponse.class),
                        typeResolver.resolve(NotFoundResponse.class),
                        typeResolver.resolve(InternalServerResponse.class)
                )
                .host(baseUrl);

And for the following endpoint/annotations:

    @ApiOperation(
            value = "List all projects"
    )
    @ApiResponses(value = {
            @ApiResponse(
                    code = 200,
                    message = SuccessMessages.CONTENT_READY
            )
    })
    @GetMapping(path = "/projects", produces = MediaType.APPLICATION_JSON_VALUE)
    @ResponseBody
    @JsonView({View.List.class})
    Mono<ResponseEntity<SuccessResponse<PaginatedListResult<ProjectModel>>>> getAll(

Now i get the schema of :

"responses": {
          "200": {
            "description": "content ready",
            "schema": {
              "$ref": "#/definitions/Error-ModelName{namespace='reactor.core.publisher', name='Mono«ResponseEntity«SuccessResponse«PaginatedListResult«Project»»»»'}"
            }
          }
        }

And the model definition is exported as :

"SuccessResponse«PaginatedListResult«Project»»View": {
      "type": "object",
      "properties": {
        "message": {
          "type": "string",
          "example": "content ready!"
        },
        "result": {
          "example": "null",
          "$ref": "#/definitions/PaginatedListResult«Project»View"
        },
        "status": {
          "type": "boolean",
          "example": true
        }
      },
      "title": "SuccessResponse«PaginatedListResult«Project»»View",
      "description": "Success response model"
    }

Before the last update this was working with the schema being generated similar to what is shown below

"responses": {
          "200": {
            "description": "content ready",
            "schema": {
              "$ref": "#/definitions/Mono«ResponseEntity«SuccessResponse«PaginatedListResult«Project»»»»"
            }
          }
        }

....

"Mono«ResponseEntity«SuccessResponse«PaginatedListResult«Project»»»»": {
      "type": "object",
      "properties": {
        "message": {
          "type": "string",
          "example": "content ready!"
        },
        "result": {
          "example": "null",
          "$ref": "#/definitions/PaginatedListResult«Project»View"
        },
        "status": {
          "type": "boolean",
          "example": true
        }
      },
      "title": "SuccessResponse«PaginatedListResult«Project»»View",
      "description": "Success response model"
    }`

What should i do different to fix this up ?

Issue Analytics

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

github_iconTop GitHub Comments

2reactions
hexmindcommented, Jan 11, 2021

Hi,

With the latest approach of going with globalResponses instead of globalResponseMessage, how can we have custom response models which we used to create with ModelRef.

new ModelRef(“ErrorResponse500”)

There is a sad example with DTO class:

new ResponseBuilder()
        .code(code)
        .description(description)
        .representation(MediaType.ALL)
        .apply(r -> r.model(m ->
                m.referenceModel(ref ->
                        ref.key(k ->
                                k.qualifiedModelName(q ->
                                        q.namespace("com.example.api").name("ErrorDto"))))))
        .build();
2reactions
dilipkrishcommented, Jun 25, 2020

It should still work however. I’ll try and fix that 😃 Thanks for reporting

Read more comments on GitHub >

github_iconTop Results From Across the Web

Springfox 3.0.0 is not working with Spring Boot 2.6.0 [duplicate]
Up to now, Springfox 3.0.0 only works with Spring 2.6.0-M2 but not with versions ... EDIT: The server starts, but no API info...
Read more >
Springfox Reference Documentation - GitHub Pages
1. Introduction. The Springfox suite of java libraries are all about automating the generation of machine and human readable specifications for ...
Read more >
springfox/springfox - Gitter
I'm using Springfox / Swagger / Spring Boot, and trying to figure out how to make the Swagger UI use https. In Spring...
Read more >
OpenAPI 3 Library for spring-boot
Automatically generates documentation in JSON/YAML and HTML format APIs. This documentation can be completed by comments using swagger-api ...
Read more >
Spring Boot and Swagger - Documenting RESTful Services ...
We will learn how to expose automated swagger documentation from your application. We will also add documentation to the REST API with ...
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