Skip to content

Commit 7cad47d

Browse files
jimschubertwing328
authored andcommitted
[kotlin-server] --library=ktor (barebones implementation) (#7412)
* [tools] Make sed in new.sh more cross-platform The -r option passed to sed is a GNU sed option for extended regex evaluation. The -E option evaluates the same option, and is part of the POSIX standard, meaning this option is available in GNU sed as well as Apple's BSD variant. This commit removes the need for users to install gnu-sed on Mac. * [ktor] Initial ktor (kotlin-server) This adds a very barebones implementation for a ktor server generator. This supports metrics and typed locations. All endpoins are stubbed to return HTTP/1.1 501 Not Implemented. * [ktor] Initial sample * [ktor] Adding options for select feature installs Options available: * featureAutoHead * featureConditionalHeaders * featureHSTS * featureCORS * featureCompression * [ktor] Start of auth functionality * [ktor] API key auth placeholder * Add basic support for oauth2 configurations ktor doesn't seem to explicitly accept oauth flow properties in its configuration object. This may be a blocker for 'implicit' flow definitions. * Added example response objects * [ktor] Route for apis with bodies, some cleanup ktor locations are only supported for routes with path/query parameters. Routes with body or file parameters must be declared with traditional route api. This commit also includes lambdas for simplifying processing in library-based server generator code. As an example, ktor requires lowercase http methods while spring (a potential future generator) would require an uppercase such as HttpMethod.GET. It doesn't make sense to modify these in the operations post-process method because that format wouldn't be universally desirable. The lambdas included in the KotlinServerCodegen: * lowercase: converts all text to lowercase * uppercase: converts all text to UPPERCASE * titlecase: converts words (with configurable delim) to Title Case * indented|indented_8|indented_12|indented_16: these helpers apply the same desired indent to all lines of an included fragment's text. * Fix some javadoc issues in lambda classes * Update kotlin-server-petstore.bat Change `kotlin` to `kotlin-server` * Fix javadoc error messages in CI
1 parent a2410b2 commit 7cad47d

File tree

72 files changed

+3644
-496
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

72 files changed

+3644
-496
lines changed

bin/kotlin-server-petstore.sh

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
#!/bin/sh
2+
3+
SCRIPT="$0"
4+
5+
while [ -h "$SCRIPT" ] ; do
6+
ls=$(ls -ld "$SCRIPT")
7+
link=$(expr "$ls" : '.*-> \(.*\)$')
8+
if expr "$link" : '/.*' > /dev/null; then
9+
SCRIPT="$link"
10+
else
11+
SCRIPT=$(dirname "$SCRIPT")/"$link"
12+
fi
13+
done
14+
15+
if [ ! -d "${APP_DIR}" ]; then
16+
APP_DIR=$(dirname "$SCRIPT")/..
17+
APP_DIR=$(cd "${APP_DIR}"; pwd)
18+
fi
19+
20+
executable="./modules/swagger-codegen-cli/target/swagger-codegen-cli.jar"
21+
22+
if [ ! -f "$executable" ]
23+
then
24+
mvn clean package
25+
fi
26+
27+
# if you've executed sbt assembly previously it will use that instead.
28+
export JAVA_OPTS="${JAVA_OPTS} -XX:MaxPermSize=256M -Xmx1024M -DloggerPath=conf/log4j.properties -DdebugSupportingFiles=true"
29+
ags="generate -i modules/swagger-codegen/src/test/resources/2_0/petstore.yaml -t modules/swagger-codegen/src/main/resources/kotlin-server -l kotlin-server --library=ktor -o samples/server/petstore/kotlin-server/ktor $@"
30+
31+
java ${JAVA_OPTS} -jar ${executable} ${ags}
+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
set executable=.\modules\swagger-codegen-cli\target\swagger-codegen-cli.jar
2+
3+
If Not Exist %executable% (
4+
mvn clean package
5+
)
6+
7+
REM set JAVA_OPTS=%JAVA_OPTS% -Xmx1024M -DloggerPath=conf/log4j.properties
8+
set ags=generate --artifact-id "kotlin-petstore-server" -i modules\swagger-codegen\src\test\resources\2_0\petstore.yaml -l kotlin-server --library=ktor -o samples\server\petstore\kotlin
9+
10+
java %JAVA_OPTS% -jar %executable% %ags%

modules/swagger-codegen/src/main/java/io/swagger/codegen/CodegenConstants.java

+3
Original file line numberDiff line numberDiff line change
@@ -194,12 +194,15 @@ public static enum ENUM_PROPERTY_NAMING_TYPE {camelCase, PascalCase, snake_case,
194194
public static final String EXCLUDE_TESTS_DESC = "Specifies that no tests are to be generated.";
195195

196196
// Not user-configurable. System provided for use in templates.
197+
198+
public static final String GENERATE_APIS = "generateApis";
197199
public static final String GENERATE_API_DOCS = "generateApiDocs";
198200

199201
public static final String GENERATE_API_TESTS = "generateApiTests";
200202
public static final String GENERATE_API_TESTS_DESC = "Specifies that api tests are to be generated.";
201203

202204
// Not user-configurable. System provided for use in templates.
205+
public static final String GENERATE_MODELS = "generateModels";
203206
public static final String GENERATE_MODEL_DOCS = "generateModelDocs";
204207

205208
public static final String GENERATE_MODEL_TESTS = "generateModelTests";

modules/swagger-codegen/src/main/java/io/swagger/codegen/DefaultGenerator.java

+3
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,9 @@ private void configureGeneratorProperties() {
157157
config.additionalProperties().put(CodegenConstants.GENERATE_API_DOCS, generateApiDocumentation);
158158
config.additionalProperties().put(CodegenConstants.GENERATE_MODEL_DOCS, generateModelDocumentation);
159159

160+
config.additionalProperties().put(CodegenConstants.GENERATE_APIS, generateApis);
161+
config.additionalProperties().put(CodegenConstants.GENERATE_MODELS, generateModels);
162+
160163
if (!generateApiTests && !generateModelTests) {
161164
config.additionalProperties().put(CodegenConstants.EXCLUDE_TESTS, true);
162165
}

modules/swagger-codegen/src/main/java/io/swagger/codegen/InlineModelResolver.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -434,7 +434,7 @@ public Model modelFromProperty(MapProperty object, @SuppressWarnings("unused") S
434434
*
435435
* @param ref new property name
436436
* @param property Property
437-
* @return
437+
* @return {@link Property} A constructed Swagger property
438438
*/
439439
public Property makeRefProperty(String ref, Property property) {
440440
RefProperty newProperty = new RefProperty(ref);

0 commit comments

Comments
 (0)