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.

Cannot find class RelativePathProvider when building project using "openapi-generator-maven-plugin-5.0.0"

See original GitHub issue

Bug Report Checklist

  • Have you provided a full/minimal spec to reproduce the issue?
  • Have you validated the input using an OpenAPI validator (example)?
  • Have you tested with the latest master to confirm the issue still exists?
  • Have you searched for related issues/PRs?
  • What’s the actual output vs expected output?
  • [Optional] Sponsorship to speed up the bug fix or feature request (example)
Description

I’m trying to use openapi-generator with a simple yaml and use it to auto-generate some code for my project. However, when I try to build my project I get this error:

[ERROR] src/service/target/generated-sources/src/main/java/org/openapitools/configuration/OpenAPIDocumentationConfig.java:[14,48] cannot find symbol [ERROR] symbol: class RelativePathProvider [ERROR] location: package springfox.documentation.spring.web.paths

In addition in OpenAPIDocumentationConfig.java, I see that: @javax.annotation.Generated(value = “org.openapitools.codegen.languages.SpringCodegen”, date = “…”) and @EnableSwagger2

while I was expecting not to include @EnableSwagger2 and have this type of generator: @javax.annotation.Generated(value = “io.swagger.codegen.v3.generators.java.SpringCodegen”, date = “…”)

Following you can also find relevant part of my pom.xml:

<dependencies> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-tomcat</artifactId> <scope>provided</scope> </dependency> <dependency> <groupId>org.openapitools</groupId> <artifactId>openapi-generator-maven-plugin</artifactId> <version>5.0.0</version> </dependency> <dependency> <groupId>io.springfox</groupId> <artifactId>springfox-boot-starter</artifactId> <version>3.0.0</version> </dependency> <dependency> <groupId>io.swagger.core.v3</groupId> <artifactId>swagger-annotations</artifactId> <version>2.1.4</version> </dependency> <dependency> <groupId>io.springfox</groupId> <artifactId>springfox-oas</artifactId> <version>3.0.0</version> </dependency> <dependency> <groupId>io.springfox</groupId> <artifactId>springfox-swagger-ui</artifactId> <version>3.0.0</version> </dependency> </dependencies> . . <plugin> <groupId>org.openapitools</groupId> <artifactId>openapi-generator-maven-plugin</artifactId> <version>5.0.0</version> <executions> <execution> <goals> <goal>generate</goal> </goals> <configuration> <inputSpec>${swagger.yaml.file}</inputSpec> <output>target/generated-sources</output> <generatorName>spring</generatorName> <generateApis>true</generateApis> <generateApiDocumentation>true</generateApiDocumentation> <generateModelDocumentation>true</generateModelDocumentation> <generateApiTests>true</generateApiTests> <ignoreFileOverride>target/generated-sources/.openapi-generator-ignore</ignoreFileOverride> <configOptions> <sourceFolder>${swagger.generated.sourcepath}</sourceFolder> <library>spring-boot</library> <useBeanValidation>true</useBeanValidation> <dateLibrary>java8</dateLibrary> <java8>false</java8> </configOptions> </configuration> </execution> </executions>

I cannot understand how the generator builds a code that do not compile and why it uses old swagger 2 instead of OAS 3.

You can also see the qutogenerated class:

`package org.openapitools.configuration;

import org.springframework.beans.factory.annotation.Value; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration;

import org.springframework.web.util.UriComponentsBuilder; import springfox.documentation.builders.ApiInfoBuilder; import springfox.documentation.builders.RequestHandlerSelectors; import springfox.documentation.service.ApiInfo; import springfox.documentation.service.Contact; import springfox.documentation.spi.DocumentationType; import springfox.documentation.spring.web.paths.Paths; import springfox.documentation.spring.web.paths.RelativePathProvider; import springfox.documentation.spring.web.plugins.Docket; import springfox.documentation.swagger2.annotations.EnableSwagger2;

import javax.servlet.ServletContext;

@javax.annotation.Generated(value = “org.openapitools.codegen.languages.SpringCodegen”, date = “2021-01-28T14:30:45.743778100+02:00[Europe/Athens]”) @Configuration @EnableSwagger2 public class OpenAPIDocumentationConfig {

ApiInfo apiInfo() {
    return new ApiInfoBuilder()
        .title("VPN Service")
        .description("VPN Service |")
        .license("")
        .licenseUrl("http://unlicense.org")
        .termsOfServiceUrl("")
        .version("1.0.0.1")
        .contact(new Contact("","", ""))
        .build();
}

@Bean
public Docket customImplementation(ServletContext servletContext, @Value("${openapi.vPNService.base-path:}") String basePath) {
    return new Docket(DocumentationType.SWAGGER_2)
            .select()
                .apis(RequestHandlerSelectors.basePackage("org.openapitools.api"))
                .build()
            .pathProvider(new BasePathAwareRelativePathProvider(servletContext, basePath))
            .directModelSubstitute(java.time.LocalDate.class, java.sql.Date.class)
            .directModelSubstitute(java.time.OffsetDateTime.class, java.util.Date.class)
            .apiInfo(apiInfo());
}

class BasePathAwareRelativePathProvider extends RelativePathProvider {
    private String basePath;

    public BasePathAwareRelativePathProvider(ServletContext servletContext, String basePath) {
        super(servletContext);
        this.basePath = basePath;
    }

    @Override
    protected String applicationPath() {
        return  Paths.removeAdjacentForwardSlashes(UriComponentsBuilder.fromPath(super.applicationPath()).path(basePath).build().toString());
    }

    @Override
    public String getOperationPath(String operationPath) {
        UriComponentsBuilder uriComponentsBuilder = UriComponentsBuilder.fromPath("/");
        return Paths.removeAdjacentForwardSlashes(
                uriComponentsBuilder.path(operationPath.replaceFirst("^" + basePath, "")).build().toString());
    }
}

} `

openapi-generator version

version 5.0.0

Issue Analytics

  • State:open
  • Created 3 years ago
  • Reactions:8
  • Comments:11

github_iconTop GitHub Comments

4reactions
batigoal82commented, Mar 19, 2021

use spring fox version 2.9.0 rather than 3.0

3reactions
mercurietecommented, Jul 28, 2021

I am here just to say thanks to @batigoal82

I am having success with: springboot 2.5.3 springfox 2.9.2 openapi-generator-maven-plugin 5.2.0

you can see my pom here

edited: new versions automatically updated by renovatebot since I posted this post.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Generated RelativePathProvider doesn't compile when use ...
I'm trying to implement a simple spring boot web mvc application, but requirements are: Generate code from api.yaml (openapi 3.0) ...
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