├── .github
└── FUNDING.yml
├── .gitignore
├── .travis.yml
├── CONTRIBUTING.adoc
├── LICENSE
├── README.md
├── pom.xml
├── settings.xml
└── src
└── main
└── java
└── org
└── springdoc
└── maven
└── plugin
└── SpringDocMojo.java
/.github/FUNDING.yml:
--------------------------------------------------------------------------------
1 | open_collective: springdoc-openapi
2 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | ######################
2 | # Project Specific
3 | ######################
4 | /target/www/**
5 | /src/test/javascript/coverage/
6 |
7 | ######################
8 | # Node
9 | ######################
10 | /node/
11 | node_tmp/
12 | node_modules/
13 | npm-debug.log.*
14 | /.awcache/*
15 | /.cache-loader/*
16 |
17 | ######################
18 | # SASS
19 | ######################
20 | .sass-cache/
21 |
22 | ######################
23 | # Eclipse
24 | ######################
25 | *.pydevproject
26 | .project
27 | .metadata
28 | tmp/
29 | tmp/**/*
30 | *.tmp
31 | *.bak
32 | *.swp
33 | *~.nib
34 | local.properties
35 | .classpath
36 | .settings/
37 | .loadpath
38 | .factorypath
39 | /src/main/resources/rebel.xml
40 |
41 | # External tool builders
42 | .externalToolBuilders/**
43 |
44 | # Locally stored "Eclipse launch configurations"
45 | *.launch
46 |
47 | # CDT-specific
48 | .cproject
49 |
50 | # PDT-specific
51 | .buildpath
52 |
53 | ######################
54 | # Intellij
55 | ######################
56 | .idea/
57 | *.iml
58 | *.iws
59 | *.ipr
60 | *.ids
61 | *.orig
62 | classes/
63 | out/
64 |
65 | ######################
66 | # Visual Studio Code
67 | ######################
68 | .vscode/
69 |
70 | ######################
71 | # Maven
72 | ######################
73 | /log/
74 | /target/
75 |
76 | ######################
77 | # Gradle
78 | ######################
79 | .gradle/
80 | /build/
81 |
82 | ######################
83 | # Package Files
84 | ######################
85 | *.jar
86 | *.war
87 | *.ear
88 | *.db
89 |
90 | ######################
91 | # Windows
92 | ######################
93 | # Windows image file caches
94 | Thumbs.db
95 |
96 | # Folder config file
97 | Desktop.ini
98 |
99 | ######################
100 | # Mac OSX
101 | ######################
102 | .DS_Store
103 | .svn
104 |
105 | # Thumbnails
106 | ._*
107 |
108 | # Files that might appear on external disk
109 | .Spotlight-V100
110 | .Trashes
111 |
112 | ######################
113 | # Directories
114 | ######################
115 | /bin/
116 | /deploy/
117 |
118 | ######################
119 | # Logs
120 | ######################
121 | *.log*
122 |
123 | ######################
124 | # Others
125 | ######################
126 | *.class
127 | *.*~
128 | *~
129 | .merge_file*
130 |
131 | ######################
132 | # Gradle Wrapper
133 | ######################
134 | !gradle/wrapper/gradle-wrapper.jar
135 |
136 | ######################
137 | # Maven Wrapper
138 | ######################
139 | !.mvn/wrapper/maven-wrapper.jar
140 |
141 | ######################
142 | # ESLint
143 | ######################
144 | .eslintcache
--------------------------------------------------------------------------------
/.travis.yml:
--------------------------------------------------------------------------------
1 | language: java
2 | jdk:
3 | - openjdk11
4 | cache:
5 | directories:
6 | - $HOME/.m2
7 | - $HOME/.sonar/cache
8 |
9 | addons:
10 | sonarcloud:
11 | organization: "springdoc-openapi"
12 |
13 | script:
14 | - mvn clean package sonar:sonar -Dsonar.projectKey=springdoc_springdoc-openapi-maven-plugin -Dsonar.scanner.force-deprecated-java-version-grace-period=true
15 |
16 | deploy:
17 | provider: script
18 | script: mvn deploy -DskipTests --settings settings.xml
19 | on:
20 | branch: master
21 |
22 |
23 |
24 |
--------------------------------------------------------------------------------
/CONTRIBUTING.adoc:
--------------------------------------------------------------------------------
1 |
2 | = Contributing to springdoc-openapi-maven-plugin
3 |
4 | springdoc-openapi is released under the Apache 2.0 license. If you would like to contribute
5 | something, or simply want to hack on the code this document should help you get started.
6 |
7 |
8 |
9 | == Code of Conduct
10 | This project adheres to the Contributor Covenant link:CODE_OF_CONDUCT.adoc[code of
11 | conduct]. By participating, you are expected to uphold this code.
12 |
13 |
14 | == Using GitHub Issues
15 | We use GitHub issues to track bugs and enhancements. If you have a general usage question
16 | please ask on https://stackoverflow.com[Stack Overflow]. The springdoc-openapi team and the
17 | broader community monitor the https://stackoverflow.com/tags/springdoc[`springdoc`]
18 | tag.
19 |
20 | These are some basic guidelines before opening an issue. First of all you need to make sure, you don't create duplicate issues, and there no question already answred on https://stackoverflow.com/tags/springdoc.
21 |
22 | If you are starting using springdoc-openapi, we advise you to use the last available release.
23 |
24 | Then refer to the relevant documentation:
25 |
26 | 1. For OpenAPI specification 3:
27 | - https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.0.2.md
28 | 2. For swagger2-annotations:
29 | - https://github.com/swagger-api/swagger-core/wiki/Swagger-2.X---Annotations
30 | 3. For swagger-ui configuration:
31 | - https://github.com/swagger-api/swagger-ui/blob/master/docs/usage/configuration.md
32 | 4. For springdoc-openapi:
33 | - https://springdoc.github.io/springdoc-openapi-demos/
34 | - https://springdoc.github.io/springdoc-openapi-demos/faq.html
35 | - https://springdoc.github.io/springdoc-openapi-demos/migrating-from-springfox.html
36 |
37 |
38 | If you are reporting a bug, please help to speed up problem diagnosis by providing as
39 | much information as possible:
40 |
41 | - You need to describe your context (the title of an issue is not enough)
42 | - What version of spring-boot you are using?
43 | - What modules and versions of springdoc-openapi are you using?
44 | - What are the actual and the expected result using OpenAPI Description (yml or json)?
45 | - Provide with a sample code (HelloController) or Test that reproduces the problem
46 |
47 |
48 | == Reporting Security Vulnerabilities
49 | If you think you have found a security vulnerability in Spring Boot please *DO NOT*
50 | disclose it publicly until we've had a chance to fix it. Please don't report security
51 | vulnerabilities using GitHub issues, instead head over to support@springdoc.org and
52 | learn how to disclose them responsibly.
53 |
54 |
55 | == Code Conventions and Housekeeping
56 | None of these is essential for a pull request, but they will all help. They can also be
57 | added after the original pull request but before a merge.
58 |
59 | * We use the https://github.com/spring-io/spring-javaformat/[Spring JavaFormat] project
60 | to apply code formatting conventions. If you use Eclipse and you follow the '`Importing
61 | into eclipse`' instructions below you should get project specific formatting
62 | automatically. You can also install the
63 | https://github.com/spring-io/spring-javaformat/#intellij-idea[Spring JavaFormat IntelliJ
64 | Plugin]
65 | * Make sure all new `.java` files to have a simple Javadoc class comment with at least an
66 | `@author` tag identifying you, and preferably at least a paragraph on what the class is
67 | for.
68 | * Add the ASF license header comment to all new `.java` files (copy from existing files
69 | in the project)
70 | * Add yourself as an `@author` to the `.java` files that you modify substantially (more
71 | than cosmetic changes).
72 | * Add some Javadocs.
73 | * A few unit tests would help a lot as well -- someone has to do it.
74 | * If no-one else is using your branch, please rebase it against the current master (or
75 | other target branch in the main project).
76 | * When writing a commit message please follow https://tbaggery.com/2008/04/19/a-note-about-git-commit-messages.html[these conventions],
77 | if you are fixing an existing issue please add `Fixes #XXXX` at the end of the commit
78 | message (where `XXXX` is the issue number).
79 |
80 |
81 |
82 | == Working with the Code
83 | If you don't have an IDE preference we would recommend that you use IntellIJ.
84 |
85 | === Importing into IntelliJ IDEA
86 | If you have performed a checkout of this repository already, use "`File`" -> "`Open`" and
87 | then select the root `build.gradle` file to import the code.
88 |
89 | Alternatively, you can let IntellIJ IDEA checkout the code for you. Use "`File`" ->
90 | "`New`" -> "`Project from Version Control`" and
91 | `https://github.com/spring-projects/spring-boot` for the URL. Once the checkout has
92 | completed, a pop-up will suggest to open the project.
93 |
94 |
95 | ==== Install the Spring Formatter plugin
96 | If you haven't done so, install the formatter plugin so that proper formatting rules are
97 | applied automatically when you reformat code in the IDE.
98 |
99 | * Download the latest https://search.maven.org/search?q=g:io.spring.javaformat%20AND%20a:spring-javaformat-intellij-plugin[IntelliJ IDEA plugin].
100 | * Select "`IntelliJ IDEA`" -> "`Preferences`".
101 | * Select "`Plugins`".
102 | * Select the wheel and "`Install Plugin from Disk...`".
103 | * Select the jar file you've downloaded.
104 |
105 |
106 | ==== Import additional code style
107 | The formatter does not cover all rules (such as order of imports) and an additional file
108 | needs to be added.
109 |
110 | * Select "`IntelliJ IDEA`" -> "`Preferences`".
111 | * Select "`Editor`" -> "`Code Style`".
112 | * Select the wheel and "`Import Scheme`" -> "`IntelliJ IDEA code style XML`".
113 | * Select https://github.com/spring-projects/spring-boot/blob/master/idea/codeStyleConfig.xml[`idea/codeStyleConfig.xml`] from this repository.
114 |
115 | ==== Importing into Eclipse
116 |
117 | You can use Spring Boot project specific source formatting settings.
118 |
119 |
120 | ===== Install the Spring Formatter plugin
121 | * Select "`Help`" -> "`Install New Software`".
122 | * Add `https://repo.spring.io/javaformat-eclipse-update-site/` as a site.
123 | * Install "Spring Java Format".
124 |
125 | NOTE: The plugin is optional. Projects can be imported without the plugins, your code
126 | changes just won't be automatically formatted.
127 |
128 | === Building from Source
129 | springdoc-openapi source can be built from the command line using https://maven.apache.org/[Maven] on
130 | JDK 1.8 or above.
131 |
132 | The project can be built from the root directory using the standard maven command:
133 |
134 | [indent=0]
135 | ----
136 | $ ./mvn install
137 | ----
138 |
139 |
140 | == Cloning the git repository on Windows
141 | Some files in the git repository may exceed the Windows maximum file path (260
142 | characters), depending on where you clone the repository. If you get `Filename too long`
143 | errors, set the `core.longPaths=true` git option:
144 |
145 | ```
146 | git clone -c core.longPaths=true https://github.com/springdoc/springdoc-openapi
147 | ```
148 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | Apache License
2 | Version 2.0, January 2004
3 | http://www.apache.org/licenses/
4 |
5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6 |
7 | 1. Definitions.
8 |
9 | "License" shall mean the terms and conditions for use, reproduction,
10 | and distribution as defined by Sections 1 through 9 of this document.
11 |
12 | "Licensor" shall mean the copyright owner or entity authorized by
13 | the copyright owner that is granting the License.
14 |
15 | "Legal Entity" shall mean the union of the acting entity and all
16 | other entities that control, are controlled by, or are under common
17 | control with that entity. For the purposes of this definition,
18 | "control" means (i) the power, direct or indirect, to cause the
19 | direction or management of such entity, whether by contract or
20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the
21 | outstanding shares, or (iii) beneficial ownership of such entity.
22 |
23 | "You" (or "Your") shall mean an individual or Legal Entity
24 | exercising permissions granted by this License.
25 |
26 | "Source" form shall mean the preferred form for making modifications,
27 | including but not limited to software source code, documentation
28 | source, and configuration files.
29 |
30 | "Object" form shall mean any form resulting from mechanical
31 | transformation or translation of a Source form, including but
32 | not limited to compiled object code, generated documentation,
33 | and conversions to other media types.
34 |
35 | "Work" shall mean the work of authorship, whether in Source or
36 | Object form, made available under the License, as indicated by a
37 | copyright notice that is included in or attached to the work
38 | (an example is provided in the Appendix below).
39 |
40 | "Derivative Works" shall mean any work, whether in Source or Object
41 | form, that is based on (or derived from) the Work and for which the
42 | editorial revisions, annotations, elaborations, or other modifications
43 | represent, as a whole, an original work of authorship. For the purposes
44 | of this License, Derivative Works shall not include works that remain
45 | separable from, or merely link (or bind by name) to the interfaces of,
46 | the Work and Derivative Works thereof.
47 |
48 | "Contribution" shall mean any work of authorship, including
49 | the original version of the Work and any modifications or additions
50 | to that Work or Derivative Works thereof, that is intentionally
51 | submitted to Licensor for inclusion in the Work by the copyright owner
52 | or by an individual or Legal Entity authorized to submit on behalf of
53 | the copyright owner. For the purposes of this definition, "submitted"
54 | means any form of electronic, verbal, or written communication sent
55 | to the Licensor or its representatives, including but not limited to
56 | communication on electronic mailing lists, source code control systems,
57 | and issue tracking systems that are managed by, or on behalf of, the
58 | Licensor for the purpose of discussing and improving the Work, but
59 | excluding communication that is conspicuously marked or otherwise
60 | designated in writing by the copyright owner as "Not a Contribution."
61 |
62 | "Contributor" shall mean Licensor and any individual or Legal Entity
63 | on behalf of whom a Contribution has been received by Licensor and
64 | subsequently incorporated within the Work.
65 |
66 | 2. Grant of Copyright License. Subject to the terms and conditions of
67 | this License, each Contributor hereby grants to You a perpetual,
68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69 | copyright license to reproduce, prepare Derivative Works of,
70 | publicly display, publicly perform, sublicense, and distribute the
71 | Work and such Derivative Works in Source or Object form.
72 |
73 | 3. Grant of Patent License. Subject to the terms and conditions of
74 | this License, each Contributor hereby grants to You a perpetual,
75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76 | (except as stated in this section) patent license to make, have made,
77 | use, offer to sell, sell, import, and otherwise transfer the Work,
78 | where such license applies only to those patent claims licensable
79 | by such Contributor that are necessarily infringed by their
80 | Contribution(s) alone or by combination of their Contribution(s)
81 | with the Work to which such Contribution(s) was submitted. If You
82 | institute patent litigation against any entity (including a
83 | cross-claim or counterclaim in a lawsuit) alleging that the Work
84 | or a Contribution incorporated within the Work constitutes direct
85 | or contributory patent infringement, then any patent licenses
86 | granted to You under this License for that Work shall terminate
87 | as of the date such litigation is filed.
88 |
89 | 4. Redistribution. You may reproduce and distribute copies of the
90 | Work or Derivative Works thereof in any medium, with or without
91 | modifications, and in Source or Object form, provided that You
92 | meet the following conditions:
93 |
94 | (a) You must give any other recipients of the Work or
95 | Derivative Works a copy of this License; and
96 |
97 | (b) You must cause any modified files to carry prominent notices
98 | stating that You changed the files; and
99 |
100 | (c) You must retain, in the Source form of any Derivative Works
101 | that You distribute, all copyright, patent, trademark, and
102 | attribution notices from the Source form of the Work,
103 | excluding those notices that do not pertain to any part of
104 | the Derivative Works; and
105 |
106 | (d) If the Work includes a "NOTICE" text file as part of its
107 | distribution, then any Derivative Works that You distribute must
108 | include a readable copy of the attribution notices contained
109 | within such NOTICE file, excluding those notices that do not
110 | pertain to any part of the Derivative Works, in at least one
111 | of the following places: within a NOTICE text file distributed
112 | as part of the Derivative Works; within the Source form or
113 | documentation, if provided along with the Derivative Works; or,
114 | within a display generated by the Derivative Works, if and
115 | wherever such third-party notices normally appear. The contents
116 | of the NOTICE file are for informational purposes only and
117 | do not modify the License. You may add Your own attribution
118 | notices within Derivative Works that You distribute, alongside
119 | or as an addendum to the NOTICE text from the Work, provided
120 | that such additional attribution notices cannot be construed
121 | as modifying the License.
122 |
123 | You may add Your own copyright statement to Your modifications and
124 | may provide additional or different license terms and conditions
125 | for use, reproduction, or distribution of Your modifications, or
126 | for any such Derivative Works as a whole, provided Your use,
127 | reproduction, and distribution of the Work otherwise complies with
128 | the conditions stated in this License.
129 |
130 | 5. Submission of Contributions. Unless You explicitly state otherwise,
131 | any Contribution intentionally submitted for inclusion in the Work
132 | by You to the Licensor shall be under the terms and conditions of
133 | this License, without any additional terms or conditions.
134 | Notwithstanding the above, nothing herein shall supersede or modify
135 | the terms of any separate license agreement you may have executed
136 | with Licensor regarding such Contributions.
137 |
138 | 6. Trademarks. This License does not grant permission to use the trade
139 | names, trademarks, service marks, or product names of the Licensor,
140 | except as required for reasonable and customary use in describing the
141 | origin of the Work and reproducing the content of the NOTICE file.
142 |
143 | 7. Disclaimer of Warranty. Unless required by applicable law or
144 | agreed to in writing, Licensor provides the Work (and each
145 | Contributor provides its Contributions) on an "AS IS" BASIS,
146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147 | implied, including, without limitation, any warranties or conditions
148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149 | PARTICULAR PURPOSE. You are solely responsible for determining the
150 | appropriateness of using or redistributing the Work and assume any
151 | risks associated with Your exercise of permissions under this License.
152 |
153 | 8. Limitation of Liability. In no event and under no legal theory,
154 | whether in tort (including negligence), contract, or otherwise,
155 | unless required by applicable law (such as deliberate and grossly
156 | negligent acts) or agreed to in writing, shall any Contributor be
157 | liable to You for damages, including any direct, indirect, special,
158 | incidental, or consequential damages of any character arising as a
159 | result of this License or out of the use or inability to use the
160 | Work (including but not limited to damages for loss of goodwill,
161 | work stoppage, computer failure or malfunction, or any and all
162 | other commercial damages or losses), even if such Contributor
163 | has been advised of the possibility of such damages.
164 |
165 | 9. Accepting Warranty or Additional Liability. While redistributing
166 | the Work or Derivative Works thereof, You may choose to offer,
167 | and charge a fee for, acceptance of support, warranty, indemnity,
168 | or other liability obligations and/or rights consistent with this
169 | License. However, in accepting such obligations, You may act only
170 | on Your own behalf and on Your sole responsibility, not on behalf
171 | of any other Contributor, and only if You agree to indemnify,
172 | defend, and hold each Contributor harmless for any liability
173 | incurred by, or claims asserted against, such Contributor by reason
174 | of your accepting any such warranty or additional liability.
175 |
176 | END OF TERMS AND CONDITIONS
177 |
178 | APPENDIX: How to apply the Apache License to your work.
179 |
180 | To apply the Apache License to your work, attach the following
181 | boilerplate notice, with the fields enclosed by brackets "[]"
182 | replaced with your own identifying information. (Don't include
183 | the brackets!) The text should be enclosed in the appropriate
184 | comment syntax for the file format. We also recommend that a
185 | file or class name and description of purpose be included on the
186 | same "printed page" as the copyright notice for easier
187 | identification within third-party archives.
188 |
189 | Copyright [yyyy] [name of copyright owner]
190 |
191 | Licensed under the Apache License, Version 2.0 (the "License");
192 | you may not use this file except in compliance with the License.
193 | You may obtain a copy of the License at
194 |
195 | http://www.apache.org/licenses/LICENSE-2.0
196 |
197 | Unless required by applicable law or agreed to in writing, software
198 | distributed under the License is distributed on an "AS IS" BASIS,
199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200 | See the License for the specific language governing permissions and
201 | limitations under the License.
202 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | [](https://ci-cd.springdoc.org:8443/view/springdoc-openapi-maven/job/springdoc-openapi-maven-plugin-IC/)
2 |
3 | ## **Introduction to springdoc-openapi-maven-plugin**
4 |
5 | The aim of springdoc-openapi-maven-plugin is to generate json and yaml OpenAPI description during runtime. If you want to get swagger definitions properly, the application should completely running as locally.
6 | The plugin works during integration-tests phase, and generate the OpenAPI description.
7 | The plugin works in conjunction with spring-boot-maven plugin.
8 |
9 | You can test it during the integration tests phase using the maven command:
10 |
11 | ```shell
12 | mvn verify
13 | ```
14 |
15 | In order to use this functionality, you need to add the plugin declaration on the plugins section of your pom.xml:
16 |
17 | ```xml
18 |
19 |
20 | org.springframework.boot
21 | spring-boot-maven-plugin
22 | ${spring-boot-maven-plugin.version}
23 |
24 | -Dspring.application.admin.enabled=true
25 |
26 |
27 |
28 | pre-integration-test
29 |
30 | start
31 |
32 |
33 |
34 | post-integration-test
35 |
36 | stop
37 |
38 |
39 |
40 |
41 |
42 | org.springdoc
43 | springdoc-openapi-maven-plugin
44 | last-release-version
45 |
46 |
47 | integration-test
48 |
49 | generate
50 |
51 |
52 |
53 |
54 |
55 | ```
56 |
57 | ## **Custom settings of the springdoc-openapi-maven-plugin**
58 |
59 | It possible to customise the following plugin properties:
60 | * attachArtifact: install / deploy the api doc to the repository
61 | * The default value is: false
62 | * apiDocsUrl: The local url of your (json or yaml).
63 | * The default value is: http://localhost:8080/v3/api-docs
64 | * outputDir: The output directory, where to generate the OpenAPI description. The directory name shouldn't start with "/".
65 | * The default value is: ${project.build.directory}
66 | * outputFileName: The file name that contains the OpenAPI description.
67 | * The default value is: openapi.json
68 | * skip: Skip execution if set to true.
69 | * The default value is: false
70 | * headers: List of headers to send in request
71 | * The default value is empty
72 | * failOnError: Fail build on error, if set to `true`. Default is `false`.
73 | * The default value is false
74 |
75 | ```xml
76 |
77 | org.springdoc
78 | springdoc-openapi-maven-plugin
79 | last-release-version
80 |
81 |
82 | integration-test
83 |
84 | generate
85 |
86 |
87 |
88 |
89 | http://localhost:8080/v3/api-docs
90 | openapi.json
91 | home/springdoc/maven-output
92 | false
93 | true
94 |
95 | header1value
96 | header2value
97 |
98 |
99 |
100 | ```
101 |
102 | # **Thank you for the support**
103 |
104 | * Thanks a lot [JetBrains](https://www.jetbrains.com/?from=springdoc-openapi) for supporting springdoc-openapi project.
105 |
106 | 
107 |
--------------------------------------------------------------------------------
/pom.xml:
--------------------------------------------------------------------------------
1 |
2 | 4.0.0
3 | org.springdoc
4 | springdoc-openapi-maven-plugin
5 | 1.6-SNAPSHOT
6 | maven-plugin
7 | springdoc-openapi-maven-plugin
8 | springdoc OpenAPI 3 maven plugin
9 | http://springdoc.org
10 |
11 |
12 |
13 | The Apache License, Version 2.0
14 | http://www.apache.org/licenses/LICENSE-2.0.txt
15 |
16 |
17 |
18 |
19 |
20 | Badr NASS LAHSEN
21 | support@springdoc.org
22 | springdoc
23 | https://springdoc.github.io/springdoc-openapi/
24 |
25 |
26 |
27 |
28 |
29 | git@github.com:springdoc/springdoc-openapi-maven-plugin.git
30 | scm:git:git@github.com:springdoc/springdoc-openapi-maven-plugin.git
31 |
32 |
33 | scm:git:git@github.com:springdoc/springdoc-openapi-maven-plugin.git
34 |
35 | HEAD
36 |
37 |
38 |
39 | UTF-8
40 | UTF-8
41 | 1.8
42 | ${java.version}
43 | ${java.version}
44 | 1.6
45 | 2.5.3
46 | 0.7.0
47 |
48 | 3.0.1
49 | 3.0.1
50 |
51 |
52 |
53 |
54 | org.apache.maven
55 | maven-plugin-api
56 | 3.8.4
57 | provided
58 |
59 |
60 | org.apache.maven
61 | maven-core
62 | 3.8.4
63 | provided
64 |
65 |
66 | org.apache.maven.plugin-tools
67 | maven-plugin-annotations
68 | 3.6.4
69 | provided
70 |
71 |
72 |
73 |
74 |
75 |
76 | org.apache.maven.plugins
77 | maven-plugin-plugin
78 | 3.6.4
79 |
80 | springdoc-openapi
81 | true
82 |
83 |
84 |
85 | generate-descriptor
86 |
87 | descriptor
88 |
89 |
90 |
91 | generated-helpmojo
92 |
93 | helpmojo
94 |
95 |
96 |
97 |
98 |
99 |
100 |
101 |
102 |
103 | gpg
104 |
105 |
106 |
107 | maven-source-plugin
108 | ${maven-source-plugin.version}
109 |
110 |
111 | attach-sources
112 |
113 | jar
114 |
115 |
116 |
117 |
118 |
119 | maven-javadoc-plugin
120 | ${maven-javadoc-plugin.version}
121 |
122 |
123 | attach-javadocs
124 |
125 | jar
126 |
127 |
128 |
129 |
130 |
131 | maven-gpg-plugin
132 | ${maven-gpg-plugin.version}
133 |
134 |
135 | sign-artifacts
136 | verify
137 |
138 | sign
139 |
140 |
141 |
142 |
143 |
144 | org.sonatype.central
145 | central-publishing-maven-plugin
146 | ${central-publishing-maven-plugin.version}
147 | true
148 |
149 | central
150 | true
151 | published
152 |
153 |
154 |
155 | maven-release-plugin
156 | ${maven-release-plugin.version}
157 |
158 | v@{project.version}
159 | true
160 | false
161 | gpg
162 | deploy
163 |
164 |
165 |
166 |
167 |
168 |
169 |
170 |
--------------------------------------------------------------------------------
/settings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | ossrh
5 | ${env.OSSRH_USER}
6 | ${env.OSSRH_PASS}
7 |
8 |
9 |
10 |
--------------------------------------------------------------------------------
/src/main/java/org/springdoc/maven/plugin/SpringDocMojo.java:
--------------------------------------------------------------------------------
1 | package org.springdoc.maven.plugin;
2 |
3 | import java.io.ByteArrayOutputStream;
4 | import java.io.File;
5 | import java.io.IOException;
6 | import java.io.InputStream;
7 | import java.net.HttpURLConnection;
8 | import java.net.URL;
9 | import java.nio.charset.StandardCharsets;
10 | import java.nio.file.Files;
11 | import java.nio.file.Paths;
12 | import java.util.Map;
13 |
14 | import org.apache.maven.plugin.AbstractMojo;
15 | import org.apache.maven.plugin.MojoFailureException;
16 | import org.apache.maven.plugins.annotations.Component;
17 | import org.apache.maven.plugins.annotations.LifecyclePhase;
18 | import org.apache.maven.plugins.annotations.Mojo;
19 | import org.apache.maven.plugins.annotations.Parameter;
20 | import org.apache.maven.plugins.annotations.ResolutionScope;
21 | import org.apache.maven.project.MavenProject;
22 | import org.apache.maven.project.MavenProjectHelper;
23 |
24 | /**
25 | * Generate a openapi specification file.
26 | *
27 | * @author bnasslashen
28 | */
29 | @Mojo(name = "generate", requiresProject = true, defaultPhase = LifecyclePhase.INTEGRATION_TEST, requiresDependencyResolution = ResolutionScope.TEST, threadSafe = true)
30 | public class SpringDocMojo extends AbstractMojo {
31 |
32 | /**
33 | * The DEFAULT OUTPUT FILE NAME.
34 | */
35 | private static final String DEFAULT_OUTPUT_FILE_NAME= "openapi";
36 |
37 | /**
38 | * The DEFAULT OUTPUT EXTENSION.
39 | */
40 | private static final String DEFAULT_OUTPUT_EXTENSION= ".json";
41 |
42 | /**
43 | * The DEFAULT OUTPUT FILE.
44 | */
45 | private static final String DEFAULT_OUTPUT_FILE = DEFAULT_OUTPUT_FILE_NAME+DEFAULT_OUTPUT_EXTENSION;
46 |
47 | /**
48 | * The URL from where the api doc is retrieved.
49 | */
50 | @Parameter(defaultValue = "http://localhost:8080/v3/api-docs", property = "springdoc.apiDocsUrl", required = true)
51 | private String apiDocsUrl;
52 |
53 | /**
54 | * File name of the generated api doc.
55 | */
56 | @Parameter(defaultValue = DEFAULT_OUTPUT_FILE, property = "springdoc.outputFileName", required = true)
57 | private String outputFileName;
58 |
59 | /**
60 | * Output directory for the generated api doc.
61 | */
62 | @Parameter(defaultValue = "${project.build.directory}", property = "springdoc.outputDir", required = true)
63 | private File outputDir;
64 |
65 | /**
66 | * Attach generated documentation as artifact to the Maven project.
67 | * If true documentation will be deployed along with other artifacts.
68 | */
69 | @Parameter(defaultValue = "false", property = "springdoc.attachArtifact")
70 | private boolean attachArtifact;
71 |
72 | /**
73 | * The Project.
74 | */
75 | @Parameter(defaultValue = "${project}", readonly = true)
76 | private MavenProject project;
77 |
78 | /**
79 | * Skip execution if set to true. Default is false.
80 | */
81 | @Parameter(defaultValue = "false", property = "springdoc.skip")
82 | private boolean skip;
83 |
84 | /**
85 | * Fail build on error, if set to true. Default is false.
86 | */
87 | @Parameter(defaultValue = "false", property = "springdoc.failOnError")
88 | private boolean failOnError;
89 |
90 | /**
91 | * Headers to send in request
92 | */
93 | @Parameter(property = "headers")
94 | private Map headers;
95 |
96 | /**
97 | * The Project helper.
98 | */
99 | @Component
100 | private MavenProjectHelper projectHelper;
101 |
102 | /**
103 | * The constant GET.
104 | */
105 | private static final String GET = "GET";
106 |
107 | public void execute() throws MojoFailureException {
108 | if (skip) {
109 | getLog().info("Skip execution as per configuration");
110 | return;
111 | }
112 | try {
113 | URL urlForGetRequest = new URL(apiDocsUrl);
114 | HttpURLConnection connection = (HttpURLConnection) urlForGetRequest.openConnection();
115 | if (headers.size() > 0) {headers.forEach((k, v) -> connection.setRequestProperty(k, v));}
116 | connection.setRequestMethod(GET);
117 | int responseCode = connection.getResponseCode();
118 | if (responseCode == HttpURLConnection.HTTP_OK) {
119 | String result = this.readFullyAsString(connection.getInputStream());
120 | outputDir.mkdirs();
121 | Files.write(Paths.get(outputDir.getAbsolutePath() + "/" + outputFileName), result.getBytes(StandardCharsets.UTF_8));
122 | if (attachArtifact) addArtifactToMaven();
123 | } else {
124 | String message = "An error has occurred, response code: " + responseCode;
125 | if(failOnError) {
126 | throw new MojoFailureException(message);
127 | } else {
128 | getLog().error(message);
129 | }
130 | }
131 | } catch (Exception e) {
132 | getLog().error("An error has occurred", e);
133 | if(failOnError) {
134 | throw new MojoFailureException("An error has occurred: " + e.getMessage());
135 | }
136 | }
137 | }
138 |
139 |
140 | /**
141 | * Read fully as string string.
142 | *
143 | * @param inputStream the input stream
144 | * @return the string
145 | * @throws IOException the io exception
146 | */
147 | private String readFullyAsString(InputStream inputStream) throws IOException {
148 | return readFully(inputStream).toString(StandardCharsets.UTF_8.name());
149 | }
150 |
151 | /**
152 | * Read fully byte array output stream.
153 | *
154 | * @param inputStream the input stream
155 | * @return the byte array output stream
156 | * @throws IOException the io exception
157 | */
158 | private ByteArrayOutputStream readFully(InputStream inputStream) throws IOException {
159 | ByteArrayOutputStream baos = new ByteArrayOutputStream();
160 | byte[] buffer = new byte[1024];
161 | int length;
162 | while ((length = inputStream.read(buffer)) != -1) {
163 | baos.write(buffer, 0, length);
164 | }
165 | return baos;
166 | }
167 |
168 | /**
169 | * Add artifact to maven.
170 | */
171 | private void addArtifactToMaven() {
172 | File swaggerFile = new File(outputDir.getAbsolutePath() + '/' + outputFileName);
173 | String extension = getFileExtension();
174 | projectHelper.attachArtifact(project, extension, DEFAULT_OUTPUT_FILE_NAME, swaggerFile);
175 | }
176 |
177 | /**
178 | * Gets file extension.
179 | *
180 | * @return the file extension
181 | */
182 | private String getFileExtension() {
183 | String extension = DEFAULT_OUTPUT_EXTENSION;
184 | int i = outputFileName.lastIndexOf('.');
185 | if (i > 0)
186 | extension = outputFileName.substring(i + 1);
187 | return extension;
188 | }
189 | }
190 |
--------------------------------------------------------------------------------