├── .github
├── .dependabot.yml
├── FUNDING.yml
├── README.md
└── workflows
│ ├── gradle.yml
│ └── publish-to-reposilite.yml
├── .gitignore
├── .gitmodules
├── .run
└── Examples __ Gradle - JavalinTest.run.xml
├── LICENSE
├── build.gradle.kts
├── examples
├── README.md
├── javalin-gradle-kotlin
│ ├── build.gradle.kts
│ └── src
│ │ └── main
│ │ ├── compile
│ │ └── openapi.groovy
│ │ ├── java
│ │ └── io
│ │ │ └── javalin
│ │ │ └── openapi
│ │ │ └── plugin
│ │ │ └── test
│ │ │ └── JavalinTest.java
│ │ ├── kotlin
│ │ └── io
│ │ │ └── javalin
│ │ │ └── openapi
│ │ │ └── plugin
│ │ │ └── test
│ │ │ └── KotlinEntity.kt
│ │ └── resources
│ │ ├── logback.xml
│ │ └── tinylog.properties
├── javalin-maven-java
│ ├── pom.xml
│ └── src
│ │ └── main
│ │ ├── java
│ │ └── io
│ │ │ └── javalin
│ │ │ └── openapi
│ │ │ └── plugin
│ │ │ └── test
│ │ │ └── JavalinTest.java
│ │ ├── kotlin
│ │ └── io
│ │ │ └── javalin
│ │ │ └── openapi
│ │ │ └── plugin
│ │ │ └── test
│ │ │ └── KotlinEntity.kt
│ │ └── resources
│ │ └── logback.xml
└── javalin-maven-kotlin
│ ├── .mvn
│ └── jvm.config
│ ├── README.md
│ ├── pom.xml
│ └── src
│ └── main
│ ├── kotlin
│ └── io
│ │ └── javalin
│ │ └── openapi
│ │ └── plugin
│ │ └── test
│ │ └── KotlinTest.kt
│ └── resources
│ └── logback.xml
├── gradle.properties
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── gradlew
├── gradlew.bat
├── javalin-plugins
├── javalin-openapi-plugin
│ ├── build.gradle.kts
│ └── src
│ │ ├── main
│ │ └── kotlin
│ │ │ └── io
│ │ │ └── javalin
│ │ │ └── openapi
│ │ │ └── plugin
│ │ │ ├── OpenApiConfiguration.kt
│ │ │ ├── OpenApiHandler.kt
│ │ │ └── OpenApiPlugin.kt
│ │ └── test
│ │ └── kotlin
│ │ └── OpenApiPluginTest.kt
├── javalin-redoc-plugin
│ ├── build.gradle.kts
│ └── src
│ │ ├── main
│ │ └── kotlin
│ │ │ └── io
│ │ │ └── javalin
│ │ │ └── openapi
│ │ │ └── plugin
│ │ │ └── redoc
│ │ │ ├── ReDocHandler.kt
│ │ │ ├── ReDocPlugin.kt
│ │ │ └── ReDocWebJarHandler.kt
│ │ └── test
│ │ ├── kotlin
│ │ └── io
│ │ │ └── javalin
│ │ │ └── openapi
│ │ │ └── plugin
│ │ │ └── redoc
│ │ │ ├── RedocPluginTest.kt
│ │ │ └── specification
│ │ │ └── JavalinBehindProxy.kt
│ │ └── resources
│ │ ├── logback.xml
│ │ └── openapi-plugin
│ │ ├── .index
│ │ └── test.json
└── javalin-swagger-plugin
│ ├── build.gradle.kts
│ └── src
│ ├── main
│ └── kotlin
│ │ └── io
│ │ └── javalin
│ │ └── openapi
│ │ └── plugin
│ │ └── swagger
│ │ ├── SwaggerHandler.kt
│ │ ├── SwaggerPlugin.kt
│ │ └── SwaggerWebJarHandler.kt
│ └── test
│ ├── kotlin
│ └── io
│ │ └── javalin
│ │ └── openapi
│ │ └── plugin
│ │ └── swagger
│ │ ├── SwaggerPluginTest.kt
│ │ └── specification
│ │ └── JavalinBehindProxy.kt
│ └── resources
│ ├── logback.xml
│ └── openapi-plugin
│ ├── .index
│ └── test.json
├── openapi-annotation-processor
├── build.gradle.kts
└── src
│ ├── main
│ ├── kotlin
│ │ └── io
│ │ │ └── javalin
│ │ │ └── openapi
│ │ │ └── processor
│ │ │ ├── AnnotationProcessorTools.kt
│ │ │ ├── OpenApiAnnotationProcessor.kt
│ │ │ ├── configuration
│ │ │ └── OpenApiPrecompileScriptingEngine.kt
│ │ │ └── generators
│ │ │ ├── JsonSchemaGenerator.kt
│ │ │ └── OpenApiGenerator.kt
│ └── resources
│ │ ├── META-INF
│ │ └── services
│ │ │ └── javax.annotation.processing.Processor
│ │ └── logback.xml
│ └── test
│ ├── compile
│ └── openapi.groovy
│ ├── kotlin
│ └── io
│ │ └── javalin
│ │ └── openapi
│ │ └── processor
│ │ ├── ComponentAnnotationsTest.kt
│ │ ├── CompositionTest.kt
│ │ ├── CustomAnnotationsTest.kt
│ │ ├── CustomTypeMappingsTest.kt
│ │ ├── OpenApiAnnotationTest.kt
│ │ ├── SchemeTest.kt
│ │ ├── TypeMappersTest.kt
│ │ ├── UserCasesTest.kt
│ │ └── specification
│ │ └── OpenApiAnnotationProcessorSpecification.kt
│ └── resources
│ ├── META-INF
│ └── services
│ │ └── javax.annotation.processing.Processor
│ └── logback-test.xml
├── openapi-specification
├── build.gradle.kts
└── src
│ └── main
│ └── kotlin
│ └── io
│ └── javalin
│ └── openapi
│ ├── Info.kt
│ ├── JsonSchemaAnnotations.kt
│ ├── OpenApiAnnotations.kt
│ ├── Security.kt
│ ├── Server.kt
│ ├── data
│ └── OpenApiAnnotationsData.kt
│ └── experimental
│ ├── AnnotationProcessorContext.kt
│ ├── ClassDefinitionApi.kt
│ ├── OpenApiAnnotationProcessorConfiguration.kt
│ ├── OpenApiAnnotationProcessorParameters.kt
│ ├── defaults
│ ├── ArrayEmbeddedTypeProcessor.kt
│ ├── CompositionEmbeddedTypeProcessor.kt
│ ├── DefaultSimpleTypeMappings.kt
│ └── DictionaryEmbeddedTypeProcessor.kt
│ └── processor
│ ├── generators
│ ├── CompositionGenerator.kt
│ ├── ExampleGenerator.kt
│ └── TypeSchemaGenerator.kt
│ └── shared
│ ├── AnnotationProcessorExtensions.kt
│ ├── JsonExtensions.kt
│ └── ModelExtensions.kt
└── settings.gradle.kts
/.github/.dependabot.yml:
--------------------------------------------------------------------------------
1 | version: 2
2 | updates:
3 | - package-ecosystem: "gradle"
4 | directory: "/"
5 | schedule:
6 | interval: "daily"
7 |
--------------------------------------------------------------------------------
/.github/FUNDING.yml:
--------------------------------------------------------------------------------
1 | github: dzikoysk
2 |
--------------------------------------------------------------------------------
/.github/README.md:
--------------------------------------------------------------------------------
1 | # OpenAPI Plugin [](https://github.com/javalin/javalin-openapi/actions/workflows/gradle.yml)  [](https://maven.reposilite.com/#/snapshots/io/javalin/community/openapi)
2 | Compile-time OpenAPI integration for Javalin 6.x ecosystem.
3 | This is a new plugin that replaces [old built-in OpenApi module](https://github.com/javalin/javalin/tree/javalin-4x/javalin-openapi),
4 | the API looks quite the same despite some minor changes.
5 |
6 | 
7 |
8 | ### How to use
9 |
10 | * [Wiki / Installation](https://github.com/javalin/javalin-openapi/wiki/1.-Installation)
11 | * [Wiki / Setup](https://github.com/javalin/javalin-openapi/wiki/2.-Setup)
12 | * [Wiki / Features](https://github.com/javalin/javalin-openapi/wiki/3.-Features)
13 |
14 | ### Notes
15 | * Reflection free, does not perform any extra operations at runtime
16 | * Uses `@OpenApi` to simplify migration from bundled OpenApi implementation
17 | * Supports Java 11+ (also 16 and any further releases) and Kotlin (through [Kapt](https://kotlinlang.org/docs/kapt.html))
18 | * Uses internal WebJar handler that works with `/*` route out of the box
19 | * Provides better projection of OpenAPI specification
20 | * Schema validation through Swagger core module
21 |
22 | ### Other examples
23 | * [Test module](https://github.com/javalin/javalin-openapi/blob/main/examples/javalin-gradle-kotlin/src/main/java/io/javalin/openapi/plugin/test/JavalinTest.java) - `JavalinTest` shows how this plugin work in Java codebase using various features
24 | * [Reposilite](https://github.com/dzikoysk/reposilite) - real world app using Javalin and OpenApi integration
25 |
26 | ### Repository structure
27 |
28 | #### Universal modules
29 |
30 | | Module | Description |
31 | |:-------------------------------|:-------------------------------------------------------------------------------------------|
32 | | `openapi-annotation-processor` | Compile-time annotation processor, should generate `/openapi-plugin/openapi.json` resource |
33 | | `openapi-specification` | Annotations & classes used to describe OpenAPI specification |
34 | | `openapi-test` | Example Javalin application that uses OpenApi plugin in Gradle & Maven |
35 |
36 | #### Javalin plugins
37 |
38 | | Plugin | Description |
39 | |:-------------------------|:-------------------------------------------------------------------------------|
40 | | `javalin-openapi-plugin` | Loads `/openapi-plugin/openapi.json` resource and serves main OpenApi endpoint |
41 | | `javalin-swagger-plugin` | Serves Swagger UI |
42 | | `javalin-redoc-plugin` | Serves ReDoc UI |
43 |
44 | #### Branches
45 |
46 | | Branch | Javalin version | OpenApi Version | Java Version |
47 | |:-------------------------------------------------------------|:----------------|:----------------|:-------------|
48 | | [main](https://github.com/javalin/javalin-openapi/tree/main) | 6.x | 6.x | JDK11 |
49 | | [5.x](https://github.com/javalin/javalin-openapi/tree/5.x) | 5.x | 5.x | JDK11 |
50 | | [4.x](https://github.com/javalin/javalin-openapi/tree/4.x) | 4.x | 1.x | JDK8 |
51 |
--------------------------------------------------------------------------------
/.github/workflows/gradle.yml:
--------------------------------------------------------------------------------
1 | name: CI
2 | on:
3 | push:
4 | branches: [ main ]
5 | pull_request:
6 | branches: [ main ]
7 | jobs:
8 | build:
9 | name: "Build with JDK${{ matrix.jdk }}"
10 | runs-on: ubuntu-latest
11 | strategy:
12 | matrix:
13 | jdk: [ 17, 21 ]
14 | steps:
15 | - uses: actions/checkout@v2
16 | - name: Set up JDK
17 | uses: actions/setup-java@v1
18 | with:
19 | java-version: ${{ matrix.jdk }}
20 | - name: Grant execute permission for gradlew
21 | run: chmod +x gradlew
22 | - name: Build with Gradle
23 | run: ./gradlew build
24 | - name: Upload coverage to Codecov
25 | uses: codecov/codecov-action@v1
26 |
--------------------------------------------------------------------------------
/.github/workflows/publish-to-reposilite.yml:
--------------------------------------------------------------------------------
1 | # GitHub Actions workflow to automatically publish snapshot builds.
2 | name: "Publish snapshots"
3 | on:
4 | push:
5 | branches: [ "main" ]
6 |
7 | env:
8 | JAVA_VERSION: 17
9 |
10 | jobs:
11 | maven:
12 | name: "Maven"
13 | runs-on: ubuntu-latest
14 | steps:
15 | - name: "Checkout repository"
16 | uses: actions/checkout@v3
17 |
18 | - name: "Set up Java ${{ env.JAVA_VERSION }}"
19 | uses: actions/setup-java@v3
20 | with:
21 | java-version: "${{ env.JAVA_VERSION }}"
22 | distribution: "adopt"
23 |
24 | - name: "Grant execute permission for gradlew"
25 | run: chmod +x gradlew
26 |
27 | - name: "Gradle publish"
28 | uses: gradle/gradle-build-action@v2
29 | with:
30 | arguments: "clean build publishAllPublicationsToReposilite-repositoryRepository"
31 | env:
32 | MAVEN_NAME: ${{ secrets.MAVEN_NAME }}
33 | MAVEN_TOKEN: ${{ secrets.MAVEN_TOKEN }}
34 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 |
2 | # Created by https://www.toptal.com/developers/gitignore/api/gradle,java,maven,intellij
3 | # Edit at https://www.toptal.com/developers/gitignore?templates=gradle,java,maven,intellij
4 |
5 | ### Intellij ###
6 | # Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio, WebStorm and Rider
7 | # Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839
8 |
9 | # User-specific stuff
10 | .idea/
11 |
12 | # Gradle and Maven with auto-import
13 | # When using Gradle or Maven with auto-import, you should exclude module files,
14 | # since they will be recreated, and may cause churn. Uncomment if using
15 | # auto-import.
16 | # .idea/artifacts
17 | # .idea/compiler.xml
18 | # .idea/jarRepositories.xml
19 | # .idea/modules.xml
20 | # .idea/*.iml
21 | # .idea/modules
22 | # *.iml
23 | # *.ipr
24 |
25 | # CMake
26 | cmake-build-*/
27 |
28 | # Mongo Explorer plugin
29 | .idea/**/mongoSettings.xml
30 |
31 | # File-based project format
32 | *.iws
33 | *.iml
34 |
35 | # IntelliJ
36 | out/
37 |
38 | # mpeltonen/sbt-idea plugin
39 | .idea_modules/
40 |
41 | # JIRA plugin
42 | atlassian-ide-plugin.xml
43 |
44 | # Cursive Clojure plugin
45 | .idea/replstate.xml
46 |
47 | # Crashlytics plugin (for Android Studio and IntelliJ)
48 | com_crashlytics_export_strings.xml
49 | crashlytics.properties
50 | crashlytics-build.properties
51 | fabric.properties
52 |
53 | # Editor-based Rest Client
54 | .idea/httpRequests
55 |
56 | # Android studio 3.1+ serialized cache file
57 | .idea/caches/build_file_checksums.ser
58 |
59 | ### Intellij Patch ###
60 | # Comment Reason: https://github.com/joeblau/gitignore.io/issues/186#issuecomment-215987721
61 |
62 | # *.iml
63 | # modules.xml
64 | # .idea/misc.xml
65 | # *.ipr
66 |
67 | # Sonarlint plugin
68 | # https://plugins.jetbrains.com/plugin/7973-sonarlint
69 | .idea/**/sonarlint/
70 |
71 | # SonarQube Plugin
72 | # https://plugins.jetbrains.com/plugin/7238-sonarqube-community-plugin
73 | .idea/**/sonarIssues.xml
74 |
75 | # Markdown Navigator plugin
76 | # https://plugins.jetbrains.com/plugin/7896-markdown-navigator-enhanced
77 | .idea/**/markdown-navigator.xml
78 | .idea/**/markdown-navigator-enh.xml
79 | .idea/**/markdown-navigator/
80 |
81 | # Cache file creation bug
82 | # See https://youtrack.jetbrains.com/issue/JBR-2257
83 | .idea/$CACHE_FILE$
84 |
85 | # CodeStream plugin
86 | # https://plugins.jetbrains.com/plugin/12206-codestream
87 | .idea/codestream.xml
88 |
89 | ### Java ###
90 | # Compiled class file
91 | *.class
92 |
93 | # Log file
94 | *.log
95 |
96 | # BlueJ files
97 | *.ctxt
98 |
99 | # Mobile Tools for Java (J2ME)
100 | .mtj.tmp/
101 |
102 | # Package Files #
103 | *.jar
104 | *.war
105 | *.nar
106 | *.ear
107 | *.zip
108 | *.tar.gz
109 | *.rar
110 |
111 | # virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
112 | hs_err_pid*
113 |
114 | ### Maven ###
115 | target/
116 | pom.xml.tag
117 | pom.xml.releaseBackup
118 | pom.xml.versionsBackup
119 | pom.xml.next
120 | release.properties
121 | dependency-reduced-pom.xml
122 | buildNumber.properties
123 | .mvn/timing.properties
124 | # https://github.com/takari/maven-wrapper#usage-without-binary-jar
125 | .mvn/wrapper/maven-wrapper.jar
126 | .flattened-pom.xml
127 |
128 | ### Gradle ###
129 | .gradle
130 | build/
131 |
132 | # Ignore Gradle GUI config
133 | gradle-app.setting
134 |
135 | # Avoid ignoring Gradle wrapper jar file (.jar files are usually ignored)
136 | !gradle-wrapper.jar
137 |
138 | # Cache of project
139 | .gradletasknamecache
140 |
141 | # # Work around https://youtrack.jetbrains.com/issue/IDEA-116898
142 | # gradle/wrapper/gradle-wrapper.properties
143 |
144 | ### Gradle Patch ###
145 | **/build/
146 |
147 | # End of https://www.toptal.com/developers/gitignore/api/gradle,java,maven,intellij
148 |
--------------------------------------------------------------------------------
/.gitmodules:
--------------------------------------------------------------------------------
1 | [submodule "wiki"]
2 | path = wiki
3 | url = https://github.com/javalin/javalin-openapi.wiki.git
4 |
--------------------------------------------------------------------------------
/.run/Examples __ Gradle - JavalinTest.run.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
--------------------------------------------------------------------------------
/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 |
--------------------------------------------------------------------------------
/build.gradle.kts:
--------------------------------------------------------------------------------
1 | import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
2 |
3 | plugins {
4 | `java-library`
5 | kotlin("jvm") version "1.9.22"
6 | `maven-publish`
7 | signing
8 | id("io.github.gradle-nexus.publish-plugin") version "1.3.0"
9 | }
10 |
11 | description = "Javalin OpenAPI Parent | Parent"
12 |
13 | allprojects {
14 | apply(plugin = "java-library")
15 | apply(plugin = "signing")
16 | apply(plugin = "maven-publish")
17 |
18 | group = "io.javalin.community.openapi"
19 | version = "6.6.0"
20 |
21 | repositories {
22 | mavenCentral()
23 | maven("https://maven.reposilite.com/snapshots")
24 | }
25 |
26 | publishing {
27 | repositories {
28 | maven {
29 | name = "reposilite-repository"
30 | url = uri("https://maven.reposilite.com/${if (version.toString().endsWith("-SNAPSHOT")) "snapshots" else "releases"}")
31 |
32 | credentials {
33 | username = getEnvOrProperty("MAVEN_NAME", "mavenUser")
34 | password = getEnvOrProperty("MAVEN_TOKEN", "mavenPassword")
35 | }
36 | }
37 | }
38 | }
39 |
40 | afterEvaluate {
41 | description
42 | ?.takeIf { it.isNotEmpty() }
43 | ?.split("|")
44 | ?.let { (projectName, projectDescription) ->
45 | publishing {
46 | publications {
47 | create("library") {
48 | pom {
49 | name.set(projectName)
50 | description.set(projectDescription)
51 | url.set("https://github.com/javalin/javalin-openapi")
52 |
53 | licenses {
54 | license {
55 | name.set("The Apache License, Version 2.0")
56 | url.set("https://www.apache.org/licenses/LICENSE-2.0.txt")
57 | }
58 | }
59 | developers {
60 | developer {
61 | id.set("dzikoysk")
62 | name.set("dzikoysk")
63 | email.set("dzikoysk@dzikoysk.net")
64 | }
65 | }
66 | scm {
67 | connection.set("scm:git:git://github.com/javalin/javalin-openapi.git")
68 | developerConnection.set("scm:git:ssh://github.com/javalin/javalin-openapi.git")
69 | url.set("https://github.com/javalin/javalin-openapi.git")
70 | }
71 | }
72 |
73 | from(components.getByName("java"))
74 | }
75 | }
76 | }
77 |
78 | if (findProperty("signing.keyId").takeIf { it != null && it.toString().trim().isNotEmpty() } != null) {
79 | signing {
80 | sign(publishing.publications.getByName("library"))
81 | }
82 | }
83 | }
84 | }
85 |
86 | java {
87 | withJavadocJar()
88 | withSourcesJar()
89 | }
90 |
91 | java {
92 | sourceCompatibility = JavaVersion.VERSION_11
93 | targetCompatibility = JavaVersion.VERSION_11
94 | }
95 |
96 | tasks.withType().configureEach {
97 | kotlinOptions {
98 | jvmTarget = "11"
99 | languageVersion = "1.8"
100 | freeCompilerArgs = listOf(
101 | "-Xjvm-default=all", // For generating default methods in interfaces
102 | // "-Xcontext-receivers"
103 | )
104 | }
105 | }
106 | }
107 |
108 | subprojects {
109 | apply(plugin = "application")
110 | apply(plugin = "org.jetbrains.kotlin.jvm")
111 |
112 | dependencies {
113 | val javalin = "6.6.0"
114 | compileOnly("io.javalin:javalin:$javalin")
115 | testImplementation("io.javalin:javalin:$javalin")
116 |
117 | val junit = "5.9.3"
118 | testImplementation("org.junit.jupiter:junit-jupiter-params:$junit")
119 | testImplementation("org.junit.jupiter:junit-jupiter-api:$junit")
120 | testImplementation("org.junit.jupiter:junit-jupiter-engine:$junit")
121 |
122 | testImplementation("org.assertj:assertj-core:3.24.2")
123 | testImplementation("net.javacrumbs.json-unit:json-unit-assertj:2.38.0")
124 | testImplementation("com.konghq:unirest-java:3.14.2")
125 |
126 | testImplementation("ch.qos.logback:logback-classic:1.4.14")
127 | }
128 |
129 | tasks.withType {
130 | useJUnitPlatform()
131 | }
132 | }
133 |
134 | nexusPublishing {
135 | repositories {
136 | sonatype {
137 | username.set(getEnvOrProperty("SONATYPE_USER", "sonatypeUser"))
138 | password.set(getEnvOrProperty("SONATYPE_PASSWORD", "sonatypePassword"))
139 | }
140 | }
141 | }
142 |
143 | fun getEnvOrProperty(env: String, property: String): String? =
144 | System.getenv(env) ?: findProperty(property)?.toString()
145 |
--------------------------------------------------------------------------------
/examples/README.md:
--------------------------------------------------------------------------------
1 | # Examples
2 |
3 |
--------------------------------------------------------------------------------
/examples/javalin-gradle-kotlin/build.gradle.kts:
--------------------------------------------------------------------------------
1 | import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
2 |
3 | plugins {
4 | kotlin("kapt")
5 | }
6 |
7 | java {
8 | sourceCompatibility = JavaVersion.VERSION_17
9 | targetCompatibility = JavaVersion.VERSION_17
10 | }
11 |
12 | tasks.withType().configureEach {
13 | kotlinOptions {
14 | jvmTarget = "17"
15 | languageVersion = "1.8"
16 | freeCompilerArgs = listOf("-Xjvm-default=all") // For generating default methods in interfaces
17 | }
18 | }
19 |
20 | sourceSets.getByName("main") {
21 | java.srcDir("src/main/kotlin")
22 | }
23 |
24 | dependencies {
25 | // declare lombok annotation processor as first
26 | val lombok = "1.18.28"
27 | compileOnly("org.projectlombok:lombok:$lombok")
28 | annotationProcessor("org.projectlombok:lombok:$lombok")
29 | testCompileOnly("org.projectlombok:lombok:$lombok")
30 | testAnnotationProcessor("org.projectlombok:lombok:$lombok")
31 | implementation("jakarta.validation:jakarta.validation-api:2.0.2")
32 |
33 | // then openapi annotation processor
34 | kapt(project(":openapi-annotation-processor"))
35 | implementation(project(":javalin-plugins:javalin-openapi-plugin"))
36 | implementation(project(":javalin-plugins:javalin-swagger-plugin"))
37 | implementation(project(":javalin-plugins:javalin-redoc-plugin"))
38 | testImplementation("org.apache.groovy:groovy:4.0.12")
39 |
40 | // javalin
41 | implementation("io.javalin:javalin:6.6.0")
42 | implementation("com.fasterxml.jackson.core:jackson-databind:2.18.1")
43 |
44 | // logging
45 | implementation("ch.qos.logback:logback-classic:1.4.14")
46 |
47 | // some test integrations
48 | implementation("org.mongodb:bson:4.9.1")
49 | }
50 |
51 | kapt {
52 | arguments {
53 | arg("openapi.info.title", "Awesome App")
54 | arg("openapi.info.version", "1.0.0")
55 | }
56 | }
57 |
58 | repositories {
59 | mavenCentral()
60 | }
61 |
--------------------------------------------------------------------------------
/examples/javalin-gradle-kotlin/src/main/compile/openapi.groovy:
--------------------------------------------------------------------------------
1 | import io.javalin.openapi.experimental.ExperimentalCompileOpenApiConfiguration
2 | import io.javalin.openapi.experimental.OpenApiAnnotationProcessorConfiguration
3 | import io.javalin.openapi.experimental.OpenApiAnnotationProcessorConfigurer
4 |
5 | @ExperimentalCompileOpenApiConfiguration
6 | class OpenApiConfiguration implements OpenApiAnnotationProcessorConfigurer {
7 |
8 | @Override
9 | void configure(OpenApiAnnotationProcessorConfiguration openApiAnnotationProcessorConfiguration) {
10 | // openApiAnnotationProcessorConfiguration.debug = true
11 | }
12 |
13 | }
--------------------------------------------------------------------------------
/examples/javalin-gradle-kotlin/src/main/kotlin/io/javalin/openapi/plugin/test/KotlinEntity.kt:
--------------------------------------------------------------------------------
1 | package io.javalin.openapi.plugin.test
2 |
3 | import io.javalin.openapi.CustomAnnotation
4 | import io.javalin.openapi.JsonSchema
5 | import io.javalin.openapi.OneOf
6 | import io.javalin.openapi.plugin.test.JavalinTest.Description
7 |
8 | @JsonSchema(
9 | generateResource = false,
10 | requireNonNulls = false
11 | )
12 | data class KotlinEntity(
13 | val name: String,
14 | val primitive: Int,
15 | val custom: Elements,
16 | val oneOfResult: Result,
17 | val nullable: Any?,
18 | )
19 |
20 | @JsonSchema(
21 | requireNonNulls = false
22 | )
23 | @Description(
24 | title = "Kotlin Scheme",
25 | description =
26 | """
27 | Example usage of custom annotation on Kotlin class
28 | """,
29 | statusCode = -1
30 | )
31 | data class KotlinScheme(
32 | @get:Description(title = "Value", description = "Int value", statusCode = 200)
33 | val value: Int,
34 | @get:OneOf(KotlinEntity::class)
35 | val any: Any,
36 | )
37 |
38 | @CustomAnnotation
39 | @Target(AnnotationTarget.PROPERTY_GETTER)
40 | annotation class CustomAnnotationInKotlinWithArray(
41 | val standard: String = "default",
42 | // should support arrays
43 | val value: Array = [],
44 | )
45 |
46 | @JsonSchema
47 | data class Elements(
48 | @get:CustomAnnotationInKotlinWithArray(value = ["a", "b"])
49 | val value: String
50 | )
51 |
52 | @OneOf(Ok::class, Error::class)
53 | sealed interface Result
54 | object Ok : Result
55 | object Error : Result
--------------------------------------------------------------------------------
/examples/javalin-gradle-kotlin/src/main/resources/logback.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | %d{HH:mm:ss.SSS} [%thread] %-5level %logger - %msg%n
5 |
6 |
7 |
8 |
9 |
10 |
11 |
--------------------------------------------------------------------------------
/examples/javalin-gradle-kotlin/src/main/resources/tinylog.properties:
--------------------------------------------------------------------------------
1 | writer = console
2 | writer.level = info
3 | writer.format = {date: HH:mm:ss.SSS} {level} | {message}
--------------------------------------------------------------------------------
/examples/javalin-maven-java/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 | 4.0.0
6 |
7 | io.javalin.community.openapi.examples
8 | javalin-apptest
9 | 1.0.0
10 |
11 |
12 | 11
13 | 11
14 | 6.6.0
15 | 6.6.0
16 |
17 |
18 |
19 |
20 | reposilite-repository
21 | https://maven.reposilite.com/snapshots
22 |
23 |
24 |
25 |
26 |
27 | io.javalin
28 | javalin
29 | ${javalin.version}
30 |
31 |
32 | io.javalin.community.openapi
33 | javalin-openapi-plugin
34 | ${javalin.openapi.version}
35 |
36 |
37 | io.javalin.community.openapi
38 | javalin-swagger-plugin
39 | ${javalin.openapi.version}
40 |
41 |
42 | io.javalin.community.openapi
43 | javalin-redoc-plugin
44 | ${javalin.openapi.version}
45 |
46 |
47 | org.webjars.npm
48 | redoc
49 | 2.0.0-rc.56
50 |
51 |
52 | *
53 | *
54 |
55 |
56 |
57 |
58 | org.tinylog
59 | tinylog-api
60 | 2.4.1
61 |
62 |
63 | org.tinylog
64 | tinylog-impl
65 | 2.4.1
66 |
67 |
68 | org.tinylog
69 | slf4j-tinylog
70 | 2.4.1
71 |
72 |
73 |
74 |
75 |
76 |
77 |
78 | org.apache.maven.plugins
79 | maven-compiler-plugin
80 | 3.10.1
81 |
82 |
83 |
84 | io.javalin.community.openapi
85 | openapi-annotation-processor
86 | ${javalin.openapi.version}
87 |
88 |
89 |
90 |
91 |
92 |
93 |
94 |
95 |
--------------------------------------------------------------------------------
/examples/javalin-maven-java/src/main/kotlin/io/javalin/openapi/plugin/test/KotlinEntity.kt:
--------------------------------------------------------------------------------
1 | package io.javalin.openapi.plugin.test
2 |
3 | data class KotlinEntity(
4 | val name: String,
5 | val value: Int
6 | )
--------------------------------------------------------------------------------
/examples/javalin-maven-java/src/main/resources/logback.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | %d{HH:mm:ss.SSS} [%thread] %-5level %logger - %msg%n
5 |
6 |
7 |
8 |
9 |
10 |
11 |
--------------------------------------------------------------------------------
/examples/javalin-maven-kotlin/.mvn/jvm.config:
--------------------------------------------------------------------------------
1 | --add-opens=java.base/java.lang=ALL-UNNAMED
2 | --add-opens=java.base/java.io=ALL-UNNAMED
--------------------------------------------------------------------------------
/examples/javalin-maven-kotlin/README.md:
--------------------------------------------------------------------------------
1 | # javalin-maven-kotlin
2 |
3 | This is a simple example of a Javalin application using Maven and Kotlin.
4 | In order to generate OpenAPI specification with Maven, run the following command:
5 |
6 | ```shell
7 | $ mvn clean compile
8 | ```
9 |
10 | Once the command is executed, the OpenAPI annotation processor will generate output files in the `target/classes/openapi-plugin` directory.
11 | These files will be picked up by the OpenAPI plugin and hosted at `http://localhost:8080/openapi`.
12 | You can also access the Swagger UI at `http://localhost:8080/swagger-ui`.
13 |
--------------------------------------------------------------------------------
/examples/javalin-maven-kotlin/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 | 4.0.0
6 |
7 | io.javalin.community.openapi.examples
8 | javalin-apptest
9 | 1.0.0
10 |
11 |
12 | 6.6.0
13 | 6.6.0
14 | 2.1.0
15 |
16 |
17 |
18 |
19 | reposilite-repository
20 | https://maven.reposilite.com/snapshots
21 |
22 |
23 |
24 |
25 |
26 | org.jetbrains.kotlin
27 | kotlin-stdlib
28 | ${kotlin.version}
29 |
30 |
31 |
32 | io.javalin
33 | javalin
34 | ${javalin.version}
35 |
36 |
37 | io.javalin.community.openapi
38 | javalin-openapi-plugin
39 | ${javalin.openapi.version}
40 |
41 |
42 | io.javalin.community.openapi
43 | javalin-swagger-plugin
44 | ${javalin.openapi.version}
45 |
46 |
47 | io.javalin.community.openapi
48 | javalin-redoc-plugin
49 | ${javalin.openapi.version}
50 |
51 |
52 | org.webjars.npm
53 | redoc
54 | 2.0.0-rc.56
55 |
56 |
57 | *
58 | *
59 |
60 |
61 |
62 |
63 |
64 | org.tinylog
65 | tinylog-api
66 | 2.4.1
67 |
68 |
69 | org.tinylog
70 | tinylog-impl
71 | 2.4.1
72 |
73 |
74 | org.tinylog
75 | slf4j-tinylog
76 | 2.4.1
77 |
78 |
79 |
80 |
81 |
82 |
83 |
84 | kotlin-maven-plugin
85 | org.jetbrains.kotlin
86 | 2.1.0
87 |
88 |
89 |
90 |
91 |
92 |
93 | org.jetbrains.kotlin
94 | kotlin-maven-plugin
95 | ${kotlin.version}
96 |
97 |
98 | kapt
99 |
100 | kapt
101 |
102 |
103 |
104 | src/main/kotlin
105 |
106 |
107 |
108 | io.javalin.community.openapi
109 | openapi-annotation-processor
110 | ${javalin.openapi.version}
111 |
112 |
113 |
114 |
115 |
116 | compile
117 | compile
118 |
119 | compile
120 |
121 |
122 |
123 |
124 |
125 |
126 |
127 |
--------------------------------------------------------------------------------
/examples/javalin-maven-kotlin/src/main/kotlin/io/javalin/openapi/plugin/test/KotlinTest.kt:
--------------------------------------------------------------------------------
1 | package io.javalin.openapi.plugin.test
2 |
3 | import io.javalin.Javalin
4 | import io.javalin.openapi.HttpMethod
5 | import io.javalin.openapi.OpenApi
6 | import io.javalin.openapi.plugin.OpenApiPlugin
7 | import io.javalin.openapi.plugin.swagger.SwaggerPlugin
8 |
9 | @OpenApi(
10 | description = "Test description",
11 | summary = "Test summary",
12 | tags = ["test-tag"],
13 | methods = [HttpMethod.GET],
14 | path = "/"
15 | )
16 | fun main() {
17 | Javalin.createAndStart { config ->
18 | config.registerPlugin(
19 | OpenApiPlugin {
20 | it.documentationPath = "/openapi"
21 | }
22 | )
23 |
24 | config.registerPlugin(
25 | SwaggerPlugin {
26 | it.uiPath = "/swagger"
27 | it.documentationPath = "/openapi"
28 | }
29 | )
30 | }
31 | }
--------------------------------------------------------------------------------
/examples/javalin-maven-kotlin/src/main/resources/logback.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | %d{HH:mm:ss.SSS} [%thread] %-5level %logger - %msg%n
5 |
6 |
7 |
8 |
9 |
10 |
11 |
--------------------------------------------------------------------------------
/gradle.properties:
--------------------------------------------------------------------------------
1 | # Gradle
2 | org.gradle.daemon=false
3 | org.gradle.parallel=false
4 | org.gradle.jvmargs=-Dfile.encoding=UTF-8
5 | org.gradle.logging.stacktrace=full
6 |
7 | # Kapt
8 | kapt.include.compile.classpath=false
9 | # kapt.incremental.apt=false
10 | # kapt.use.worker.api=false
11 |
12 | # Maven
13 | mavenUser=
14 | mavenPassword=
15 |
16 | # Sonatype
17 | sonatypeUser=
18 | sonatypePassword=
19 |
20 | # Sign
21 | signing.keyId=
22 | signing.password=
23 | signing.secretKeyRingFile=
24 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/javalin/javalin-openapi/5ae46dabcd883fc1f5ef40a3b832bf578cc0349b/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | distributionBase=GRADLE_USER_HOME
2 | distributionPath=wrapper/dists
3 | distributionUrl=https\://services.gradle.org/distributions/gradle-8.9-all.zip
4 | zipStoreBase=GRADLE_USER_HOME
5 | zipStorePath=wrapper/dists
--------------------------------------------------------------------------------
/gradlew:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env sh
2 |
3 | #
4 | # Copyright 2015 the original author or authors.
5 | #
6 | # Licensed under the Apache License, Version 2.0 (the "License");
7 | # you may not use this file except in compliance with the License.
8 | # You may obtain a copy of the License at
9 | #
10 | # https://www.apache.org/licenses/LICENSE-2.0
11 | #
12 | # Unless required by applicable law or agreed to in writing, software
13 | # distributed under the License is distributed on an "AS IS" BASIS,
14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | # See the License for the specific language governing permissions and
16 | # limitations under the License.
17 | #
18 |
19 | ##############################################################################
20 | ##
21 | ## Gradle start up script for UN*X
22 | ##
23 | ##############################################################################
24 |
25 | # Attempt to set APP_HOME
26 | # Resolve links: $0 may be a link
27 | PRG="$0"
28 | # Need this for relative symlinks.
29 | while [ -h "$PRG" ] ; do
30 | ls=`ls -ld "$PRG"`
31 | link=`expr "$ls" : '.*-> \(.*\)$'`
32 | if expr "$link" : '/.*' > /dev/null; then
33 | PRG="$link"
34 | else
35 | PRG=`dirname "$PRG"`"/$link"
36 | fi
37 | done
38 | SAVED="`pwd`"
39 | cd "`dirname \"$PRG\"`/" >/dev/null
40 | APP_HOME="`pwd -P`"
41 | cd "$SAVED" >/dev/null
42 |
43 | APP_NAME="Gradle"
44 | APP_BASE_NAME=`basename "$0"`
45 |
46 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
47 | DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
48 |
49 | # Use the maximum available, or set MAX_FD != -1 to use that value.
50 | MAX_FD="maximum"
51 |
52 | warn () {
53 | echo "$*"
54 | }
55 |
56 | die () {
57 | echo
58 | echo "$*"
59 | echo
60 | exit 1
61 | }
62 |
63 | # OS specific support (must be 'true' or 'false').
64 | cygwin=false
65 | msys=false
66 | darwin=false
67 | nonstop=false
68 | case "`uname`" in
69 | CYGWIN* )
70 | cygwin=true
71 | ;;
72 | Darwin* )
73 | darwin=true
74 | ;;
75 | MINGW* )
76 | msys=true
77 | ;;
78 | NONSTOP* )
79 | nonstop=true
80 | ;;
81 | esac
82 |
83 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
84 |
85 |
86 | # Determine the Java command to use to start the JVM.
87 | if [ -n "$JAVA_HOME" ] ; then
88 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
89 | # IBM's JDK on AIX uses strange locations for the executables
90 | JAVACMD="$JAVA_HOME/jre/sh/java"
91 | else
92 | JAVACMD="$JAVA_HOME/bin/java"
93 | fi
94 | if [ ! -x "$JAVACMD" ] ; then
95 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
96 |
97 | Please set the JAVA_HOME variable in your environment to match the
98 | location of your Java installation."
99 | fi
100 | else
101 | JAVACMD="java"
102 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
103 |
104 | Please set the JAVA_HOME variable in your environment to match the
105 | location of your Java installation."
106 | fi
107 |
108 | # Increase the maximum file descriptors if we can.
109 | if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then
110 | MAX_FD_LIMIT=`ulimit -H -n`
111 | if [ $? -eq 0 ] ; then
112 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
113 | MAX_FD="$MAX_FD_LIMIT"
114 | fi
115 | ulimit -n $MAX_FD
116 | if [ $? -ne 0 ] ; then
117 | warn "Could not set maximum file descriptor limit: $MAX_FD"
118 | fi
119 | else
120 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
121 | fi
122 | fi
123 |
124 | # For Darwin, add options to specify how the application appears in the dock
125 | if $darwin; then
126 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
127 | fi
128 |
129 | # For Cygwin or MSYS, switch paths to Windows format before running java
130 | if [ "$cygwin" = "true" -o "$msys" = "true" ] ; then
131 | APP_HOME=`cygpath --path --mixed "$APP_HOME"`
132 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
133 |
134 | JAVACMD=`cygpath --unix "$JAVACMD"`
135 |
136 | # We build the pattern for arguments to be converted via cygpath
137 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
138 | SEP=""
139 | for dir in $ROOTDIRSRAW ; do
140 | ROOTDIRS="$ROOTDIRS$SEP$dir"
141 | SEP="|"
142 | done
143 | OURCYGPATTERN="(^($ROOTDIRS))"
144 | # Add a user-defined pattern to the cygpath arguments
145 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then
146 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
147 | fi
148 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
149 | i=0
150 | for arg in "$@" ; do
151 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
152 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
153 |
154 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
155 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
156 | else
157 | eval `echo args$i`="\"$arg\""
158 | fi
159 | i=`expr $i + 1`
160 | done
161 | case $i in
162 | 0) set -- ;;
163 | 1) set -- "$args0" ;;
164 | 2) set -- "$args0" "$args1" ;;
165 | 3) set -- "$args0" "$args1" "$args2" ;;
166 | 4) set -- "$args0" "$args1" "$args2" "$args3" ;;
167 | 5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
168 | 6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
169 | 7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
170 | 8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
171 | 9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
172 | esac
173 | fi
174 |
175 | # Escape application args
176 | save () {
177 | for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done
178 | echo " "
179 | }
180 | APP_ARGS=`save "$@"`
181 |
182 | # Collect all arguments for the java command, following the shell quoting and substitution rules
183 | eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS"
184 |
185 | exec "$JAVACMD" "$@"
186 |
--------------------------------------------------------------------------------
/gradlew.bat:
--------------------------------------------------------------------------------
1 | @rem
2 | @rem Copyright 2015 the original author or authors.
3 | @rem
4 | @rem Licensed under the Apache License, Version 2.0 (the "License");
5 | @rem you may not use this file except in compliance with the License.
6 | @rem You may obtain a copy of the License at
7 | @rem
8 | @rem https://www.apache.org/licenses/LICENSE-2.0
9 | @rem
10 | @rem Unless required by applicable law or agreed to in writing, software
11 | @rem distributed under the License is distributed on an "AS IS" BASIS,
12 | @rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | @rem See the License for the specific language governing permissions and
14 | @rem limitations under the License.
15 | @rem
16 |
17 | @if "%DEBUG%" == "" @echo off
18 | @rem ##########################################################################
19 | @rem
20 | @rem Gradle startup script for Windows
21 | @rem
22 | @rem ##########################################################################
23 |
24 | @rem Set local scope for the variables with windows NT shell
25 | if "%OS%"=="Windows_NT" setlocal
26 |
27 | set DIRNAME=%~dp0
28 | if "%DIRNAME%" == "" set DIRNAME=.
29 | set APP_BASE_NAME=%~n0
30 | set APP_HOME=%DIRNAME%
31 |
32 | @rem Resolve any "." and ".." in APP_HOME to make it shorter.
33 | for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi
34 |
35 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
36 | set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m"
37 |
38 | @rem Find java.exe
39 | if defined JAVA_HOME goto findJavaFromJavaHome
40 |
41 | set JAVA_EXE=java.exe
42 | %JAVA_EXE% -version >NUL 2>&1
43 | if "%ERRORLEVEL%" == "0" goto execute
44 |
45 | echo.
46 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
47 | echo.
48 | echo Please set the JAVA_HOME variable in your environment to match the
49 | echo location of your Java installation.
50 |
51 | goto fail
52 |
53 | :findJavaFromJavaHome
54 | set JAVA_HOME=%JAVA_HOME:"=%
55 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe
56 |
57 | if exist "%JAVA_EXE%" goto execute
58 |
59 | echo.
60 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
61 | echo.
62 | echo Please set the JAVA_HOME variable in your environment to match the
63 | echo location of your Java installation.
64 |
65 | goto fail
66 |
67 | :execute
68 | @rem Setup the command line
69 |
70 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
71 |
72 |
73 | @rem Execute Gradle
74 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %*
75 |
76 | :end
77 | @rem End local scope for the variables with windows NT shell
78 | if "%ERRORLEVEL%"=="0" goto mainEnd
79 |
80 | :fail
81 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
82 | rem the _cmd.exe /c_ return code!
83 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
84 | exit /b 1
85 |
86 | :mainEnd
87 | if "%OS%"=="Windows_NT" endlocal
88 |
89 | :omega
90 |
--------------------------------------------------------------------------------
/javalin-plugins/javalin-openapi-plugin/build.gradle.kts:
--------------------------------------------------------------------------------
1 | description = "Javalin OpenAPI Plugin | Serve raw OpenApi documentation under dedicated endpoint"
2 |
3 | plugins {
4 | kotlin("kapt")
5 | }
6 |
7 | dependencies {
8 | api(project(":openapi-specification"))
9 |
10 | kaptTest(project(":openapi-annotation-processor"))
11 | }
12 |
--------------------------------------------------------------------------------
/javalin-plugins/javalin-openapi-plugin/src/main/kotlin/io/javalin/openapi/plugin/OpenApiConfiguration.kt:
--------------------------------------------------------------------------------
1 | @file:Suppress("MemberVisibilityCanBePrivate")
2 |
3 | package io.javalin.openapi.plugin
4 |
5 | import com.fasterxml.jackson.databind.node.ObjectNode
6 | import io.javalin.openapi.ApiKeyAuth
7 | import io.javalin.openapi.BasicAuth
8 | import io.javalin.openapi.BearerAuth
9 | import io.javalin.openapi.CookieAuth
10 | import io.javalin.openapi.OAuth2
11 | import io.javalin.openapi.OpenApiInfo
12 | import io.javalin.openapi.OpenApiServer
13 | import io.javalin.openapi.OpenID
14 | import io.javalin.openapi.Security
15 | import io.javalin.openapi.SecurityScheme
16 | import io.javalin.security.RouteRole
17 | import java.util.function.BiConsumer
18 | import java.util.function.Consumer
19 |
20 | /** Configure OpenApi plugin */
21 | class OpenApiPluginConfiguration @JvmOverloads constructor(
22 | @JvmField var documentationPath: String = "/openapi",
23 | @JvmField var roles: List? = null,
24 | @JvmField var prettyOutputEnabled: Boolean = true,
25 | @JvmField var definitionConfiguration: BiConsumer? = null
26 | ) {
27 |
28 | /** Path to host documentation as JSON */
29 | fun withDocumentationPath(path: String): OpenApiPluginConfiguration = also {
30 | this.documentationPath = path
31 | }
32 |
33 | /** List of roles eligible to access OpenApi routes */
34 | fun withRoles(vararg roles: RouteRole): OpenApiPluginConfiguration = also {
35 | this.roles = roles.toList()
36 | }
37 |
38 | /** Path to host documentation as JSON */
39 | @JvmOverloads
40 | fun withPrettyOutput(enabled: Boolean = true): OpenApiPluginConfiguration = also {
41 | this.prettyOutputEnabled = enabled
42 | }
43 |
44 | /* Dynamically apply custom changes to generated OpenApi specifications */
45 | fun withDefinitionConfiguration(definitionConfigurationConfigurer: BiConsumer): OpenApiPluginConfiguration = also {
46 | definitionConfiguration = definitionConfigurationConfigurer
47 | }
48 |
49 | }
50 |
51 | /** Modify OpenApi documentation represented by [ObjectNode] in JSON format */
52 | fun interface DefinitionProcessor {
53 | fun process(content: ObjectNode): String
54 | }
55 |
56 | class DefinitionConfiguration @JvmOverloads constructor(
57 | @JvmField @JvmSynthetic internal var info: OpenApiInfo? = null,
58 | @JvmField @JvmSynthetic internal var servers: MutableList = mutableListOf(),
59 | @JvmField @JvmSynthetic internal var security: SecurityComponentConfiguration? = null,
60 | @JvmField @JvmSynthetic internal var definitionProcessor: DefinitionProcessor? = null
61 | ) {
62 |
63 | /** Define custom info object */
64 | fun withInfo(openApiInfo: Consumer): DefinitionConfiguration = also {
65 | this.info = OpenApiInfo().also { openApiInfo.accept(it) }
66 | }
67 |
68 | @Deprecated("Use withInfo instead", ReplaceWith("withInfo(openApiInfo)"))
69 | fun withOpenApiInfo(openApiInfo: Consumer): DefinitionConfiguration =
70 | withInfo(openApiInfo)
71 |
72 | /** Add custom server **/
73 | fun withServer(server: OpenApiServer): DefinitionConfiguration = also {
74 | this.servers.add(server)
75 | }
76 |
77 | /** Add custom server **/
78 | fun withServer(serverConfigurer: Consumer): DefinitionConfiguration = also {
79 | this.servers.add(OpenApiServer().also { serverConfigurer.accept(it) })
80 | }
81 |
82 | /** Define custom security object */
83 | fun withSecurity(securityConfigurer: Consumer): DefinitionConfiguration = also {
84 | SecurityComponentConfiguration()
85 | .also { securityConfigurer.accept(it) }
86 | .let { withSecurity(it) }
87 | }
88 |
89 | /** Define custom security object */
90 | fun withSecurity(securityConfiguration: SecurityComponentConfiguration): DefinitionConfiguration = also {
91 | this.security = securityConfiguration
92 | }
93 |
94 | /** Register scheme processor */
95 | fun withDefinitionProcessor(definitionProcessor: DefinitionProcessor): DefinitionConfiguration = also {
96 | this.definitionProcessor = definitionProcessor
97 | }
98 |
99 | }
100 |
101 | class SecurityComponentConfiguration @JvmOverloads constructor(
102 | @JvmField @JvmSynthetic internal val securitySchemes: MutableMap = mutableMapOf(),
103 | @JvmField @JvmSynthetic internal val globalSecurity: MutableList = mutableListOf()
104 | ) {
105 |
106 | fun withSecurityScheme(schemeName: String, securityScheme: SecurityScheme): SecurityComponentConfiguration = also {
107 | securitySchemes[schemeName] = securityScheme
108 | }
109 |
110 | @JvmOverloads
111 | fun withBasicAuth(schemeName: String = "BasicAuth", securityScheme: Consumer = Consumer {}): SecurityComponentConfiguration =
112 | withSecurityScheme(schemeName, BasicAuth().also { securityScheme.accept(it) })
113 |
114 | @JvmOverloads
115 | fun withBearerAuth(schemeName: String = "BearerAuth", securityScheme: Consumer = Consumer {}): SecurityComponentConfiguration =
116 | withSecurityScheme(schemeName, BearerAuth().also { securityScheme.accept(it) })
117 |
118 | @JvmOverloads
119 | fun withApiKeyAuth(schemeName: String = "ApiKeyAuth", apiKeyHeader: String = "X-Api-Key", securityScheme: Consumer = Consumer {}): SecurityComponentConfiguration =
120 | withSecurityScheme(schemeName, ApiKeyAuth(name = apiKeyHeader).also { securityScheme.accept(it) })
121 |
122 | @JvmOverloads
123 | fun withCookieAuth(schemeName: String = "CookieAuth", sessionCookie: String = "JSESSIONID", securityScheme: Consumer = Consumer {}): SecurityComponentConfiguration =
124 | withSecurityScheme(schemeName, CookieAuth(name = sessionCookie).also { securityScheme.accept(it) })
125 |
126 | @JvmOverloads
127 | fun withOpenID(schemeName: String, openIdConnectUrl: String, securityScheme: Consumer = Consumer {}): SecurityComponentConfiguration =
128 | withSecurityScheme(schemeName, OpenID(openIdConnectUrl = openIdConnectUrl).also { securityScheme.accept(it) })
129 |
130 | @JvmOverloads
131 | fun withOAuth2(schemeName: String, description: String, securityScheme: Consumer = Consumer {}): SecurityComponentConfiguration =
132 | withSecurityScheme(schemeName, OAuth2(description = description).also { securityScheme.accept(it) })
133 |
134 | fun withGlobalSecurity(security: Security): SecurityComponentConfiguration = also {
135 | globalSecurity.add(security)
136 | }
137 |
138 | @JvmOverloads
139 | fun withGlobalSecurity(name: String, security: Consumer = Consumer {}): SecurityComponentConfiguration =
140 | withGlobalSecurity(Security(name = name).also { security.accept(it) })
141 |
142 | }
--------------------------------------------------------------------------------
/javalin-plugins/javalin-openapi-plugin/src/main/kotlin/io/javalin/openapi/plugin/OpenApiHandler.kt:
--------------------------------------------------------------------------------
1 | package io.javalin.openapi.plugin
2 |
3 | import io.javalin.http.ContentType
4 | import io.javalin.http.Context
5 | import io.javalin.http.Handler
6 | import io.javalin.http.Header
7 |
8 | internal class OpenApiHandler(private val documentation: Lazy