'openapi.yaml not generated successfully - Swagger Doc does not open for Windows machines

So I am working on a spring-mvc project, which suddenly started giving this issue when installed on Windows machines only. It's a thick client app.

When trying to access the swagger docs, following error comes :

enter image description here

The logs show following error in the stacktrace :

2022-04-20 04:15:44.821utc  WARN Configuration,main:117 - couldn't read inflector config from resource stream
2022-04-20 04:15:44.821utc  WARN Configuration,main:131 - couldn't read inflector config from system property
2022-04-20 04:15:44.853utc  WARN OpenAPIV3Parser,main:91 - Exception while reading:
io.swagger.v3.parser.exception.ReadContentException: Unable to read location `openapi.yaml`
    at io.swagger.v3.parser.OpenAPIV3Parser.readContentFromLocation(OpenAPIV3Parser.java:238) ~[swagger-parser-v3-2.0.27.jar:2.0.27]
    at io.swagger.v3.parser.OpenAPIV3Parser.readLocation(OpenAPIV3Parser.java:87) ~[swagger-parser-v3-2.0.27.jar:2.0.27]

..
..
2022-04-19 17:19:16.980utc ERROR [swagger-inflector],http-nio-8080-exec-8:175 - Allocate exception for servlet [swagger-inflector] 
*java.lang.NullPointerException: Cannot invoke "io.swagger.v3.oas.models.OpenAPI.getComponents()" because "openAPI" is null
at io.swagger.oas.inflector.utils.ExtensionsUtil.removeExtensions(ExtensionsUtil.java:26) ~[swagger-inflector-2.0.6.jar:2.0.6]
at io.swagger.oas.inflector.OpenAPIInflector.getExposedAPI(OpenAPIInflector.java:543) ~[swagger-inflector-2.0.6.jar:2.0.6]*
at io.swagger.oas.inflector.OpenAPIInflector.init(OpenAPIInflector.java:139) ~[swagger-inflector-2.0.6.jar:2.0.6]
at io.swagger.oas.inflector.OpenAPIInflector.<init>(OpenAPIInflector.java:117) ~[swagger-inflector-2.0.6.jar:2.0.6]
at jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) ~[?:?]
at

OpenAPIInflector.getExposedAPI reads swaggerURL location from inflector.yaml file. For some reason on windows, configuration is not picking up openapi.yaml file or corresponding openapi.json file as shown in the screenshot. xxx-openapi.yaml is something defined inside inflector.yaml which in my understanding is being used to generate an openapi.yaml file. In MacOs/local setup I can see this file getting generated and the docs coming up fine.

Please help debug, what the potential cause could be. Permissions are fine on the system this tool is running for inflector.yaml inside classes folder?

here is how the inflector.yaml is defined.

swaggerUrl: xxx-openapi.yaml

xxx-openapi.yaml & inflector.yaml are present in

src/main/resources/

I am also wondering if windows OS is not able to read the files from this path properly. Bases on other posts I have already tried different URLs such as following but they did not work for me.

  1. http://windows-machine-ip:8080/swagger-ui/
  2. http://windows-machine-ip:8080/swagger-ui/index.html
  3. http://windows-machine-ip:8080/v3/api-docs/swagger-ui.html

Note**

openapi: 3.0.0

Dependencies :

            <dependency>
                <groupId>io.swagger</groupId>
                <artifactId>swagger-annotations</artifactId>
                <version>1.6.5</version>
            </dependency>
            <dependency>
                <groupId>org.openapitools</groupId>
                <artifactId>jackson-databind-nullable</artifactId>
                <version>0.2.2</version>
            </dependency>
            <dependency>
                <groupId>io.springfox</groupId>
                <artifactId>springfox-swagger2</artifactId>
                <version>3.0.0</version>
            </dependency>
            <dependency>
                <groupId>io.swagger</groupId>
                <artifactId>swagger-inflector</artifactId>
                <version>2.0.6</version>
            </dependency>

Please guide. I am new to this project as well as swagger on spring-mvc. I will be happy to read about stuff which can lead me to fix this. Not looking for a readymade solution but I have tried almost all relevant solutions across multiple forums and hence the post as I am still not able to find the root cause to this. Also I cannot change the existing implementations (like writing it all from scratch) hence I am here more to understand the root cause.



Solution 1:[1]

I'm just installing OpenAPI 3 on Spring Core 5.3.18 (Not Boot) projetc :

1/`<dependency>
            <groupId>io.springfox</groupId>
            <artifactId>springfox-boot-starter</artifactId>
            <version>3.0.0</version>
        </dependency>
        <dependency>
            <groupId>org.springdoc</groupId>
            <artifactId>springdoc-openapi-ui</artifactId>
            <version>1.6.7</version>
        </dependency>`  

2/ Configurer :

    
@Configuration
@EnableOpenApi
public class SwaggerConfig {

    private static final Logger log = LoggerFactory.getLogger(SwaggerConfig.class);

    private static String line = "=".repeat(100);

    @Bean
    public Docket api(ServletContext servletContext) {
        log.info(line);
        log.info("Docket swagger called : {} , name :{} ", servletContext.getContextPath(), servletContext.getContext("/rs"));
        log.info(line);
        return new Docket(DocumentationType.OAS_30)
                .select()
                .apis(RequestHandlerSelectors.any())
                .paths(PathSelectors.any())
                .build()
                ;
    }

3/ WebConfigurer :

` 
@Configuration
@EnableWebMvc
public class WebConfigurer implements WebMvcConfigurer {

    private static final Logger log = LoggerFactory.getLogger(WebConfigurer.class);

    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry){
        registry.addResourceHandler("/swagger-ui/**")
                .addResourceLocations("classpath:/META-INF/resources/webjars/springfox-swagger-ui/")
                .resourceChain(false);
    }`  

4/ URL of Swagger UI is :

  • [root path]/v3/api-docs for documentation
  • [root path]/swagger-ui/index.html

Hope that help ;-)

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Rick