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.

Swagger-ui: No operations defined in spec

See original GitHub issue

Hi,

I’ve been having issues setting up the swagger UI. I’ve getting ‘No operations defined in spec’ even though Swagger API at localhost:8080/v2/api-docs returns what looks like a valid output

My build.gradle contains this:

    compile 'io.springfox:springfox-swagger2:2.8.0'
    compile 'io.springfox:springfox-swagger-ui:2.8.0'

App is written in Kotlin, this is the main entry class

@SpringBootApplication
@EnableAutoConfiguration(exclude = [(JacksonAutoConfiguration::class)])
class Application

fun main(args: Array<String>) {
    SpringApplicationBuilder()
            .sources(Application::class.java)
            .run(*args)
}

And Swagger config

@Configuration
@EnableSwagger2
class SwaggerConfig {
    @Bean
    fun api(): Docket {
        return Docket(DocumentationType.SWAGGER_2)
                .apiInfo(ApiInfoBuilder()
                        .title("Spring Boot project")
                        .description("Spring Boot bootstrap project")
                        .version("0.1")
                        .license("Unlicense")
                        .build())
                .select()
                .apis(RequestHandlerSelectors.any())
                .paths(PathSelectors.any())
                .build()
    }
}

Any help would be appreciated as my Googlefoo has failed me here

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:5

github_iconTop GitHub Comments

10reactions
mgumiero9commented, Jan 6, 2019

Just check if your basePackage is configured properly.

`@Bean public Docket greetingApi() { return new Docket(DocumentationType.SWAGGER_2) .select() .apis(RequestHandlerSelectors.basePackage(“application.controller”)) .build() .apiInfo(metaData());

}`
7reactions
TopHatCroatcommented, Apr 15, 2018

Sigh… The problem was actually that I used GSON, which wrapped the entire JSON response from Swagger API into {value: “<actual Swagger content>”} object. The problem was hiding in plain sight, as is often in life…

Anyway, for anyone wondering how to fix this, add a new configuration bean like so

@Configuration
class GsonHttpMessageConverterConfig {

    @Bean
    fun gsonHttpMessageConverter() = GsonHttpMessageConverter().apply { gson = gson() }

    private fun gson() = GsonBuilder()
            .registerTypeAdapter(Json::class.java, JsonSerializer<Json> { src, _, _ ->
                JsonParser().parse(src.value())
            }).create()

}

In hindsight, maybe Swagger should report a bit clearer message like “No data found” when nothing recognizable to it exists in the docs response, but that’s an issue for another repo

Read more comments on GitHub >

github_iconTop Results From Across the Web

No operations defined in spec! - I get this error even though ...
When I registered routes before swagger, it was showing 'no operations defined in specs':. fastify.register(require(".
Read more >
No operations defined in spec! #248 - GitHub
using js-docs it renders no path doc at all. just a message: "No operations defined in spec!" pkgs: "swagger-jsdoc": "^6.0.0",
Read more >
No operations defined in spec - IBM
If you see No operations defined in spec in the Swagger editor, the project is not yet ready for testing. Refresh the Swagger...
Read more >
Solved: Error: "No operations defined in spec!" - using ES...
My implementation of Swagger is giving me "No operations defined in ... const swaggerUi = require('swagger-ui-express'); const bodyParser ...
Read more >
Swagger UI
Swagger UI. Select a definition. Bursa Web Api V1. Bursa Web Api - (METRAMGMT-PRODUCTION) ... Bursa Web Api. No operations defined in spec!...
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