swagger-api / swagger-ui

Swagger UI is a collection of HTML, JavaScript, and CSS assets that dynamically generate beautiful documentation from a Swagger-compliant API.
https://swagger.io
Apache License 2.0
26.34k stars 8.92k forks source link

No operations defined in spec! #2972

Closed Kiolali closed 7 years ago

Kiolali commented 7 years ago

Hey,

I also get the "No operations defined in spec" error using the swagger-ui. If I directly access the url (http://localhost:8080//rest/api-docs) HTTP 200 is returned and the JSON-file contents is displayed. So displaying it via swagger-ui doesn't seem to work. I pulled the swagger-ui-master branch today. What am I doing wrong?

Thanks in advance!

Kiolali commented 7 years ago

Version 2.2.10 seems to work (but 3.0.7 not)

webron commented 7 years ago

Possibly there's an issue with the spec that's breaking the UI. Can you share it?

Kiolali commented 7 years ago

I did this Tutorial: http://jmchung.github.io/blog/2013/12/14/integrating-swagger-into-jax-rs-with-java-ee-6-specification/

So the json file is automatically generated:

{"apiVersion":"1.0.0","swaggerVersion":"1.2","apis":[{"path":"/hello","description":"Say Hello!"}]}

webron commented 7 years ago

Following a tutorial from 2013 will normally lead you to outdated information. You ended up with an old version of the spec which is not supported by the UI anymore. Please refer to the 1.5.x integration guides at https://github.com/swagger-api/swagger-core/wiki.

Kiolali commented 7 years ago

I have the same behavior using Swagger-Core 1.5.X and Jersey 2.X following this guide: https://github.com/swagger-api/swagger-core/wiki/Swagger-Core-JAX-RS-Project-Setup-1.5.X#adding-swaggers-dependencies-to-your-project

Displaying http://petstore.swagger.io/v2/swagger.json via Swagger UI is no problem (after enabling CORS). But trying to display http://localhost:8080/<project-name>/rest/xyAPI via Swagger UI doesn't work ("No operations defined in spec!"). Accessing the mentioned url directly via browser provides a json object. http://localhost:8080/<project-name>/rest/swagger.json is available as well showing:

{"swagger":"2.0","info":{"version":"1.0.2"},"basePath":"/http://localhost:8080/<project-name>/rest"} . Any ideas?

Kiolali commented 7 years ago

maybe my urls are wrong?

This is my Application class:

@javax.ws.rs.ApplicationPath("rest")
public class ApplicationConfig extends Application {

    public ApplicationConfig(){
        BeanConfig beanConfig = new BeanConfig();
        beanConfig.setVersion("1.0.2");
        beanConfig.setBasePath("http://localhost:8080/<project-name\>/rest");
        beanConfig.setResourcePackage("io.swagger.resources");
        beanConfig.setScan(true);
    }

    @Override
    public Set<Class<?>> getClasses() {
        Set<Class<?>> resources = new java.util.HashSet<>();
        resources.add(io.swagger.jaxrs.listing.ApiListingResource.class);
        resources.add(io.swagger.jaxrs.listing.SwaggerSerializers.class);
        addRestResourceClasses(resources);
        return resources;
    }

then adding CORS-Filter-Class and myClass.

in index.html of SwaggerUI:

const ui = SwaggerUIBundle({
    url: "http://localhost:8080/<project-name\>/rest/swagger.json",
    dom_id: '#swagger-ui',
webron commented 7 years ago

beanConfig.setResourcePackage("io.swagger.resources"); should point to your own resources.

Kiolali commented 7 years ago

Thanks! using MyResource.class.getPackage().getName() works.

asghar3166 commented 6 years ago

Hi Everyone,

I am also seeing (No operations defined in spec!) . The Flasgger json details and screen shot below. I am programming using Python 3.6. Thanks for you help.

{ "definitions": {}, "info": { "description": "powered by Flasgger", "termsOfService": "/tos", "title": "A swagger API", "version": "0.0.1" }, "paths": {}, "swagger": "2.0" } image

ezinzombe commented 5 years ago

Add Swagger Configuration and specify the packages that contains your REST API's

@Configuration @EnableSwagger2 public class SwaggerConfig {

@Bean
public Docket productApi() {
    return new Docket(DocumentationType.SWAGGER_2)
            .select()
            .apis(RequestHandlerSelectors.basePackage("zw.co.soskode.angular.controller"))
            .paths(regex("/api.*"))
            .build()
            .apiInfo(metaData());
}
}
mgumiero9 commented 5 years ago

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());}

`