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.

Lots of miscellaneous definitions are being created in swagger, how can I limit these to a package?

See original GitHub issue
  • Version: 2.9.0

I’m currently running into an odd issue where I am getting a lot of miscellaneous models being added to my definitions. Is there a way to control which packages Springfox looks at for definition creation?

Here is my current configuration, which lives in a @Component that has @EnableSwagger2:

@Bean
Docket api() {
    return new Docket(DocumentationType.SWAGGER_2)
            .select()
            .apis(RequestHandlerSelectors.basePackage("com.my.package.controller"))
            .build()
            .pathMapping('/')
}

and here is a small subset of the definitions being generated:

    "ASTNode": {
      "type": "object",
      "properties": {
        "columnNumber": {
          "type": "integer",
          "format": "int32"
        },
        "lastColumnNumber": {
          "type": "integer",
          "format": "int32"
        },
        "lastLineNumber": {
          "type": "integer",
          "format": "int32"
        },
        "lineNumber": {
          "type": "integer",
          "format": "int32"
        },
        "nodeMetaData": {
          "type": "object"
        },
        "sourcePosition": {
          "$ref": "#/definitions/ASTNode"
        },
        "text": {
          "type": "string"
        }
      },
      "title": "ASTNode"
    },
    "AnnotatedType": {
      "type": "object",
      "properties": {
        "annotations": {
          "type": "array",
          "items": {
            "$ref": "#/definitions/Annotation"
          }
        },
        "declaredAnnotations": {
          "type": "array",
          "items": {
            "$ref": "#/definitions/Annotation"
          }
        },
        "type": {
          "$ref": "#/definitions/Type"
        }
      },
      "title": "AnnotatedType"
    },
    "Annotation": {
      "type": "object",
      "title": "Annotation"
    },
    ```

Issue Analytics

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

github_iconTop GitHub Comments

1reaction
dilipkrishcommented, Jun 21, 2018

@ahatzz11 thats awesome! glad you figured it out. Yes the meta class does cause additional models to be generated. However I did not realize how many. It would certainly be nice to add it, but thats not really part of this library. At the core, springfox doesnt/should not care about what the target language/framework is.

1reaction
ahatzz11commented, Jun 20, 2018

I just deleted all of my models except for one to test this out. This leftover model has a single String in it. When I generate my swagger through Springfox it is still pulling in all of these additional models. Here is the model TestRequest.groovy:

package com.my.package.hey

import com.fasterxml.jackson.annotation.JsonProperty
import groovy.transform.Canonical

@Canonical
class TestRequest {

    @JsonProperty('test_prop')
    String testProp
}

I tried to convert this model to a java class - TestRequest.java, and all of the extra models in the swagger spec disappeared. It seems there’s an issue with between groovy and springfox.

Some additional details:

groovyVersion = '2.4.15'
springBootVersion = '2.0.2.RELEASE'
springfoxVersion ='2.9.0'
swaggerVersion = '1.5.10'

I continued to play and I think I found a solution. I was looking at #752 and decided to try ignoring the groovy MetaClass in my docket creation.

.ignoredParameterTypes(MetaClass)

This ends up removing all of the extra classes that were created in the definitions.

Is this intended behavior? It would be cool if springfox was able to automatically filter out all the groovy classes that are found. This creates a lot of noise in swagger specs.

Read more comments on GitHub >

github_iconTop Results From Across the Web

OpenAPI Specification - Version 2.0 - Swagger
Version 2.0 specification defines a set of files required to describe an API. These files can then be used by the Swagger-UI project...
Read more >
Inheritance and Polymorphism - Swagger
OAS 3 This guide is for OpenAPI 3.0. Inheritance and Polymorphism. Model Composition. In your API, you may have model schemas that share...
Read more >
Configuration - Swagger Documentation
Configuration. How to configure. Swagger UI accepts configuration parameters in four locations. From lowest to highest precedence: The swagger-config.yaml ...
Read more >
Describing Responses - Swagger
OAS 2 This page applies to OpenAPI Specification ver. ... A response is defined by its HTTP status code and the data returned...
Read more >
Open API | Documentation - ServiceStack Docs
Open API is a specification and complete framework implementation for describing, producing, consuming, and visualizing RESTful web services.
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