Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Spring] Support disabling ApiIgnore & Pageable imports #8421

Closed

Conversation

morphlne
Copy link
Contributor

@morphlne morphlne commented Jan 12, 2021

Issues

To fix #8360, #8192, #8916, #8776

Description

Support for vendor extension x-spring-paginated added in #5022 provides non-configurable imports:

import org.springframework.data.domain.Pageable;
import springfox.documentation.annotations.ApiIgnore; 

Both imports appears even if x-spring-paginated is not specified. Those imports are undesirable cause they demand additional dependencies, otherwise compilation fails.

Suggested fix

The PR adds config option for separately disabling imports usePageable, useApiIgnore. Both options are true by default for backward compatibility.

Alternative approach

On other hand, imports can be simple disabled using {{vendorExtension.x-spring-paginated}} without new configs, but i believe, that generator behavior should depends on generator config, not on API description.

Tests

Added generated samples with new config options

PR checklist

  • Read the contribution guidelines.
  • Pull Request title clearly describes the work in the pull request and Pull Request description provides details about how to validate the work. Missing information here may result in delayed response from the community.
  • If contributing template-only or documentation-only changes which will change sample output, build the project beforehand.
  • Run
    mvn clean package
    ./bin/generate-samples.sh
    ./bin/utils/export_docs_generators.sh
    
    to update all Petstore samples related to your fix.
    Commit all changed files.
    This is important, as CI jobs will verify all generator outputs of your HEAD commit as it would merge with master.
    These must match the expectations made by your contribution.
    You may regenerate an individual generator by passing the relevant config(s) as an argument to the script, for example ./bin/generate-samples.sh bin/configs/java*.
    For Windows users, please run the script in Git BASH.
  • File the PR against the correct branch: master, 5.1.x, 6.0.x
  • Copy the technical committee to review the pull request if your PR is targeting a particular programming language.

@morphlne
Copy link
Contributor Author

@bbdouglas (2017/07) @sreeshas (2017/08) @jfiala (2017/08) @lukoyanov (2017/09) @cbornet (2017/09) @jeff9finger (2018/01) @karismann (2019/03) @Zomzog (2019/04) @lwlee2608 (2019/10) @nmuesch (2021/01)

@cbornet
Copy link
Member

cbornet commented Jan 13, 2021

We shouldn't add 2 more options just to remove imports. I'd rather have only one option to completely add/remove the support for x-spring-paginated

@morphlne
Copy link
Contributor Author

If it's considered to have only one option for config, may be better not use options at all and apply vendor extension...
But this solution can break backward compatibility if someone use pageable & apiignore imports without x-spring-paginated. It will affect a small amount of users cause this case is very specific and relevant only to 5.0.0 & 5.0.0-beta3 versions
@cbornet what do you think about it?

@borsch agree with you, it makes sense, will add new samples as modules

@morphlne morphlne force-pushed the fix_apiignore_and_pageable branch 2 times, most recently from 6b8b6d1 to 3c4eade Compare March 7, 2021 15:51
@morphlne
Copy link
Contributor Author

morphlne commented Mar 8, 2021

CircleCI build blocked by #8922

@morphlne
Copy link
Contributor Author

Rebase on resolved blocker

Merge branch 'master' of github.com:OpenAPITools/openapi-generator into fix_apiignore_and_pageable
@morphlne
Copy link
Contributor Author

Reworked - now one property usePagination enable/disable both imports

Please review
@bbdouglas (2017/07) @sreeshas (2017/08) @jfiala (2017/08) @lukoyanov (2017/09) @cbornet (2017/09) @jeff9finger (2018/01) @karismann (2019/03) @Zomzog (2019/04) @lwlee2608 (2019/10) @nmuesch (2021/01) @wing328

@ghost
Copy link

ghost commented Mar 17, 2021

It would be great if this would be part of the 5.1 release.

@rfelgent
Copy link

It would be great if this would be part of the 5.1 release.

Unfortunatley, this fix is not part of 5.1.0 :-(

@Blubb324
Copy link

Blubb324 commented Aug 28, 2021

This topic is still relevant and occurs in current version: openapi-generator-maven-plugin: 5.2.1

The class import springfox.documentation.annotations.ApiIgnore; is still generated and unused within API and should be removed - also because of dependency to springfox.

@wangq8
Copy link

wangq8 commented Sep 21, 2021

This PR is not merged.
How can I get rid of this ApiIgnore manually, I don't want this annotation.

@pschichtel
Copy link

@wangq8 you can locally customize the template

@rfelgent
Copy link

Hi @wangq8 ,

as I am not so familiar with the customization possibilities provided by openapi tool, I manipulate the source files right after its creation:

<plugin>
        <artifactId>maven-antrun-plugin</artifactId>
        <executions>
          <!-- remove this execution as soon as 
   -  https://github.com/OpenAPITools/openapi-generator/issues/8192 
   - https://github.com/OpenAPITools/openapi-generator/pull/8421 
   is resolved 
-->
          <execution>
            <id>remove-springfox-classes</id>
            <phase>generate-sources</phase>
            <goals>
              <goal>run</goal>
            </goals>
            <configuration>
              <target>
                <replace dir="${project.build.directory}/generated-sources" token="import springfox.documentation.annotations.ApiIgnore;" failOnNoReplacements="true">
                  <include name="**/*.java"/>
                  <replacevalue/>
                </replace>
                <replace dir="${project.build.directory}/generated-sources" token="@ApiIgnore final" failOnNoReplacements="true">
                  <include name="**/*.java"/>
                  <replacevalue/>
                </replace>
              </target>
            </configuration>
          </execution>
        </executions>
      </plugin>

Maybe this helps you, too

@morphlne
Copy link
Contributor Author

Fixed in 5.3.0, working sample

@morphlne morphlne closed this Oct 31, 2021
@morphlne morphlne deleted the fix_apiignore_and_pageable branch October 31, 2021 20:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[BUG][JAVA][Spring] Config options for Pageable & ApiIgnore
6 participants