├── .gitignore ├── docs ├── _config.yml └── index.md ├── multi-modules ├── .gradle │ ├── 7.4.2 │ │ ├── checksums │ │ │ ├── checksums.lock │ │ │ ├── md5-checksums.bin │ │ │ └── sha1-checksums.bin │ │ ├── dependencies-accessors │ │ │ ├── dependencies-accessors.lock │ │ │ └── gc.properties │ │ ├── executionHistory │ │ │ ├── executionHistory.bin │ │ │ └── executionHistory.lock │ │ ├── fileChanges │ │ │ └── last-build.bin │ │ ├── fileHashes │ │ │ ├── fileHashes.bin │ │ │ ├── fileHashes.lock │ │ │ └── resourceHashesCache.bin │ │ └── gc.properties │ ├── buildOutputCleanup │ │ ├── buildOutputCleanup.lock │ │ ├── cache.properties │ │ └── outputFiles.bin │ ├── checksums │ │ └── checksums.lock │ ├── file-system.probe │ └── vcs-1 │ │ └── gc.properties ├── buildSrc │ ├── .gradle │ │ ├── 7.4.2 │ │ │ ├── checksums │ │ │ │ ├── checksums.lock │ │ │ │ ├── md5-checksums.bin │ │ │ │ └── sha1-checksums.bin │ │ │ ├── dependencies-accessors │ │ │ │ ├── dependencies-accessors.lock │ │ │ │ └── gc.properties │ │ │ ├── executionHistory │ │ │ │ ├── executionHistory.bin │ │ │ │ └── executionHistory.lock │ │ │ ├── fileChanges │ │ │ │ └── last-build.bin │ │ │ ├── fileHashes │ │ │ │ └── fileHashes.lock │ │ │ └── gc.properties │ │ ├── buildOutputCleanup │ │ │ ├── buildOutputCleanup.lock │ │ │ ├── cache.properties │ │ │ └── outputFiles.bin │ │ ├── file-system.probe │ │ ├── noVersion │ │ │ └── buildSrc.lock │ │ └── vcs-1 │ │ │ └── gc.properties │ ├── build.gradle │ └── src │ │ └── main │ │ └── groovy │ │ ├── multimodule-config.gradle │ │ └── spring-conventions.gradle ├── gradle │ └── wrapper │ │ ├── gradle-wrapper.jar │ │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── implementation-A │ ├── build.gradle │ └── src │ │ └── main │ │ └── java │ │ └── com │ │ └── tmsvr │ │ └── partnera │ │ └── PartnerAResultProvider.java ├── implementation-B │ ├── build.gradle │ └── src │ │ └── main │ │ └── java │ │ └── com │ │ └── tmsvr │ │ └── partnerb │ │ └── PartnerBResultProvider.java ├── interface │ ├── build.gradle │ └── src │ │ └── main │ │ └── java │ │ └── com │ │ └── tmsvr │ │ └── common │ │ ├── Result.java │ │ └── ResultProvider.java ├── service │ ├── build.gradle │ └── src │ │ └── main │ │ └── java │ │ └── com │ │ └── tmsvr │ │ └── Service.java └── settings.gradle ├── oauth-demo ├── .gitignore ├── README.md ├── build.gradle ├── gradle │ └── wrapper │ │ ├── gradle-wrapper.jar │ │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── settings.gradle └── src │ ├── main │ ├── java │ │ └── com │ │ │ └── tmsvr │ │ │ └── oauthdemo │ │ │ ├── OauthDemoApplication.java │ │ │ ├── config │ │ │ └── OAuthConfig.java │ │ │ ├── persistence │ │ │ ├── InMemoryTokenRepository.java │ │ │ ├── Token.java │ │ │ └── TokenRepository.java │ │ │ ├── rest │ │ │ ├── AuthorizationController.java │ │ │ └── FinishAuthRequest.java │ │ │ └── service │ │ │ ├── AuthorizationService.java │ │ │ └── TokenResponse.java │ └── resources │ │ └── application.yml │ └── test │ └── java │ └── com │ └── tmsvr │ └── oauthdemo │ └── OauthDemoApplicationTests.java ├── openapi-demo ├── README.md ├── build.gradle ├── gradle │ └── wrapper │ │ ├── gradle-wrapper.jar │ │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── petstore.yml ├── settings.gradle ├── src │ └── main │ │ ├── java │ │ └── com │ │ │ └── tmsvr │ │ │ └── openapidemo │ │ │ ├── OpenapiDemoApplication.java │ │ │ ├── configuration │ │ │ └── RestTemplateConfig.java │ │ │ ├── controllers │ │ │ └── PetStoreController.java │ │ │ └── service │ │ │ └── UuidService.java │ │ └── resources │ │ └── application.yml └── uuid.yml └── react-choropleth-map ├── .gitignore ├── README.md ├── package-lock.json ├── package.json ├── public ├── favicon.ico ├── index.html ├── logo192.png ├── logo512.png ├── manifest.json └── robots.txt └── src ├── ChoroplethMap.jsx ├── DataScopeSelector.jsx ├── InfoBox.jsx ├── custom.geo.50.json ├── index.css ├── index.js └── infobox.css /.gitignore: -------------------------------------------------------------------------------- 1 | .idea 2 | .build 3 | *.iws 4 | *.iml 5 | *.ipr 6 | 7 | -------------------------------------------------------------------------------- /docs/_config.yml: -------------------------------------------------------------------------------- 1 | theme: jekyll-theme-architect -------------------------------------------------------------------------------- /docs/index.md: -------------------------------------------------------------------------------- 1 | # TMSVR Blog code examples 2 | 3 | This page is about the code examples created for my blog [TMSVR.com](https://tmsvr.com). 4 | 5 | ## React leaflet interactive map examples 6 | 7 | One topic is the Interactive leaflet map that I have created in React to learn these new technologies. This experimenting later turned into a side-project called [AtlasNinja](https://atlasninja.com). There are 2 articles on my blog about the technical aspects of creating an interactive amp in React using Leaflet: 8 | 9 | - [Making an interactive map with React and Leaflet](https://tmsvr.com/making-an-interactive-map-with-react-and-leaflet/) 10 | - [React interactive choropleth map - Part 2](https://tmsvr.com/react-leaflet-map-performance-issues/) 11 | 12 | There are code examples for these articles in my git repo here: https://github.com/Timester/tmsvr-blog/tree/master/react-choropleth-map 13 | 14 | And a third one is about the AtlasNinja project, whic is a website providing factual information about countries ina modern clean design. 15 | 16 | - [Introducing a new app, AtlasNinja](https://tmsvr.com/introducing-a-new-app-atlasninja/) 17 | - [AtlasNinja](https://atlasninja.com) 18 | 19 | ## Spring Boot OAuth handling 20 | 21 | The first topic I have covered was the OAuth protocol and implementing OAuth based functions in Spring Boot with Java. 22 | 23 | - [OAuth 2.0 - A practical intro](https://tmsvr.com/oauth-2-practical-intro/) 24 | - [OAuth 2.0 - Implementing a client](https://tmsvr.com/oauth-2-client-implementation/) 25 | - [OAuth 2.0 - Token management](https://tmsvr.com/oauth-2-0-token-management/) 26 | 27 | The code examples for these articles can be found here: https://github.com/Timester/tmsvr-blog/tree/master/oauth-demo 28 | -------------------------------------------------------------------------------- /multi-modules/.gradle/7.4.2/checksums/checksums.lock: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tmsvr/tmsvr-blog/e5197548705ca360a2ac9616405e51201cae6cf3/multi-modules/.gradle/7.4.2/checksums/checksums.lock -------------------------------------------------------------------------------- /multi-modules/.gradle/7.4.2/checksums/md5-checksums.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tmsvr/tmsvr-blog/e5197548705ca360a2ac9616405e51201cae6cf3/multi-modules/.gradle/7.4.2/checksums/md5-checksums.bin -------------------------------------------------------------------------------- /multi-modules/.gradle/7.4.2/checksums/sha1-checksums.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tmsvr/tmsvr-blog/e5197548705ca360a2ac9616405e51201cae6cf3/multi-modules/.gradle/7.4.2/checksums/sha1-checksums.bin -------------------------------------------------------------------------------- /multi-modules/.gradle/7.4.2/dependencies-accessors/dependencies-accessors.lock: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tmsvr/tmsvr-blog/e5197548705ca360a2ac9616405e51201cae6cf3/multi-modules/.gradle/7.4.2/dependencies-accessors/dependencies-accessors.lock -------------------------------------------------------------------------------- /multi-modules/.gradle/7.4.2/dependencies-accessors/gc.properties: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tmsvr/tmsvr-blog/e5197548705ca360a2ac9616405e51201cae6cf3/multi-modules/.gradle/7.4.2/dependencies-accessors/gc.properties -------------------------------------------------------------------------------- /multi-modules/.gradle/7.4.2/executionHistory/executionHistory.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tmsvr/tmsvr-blog/e5197548705ca360a2ac9616405e51201cae6cf3/multi-modules/.gradle/7.4.2/executionHistory/executionHistory.bin -------------------------------------------------------------------------------- /multi-modules/.gradle/7.4.2/executionHistory/executionHistory.lock: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tmsvr/tmsvr-blog/e5197548705ca360a2ac9616405e51201cae6cf3/multi-modules/.gradle/7.4.2/executionHistory/executionHistory.lock -------------------------------------------------------------------------------- /multi-modules/.gradle/7.4.2/fileChanges/last-build.bin: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /multi-modules/.gradle/7.4.2/fileHashes/fileHashes.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tmsvr/tmsvr-blog/e5197548705ca360a2ac9616405e51201cae6cf3/multi-modules/.gradle/7.4.2/fileHashes/fileHashes.bin -------------------------------------------------------------------------------- /multi-modules/.gradle/7.4.2/fileHashes/fileHashes.lock: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tmsvr/tmsvr-blog/e5197548705ca360a2ac9616405e51201cae6cf3/multi-modules/.gradle/7.4.2/fileHashes/fileHashes.lock -------------------------------------------------------------------------------- /multi-modules/.gradle/7.4.2/fileHashes/resourceHashesCache.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tmsvr/tmsvr-blog/e5197548705ca360a2ac9616405e51201cae6cf3/multi-modules/.gradle/7.4.2/fileHashes/resourceHashesCache.bin -------------------------------------------------------------------------------- /multi-modules/.gradle/7.4.2/gc.properties: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tmsvr/tmsvr-blog/e5197548705ca360a2ac9616405e51201cae6cf3/multi-modules/.gradle/7.4.2/gc.properties -------------------------------------------------------------------------------- /multi-modules/.gradle/buildOutputCleanup/buildOutputCleanup.lock: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tmsvr/tmsvr-blog/e5197548705ca360a2ac9616405e51201cae6cf3/multi-modules/.gradle/buildOutputCleanup/buildOutputCleanup.lock -------------------------------------------------------------------------------- /multi-modules/.gradle/buildOutputCleanup/cache.properties: -------------------------------------------------------------------------------- 1 | #Sun May 22 16:27:59 CEST 2022 2 | gradle.version=7.4.2 3 | -------------------------------------------------------------------------------- /multi-modules/.gradle/buildOutputCleanup/outputFiles.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tmsvr/tmsvr-blog/e5197548705ca360a2ac9616405e51201cae6cf3/multi-modules/.gradle/buildOutputCleanup/outputFiles.bin -------------------------------------------------------------------------------- /multi-modules/.gradle/checksums/checksums.lock: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tmsvr/tmsvr-blog/e5197548705ca360a2ac9616405e51201cae6cf3/multi-modules/.gradle/checksums/checksums.lock -------------------------------------------------------------------------------- /multi-modules/.gradle/file-system.probe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tmsvr/tmsvr-blog/e5197548705ca360a2ac9616405e51201cae6cf3/multi-modules/.gradle/file-system.probe -------------------------------------------------------------------------------- /multi-modules/.gradle/vcs-1/gc.properties: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tmsvr/tmsvr-blog/e5197548705ca360a2ac9616405e51201cae6cf3/multi-modules/.gradle/vcs-1/gc.properties -------------------------------------------------------------------------------- /multi-modules/buildSrc/.gradle/7.4.2/checksums/checksums.lock: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tmsvr/tmsvr-blog/e5197548705ca360a2ac9616405e51201cae6cf3/multi-modules/buildSrc/.gradle/7.4.2/checksums/checksums.lock -------------------------------------------------------------------------------- /multi-modules/buildSrc/.gradle/7.4.2/checksums/md5-checksums.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tmsvr/tmsvr-blog/e5197548705ca360a2ac9616405e51201cae6cf3/multi-modules/buildSrc/.gradle/7.4.2/checksums/md5-checksums.bin -------------------------------------------------------------------------------- /multi-modules/buildSrc/.gradle/7.4.2/checksums/sha1-checksums.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tmsvr/tmsvr-blog/e5197548705ca360a2ac9616405e51201cae6cf3/multi-modules/buildSrc/.gradle/7.4.2/checksums/sha1-checksums.bin -------------------------------------------------------------------------------- /multi-modules/buildSrc/.gradle/7.4.2/dependencies-accessors/dependencies-accessors.lock: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tmsvr/tmsvr-blog/e5197548705ca360a2ac9616405e51201cae6cf3/multi-modules/buildSrc/.gradle/7.4.2/dependencies-accessors/dependencies-accessors.lock -------------------------------------------------------------------------------- /multi-modules/buildSrc/.gradle/7.4.2/dependencies-accessors/gc.properties: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tmsvr/tmsvr-blog/e5197548705ca360a2ac9616405e51201cae6cf3/multi-modules/buildSrc/.gradle/7.4.2/dependencies-accessors/gc.properties -------------------------------------------------------------------------------- /multi-modules/buildSrc/.gradle/7.4.2/executionHistory/executionHistory.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tmsvr/tmsvr-blog/e5197548705ca360a2ac9616405e51201cae6cf3/multi-modules/buildSrc/.gradle/7.4.2/executionHistory/executionHistory.bin -------------------------------------------------------------------------------- /multi-modules/buildSrc/.gradle/7.4.2/executionHistory/executionHistory.lock: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tmsvr/tmsvr-blog/e5197548705ca360a2ac9616405e51201cae6cf3/multi-modules/buildSrc/.gradle/7.4.2/executionHistory/executionHistory.lock -------------------------------------------------------------------------------- /multi-modules/buildSrc/.gradle/7.4.2/fileChanges/last-build.bin: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /multi-modules/buildSrc/.gradle/7.4.2/fileHashes/fileHashes.lock: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tmsvr/tmsvr-blog/e5197548705ca360a2ac9616405e51201cae6cf3/multi-modules/buildSrc/.gradle/7.4.2/fileHashes/fileHashes.lock -------------------------------------------------------------------------------- /multi-modules/buildSrc/.gradle/7.4.2/gc.properties: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tmsvr/tmsvr-blog/e5197548705ca360a2ac9616405e51201cae6cf3/multi-modules/buildSrc/.gradle/7.4.2/gc.properties -------------------------------------------------------------------------------- /multi-modules/buildSrc/.gradle/buildOutputCleanup/buildOutputCleanup.lock: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tmsvr/tmsvr-blog/e5197548705ca360a2ac9616405e51201cae6cf3/multi-modules/buildSrc/.gradle/buildOutputCleanup/buildOutputCleanup.lock -------------------------------------------------------------------------------- /multi-modules/buildSrc/.gradle/buildOutputCleanup/cache.properties: -------------------------------------------------------------------------------- 1 | #Sun May 22 16:32:28 CEST 2022 2 | gradle.version=7.4.2 3 | -------------------------------------------------------------------------------- /multi-modules/buildSrc/.gradle/buildOutputCleanup/outputFiles.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tmsvr/tmsvr-blog/e5197548705ca360a2ac9616405e51201cae6cf3/multi-modules/buildSrc/.gradle/buildOutputCleanup/outputFiles.bin -------------------------------------------------------------------------------- /multi-modules/buildSrc/.gradle/file-system.probe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tmsvr/tmsvr-blog/e5197548705ca360a2ac9616405e51201cae6cf3/multi-modules/buildSrc/.gradle/file-system.probe -------------------------------------------------------------------------------- /multi-modules/buildSrc/.gradle/noVersion/buildSrc.lock: -------------------------------------------------------------------------------- 1 |  -------------------------------------------------------------------------------- /multi-modules/buildSrc/.gradle/vcs-1/gc.properties: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tmsvr/tmsvr-blog/e5197548705ca360a2ac9616405e51201cae6cf3/multi-modules/buildSrc/.gradle/vcs-1/gc.properties -------------------------------------------------------------------------------- /multi-modules/buildSrc/build.gradle: -------------------------------------------------------------------------------- 1 | plugins { 2 | id 'groovy-gradle-plugin' 3 | } 4 | 5 | repositories { 6 | mavenCentral() 7 | } 8 | 9 | dependencies { 10 | implementation 'org.springframework.boot:spring-boot-gradle-plugin:2.7.0' 11 | } 12 | -------------------------------------------------------------------------------- /multi-modules/buildSrc/src/main/groovy/multimodule-config.gradle: -------------------------------------------------------------------------------- 1 | plugins { 2 | id 'java' 3 | } 4 | 5 | sourceCompatibility = JavaVersion.VERSION_17 6 | targetCompatibility = JavaVersion.VERSION_17 7 | 8 | repositories { 9 | mavenCentral() 10 | } 11 | 12 | test { 13 | useJUnitPlatform() 14 | } 15 | 16 | dependencies { 17 | compileOnly 'org.projectlombok:lombok:1.18.24' 18 | annotationProcessor 'org.projectlombok:lombok:1.18.24' 19 | 20 | implementation 'ch.qos.logback:logback-classic:1.2.11' 21 | 22 | } -------------------------------------------------------------------------------- /multi-modules/buildSrc/src/main/groovy/spring-conventions.gradle: -------------------------------------------------------------------------------- 1 | plugins { 2 | id 'org.springframework.boot' 3 | } 4 | 5 | dependencies { 6 | implementation platform(org.springframework.boot.gradle.plugin.SpringBootPlugin.BOM_COORDINATES) 7 | implementation 'org.springframework.boot:spring-boot-starter' 8 | } 9 | -------------------------------------------------------------------------------- /multi-modules/gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tmsvr/tmsvr-blog/e5197548705ca360a2ac9616405e51201cae6cf3/multi-modules/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /multi-modules/gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionBase=GRADLE_USER_HOME 2 | distributionPath=wrapper/dists 3 | distributionUrl=https\://services.gradle.org/distributions/gradle-7.4.2-bin.zip 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | -------------------------------------------------------------------------------- /multi-modules/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 | MSYS* | 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 | -------------------------------------------------------------------------------- /multi-modules/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 | -------------------------------------------------------------------------------- /multi-modules/implementation-A/build.gradle: -------------------------------------------------------------------------------- 1 | plugins { 2 | id 'multimodule-config' 3 | } 4 | 5 | dependencies { 6 | implementation project(":interface") 7 | } -------------------------------------------------------------------------------- /multi-modules/implementation-A/src/main/java/com/tmsvr/partnera/PartnerAResultProvider.java: -------------------------------------------------------------------------------- 1 | package com.tmsvr.partnera; 2 | 3 | import com.tmsvr.common.Result; 4 | import com.tmsvr.common.ResultProvider; 5 | import lombok.extern.slf4j.Slf4j; 6 | 7 | @Slf4j 8 | public class PartnerAResultProvider implements ResultProvider { 9 | @Override 10 | public Result getResult() { 11 | log.info("Partner A implementation working."); 12 | return new Result(1, "From partner A"); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /multi-modules/implementation-B/build.gradle: -------------------------------------------------------------------------------- 1 | plugins { 2 | id 'multimodule-config' 3 | } 4 | 5 | dependencies { 6 | implementation project(":interface") 7 | } 8 | -------------------------------------------------------------------------------- /multi-modules/implementation-B/src/main/java/com/tmsvr/partnerb/PartnerBResultProvider.java: -------------------------------------------------------------------------------- 1 | package com.tmsvr.partnerb; 2 | 3 | import com.tmsvr.common.Result; 4 | import com.tmsvr.common.ResultProvider; 5 | import lombok.extern.slf4j.Slf4j; 6 | 7 | @Slf4j 8 | public class PartnerBResultProvider implements ResultProvider { 9 | @Override 10 | public Result getResult() { 11 | log.info("Partner B implementation working."); 12 | return new Result(2, "From partner B"); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /multi-modules/interface/build.gradle: -------------------------------------------------------------------------------- 1 | plugins { 2 | id 'java' 3 | } 4 | -------------------------------------------------------------------------------- /multi-modules/interface/src/main/java/com/tmsvr/common/Result.java: -------------------------------------------------------------------------------- 1 | package com.tmsvr.common; 2 | 3 | public record Result(int a, String code) {} 4 | -------------------------------------------------------------------------------- /multi-modules/interface/src/main/java/com/tmsvr/common/ResultProvider.java: -------------------------------------------------------------------------------- 1 | package com.tmsvr.common; 2 | 3 | public interface ResultProvider { 4 | Result getResult(); 5 | } 6 | -------------------------------------------------------------------------------- /multi-modules/service/build.gradle: -------------------------------------------------------------------------------- 1 | plugins { 2 | id 'multimodule-config' 3 | id 'spring-conventions' 4 | } 5 | 6 | dependencies { 7 | implementation project(":interface") 8 | implementation project(":implementation-A") 9 | implementation project(":implementation-B") 10 | } 11 | 12 | -------------------------------------------------------------------------------- /multi-modules/service/src/main/java/com/tmsvr/Service.java: -------------------------------------------------------------------------------- 1 | package com.tmsvr; 2 | 3 | import com.tmsvr.common.ResultProvider; 4 | import com.tmsvr.partnera.PartnerAResultProvider; 5 | import com.tmsvr.partnerb.PartnerBResultProvider; 6 | import lombok.extern.slf4j.Slf4j; 7 | import org.springframework.boot.CommandLineRunner; 8 | import org.springframework.boot.SpringApplication; 9 | import org.springframework.boot.autoconfigure.SpringBootApplication; 10 | 11 | @Slf4j 12 | @SpringBootApplication 13 | public class Service implements CommandLineRunner { 14 | 15 | public static void main(String[] args) { 16 | SpringApplication.run(Service.class, args); 17 | } 18 | 19 | @Override 20 | public void run(String... args) { 21 | ResultProvider partnerA = new PartnerAResultProvider(); 22 | ResultProvider partnerB = new PartnerBResultProvider(); 23 | 24 | log.info(partnerA.getResult().code()); 25 | log.info(partnerB.getResult().code()); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /multi-modules/settings.gradle: -------------------------------------------------------------------------------- 1 | rootProject.name = 'multi-modules' 2 | 3 | include 'interface' 4 | include 'service' 5 | include 'implementation-A' 6 | include 'implementation-B' 7 | 8 | 9 | -------------------------------------------------------------------------------- /oauth-demo/.gitignore: -------------------------------------------------------------------------------- 1 | HELP.md 2 | .gradle 3 | build/ 4 | !gradle/wrapper/gradle-wrapper.jar 5 | !**/src/main/**/build/ 6 | !**/src/test/**/build/ 7 | 8 | ### STS ### 9 | .apt_generated 10 | .classpath 11 | .factorypath 12 | .project 13 | .settings 14 | .springBeans 15 | .sts4-cache 16 | bin/ 17 | !**/src/main/**/bin/ 18 | !**/src/test/**/bin/ 19 | 20 | ### IntelliJ IDEA ### 21 | .idea 22 | *.iws 23 | *.iml 24 | *.ipr 25 | out/ 26 | !**/src/main/**/out/ 27 | !**/src/test/**/out/ 28 | 29 | ### NetBeans ### 30 | /nbproject/private/ 31 | /nbbuild/ 32 | /dist/ 33 | /nbdist/ 34 | /.nb-gradle/ 35 | 36 | ### VS Code ### 37 | .vscode/ 38 | -------------------------------------------------------------------------------- /oauth-demo/README.md: -------------------------------------------------------------------------------- 1 | # OAuth 2.0 demo 2 | 3 | 1. Set up the config in `application.yml` 4 | 2. Start the app, call the endpoints 5 | 1. `curl --request GET \ 6 | --url http://localhost:8080/api/authorization/start-auth` 7 | 2. `curl --request POST \ 8 | --url http://localhost:8080/api/authorization/finish-auth \ 9 | --header 'Content-Type: application/json' \ 10 | --data '{ 11 | "state":"dont-do-this", 12 | "code":"4/0AX4...35LBw" 13 | }'` 14 | 15 | For details see: https://tmsvr.com/oauth-2-implementation -------------------------------------------------------------------------------- /oauth-demo/build.gradle: -------------------------------------------------------------------------------- 1 | plugins { 2 | id 'org.springframework.boot' version '2.6.2' 3 | id 'io.spring.dependency-management' version '1.0.11.RELEASE' 4 | id 'java' 5 | } 6 | 7 | group = 'com.tmsvr' 8 | version = '0.0.1-SNAPSHOT' 9 | sourceCompatibility = '17' 10 | 11 | configurations { 12 | compileOnly { 13 | extendsFrom annotationProcessor 14 | } 15 | } 16 | 17 | repositories { 18 | mavenCentral() 19 | } 20 | 21 | dependencies { 22 | implementation 'org.springframework.boot:spring-boot-starter-web' 23 | compileOnly 'org.projectlombok:lombok' 24 | annotationProcessor 'org.projectlombok:lombok' 25 | testImplementation 'org.springframework.boot:spring-boot-starter-test' 26 | } 27 | 28 | test { 29 | useJUnitPlatform() 30 | } 31 | -------------------------------------------------------------------------------- /oauth-demo/gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tmsvr/tmsvr-blog/e5197548705ca360a2ac9616405e51201cae6cf3/oauth-demo/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /oauth-demo/gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionBase=GRADLE_USER_HOME 2 | distributionPath=wrapper/dists 3 | distributionUrl=https\://services.gradle.org/distributions/gradle-7.3.2-bin.zip 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | -------------------------------------------------------------------------------- /oauth-demo/gradlew: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | # 4 | # Copyright © 2015-2021 the original 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 POSIX generated by Gradle. 22 | # 23 | # Important for running: 24 | # 25 | # (1) You need a POSIX-compliant shell to run this script. If your /bin/sh is 26 | # noncompliant, but you have some other compliant shell such as ksh or 27 | # bash, then to run this script, type that shell name before the whole 28 | # command line, like: 29 | # 30 | # ksh Gradle 31 | # 32 | # Busybox and similar reduced shells will NOT work, because this script 33 | # requires all of these POSIX shell features: 34 | # * functions; 35 | # * expansions «$var», «${var}», «${var:-default}», «${var+SET}», 36 | # «${var#prefix}», «${var%suffix}», and «$( cmd )»; 37 | # * compound commands having a testable exit status, especially «case»; 38 | # * various built-in commands including «command», «set», and «ulimit». 39 | # 40 | # Important for patching: 41 | # 42 | # (2) This script targets any POSIX shell, so it avoids extensions provided 43 | # by Bash, Ksh, etc; in particular arrays are avoided. 44 | # 45 | # The "traditional" practice of packing multiple parameters into a 46 | # space-separated string is a well documented source of bugs and security 47 | # problems, so this is (mostly) avoided, by progressively accumulating 48 | # options in "$@", and eventually passing that to Java. 49 | # 50 | # Where the inherited environment variables (DEFAULT_JVM_OPTS, JAVA_OPTS, 51 | # and GRADLE_OPTS) rely on word-splitting, this is performed explicitly; 52 | # see the in-line comments for details. 53 | # 54 | # There are tweaks for specific operating systems such as AIX, CygWin, 55 | # Darwin, MinGW, and NonStop. 56 | # 57 | # (3) This script is generated from the Groovy template 58 | # https://github.com/gradle/gradle/blob/master/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt 59 | # within the Gradle project. 60 | # 61 | # You can find Gradle at https://github.com/gradle/gradle/. 62 | # 63 | ############################################################################## 64 | 65 | # Attempt to set APP_HOME 66 | 67 | # Resolve links: $0 may be a link 68 | app_path=$0 69 | 70 | # Need this for daisy-chained symlinks. 71 | while 72 | APP_HOME=${app_path%"${app_path##*/}"} # leaves a trailing /; empty if no leading path 73 | [ -h "$app_path" ] 74 | do 75 | ls=$( ls -ld "$app_path" ) 76 | link=${ls#*' -> '} 77 | case $link in #( 78 | /*) app_path=$link ;; #( 79 | *) app_path=$APP_HOME$link ;; 80 | esac 81 | done 82 | 83 | APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit 84 | 85 | APP_NAME="Gradle" 86 | APP_BASE_NAME=${0##*/} 87 | 88 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 89 | DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' 90 | 91 | # Use the maximum available, or set MAX_FD != -1 to use that value. 92 | MAX_FD=maximum 93 | 94 | warn () { 95 | echo "$*" 96 | } >&2 97 | 98 | die () { 99 | echo 100 | echo "$*" 101 | echo 102 | exit 1 103 | } >&2 104 | 105 | # OS specific support (must be 'true' or 'false'). 106 | cygwin=false 107 | msys=false 108 | darwin=false 109 | nonstop=false 110 | case "$( uname )" in #( 111 | CYGWIN* ) cygwin=true ;; #( 112 | Darwin* ) darwin=true ;; #( 113 | MSYS* | MINGW* ) msys=true ;; #( 114 | NONSTOP* ) nonstop=true ;; 115 | esac 116 | 117 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar 118 | 119 | 120 | # Determine the Java command to use to start the JVM. 121 | if [ -n "$JAVA_HOME" ] ; then 122 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 123 | # IBM's JDK on AIX uses strange locations for the executables 124 | JAVACMD=$JAVA_HOME/jre/sh/java 125 | else 126 | JAVACMD=$JAVA_HOME/bin/java 127 | fi 128 | if [ ! -x "$JAVACMD" ] ; then 129 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME 130 | 131 | Please set the JAVA_HOME variable in your environment to match the 132 | location of your Java installation." 133 | fi 134 | else 135 | JAVACMD=java 136 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 137 | 138 | Please set the JAVA_HOME variable in your environment to match the 139 | location of your Java installation." 140 | fi 141 | 142 | # Increase the maximum file descriptors if we can. 143 | if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then 144 | case $MAX_FD in #( 145 | max*) 146 | MAX_FD=$( ulimit -H -n ) || 147 | warn "Could not query maximum file descriptor limit" 148 | esac 149 | case $MAX_FD in #( 150 | '' | soft) :;; #( 151 | *) 152 | ulimit -n "$MAX_FD" || 153 | warn "Could not set maximum file descriptor limit to $MAX_FD" 154 | esac 155 | fi 156 | 157 | # Collect all arguments for the java command, stacking in reverse order: 158 | # * args from the command line 159 | # * the main class name 160 | # * -classpath 161 | # * -D...appname settings 162 | # * --module-path (only if needed) 163 | # * DEFAULT_JVM_OPTS, JAVA_OPTS, and GRADLE_OPTS environment variables. 164 | 165 | # For Cygwin or MSYS, switch paths to Windows format before running java 166 | if "$cygwin" || "$msys" ; then 167 | APP_HOME=$( cygpath --path --mixed "$APP_HOME" ) 168 | CLASSPATH=$( cygpath --path --mixed "$CLASSPATH" ) 169 | 170 | JAVACMD=$( cygpath --unix "$JAVACMD" ) 171 | 172 | # Now convert the arguments - kludge to limit ourselves to /bin/sh 173 | for arg do 174 | if 175 | case $arg in #( 176 | -*) false ;; # don't mess with options #( 177 | /?*) t=${arg#/} t=/${t%%/*} # looks like a POSIX filepath 178 | [ -e "$t" ] ;; #( 179 | *) false ;; 180 | esac 181 | then 182 | arg=$( cygpath --path --ignore --mixed "$arg" ) 183 | fi 184 | # Roll the args list around exactly as many times as the number of 185 | # args, so each arg winds up back in the position where it started, but 186 | # possibly modified. 187 | # 188 | # NB: a `for` loop captures its iteration list before it begins, so 189 | # changing the positional parameters here affects neither the number of 190 | # iterations, nor the values presented in `arg`. 191 | shift # remove old arg 192 | set -- "$@" "$arg" # push replacement arg 193 | done 194 | fi 195 | 196 | # Collect all arguments for the java command; 197 | # * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $GRADLE_OPTS can contain fragments of 198 | # shell script including quotes and variable substitutions, so put them in 199 | # double quotes to make sure that they get re-expanded; and 200 | # * put everything else in single quotes, so that it's not re-expanded. 201 | 202 | set -- \ 203 | "-Dorg.gradle.appname=$APP_BASE_NAME" \ 204 | -classpath "$CLASSPATH" \ 205 | org.gradle.wrapper.GradleWrapperMain \ 206 | "$@" 207 | 208 | # Use "xargs" to parse quoted args. 209 | # 210 | # With -n1 it outputs one arg per line, with the quotes and backslashes removed. 211 | # 212 | # In Bash we could simply go: 213 | # 214 | # readarray ARGS < <( xargs -n1 <<<"$var" ) && 215 | # set -- "${ARGS[@]}" "$@" 216 | # 217 | # but POSIX shell has neither arrays nor command substitution, so instead we 218 | # post-process each arg (as a line of input to sed) to backslash-escape any 219 | # character that might be a shell metacharacter, then use eval to reverse 220 | # that process (while maintaining the separation between arguments), and wrap 221 | # the whole thing up as a single "set" statement. 222 | # 223 | # This will of course break if any of these variables contains a newline or 224 | # an unmatched quote. 225 | # 226 | 227 | eval "set -- $( 228 | printf '%s\n' "$DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS" | 229 | xargs -n1 | 230 | sed ' s~[^-[:alnum:]+,./:=@_]~\\&~g; ' | 231 | tr '\n' ' ' 232 | )" '"$@"' 233 | 234 | exec "$JAVACMD" "$@" 235 | -------------------------------------------------------------------------------- /oauth-demo/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 | -------------------------------------------------------------------------------- /oauth-demo/settings.gradle: -------------------------------------------------------------------------------- 1 | rootProject.name = 'oauth-demo' 2 | -------------------------------------------------------------------------------- /oauth-demo/src/main/java/com/tmsvr/oauthdemo/OauthDemoApplication.java: -------------------------------------------------------------------------------- 1 | package com.tmsvr.oauthdemo; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | import org.springframework.boot.context.properties.ConfigurationPropertiesScan; 6 | 7 | @SpringBootApplication 8 | @ConfigurationPropertiesScan("com.tmsvr.oauthdemo.config") 9 | public class OauthDemoApplication { 10 | 11 | public static void main(String[] args) { 12 | SpringApplication.run(OauthDemoApplication.class, args); 13 | } 14 | 15 | } 16 | -------------------------------------------------------------------------------- /oauth-demo/src/main/java/com/tmsvr/oauthdemo/config/OAuthConfig.java: -------------------------------------------------------------------------------- 1 | package com.tmsvr.oauthdemo.config; 2 | 3 | import org.springframework.boot.context.properties.ConfigurationProperties; 4 | import org.springframework.boot.context.properties.ConstructorBinding; 5 | 6 | @ConstructorBinding 7 | @ConfigurationProperties("awesomeapp.oauth") 8 | public record OAuthConfig( 9 | String clientId, 10 | String clientSecret, 11 | String authUrl, 12 | String tokenUrl, 13 | String redirectUrl, 14 | String scopes 15 | ) { } 16 | -------------------------------------------------------------------------------- /oauth-demo/src/main/java/com/tmsvr/oauthdemo/persistence/InMemoryTokenRepository.java: -------------------------------------------------------------------------------- 1 | package com.tmsvr.oauthdemo.persistence; 2 | 3 | import org.springframework.stereotype.Component; 4 | 5 | import java.util.HashMap; 6 | import java.util.Map; 7 | 8 | @Component 9 | public class InMemoryTokenRepository implements TokenRepository { 10 | 11 | private final Map tokenStore; 12 | 13 | public InMemoryTokenRepository() { 14 | this.tokenStore = new HashMap<>(); 15 | } 16 | 17 | @Override 18 | public Token save(Token token) { 19 | return this.tokenStore.put(token.userid(), token); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /oauth-demo/src/main/java/com/tmsvr/oauthdemo/persistence/Token.java: -------------------------------------------------------------------------------- 1 | package com.tmsvr.oauthdemo.persistence; 2 | 3 | import java.time.Instant; 4 | 5 | public record Token ( 6 | String accessToken, 7 | Instant accessTokenExpiresAt, 8 | String refreshToken, 9 | Instant refreshTokenExpiresAt, 10 | Instant createdAt, 11 | long userid) { 12 | } 13 | -------------------------------------------------------------------------------- /oauth-demo/src/main/java/com/tmsvr/oauthdemo/persistence/TokenRepository.java: -------------------------------------------------------------------------------- 1 | package com.tmsvr.oauthdemo.persistence; 2 | 3 | public interface TokenRepository { 4 | Token save(Token token); 5 | } 6 | -------------------------------------------------------------------------------- /oauth-demo/src/main/java/com/tmsvr/oauthdemo/rest/AuthorizationController.java: -------------------------------------------------------------------------------- 1 | package com.tmsvr.oauthdemo.rest; 2 | 3 | import com.tmsvr.oauthdemo.service.AuthorizationService; 4 | import lombok.AllArgsConstructor; 5 | import org.springframework.http.HttpStatus; 6 | import org.springframework.http.ResponseEntity; 7 | import org.springframework.web.bind.annotation.*; 8 | 9 | @AllArgsConstructor 10 | @RestController 11 | @RequestMapping("/api/authorization") 12 | public class AuthorizationController { 13 | 14 | private final AuthorizationService authorizationService; 15 | 16 | @GetMapping("/start-auth") 17 | public ResponseEntity getRedirectUrl() { 18 | return ResponseEntity.ok(authorizationService.getAuthorizationUrl()); 19 | } 20 | 21 | @PostMapping("/finish-auth") 22 | public ResponseEntity finishAuth(@RequestBody FinishAuthRequest finishAuthRequest) { 23 | authorizationService.finishAuth(finishAuthRequest.code(), finishAuthRequest.state()); 24 | return ResponseEntity.status(HttpStatus.OK).build(); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /oauth-demo/src/main/java/com/tmsvr/oauthdemo/rest/FinishAuthRequest.java: -------------------------------------------------------------------------------- 1 | package com.tmsvr.oauthdemo.rest; 2 | 3 | public record FinishAuthRequest (String state, String code){ } 4 | -------------------------------------------------------------------------------- /oauth-demo/src/main/java/com/tmsvr/oauthdemo/service/AuthorizationService.java: -------------------------------------------------------------------------------- 1 | package com.tmsvr.oauthdemo.service; 2 | 3 | import com.tmsvr.oauthdemo.config.OAuthConfig; 4 | import com.tmsvr.oauthdemo.persistence.Token; 5 | import com.tmsvr.oauthdemo.persistence.TokenRepository; 6 | import lombok.AllArgsConstructor; 7 | import lombok.extern.slf4j.Slf4j; 8 | import org.springframework.http.HttpEntity; 9 | import org.springframework.http.HttpHeaders; 10 | import org.springframework.http.MediaType; 11 | import org.springframework.stereotype.Service; 12 | import org.springframework.util.LinkedMultiValueMap; 13 | import org.springframework.util.MultiValueMap; 14 | import org.springframework.web.client.RestTemplate; 15 | 16 | import java.time.Instant; 17 | import java.time.temporal.ChronoUnit; 18 | 19 | @Slf4j 20 | @Service 21 | @AllArgsConstructor 22 | public class AuthorizationService { 23 | private final OAuthConfig oAuthConfig; 24 | private final TokenRepository tokenRepository; 25 | 26 | public String getAuthorizationUrl() { 27 | return oAuthConfig.authUrl() + 28 | "?response_type=code" + 29 | "&redirect_uri=" + oAuthConfig.redirectUrl() + 30 | "&client_id=" + oAuthConfig.clientId() + 31 | "&scope=" + oAuthConfig.scopes() + 32 | "&state=" + generateState() + 33 | "&access_type=offline"; 34 | } 35 | 36 | public void finishAuth(String code, String state) { 37 | checkState(state); 38 | 39 | Token token = exchangeCodeForTokens(code); 40 | 41 | tokenRepository.save(token); 42 | 43 | log.info("Auth successful. Token saved to database {}", token.refreshToken().substring(token.refreshToken().length() - 4)); 44 | } 45 | 46 | private Token exchangeCodeForTokens(String code) { 47 | String tokenUrl = oAuthConfig.tokenUrl(); 48 | 49 | HttpHeaders headers = new HttpHeaders(); 50 | headers.setContentType(MediaType.APPLICATION_FORM_URLENCODED); 51 | 52 | MultiValueMap map = new LinkedMultiValueMap<>(); 53 | map.add("grant_type", "authorization_code"); 54 | map.add("client_id", oAuthConfig.clientId()); 55 | map.add("client_secret", oAuthConfig.clientSecret()); 56 | map.add("redirect_uri", oAuthConfig.redirectUrl()); 57 | map.add("code", code); 58 | 59 | HttpEntity> request = new HttpEntity<>(map, headers); 60 | 61 | RestTemplate restTemplate = new RestTemplate(); 62 | TokenResponse response = restTemplate.postForEntity(tokenUrl, request, TokenResponse.class).getBody(); 63 | 64 | return new Token(response.getAccessToken(), 65 | Instant.now().plusSeconds(response.getExpiresIn()), 66 | response.getRefreshToken(), 67 | Instant.now().plus(30, ChronoUnit.DAYS), 68 | Instant.now(), 69 | 1L 70 | ); 71 | } 72 | 73 | private String generateState() { 74 | // generate a state string that you have to store until the auth flow is completed, 75 | // or it could be computed from some user property for example 76 | return "dont-do-this"; 77 | } 78 | 79 | private void checkState(String state) { 80 | // validate that the state is the same that we have sent 81 | // throw exception if not 82 | } 83 | } 84 | -------------------------------------------------------------------------------- /oauth-demo/src/main/java/com/tmsvr/oauthdemo/service/TokenResponse.java: -------------------------------------------------------------------------------- 1 | package com.tmsvr.oauthdemo.service; 2 | 3 | 4 | import com.fasterxml.jackson.annotation.JsonProperty; 5 | import lombok.Data; 6 | 7 | @Data 8 | public class TokenResponse { 9 | @JsonProperty("access_token") 10 | String accessToken; 11 | 12 | @JsonProperty("token_type") 13 | String tokenType; 14 | 15 | @JsonProperty("scope") 16 | String scope; 17 | 18 | @JsonProperty("expires_in") 19 | int expiresIn; 20 | 21 | @JsonProperty("refresh_token") 22 | String refreshToken; 23 | 24 | @JsonProperty("id_token") 25 | String idToken; 26 | } 27 | -------------------------------------------------------------------------------- /oauth-demo/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | awesomeapp: 2 | oauth: 3 | client-id: x 4 | client-secret: x 5 | auth-url: https://accounts.google.com/o/oauth2/auth 6 | token-url: https://oauth2.googleapis.com/token 7 | redirect-url: http://localhost:8080/ok 8 | scopes: openid profile 9 | 10 | -------------------------------------------------------------------------------- /oauth-demo/src/test/java/com/tmsvr/oauthdemo/OauthDemoApplicationTests.java: -------------------------------------------------------------------------------- 1 | package com.tmsvr.oauthdemo; 2 | 3 | import org.junit.jupiter.api.Test; 4 | import org.springframework.boot.test.context.SpringBootTest; 5 | 6 | @SpringBootTest 7 | class OauthDemoApplicationTests { 8 | 9 | @Test 10 | void contextLoads() { 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /openapi-demo/README.md: -------------------------------------------------------------------------------- 1 | # OpenAPI demo 2 | 3 | This PoC application demonstrates the usage of OpenAPI descriptors and the [openapi generator](https://github.com/OpenAPITools/openapi-generator) project to generate client and server code from OpenAPI descriptors with Gradle for Spring Boot projects. 4 | 5 | ## Setup 6 | 7 | For the code generation to work there must be OpenAPI descriptors available. These should represent a contract between services, fontend-backend etc. on how the API looks like. 8 | 9 | The ```build.gradle``` file is commented to highlight the necessary modifications to enable code generation. Generation can be used to create client and server code as well. This example application implements the API described in ```petstore.yml``` and consumes an API described by ```uuid.yml```. The business logic is nonsense, the goal of the PoC is to demonstrate the code generation, and the basic usage of the generated code. 10 | 11 | ## Code generation on the backend 12 | 13 | The ```build.gradle``` file contains the configuration for the code generation in the ```buildUuidClient``` and ```buildPetStoreServer``` tasks. Details on the configuration options can be found [here](https://openapi-generator.tech/docs/generators/) for the various generator options (the PoC uses java for client and spring for server generation), generic config options are [here](https://github.com/OpenAPITools/openapi-generator/tree/master/modules/openapi-generator-gradle-plugin) 14 | 15 | The generated code is an independent gradle/maven project created in the folder specified in ```build.gradle```. Since it is a project in itself it is possible to publish artifacts built from it to Maven repositories. A scenario can be to generate both client and server code for the API of a service. The client code can be published to a Maven repository and used by other services connecting to this one as a dependency. 16 | 17 | In the PoC project instead of depending on the separate artifact created from the generated code, we include the generated source folders in the source sets of the project, and adding the necessary dependencies for it to compile. 18 | 19 | ## Frontend use 20 | 21 | The openapi generator used in the PoC is capable of creating clients for many languages and frameworks, however frontend developers often choose [NSwag](https://github.com/RicoSuter/NSwag) (an other genertor) instead. It is better in generating code for Angular projects. 22 | 23 | ## How to try out this PoC 24 | 25 | Just clone the repo and run the ```bootRun``` gradle task. The code will be generated in the ```build/generated``` folder, according to the settings in ```build.gradle```. 26 | 27 | There is an endpoint (generated) which is implemented in the PetStoreController. The delete pet method calls the UUID API using the also generated client code. So by calling the following, you can try out both the server and client generated parts. 28 | 29 | ```shell 30 | curl --location -H 'Content-Type: application/json' -H 'Accept: application/json' --request GET 'http://localhost:8080/pet/12' 31 | ``` 32 | -------------------------------------------------------------------------------- /openapi-demo/build.gradle: -------------------------------------------------------------------------------- 1 | import org.openapitools.generator.gradle.plugin.tasks.GenerateTask 2 | 3 | plugins { 4 | id 'org.springframework.boot' version '2.7.6' 5 | id 'io.spring.dependency-management' version '1.1.0' 6 | id 'java' 7 | 8 | // applying the openapi generator plugin 9 | id "org.openapi.generator" version "6.2.1" 10 | } 11 | 12 | group = 'com.tmsvr' 13 | version = '0.0.1-SNAPSHOT' 14 | sourceCompatibility = '17' 15 | 16 | // adding the generated sources to the source sets 17 | sourceSets.main.java.srcDirs += 'build/generated/petstore/src/main/java' 18 | sourceSets.main.java.srcDirs += 'build/generated/uuid/src/main/java' 19 | 20 | configurations { 21 | compileOnly { 22 | extendsFrom annotationProcessor 23 | } 24 | } 25 | 26 | repositories { 27 | mavenCentral() 28 | } 29 | 30 | dependencies { 31 | implementation 'org.springframework.boot:spring-boot-starter-web' 32 | compileOnly 'org.projectlombok:lombok' 33 | annotationProcessor 'org.projectlombok:lombok' 34 | testImplementation 'org.springframework.boot:spring-boot-starter-test' 35 | 36 | // required for generated openapi stuff 37 | implementation "javax.validation:validation-api:2.0.1.Final" 38 | implementation "io.springfox:springfox-swagger2:3.0.0" 39 | implementation 'org.openapitools:jackson-databind-nullable:0.2.4' 40 | implementation 'com.google.code.findbugs:jsr305:3.0.2' 41 | annotationProcessor 'io.swagger:swagger-annotations:1.6.8' 42 | } 43 | 44 | // 2 new tasks to generate the client and server code 45 | task buildUuidClient(type: GenerateTask) { 46 | generatorName = "java" 47 | groupId = "com.tmsvr.api" 48 | id = "uuidapi" 49 | inputSpec = "$rootDir/uuid.yml".toString() 50 | outputDir = "$buildDir/generated/uuid".toString() 51 | apiPackage = "com.tmsvr.openapidemo.uuid.api" 52 | invokerPackage = "com.tmsvr.openapidemo.uuid.invoker" 53 | modelPackage = "com.tmsvr.openapidemo.uuid.model" 54 | configOptions = [ 55 | dateLibrary: "java8", 56 | library: "resttemplate", 57 | serializableModel : "true", 58 | hideGenerationTimestamp : "true" 59 | ] 60 | } 61 | 62 | task buildPetStoreServer(type: GenerateTask) { 63 | generatorName = "spring" 64 | groupId = "$project.group" 65 | id = "$project.name-java-client" 66 | version = "$project.version" 67 | inputSpec = "$rootDir/petstore.yml".toString() 68 | outputDir = "$buildDir/generated/petstore".toString() 69 | apiPackage = "com.tmsvr.openapidemo.petstore.api" 70 | invokerPackage = "com.tmsvr.openapidemo.petstore.invoker" 71 | modelPackage = "com.tmsvr.openapidemo.petstore.model" 72 | generateApiDocumentation = false 73 | generateModelDocumentation = false 74 | generateModelTests = false 75 | generateApiTests = false 76 | configOptions = [ 77 | java8 : "true", 78 | dateLibrary : "java8", 79 | serializationLibrary: "jackson", 80 | library : "spring-boot", 81 | useBeanValidation : "true", 82 | interfaceOnly : "true", 83 | serializableModel : "true", 84 | useTags : "true" 85 | ] 86 | } 87 | 88 | // make compileJava run the code generation 89 | compileJava.dependsOn tasks.buildPetStoreServer, tasks.buildUuidClient 90 | 91 | test { 92 | useJUnitPlatform() 93 | } 94 | -------------------------------------------------------------------------------- /openapi-demo/gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tmsvr/tmsvr-blog/e5197548705ca360a2ac9616405e51201cae6cf3/openapi-demo/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /openapi-demo/gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionBase=GRADLE_USER_HOME 2 | distributionPath=wrapper/dists 3 | distributionUrl=https\://services.gradle.org/distributions/gradle-7.5.1-bin.zip 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | -------------------------------------------------------------------------------- /openapi-demo/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 | MSYS* | 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 | -------------------------------------------------------------------------------- /openapi-demo/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 | -------------------------------------------------------------------------------- /openapi-demo/petstore.yml: -------------------------------------------------------------------------------- 1 | openapi: 3.0.2 2 | servers: 3 | - url: /v3 4 | info: 5 | description: |- 6 | This is a sample Pet Store Server based on the OpenAPI 3.0 specification. You can find out more about 7 | Swagger at [http://swagger.io](http://swagger.io). In the third iteration of the pet store, we've switched to the design first approach! 8 | You can now help us improve the API whether it's by making changes to the definition itself or to the code. 9 | That way, with time, we can improve the API in general, and expose some of the new features in OAS3. 10 | 11 | Some useful links: 12 | - [The Pet Store repository](https://github.com/swagger-api/swagger-petstore) 13 | - [The source API definition for the Pet Store](https://github.com/swagger-api/swagger-petstore/blob/master/src/main/resources/openapi.yaml) 14 | version: 1.0.6 15 | title: Swagger Petstore - OpenAPI 3.0 16 | termsOfService: 'http://swagger.io/terms/' 17 | contact: 18 | email: apiteam@swagger.io 19 | license: 20 | name: Apache 2.0 21 | url: 'http://www.apache.org/licenses/LICENSE-2.0.html' 22 | tags: 23 | - name: pet 24 | description: Everything about your Pets 25 | externalDocs: 26 | description: Find out more 27 | url: 'http://swagger.io' 28 | - name: store 29 | description: Operations about user 30 | - name: user 31 | description: Access to Petstore orders 32 | externalDocs: 33 | description: Find out more about our store 34 | url: 'http://swagger.io' 35 | paths: 36 | /pet: 37 | post: 38 | tags: 39 | - pet 40 | summary: Add a new pet to the store 41 | description: Add a new pet to the store 42 | operationId: addPet 43 | responses: 44 | '200': 45 | description: Successful operation 46 | content: 47 | application/xml: 48 | schema: 49 | $ref: '#/components/schemas/Pet' 50 | application/json: 51 | schema: 52 | $ref: '#/components/schemas/Pet' 53 | '405': 54 | description: Invalid input 55 | security: 56 | - petstore_auth: 57 | - 'write:pets' 58 | - 'read:pets' 59 | requestBody: 60 | description: Create a new pet in the store 61 | required: true 62 | content: 63 | application/json: 64 | schema: 65 | $ref: '#/components/schemas/Pet' 66 | application/xml: 67 | schema: 68 | $ref: '#/components/schemas/Pet' 69 | application/x-www-form-urlencoded: 70 | schema: 71 | $ref: '#/components/schemas/Pet' 72 | put: 73 | tags: 74 | - pet 75 | summary: Update an existing pet 76 | description: Update an existing pet by Id 77 | operationId: updatePet 78 | responses: 79 | '200': 80 | description: Successful operation 81 | content: 82 | application/xml: 83 | schema: 84 | $ref: '#/components/schemas/Pet' 85 | application/json: 86 | schema: 87 | $ref: '#/components/schemas/Pet' 88 | '400': 89 | description: Invalid ID supplied 90 | '404': 91 | description: Pet not found 92 | '405': 93 | description: Validation exception 94 | security: 95 | - petstore_auth: 96 | - 'write:pets' 97 | - 'read:pets' 98 | requestBody: 99 | description: Update an existent pet in the store 100 | required: true 101 | content: 102 | application/json: 103 | schema: 104 | $ref: '#/components/schemas/Pet' 105 | application/xml: 106 | schema: 107 | $ref: '#/components/schemas/Pet' 108 | application/x-www-form-urlencoded: 109 | schema: 110 | $ref: '#/components/schemas/Pet' 111 | /pet/findByStatus: 112 | get: 113 | tags: 114 | - pet 115 | summary: Finds Pets by status 116 | description: Multiple status values can be provided with comma separated strings 117 | operationId: findPetsByStatus 118 | parameters: 119 | - name: status 120 | in: query 121 | description: Status values that need to be considered for filter 122 | required: false 123 | explode: true 124 | schema: 125 | type: string 126 | enum: 127 | - available 128 | - pending 129 | - sold 130 | default: available 131 | responses: 132 | '200': 133 | description: successful operation 134 | content: 135 | application/xml: 136 | schema: 137 | type: array 138 | items: 139 | $ref: '#/components/schemas/Pet' 140 | application/json: 141 | schema: 142 | type: array 143 | items: 144 | $ref: '#/components/schemas/Pet' 145 | '400': 146 | description: Invalid status value 147 | security: 148 | - petstore_auth: 149 | - 'write:pets' 150 | - 'read:pets' 151 | /pet/findByTags: 152 | get: 153 | tags: 154 | - pet 155 | summary: Finds Pets by tags 156 | description: >- 157 | Multiple tags can be provided with comma separated strings. Use tag1, 158 | tag2, tag3 for testing. 159 | operationId: findPetsByTags 160 | parameters: 161 | - name: tags 162 | in: query 163 | description: Tags to filter by 164 | required: false 165 | explode: true 166 | schema: 167 | type: array 168 | items: 169 | type: string 170 | responses: 171 | '200': 172 | description: successful operation 173 | content: 174 | application/xml: 175 | schema: 176 | type: array 177 | items: 178 | $ref: '#/components/schemas/Pet' 179 | application/json: 180 | schema: 181 | type: array 182 | items: 183 | $ref: '#/components/schemas/Pet' 184 | '400': 185 | description: Invalid tag value 186 | security: 187 | - petstore_auth: 188 | - 'write:pets' 189 | - 'read:pets' 190 | '/pet/{petId}': 191 | get: 192 | tags: 193 | - pet 194 | summary: Find pet by ID 195 | description: Returns a single pet 196 | operationId: getPetById 197 | parameters: 198 | - name: petId 199 | in: path 200 | description: ID of pet to return 201 | required: true 202 | schema: 203 | type: integer 204 | format: int64 205 | responses: 206 | '200': 207 | description: successful operation 208 | content: 209 | application/xml: 210 | schema: 211 | $ref: '#/components/schemas/Pet' 212 | application/json: 213 | schema: 214 | $ref: '#/components/schemas/Pet' 215 | '400': 216 | description: Invalid ID supplied 217 | '404': 218 | description: Pet not found 219 | security: 220 | - api_key: [] 221 | - petstore_auth: 222 | - 'write:pets' 223 | - 'read:pets' 224 | post: 225 | tags: 226 | - pet 227 | summary: Updates a pet in the store with form data 228 | description: '' 229 | operationId: updatePetWithForm 230 | parameters: 231 | - name: petId 232 | in: path 233 | description: ID of pet that needs to be updated 234 | required: true 235 | schema: 236 | type: integer 237 | format: int64 238 | - name: name 239 | in: query 240 | description: Name of pet that needs to be updated 241 | schema: 242 | type: string 243 | - name: status 244 | in: query 245 | description: Status of pet that needs to be updated 246 | schema: 247 | type: string 248 | responses: 249 | '405': 250 | description: Invalid input 251 | security: 252 | - petstore_auth: 253 | - 'write:pets' 254 | - 'read:pets' 255 | delete: 256 | tags: 257 | - pet 258 | summary: Deletes a pet 259 | description: '' 260 | operationId: deletePet 261 | parameters: 262 | - name: api_key 263 | in: header 264 | description: '' 265 | required: false 266 | schema: 267 | type: string 268 | - name: petId 269 | in: path 270 | description: Pet id to delete 271 | required: true 272 | schema: 273 | type: integer 274 | format: int64 275 | responses: 276 | '400': 277 | description: Invalid pet value 278 | security: 279 | - petstore_auth: 280 | - 'write:pets' 281 | - 'read:pets' 282 | '/pet/{petId}/uploadImage': 283 | post: 284 | tags: 285 | - pet 286 | summary: uploads an image 287 | description: '' 288 | operationId: uploadFile 289 | parameters: 290 | - name: petId 291 | in: path 292 | description: ID of pet to update 293 | required: true 294 | schema: 295 | type: integer 296 | format: int64 297 | - name: additionalMetadata 298 | in: query 299 | description: Additional Metadata 300 | required: false 301 | schema: 302 | type: string 303 | responses: 304 | '200': 305 | description: successful operation 306 | content: 307 | application/json: 308 | schema: 309 | $ref: '#/components/schemas/ApiResponse' 310 | security: 311 | - petstore_auth: 312 | - 'write:pets' 313 | - 'read:pets' 314 | requestBody: 315 | content: 316 | application/octet-stream: 317 | schema: 318 | type: string 319 | format: binary 320 | /store/inventory: 321 | get: 322 | tags: 323 | - store 324 | summary: Returns pet inventories by status 325 | description: Returns a map of status codes to quantities 326 | operationId: getInventory 327 | x-swagger-router-controller: OrderController 328 | responses: 329 | '200': 330 | description: successful operation 331 | content: 332 | application/json: 333 | schema: 334 | type: object 335 | additionalProperties: 336 | type: integer 337 | format: int32 338 | security: 339 | - api_key: [] 340 | /store/order: 341 | post: 342 | tags: 343 | - store 344 | summary: Place an order for a pet 345 | description: Place a new order in the store 346 | operationId: placeOrder 347 | x-swagger-router-controller: OrderController 348 | responses: 349 | '200': 350 | description: successful operation 351 | content: 352 | application/json: 353 | schema: 354 | $ref: '#/components/schemas/Order' 355 | '405': 356 | description: Invalid input 357 | requestBody: 358 | content: 359 | application/json: 360 | schema: 361 | $ref: '#/components/schemas/Order' 362 | application/xml: 363 | schema: 364 | $ref: '#/components/schemas/Order' 365 | application/x-www-form-urlencoded: 366 | schema: 367 | $ref: '#/components/schemas/Order' 368 | '/store/order/{orderId}': 369 | get: 370 | tags: 371 | - store 372 | summary: Find purchase order by ID 373 | x-swagger-router-controller: OrderController 374 | description: >- 375 | For valid response try integer IDs with value <= 5 or > 10. Other values 376 | will generated exceptions 377 | operationId: getOrderById 378 | parameters: 379 | - name: orderId 380 | in: path 381 | description: ID of order that needs to be fetched 382 | required: true 383 | schema: 384 | type: integer 385 | format: int64 386 | responses: 387 | '200': 388 | description: successful operation 389 | content: 390 | application/xml: 391 | schema: 392 | $ref: '#/components/schemas/Order' 393 | application/json: 394 | schema: 395 | $ref: '#/components/schemas/Order' 396 | '400': 397 | description: Invalid ID supplied 398 | '404': 399 | description: Order not found 400 | delete: 401 | tags: 402 | - store 403 | summary: Delete purchase order by ID 404 | x-swagger-router-controller: OrderController 405 | description: >- 406 | For valid response try integer IDs with value < 1000. Anything above 407 | 1000 or nonintegers will generate API errors 408 | operationId: deleteOrder 409 | parameters: 410 | - name: orderId 411 | in: path 412 | description: ID of the order that needs to be deleted 413 | required: true 414 | schema: 415 | type: integer 416 | format: int64 417 | responses: 418 | '400': 419 | description: Invalid ID supplied 420 | '404': 421 | description: Order not found 422 | /user: 423 | post: 424 | tags: 425 | - user 426 | summary: Create user 427 | description: This can only be done by the logged in user. 428 | operationId: createUser 429 | responses: 430 | default: 431 | description: successful operation 432 | content: 433 | application/json: 434 | schema: 435 | $ref: '#/components/schemas/User' 436 | application/xml: 437 | schema: 438 | $ref: '#/components/schemas/User' 439 | requestBody: 440 | content: 441 | application/json: 442 | schema: 443 | $ref: '#/components/schemas/User' 444 | application/xml: 445 | schema: 446 | $ref: '#/components/schemas/User' 447 | application/x-www-form-urlencoded: 448 | schema: 449 | $ref: '#/components/schemas/User' 450 | description: Created user object 451 | /user/createWithList: 452 | post: 453 | tags: 454 | - user 455 | summary: Creates list of users with given input array 456 | description: 'Creates list of users with given input array' 457 | x-swagger-router-controller: UserController 458 | operationId: createUsersWithListInput 459 | responses: 460 | '200': 461 | description: Successful operation 462 | content: 463 | application/xml: 464 | schema: 465 | $ref: '#/components/schemas/User' 466 | application/json: 467 | schema: 468 | $ref: '#/components/schemas/User' 469 | default: 470 | description: successful operation 471 | requestBody: 472 | content: 473 | application/json: 474 | schema: 475 | type: array 476 | items: 477 | $ref: '#/components/schemas/User' 478 | /user/login: 479 | get: 480 | tags: 481 | - user 482 | summary: Logs user into the system 483 | description: '' 484 | operationId: loginUser 485 | parameters: 486 | - name: username 487 | in: query 488 | description: The user name for login 489 | required: false 490 | schema: 491 | type: string 492 | - name: password 493 | in: query 494 | description: The password for login in clear text 495 | required: false 496 | schema: 497 | type: string 498 | responses: 499 | '200': 500 | description: successful operation 501 | headers: 502 | X-Rate-Limit: 503 | description: calls per hour allowed by the user 504 | schema: 505 | type: integer 506 | format: int32 507 | X-Expires-After: 508 | description: date in UTC when token expires 509 | schema: 510 | type: string 511 | format: date-time 512 | content: 513 | application/xml: 514 | schema: 515 | type: string 516 | application/json: 517 | schema: 518 | type: string 519 | '400': 520 | description: Invalid username/password supplied 521 | /user/logout: 522 | get: 523 | tags: 524 | - user 525 | summary: Logs out current logged in user session 526 | description: '' 527 | operationId: logoutUser 528 | parameters: [] 529 | responses: 530 | default: 531 | description: successful operation 532 | '/user/{username}': 533 | get: 534 | tags: 535 | - user 536 | summary: Get user by user name 537 | description: '' 538 | operationId: getUserByName 539 | parameters: 540 | - name: username 541 | in: path 542 | description: 'The name that needs to be fetched. Use user1 for testing. ' 543 | required: true 544 | schema: 545 | type: string 546 | responses: 547 | '200': 548 | description: successful operation 549 | content: 550 | application/xml: 551 | schema: 552 | $ref: '#/components/schemas/User' 553 | application/json: 554 | schema: 555 | $ref: '#/components/schemas/User' 556 | '400': 557 | description: Invalid username supplied 558 | '404': 559 | description: User not found 560 | put: 561 | tags: 562 | - user 563 | summary: Update user 564 | x-swagger-router-controller: UserController 565 | description: This can only be done by the logged in user. 566 | operationId: updateUser 567 | parameters: 568 | - name: username 569 | in: path 570 | description: name that need to be deleted 571 | required: true 572 | schema: 573 | type: string 574 | responses: 575 | default: 576 | description: successful operation 577 | requestBody: 578 | description: Update an existent user in the store 579 | content: 580 | application/json: 581 | schema: 582 | $ref: '#/components/schemas/User' 583 | application/xml: 584 | schema: 585 | $ref: '#/components/schemas/User' 586 | application/x-www-form-urlencoded: 587 | schema: 588 | $ref: '#/components/schemas/User' 589 | delete: 590 | tags: 591 | - user 592 | summary: Delete user 593 | description: This can only be done by the logged in user. 594 | operationId: deleteUser 595 | parameters: 596 | - name: username 597 | in: path 598 | description: The name that needs to be deleted 599 | required: true 600 | schema: 601 | type: string 602 | responses: 603 | '400': 604 | description: Invalid username supplied 605 | '404': 606 | description: User not found 607 | externalDocs: 608 | description: Find out more about Swagger 609 | url: 'http://swagger.io' 610 | components: 611 | schemas: 612 | Order: 613 | x-swagger-router-model: io.swagger.petstore.model.Order 614 | properties: 615 | id: 616 | type: integer 617 | format: int64 618 | example: 10 619 | petId: 620 | type: integer 621 | format: int64 622 | example: 198772 623 | quantity: 624 | type: integer 625 | format: int32 626 | example: 7 627 | shipDate: 628 | type: string 629 | format: date-time 630 | status: 631 | type: string 632 | description: Order Status 633 | enum: 634 | - placed 635 | - approved 636 | - delivered 637 | example: approved 638 | complete: 639 | type: boolean 640 | xml: 641 | name: order 642 | type: object 643 | Customer: 644 | properties: 645 | id: 646 | type: integer 647 | format: int64 648 | example: 100000 649 | username: 650 | type: string 651 | example: fehguy 652 | address: 653 | type: array 654 | items: 655 | $ref: '#/components/schemas/Address' 656 | xml: 657 | wrapped: true 658 | name: addresses 659 | xml: 660 | name: customer 661 | type: object 662 | Address: 663 | properties: 664 | street: 665 | type: string 666 | example: 437 Lytton 667 | city: 668 | type: string 669 | example: Palo Alto 670 | state: 671 | type: string 672 | example: CA 673 | zip: 674 | type: string 675 | example: 94301 676 | xml: 677 | name: address 678 | type: object 679 | Category: 680 | x-swagger-router-model: io.swagger.petstore.model.Category 681 | properties: 682 | id: 683 | type: integer 684 | format: int64 685 | example: 1 686 | name: 687 | type: string 688 | example: Dogs 689 | xml: 690 | name: category 691 | type: object 692 | User: 693 | x-swagger-router-model: io.swagger.petstore.model.User 694 | properties: 695 | id: 696 | type: integer 697 | format: int64 698 | example: 10 699 | username: 700 | type: string 701 | example: theUser 702 | firstName: 703 | type: string 704 | example: John 705 | lastName: 706 | type: string 707 | example: James 708 | email: 709 | type: string 710 | example: john@email.com 711 | password: 712 | type: string 713 | example: 12345 714 | phone: 715 | type: string 716 | example: 12345 717 | userStatus: 718 | type: integer 719 | format: int32 720 | example: 1 721 | description: User Status 722 | xml: 723 | name: user 724 | type: object 725 | Tag: 726 | x-swagger-router-model: io.swagger.petstore.model.Tag 727 | properties: 728 | id: 729 | type: integer 730 | format: int64 731 | name: 732 | type: string 733 | xml: 734 | name: tag 735 | type: object 736 | Pet: 737 | x-swagger-router-model: io.swagger.petstore.model.Pet 738 | required: 739 | - name 740 | - photoUrls 741 | properties: 742 | id: 743 | type: integer 744 | format: int64 745 | example: 10 746 | name: 747 | type: string 748 | example: doggie 749 | category: 750 | $ref: '#/components/schemas/Category' 751 | photoUrls: 752 | type: array 753 | xml: 754 | wrapped: true 755 | items: 756 | type: string 757 | xml: 758 | name: photoUrl 759 | tags: 760 | type: array 761 | xml: 762 | wrapped: true 763 | items: 764 | $ref: '#/components/schemas/Tag' 765 | xml: 766 | name: tag 767 | status: 768 | type: string 769 | description: pet status in the store 770 | enum: 771 | - available 772 | - pending 773 | - sold 774 | xml: 775 | name: pet 776 | type: object 777 | ApiResponse: 778 | properties: 779 | code: 780 | type: integer 781 | format: int32 782 | type: 783 | type: string 784 | message: 785 | type: string 786 | xml: 787 | name: '##default' 788 | type: object 789 | requestBodies: 790 | Pet: 791 | content: 792 | application/json: 793 | schema: 794 | $ref: '#/components/schemas/Pet' 795 | application/xml: 796 | schema: 797 | $ref: '#/components/schemas/Pet' 798 | description: Pet object that needs to be added to the store 799 | UserArray: 800 | content: 801 | application/json: 802 | schema: 803 | type: array 804 | items: 805 | $ref: '#/components/schemas/User' 806 | description: List of user object 807 | securitySchemes: 808 | petstore_auth: 809 | type: oauth2 810 | flows: 811 | implicit: 812 | authorizationUrl: 'https://petstore.swagger.io/oauth/authorize' 813 | scopes: 814 | 'write:pets': modify pets in your account 815 | 'read:pets': read your pets 816 | api_key: 817 | type: apiKey 818 | name: api_key 819 | in: header -------------------------------------------------------------------------------- /openapi-demo/settings.gradle: -------------------------------------------------------------------------------- 1 | rootProject.name = 'openapi-demo' 2 | -------------------------------------------------------------------------------- /openapi-demo/src/main/java/com/tmsvr/openapidemo/OpenapiDemoApplication.java: -------------------------------------------------------------------------------- 1 | package com.tmsvr.openapidemo; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | @SpringBootApplication 7 | public class OpenapiDemoApplication { 8 | 9 | public static void main(String[] args) { 10 | SpringApplication.run(OpenapiDemoApplication.class, args); 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /openapi-demo/src/main/java/com/tmsvr/openapidemo/configuration/RestTemplateConfig.java: -------------------------------------------------------------------------------- 1 | package com.tmsvr.openapidemo.configuration; 2 | 3 | import org.springframework.context.annotation.Bean; 4 | import org.springframework.context.annotation.Configuration; 5 | import org.springframework.web.client.RestTemplate; 6 | 7 | @Configuration 8 | public class RestTemplateConfig { 9 | 10 | @Bean 11 | public RestTemplate restTemplate() { 12 | return new RestTemplate(); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /openapi-demo/src/main/java/com/tmsvr/openapidemo/controllers/PetStoreController.java: -------------------------------------------------------------------------------- 1 | package com.tmsvr.openapidemo.controllers; 2 | 3 | import com.tmsvr.openapidemo.petstore.model.Pet; 4 | import com.tmsvr.openapidemo.petstore.api.PetApi; 5 | import com.tmsvr.openapidemo.service.UuidService; 6 | import lombok.RequiredArgsConstructor; 7 | import lombok.extern.slf4j.Slf4j; 8 | import org.springframework.http.HttpStatus; 9 | import org.springframework.http.ResponseEntity; 10 | import org.springframework.web.bind.annotation.RestController; 11 | 12 | import java.util.List; 13 | 14 | @Slf4j 15 | @RestController 16 | @RequiredArgsConstructor 17 | public class PetStoreController implements PetApi { 18 | 19 | private final UuidService uuidService; 20 | 21 | @Override 22 | public ResponseEntity getPetById(Long petId) { 23 | log.info("FOUND"); 24 | 25 | List uuids = uuidService.getUuids(); 26 | for (String uuid : uuids) { 27 | log.info("UUID: {}", uuid); 28 | } 29 | 30 | var foundPet = new Pet(); 31 | foundPet.setId(1L); 32 | foundPet.setName("Beethoven - " + uuids.get(0)); 33 | 34 | return ResponseEntity.ok(foundPet); 35 | } 36 | 37 | @Override 38 | public ResponseEntity addPet(Pet pet) { 39 | log.info("CREATED"); 40 | return new ResponseEntity<>(HttpStatus.CREATED); 41 | } 42 | 43 | @Override 44 | public ResponseEntity deletePet(Long petId, String apiKey) { 45 | log.info("DELETED"); 46 | return ResponseEntity.ok().build(); 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /openapi-demo/src/main/java/com/tmsvr/openapidemo/service/UuidService.java: -------------------------------------------------------------------------------- 1 | package com.tmsvr.openapidemo.service; 2 | 3 | import com.tmsvr.openapidemo.uuid.api.UuidApi; 4 | import lombok.RequiredArgsConstructor; 5 | import lombok.extern.slf4j.Slf4j; 6 | import org.springframework.stereotype.Service; 7 | import org.springframework.web.client.RestClientException; 8 | 9 | import java.util.List; 10 | 11 | @Slf4j 12 | @Service 13 | @RequiredArgsConstructor 14 | public class UuidService { 15 | 16 | private final UuidApi uuidApi; 17 | 18 | public List getUuids() { 19 | try { 20 | return uuidApi.generateUuid(4); 21 | } catch (RestClientException restClientException) { 22 | // TODO handle exceptions here 23 | log.warn(restClientException.getMessage(), restClientException); 24 | return List.of("not-so-unique"); 25 | } 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /openapi-demo/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | logging: 2 | level: 3 | feign.Logger: trace 4 | reactor: 5 | netty: trace 6 | ipc: 7 | netty: debug -------------------------------------------------------------------------------- /openapi-demo/uuid.yml: -------------------------------------------------------------------------------- 1 | openapi: 3.0.0 2 | servers: 3 | - description: UUID Generator API 4 | url: https://www.uuidtools.com/api/generate 5 | info: 6 | title: UUID Generator API 7 | version: "2.13.4" 8 | description: "These endpoints are specific to Xero Files API" 9 | tags: 10 | - name: Uuid 11 | paths: 12 | /v4/count/{count}: 13 | get: 14 | operationId: generateUuid 15 | summary: Generate type 4 UUID 16 | tags: 17 | - Uuid 18 | parameters: 19 | - name: count 20 | in: path 21 | required: true 22 | schema: 23 | type: integer 24 | format: int32 25 | responses: 26 | '200': 27 | description: search results matching criteria 28 | content: 29 | application/json: 30 | schema: 31 | $ref: '#/components/schemas/UuidResponse' 32 | components: 33 | schemas: 34 | UuidResponse: 35 | type: array 36 | items: 37 | type: string 38 | -------------------------------------------------------------------------------- /react-choropleth-map/.gitignore: -------------------------------------------------------------------------------- 1 | # See https://help.github.com/articles/ignoring-files/ for more about ignoring files. 2 | 3 | # dependencies 4 | /node_modules 5 | /.pnp 6 | .pnp.js 7 | 8 | # testing 9 | /coverage 10 | 11 | # production 12 | /build 13 | 14 | # misc 15 | .DS_Store 16 | .env.local 17 | .env.development.local 18 | .env.test.local 19 | .env.production.local 20 | 21 | npm-debug.log* 22 | yarn-debug.log* 23 | yarn-error.log* 24 | -------------------------------------------------------------------------------- /react-choropleth-map/README.md: -------------------------------------------------------------------------------- 1 | # Getting Started with Create React App 2 | 3 | This project was bootstrapped with [Create React App](https://github.com/facebook/create-react-app). 4 | 5 | ## Available Scripts 6 | 7 | In the project directory, you can run: 8 | 9 | ### `npm start` 10 | 11 | Runs the app in the development mode.\ 12 | Open [http://localhost:3000](http://localhost:3000) to view it in your browser. 13 | 14 | The page will reload when you make changes.\ 15 | You may also see any lint errors in the console. 16 | 17 | ### `npm test` 18 | 19 | Launches the test runner in the interactive watch mode.\ 20 | See the section about [running tests](https://facebook.github.io/create-react-app/docs/running-tests) for more information. 21 | 22 | ### `npm run build` 23 | 24 | Builds the app for production to the `build` folder.\ 25 | It correctly bundles React in production mode and optimizes the build for the best performance. 26 | 27 | The build is minified and the filenames include the hashes.\ 28 | Your app is ready to be deployed! 29 | 30 | See the section about [deployment](https://facebook.github.io/create-react-app/docs/deployment) for more information. 31 | 32 | ### `npm run eject` 33 | 34 | **Note: this is a one-way operation. Once you `eject`, you can't go back!** 35 | 36 | If you aren't satisfied with the build tool and configuration choices, you can `eject` at any time. This command will remove the single build dependency from your project. 37 | 38 | Instead, it will copy all the configuration files and the transitive dependencies (webpack, Babel, ESLint, etc) right into your project so you have full control over them. All of the commands except `eject` will still work, but they will point to the copied scripts so you can tweak them. At this point you're on your own. 39 | 40 | You don't have to ever use `eject`. The curated feature set is suitable for small and middle deployments, and you shouldn't feel obligated to use this feature. However we understand that this tool wouldn't be useful if you couldn't customize it when you are ready for it. 41 | 42 | ## Learn More 43 | 44 | You can learn more in the [Create React App documentation](https://facebook.github.io/create-react-app/docs/getting-started). 45 | 46 | To learn React, check out the [React documentation](https://reactjs.org/). 47 | 48 | ### Code Splitting 49 | 50 | This section has moved here: [https://facebook.github.io/create-react-app/docs/code-splitting](https://facebook.github.io/create-react-app/docs/code-splitting) 51 | 52 | ### Analyzing the Bundle Size 53 | 54 | This section has moved here: [https://facebook.github.io/create-react-app/docs/analyzing-the-bundle-size](https://facebook.github.io/create-react-app/docs/analyzing-the-bundle-size) 55 | 56 | ### Making a Progressive Web App 57 | 58 | This section has moved here: [https://facebook.github.io/create-react-app/docs/making-a-progressive-web-app](https://facebook.github.io/create-react-app/docs/making-a-progressive-web-app) 59 | 60 | ### Advanced Configuration 61 | 62 | This section has moved here: [https://facebook.github.io/create-react-app/docs/advanced-configuration](https://facebook.github.io/create-react-app/docs/advanced-configuration) 63 | 64 | ### Deployment 65 | 66 | This section has moved here: [https://facebook.github.io/create-react-app/docs/deployment](https://facebook.github.io/create-react-app/docs/deployment) 67 | 68 | ### `npm run build` fails to minify 69 | 70 | This section has moved here: [https://facebook.github.io/create-react-app/docs/troubleshooting#npm-run-build-fails-to-minify](https://facebook.github.io/create-react-app/docs/troubleshooting#npm-run-build-fails-to-minify) 71 | -------------------------------------------------------------------------------- /react-choropleth-map/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "react-choropleth-map", 3 | "version": "0.1.0", 4 | "private": true, 5 | "dependencies": { 6 | "@testing-library/jest-dom": "^5.16.1", 7 | "@testing-library/react": "^12.1.2", 8 | "@testing-library/user-event": "^13.5.0", 9 | "leaflet": "^1.7.1", 10 | "react": "^17.0.2", 11 | "react-dom": "^17.0.2", 12 | "react-leaflet": "^3.2.5", 13 | "react-scripts": "5.0.0", 14 | "web-vitals": "^2.1.4" 15 | }, 16 | "scripts": { 17 | "start": "react-scripts start", 18 | "build": "react-scripts build", 19 | "test": "react-scripts test", 20 | "eject": "react-scripts eject" 21 | }, 22 | "eslintConfig": { 23 | "extends": [ 24 | "react-app", 25 | "react-app/jest" 26 | ] 27 | }, 28 | "browserslist": { 29 | "production": [ 30 | ">0.2%", 31 | "not dead", 32 | "not op_mini all" 33 | ], 34 | "development": [ 35 | "last 1 chrome version", 36 | "last 1 firefox version", 37 | "last 1 safari version" 38 | ] 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /react-choropleth-map/public/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tmsvr/tmsvr-blog/e5197548705ca360a2ac9616405e51201cae6cf3/react-choropleth-map/public/favicon.ico -------------------------------------------------------------------------------- /react-choropleth-map/public/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 12 | 13 | 17 | 18 | 27 | React App 28 | 29 | 32 | 35 | 36 | 37 | 38 |
39 | 49 | 50 | 51 | -------------------------------------------------------------------------------- /react-choropleth-map/public/logo192.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tmsvr/tmsvr-blog/e5197548705ca360a2ac9616405e51201cae6cf3/react-choropleth-map/public/logo192.png -------------------------------------------------------------------------------- /react-choropleth-map/public/logo512.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tmsvr/tmsvr-blog/e5197548705ca360a2ac9616405e51201cae6cf3/react-choropleth-map/public/logo512.png -------------------------------------------------------------------------------- /react-choropleth-map/public/manifest.json: -------------------------------------------------------------------------------- 1 | { 2 | "short_name": "React App", 3 | "name": "Create React App Sample", 4 | "icons": [ 5 | { 6 | "src": "favicon.ico", 7 | "sizes": "64x64 32x32 24x24 16x16", 8 | "type": "image/x-icon" 9 | }, 10 | { 11 | "src": "logo192.png", 12 | "type": "image/png", 13 | "sizes": "192x192" 14 | }, 15 | { 16 | "src": "logo512.png", 17 | "type": "image/png", 18 | "sizes": "512x512" 19 | } 20 | ], 21 | "start_url": ".", 22 | "display": "standalone", 23 | "theme_color": "#000000", 24 | "background_color": "#ffffff" 25 | } 26 | -------------------------------------------------------------------------------- /react-choropleth-map/public/robots.txt: -------------------------------------------------------------------------------- 1 | # https://www.robotstxt.org/robotstxt.html 2 | User-agent: * 3 | Disallow: 4 | -------------------------------------------------------------------------------- /react-choropleth-map/src/ChoroplethMap.jsx: -------------------------------------------------------------------------------- 1 | import React, { useState } from 'react'; 2 | import { MapContainer, TileLayer, GeoJSON } from 'react-leaflet' 3 | import { InfoBox } from './InfoBox'; 4 | import { DataScopeSelector } from './DataScopeSelector'; 5 | 6 | import './index.css'; 7 | 8 | import countries from './custom.geo.50.json'; 9 | 10 | const dataScopes = [ 11 | { 12 | name: "Population", 13 | key: "pop_est", 14 | description: "The population of the country", 15 | unit: "", 16 | scale: [0, 5000000, 10000000, 25000000, 50000000, 75000000, 100000000, 200000000, 1000000000, 8000000000] 17 | }, 18 | { 19 | name: "GDP", 20 | key: "gdp_md_est", 21 | description: "The GDP of the country", 22 | unit: "USD", 23 | scale: [0, 10000, 50000, 100000, 500000, 1000000, 5000000, 1000000000] 24 | } 25 | ]; 26 | 27 | // from small to big, 15 colors https://colordesigner.io/gradient-generator 28 | const colors = [ 29 | '#fffddd', 30 | '#faf3c8', 31 | '#f6e8b3', 32 | '#f4dd9f', 33 | '#f3d18b', 34 | '#f2c578', 35 | '#f2b866', 36 | '#f2ab55', 37 | '#f39d46', 38 | '#f38e38', 39 | '#f47d2c', 40 | '#f56b23', 41 | '#f6571d', 42 | '#f63c1a', 43 | '#f6081b' 44 | ] 45 | 46 | export default function ChoroplethMap() { 47 | 48 | const [dataScope, setDataScope] = useState(dataScopes[0]); 49 | const [selectedCountry, setSelectedCountry] = useState(null); 50 | const [hoveredCountry, setHoveredCountry] = useState(null); 51 | 52 | const handleDataScopeChange = (event) => { 53 | setDataScope(dataScopes.find(element => element.key === event.target.value)); 54 | } 55 | 56 | const highlightFeature = (e) => { 57 | let layer = e.target; 58 | setHoveredCountry(layer.feature.properties); 59 | } 60 | 61 | const resetHighlight = (e) => { 62 | setHoveredCountry(null); 63 | } 64 | 65 | const onEachFeature = (feature, layer) => { 66 | layer.on({ 67 | mouseover: highlightFeature, 68 | mouseout: resetHighlight, 69 | click: () => setSelectedCountry(feature.properties) 70 | }); 71 | } 72 | 73 | const getColor = (val) => { 74 | for (let i = 1; i < dataScope.scale.length; i++) { 75 | if (val < dataScope.scale[i]) { 76 | return colors[i - 1]; 77 | } 78 | } 79 | 80 | return colors[colors.length - 1]; 81 | } 82 | 83 | const style = (feature) => { 84 | let mapStyle = { 85 | fillColor: getColor(feature.properties[dataScope.key]), 86 | weight: 1, 87 | opacity: 1, 88 | color: '#888', 89 | dashArray: '3', 90 | fillOpacity: 0.7 91 | }; 92 | 93 | if (hoveredCountry && feature.properties.iso_a3 === hoveredCountry.iso_a3) { 94 | mapStyle.color = '#444'; 95 | mapStyle.weight = 2; 96 | } 97 | 98 | return mapStyle; 99 | } 100 | 101 | return ( 102 |
103 | 104 | 105 | 106 | 107 | 108 | 109 |
110 | ); 111 | } -------------------------------------------------------------------------------- /react-choropleth-map/src/DataScopeSelector.jsx: -------------------------------------------------------------------------------- 1 | export function DataScopeSelector({ options, value, changeHandler }) { 2 | return ( 3 | 8 | ); 9 | } -------------------------------------------------------------------------------- /react-choropleth-map/src/InfoBox.jsx: -------------------------------------------------------------------------------- 1 | import './infobox.css'; 2 | 3 | function numberWithCommas(x) { 4 | if (x != null) { 5 | return x.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ","); 6 | } else { 7 | return ''; 8 | } 9 | } 10 | 11 | // TODO link is not clickable, infobox seems to be "transparent" 12 | export function InfoBox({ data, scope }) { 13 | let infoBox; 14 | if (data != null) { 15 | infoBox =

{data.name}

16 |

17 | {scope.name}: {numberWithCommas(data[scope.key])} {scope.unit} 18 |

19 | Description: {scope.description}
; 20 | } else { 21 | infoBox =

select a country

; 22 | } 23 | 24 | return ( 25 |
26 | {infoBox} 27 |
28 | ) 29 | } -------------------------------------------------------------------------------- /react-choropleth-map/src/index.css: -------------------------------------------------------------------------------- 1 | html, body { 2 | height: 100%; 3 | } 4 | 5 | #root, .mapContainer { 6 | height: 90%; 7 | } 8 | 9 | .leaflet-container { 10 | height: 100%; 11 | } -------------------------------------------------------------------------------- /react-choropleth-map/src/index.js: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | import ReactDOM from 'react-dom'; 3 | import ChoroplethMap from './ChoroplethMap' 4 | 5 | ReactDOM.render( 6 | 7 | 8 | 9 | , 10 | document.getElementById('root') 11 | ); 12 | -------------------------------------------------------------------------------- /react-choropleth-map/src/infobox.css: -------------------------------------------------------------------------------- 1 | .info { 2 | width: 200px; 3 | padding: 6px 8px; 4 | margin: 10px; 5 | font: 14px/16px Arial, Helvetica, sans-serif; 6 | color: #777; 7 | background: white; 8 | background: rgba(255, 255, 255, 0.8); 9 | box-shadow: 0 0 15px rgba(0, 0, 0, 0.2); 10 | border-radius: 5px; 11 | } 12 | 13 | .info h4 { 14 | margin: 0 0 5px; 15 | color: #777; 16 | } --------------------------------------------------------------------------------