Skip to content

Migration issue from SpringFox  #170

@aoudiamoncef

Description

@aoudiamoncef

Hi @springdoc,
I'm migrating an existing Spring boot 2 project with SpringFox and i doesn't found an equivalent of this code below:

    @Bean
    public OpenAPI customImplementation(final ServletContext servletContext, @Value("${openapi.app.base-path:/api/v1}") final String basePath) {
        return new OpenAPI(DocumentationType.SWAGGER_2)
                .select()
                .apis(RequestHandlerSelectors.basePackage(DOC_PACKAGE_NAME))
                .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(this.apiInfo())
                .enable(this.appProperties.getSwagger());
    }

    static class BasePathAwareRelativePathProvider extends RelativePathProvider {
        private final String basePath;

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

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

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

I read the hole tests and doc of the project before opening this issue.

Thanks for this great project :)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions