mirror of
https://github.com/OpenAPITools/openapi-generator.git
synced 2025-12-06 02:56:17 +00:00
Add mutable model option to kotlin generators (#4115)
* Add mutable model option to kotlin generators fix #3803 * doc * Change template name to modelMutable * Samples
This commit is contained in:
committed by
William Cheng
parent
96c1bda608
commit
2dc0220874
@@ -1,4 +1,5 @@
|
|||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
|
|
||||||
./bin/kotlin-springboot-petstore-server.sh
|
./bin/kotlin-springboot-petstore-server.sh
|
||||||
./bin/kotlin-springboot-petstore-server-reactive.sh
|
./bin/kotlin-springboot-petstore-server-reactive.sh
|
||||||
|
./bin/kotlin-springboot-petstore-server-model-mutable.sh
|
||||||
|
|||||||
35
bin/kotlin-springboot-petstore-server-model-mutable.sh
Executable file
35
bin/kotlin-springboot-petstore-server-model-mutable.sh
Executable file
@@ -0,0 +1,35 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
SCRIPT="$0"
|
||||||
|
echo "# START SCRIPT: $SCRIPT"
|
||||||
|
|
||||||
|
while [ -h "$SCRIPT" ] ; do
|
||||||
|
ls=$(ls -ld "$SCRIPT")
|
||||||
|
link=$(expr "$ls" : '.*-> \(.*\)$')
|
||||||
|
if expr "$link" : '/.*' > /dev/null; then
|
||||||
|
SCRIPT="$link"
|
||||||
|
else
|
||||||
|
SCRIPT=$(dirname "$SCRIPT")/"$link"
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
|
||||||
|
if [ ! -d "${APP_DIR}" ]; then
|
||||||
|
APP_DIR=$(dirname "$SCRIPT")/..
|
||||||
|
APP_DIR=$(cd "${APP_DIR}"; pwd)
|
||||||
|
fi
|
||||||
|
|
||||||
|
executable="./modules/openapi-generator-cli/target/openapi-generator-cli.jar"
|
||||||
|
|
||||||
|
if [ ! -f "$executable" ]
|
||||||
|
then
|
||||||
|
mvn clean package
|
||||||
|
fi
|
||||||
|
|
||||||
|
export JAVA_OPTS="${JAVA_OPTS} -Xmx1024M -DloggerPath=conf/log4j.properties"
|
||||||
|
ags="$@ generate -i modules/openapi-generator/src/test/resources/2_0/petstore.yaml -t modules/openapi-generator/src/main/resources/kotlin-spring -g kotlin-spring -o samples/server/petstore/kotlin-springboot-modelMutable --additional-properties=library=spring-boot,beanValidations=true,swaggerAnnotations=true,serviceImplementation=true,serializableModel=true,modelMutable=true"
|
||||||
|
|
||||||
|
echo "Cleaning previously generated files if any from samples/server/petstore/kotlin-springboot"
|
||||||
|
rm -rf samples/server/petstore/kotlin-springboot-modelMutable
|
||||||
|
|
||||||
|
echo "Generating Kotling Spring Boot server..."
|
||||||
|
java $JAVA_OPTS -jar $executable $ags
|
||||||
@@ -26,6 +26,6 @@ fi
|
|||||||
|
|
||||||
# if you've executed sbt assembly previously it will use that instead.
|
# if you've executed sbt assembly previously it will use that instead.
|
||||||
export JAVA_OPTS="${JAVA_OPTS} -Xmx1024M -DloggerPath=conf/log4j.properties"
|
export JAVA_OPTS="${JAVA_OPTS} -Xmx1024M -DloggerPath=conf/log4j.properties"
|
||||||
ags="$@ generate -i modules/openapi-generator/src/test/resources/2_0/petstore.yaml -g kotlin-vertx -o samples/server/petstore/kotlin/vertx"
|
ags="$@ generate -i modules/openapi-generator/src/test/resources/2_0/petstore.yaml -g kotlin-vertx -o samples/server/petstore/kotlin/vertx --additional-properties=modelMutable=false"
|
||||||
|
|
||||||
java ${JAVA_OPTS} -jar ${executable} ${ags}
|
java ${JAVA_OPTS} -jar ${executable} ${ags}
|
||||||
|
|||||||
@@ -15,6 +15,7 @@ sidebar_label: kotlin-server
|
|||||||
|serializationLibrary|What serialization library to use: 'moshi' (default), or 'gson'| |moshi|
|
|serializationLibrary|What serialization library to use: 'moshi' (default), or 'gson'| |moshi|
|
||||||
|parcelizeModels|toggle "@Parcelize" for generated models| |null|
|
|parcelizeModels|toggle "@Parcelize" for generated models| |null|
|
||||||
|serializableModel|boolean - toggle "implements Serializable" for generated models| |null|
|
|serializableModel|boolean - toggle "implements Serializable" for generated models| |null|
|
||||||
|
|modelMutable|Create mutable models| |false|
|
||||||
|library|library template (sub-template)|<dl><dt>**ktor**</dt><dd>ktor framework</dd><dl>|ktor|
|
|library|library template (sub-template)|<dl><dt>**ktor**</dt><dd>ktor framework</dd><dl>|ktor|
|
||||||
|featureAutoHead|Automatically provide responses to HEAD requests for existing routes that have the GET verb defined.| |true|
|
|featureAutoHead|Automatically provide responses to HEAD requests for existing routes that have the GET verb defined.| |true|
|
||||||
|featureConditionalHeaders|Avoid sending content if client already has same content, by checking ETag or LastModified properties.| |false|
|
|featureConditionalHeaders|Avoid sending content if client already has same content, by checking ETag or LastModified properties.| |false|
|
||||||
|
|||||||
@@ -15,6 +15,7 @@ sidebar_label: kotlin-spring
|
|||||||
|serializationLibrary|What serialization library to use: 'moshi' (default), or 'gson'| |moshi|
|
|serializationLibrary|What serialization library to use: 'moshi' (default), or 'gson'| |moshi|
|
||||||
|parcelizeModels|toggle "@Parcelize" for generated models| |null|
|
|parcelizeModels|toggle "@Parcelize" for generated models| |null|
|
||||||
|serializableModel|boolean - toggle "implements Serializable" for generated models| |null|
|
|serializableModel|boolean - toggle "implements Serializable" for generated models| |null|
|
||||||
|
|modelMutable|Create mutable models| |false|
|
||||||
|title|server title name or client service name| |OpenAPI Kotlin Spring|
|
|title|server title name or client service name| |OpenAPI Kotlin Spring|
|
||||||
|basePackage|base package (invokerPackage) for generated code| |org.openapitools|
|
|basePackage|base package (invokerPackage) for generated code| |org.openapitools|
|
||||||
|serverPort|configuration the port in which the sever is to run on| |8080|
|
|serverPort|configuration the port in which the sever is to run on| |8080|
|
||||||
|
|||||||
@@ -15,3 +15,4 @@ sidebar_label: kotlin-vertx
|
|||||||
|serializationLibrary|What serialization library to use: 'moshi' (default), or 'gson'| |moshi|
|
|serializationLibrary|What serialization library to use: 'moshi' (default), or 'gson'| |moshi|
|
||||||
|parcelizeModels|toggle "@Parcelize" for generated models| |null|
|
|parcelizeModels|toggle "@Parcelize" for generated models| |null|
|
||||||
|serializableModel|boolean - toggle "implements Serializable" for generated models| |null|
|
|serializableModel|boolean - toggle "implements Serializable" for generated models| |null|
|
||||||
|
|modelMutable|Create mutable models| |false|
|
||||||
|
|||||||
@@ -15,6 +15,7 @@ sidebar_label: kotlin
|
|||||||
|serializationLibrary|What serialization library to use: 'moshi' (default), or 'gson'| |moshi|
|
|serializationLibrary|What serialization library to use: 'moshi' (default), or 'gson'| |moshi|
|
||||||
|parcelizeModels|toggle "@Parcelize" for generated models| |null|
|
|parcelizeModels|toggle "@Parcelize" for generated models| |null|
|
||||||
|serializableModel|boolean - toggle "implements Serializable" for generated models| |null|
|
|serializableModel|boolean - toggle "implements Serializable" for generated models| |null|
|
||||||
|
|modelMutable|Create mutable models| |false|
|
||||||
|dateLibrary|Option. Date library to use|<dl><dt>**string**</dt><dd>String</dd><dt>**java8**</dt><dd>Java 8 native JSR310 (jvm only)</dd><dt>**threetenbp**</dt><dd>Threetenbp (jvm only)</dd><dl>|java8|
|
|dateLibrary|Option. Date library to use|<dl><dt>**string**</dt><dd>String</dd><dt>**java8**</dt><dd>Java 8 native JSR310 (jvm only)</dd><dt>**threetenbp**</dt><dd>Threetenbp (jvm only)</dd><dl>|java8|
|
||||||
|collectionType|Option. Collection type to use|<dl><dt>**array**</dt><dd>kotlin.Array</dd><dt>**list**</dt><dd>kotlin.collections.List</dd><dl>|array|
|
|collectionType|Option. Collection type to use|<dl><dt>**array**</dt><dd>kotlin.Array</dd><dt>**list**</dt><dd>kotlin.collections.List</dd><dl>|array|
|
||||||
|library|Library template (sub-template) to use|<dl><dt>**jvm-okhttp4**</dt><dd>[DEFAULT] Platform: Java Virtual Machine. HTTP client: OkHttp 4.2.0 (Android 5.0+ and Java 8+). JSON processing: Moshi 1.8.0.</dd><dt>**jvm-okhttp3**</dt><dd>Platform: Java Virtual Machine. HTTP client: OkHttp 3.12.4 (Android 2.3+ and Java 7+). JSON processing: Moshi 1.8.0.</dd><dt>**multiplatform**</dt><dd>Platform: Kotlin multiplatform. HTTP client: Ktor 1.2.4. JSON processing: Kotlinx Serialization: 0.12.0.</dd><dl>|jvm-okhttp4|
|
|library|Library template (sub-template) to use|<dl><dt>**jvm-okhttp4**</dt><dd>[DEFAULT] Platform: Java Virtual Machine. HTTP client: OkHttp 4.2.0 (Android 5.0+ and Java 8+). JSON processing: Moshi 1.8.0.</dd><dt>**jvm-okhttp3**</dt><dd>Platform: Java Virtual Machine. HTTP client: OkHttp 3.12.4 (Android 2.3+ and Java 7+). JSON processing: Moshi 1.8.0.</dd><dt>**multiplatform**</dt><dd>Platform: Kotlin multiplatform. HTTP client: Ktor 1.2.4. JSON processing: Kotlinx Serialization: 0.12.0.</dd><dl>|jvm-okhttp4|
|
||||||
|
|||||||
@@ -43,6 +43,9 @@ public abstract class AbstractKotlinCodegen extends DefaultCodegen implements Co
|
|||||||
|
|
||||||
public enum SERIALIZATION_LIBRARY_TYPE {moshi, gson}
|
public enum SERIALIZATION_LIBRARY_TYPE {moshi, gson}
|
||||||
|
|
||||||
|
public static final String MODEL_MUTABLE = "modelMutable";
|
||||||
|
public static final String MODEL_MUTABLE_DESC = "Create mutable models";
|
||||||
|
|
||||||
private static final Logger LOGGER = LoggerFactory.getLogger(AbstractKotlinCodegen.class);
|
private static final Logger LOGGER = LoggerFactory.getLogger(AbstractKotlinCodegen.class);
|
||||||
|
|
||||||
protected String artifactId;
|
protected String artifactId;
|
||||||
@@ -225,6 +228,8 @@ public abstract class AbstractKotlinCodegen extends DefaultCodegen implements Co
|
|||||||
|
|
||||||
cliOptions.add(new CliOption(CodegenConstants.PARCELIZE_MODELS, CodegenConstants.PARCELIZE_MODELS_DESC));
|
cliOptions.add(new CliOption(CodegenConstants.PARCELIZE_MODELS, CodegenConstants.PARCELIZE_MODELS_DESC));
|
||||||
cliOptions.add(new CliOption(CodegenConstants.SERIALIZABLE_MODEL, CodegenConstants.SERIALIZABLE_MODEL_DESC));
|
cliOptions.add(new CliOption(CodegenConstants.SERIALIZABLE_MODEL, CodegenConstants.SERIALIZABLE_MODEL_DESC));
|
||||||
|
|
||||||
|
cliOptions.add(CliOption.newBoolean(MODEL_MUTABLE, MODEL_MUTABLE_DESC, false));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -9,4 +9,4 @@
|
|||||||
@SerializedName("{{{vendorExtensions.x-base-name-literal}}}")
|
@SerializedName("{{{vendorExtensions.x-base-name-literal}}}")
|
||||||
{{/gson}}
|
{{/gson}}
|
||||||
{{/jvm}}
|
{{/jvm}}
|
||||||
{{#multiplatform}}@SerialName(value = "{{{vendorExtensions.x-base-name-literal}}}") {{/multiplatform}}val {{{name}}}: {{#isEnum}}{{#isListContainer}}{{#isList}}kotlin.collections.List{{/isList}}{{^isList}}kotlin.Array{{/isList}}<{{classname}}.{{{nameInCamelCase}}}>{{/isListContainer}}{{^isListContainer}}{{classname}}.{{{nameInCamelCase}}}{{/isListContainer}}{{/isEnum}}{{^isEnum}}{{{dataType}}}{{/isEnum}}? = {{#defaultvalue}}{{defaultvalue}}{{/defaultvalue}}{{^defaultvalue}}null{{/defaultvalue}}
|
{{#multiplatform}}@SerialName(value = "{{{vendorExtensions.x-base-name-literal}}}") {{/multiplatform}}{{>modelMutable}} {{{name}}}: {{#isEnum}}{{#isListContainer}}{{#isList}}kotlin.collections.List{{/isList}}{{^isList}}kotlin.Array{{/isList}}<{{classname}}.{{{nameInCamelCase}}}>{{/isListContainer}}{{^isListContainer}}{{classname}}.{{{nameInCamelCase}}}{{/isListContainer}}{{/isEnum}}{{^isEnum}}{{{dataType}}}{{/isEnum}}? = {{#defaultvalue}}{{defaultvalue}}{{/defaultvalue}}{{^defaultvalue}}null{{/defaultvalue}}
|
||||||
@@ -9,4 +9,4 @@
|
|||||||
@SerializedName("{{{vendorExtensions.x-base-name-literal}}}")
|
@SerializedName("{{{vendorExtensions.x-base-name-literal}}}")
|
||||||
{{/gson}}
|
{{/gson}}
|
||||||
{{/jvm}}
|
{{/jvm}}
|
||||||
{{#multiplatform}}@SerialName(value = "{{{vendorExtensions.x-base-name-literal}}}") @Required {{/multiplatform}}val {{{name}}}: {{#isEnum}}{{#isListContainer}}{{#isList}}kotlin.collections.List{{/isList}}{{^isList}}kotlin.Array{{/isList}}<{{classname}}.{{{nameInCamelCase}}}>{{/isListContainer}}{{^isListContainer}}{{classname}}.{{{nameInCamelCase}}}{{/isListContainer}}{{/isEnum}}{{^isEnum}}{{{dataType}}}{{/isEnum}}
|
{{#multiplatform}}@SerialName(value = "{{{vendorExtensions.x-base-name-literal}}}") @Required {{/multiplatform}}{{>modelMutable}} {{{name}}}: {{#isEnum}}{{#isListContainer}}{{#isList}}kotlin.collections.List{{/isList}}{{^isList}}kotlin.Array{{/isList}}<{{classname}}.{{{nameInCamelCase}}}>{{/isListContainer}}{{^isListContainer}}{{classname}}.{{{nameInCamelCase}}}{{/isListContainer}}{{/isEnum}}{{^isEnum}}{{{dataType}}}{{/isEnum}}
|
||||||
1
modules/openapi-generator/src/main/resources/kotlin-client/modelMutable.mustache
vendored
Normal file
1
modules/openapi-generator/src/main/resources/kotlin-client/modelMutable.mustache
vendored
Normal file
@@ -0,0 +1 @@
|
|||||||
|
{{#modelMutable}}var{{/modelMutable}}{{^modelMutable}}val{{/modelMutable}}
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
{{#description}}
|
{{#description}}
|
||||||
/* {{{description}}} */
|
/* {{{description}}} */
|
||||||
{{/description}}
|
{{/description}}
|
||||||
val {{{name}}}: {{#isEnum}}{{classname}}.{{nameInCamelCase}}{{/isEnum}}{{^isEnum}}{{{dataType}}}{{/isEnum}}? = {{#defaultvalue}}{{defaultvalue}}{{/defaultvalue}}{{^defaultvalue}}null{{/defaultvalue}}
|
{{>modelMutable}} {{{name}}}: {{#isEnum}}{{classname}}.{{nameInCamelCase}}{{/isEnum}}{{^isEnum}}{{{dataType}}}{{/isEnum}}? = {{#defaultvalue}}{{defaultvalue}}{{/defaultvalue}}{{^defaultvalue}}null{{/defaultvalue}}
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
{{#description}}
|
{{#description}}
|
||||||
/* {{{description}}} */
|
/* {{{description}}} */
|
||||||
{{/description}}
|
{{/description}}
|
||||||
val {{{name}}}: {{#isEnum}}{{classname}}.{{nameInCamelCase}}{{/isEnum}}{{^isEnum}}{{{dataType}}}{{/isEnum}}
|
{{>modelMutable}} {{{name}}}: {{#isEnum}}{{classname}}.{{nameInCamelCase}}{{/isEnum}}{{^isEnum}}{{{dataType}}}{{/isEnum}}
|
||||||
1
modules/openapi-generator/src/main/resources/kotlin-server/modelMutable.mustache
vendored
Normal file
1
modules/openapi-generator/src/main/resources/kotlin-server/modelMutable.mustache
vendored
Normal file
@@ -0,0 +1 @@
|
|||||||
|
{{#modelMutable}}var{{/modelMutable}}{{^modelMutable}}val{{/modelMutable}}
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
{{#useBeanValidation}}{{#required}}
|
{{#useBeanValidation}}{{#required}}
|
||||||
{{^isReadOnly}}@get:NotNull{{/isReadOnly}} {{/required}}{{>beanValidationModel}}{{/useBeanValidation}}{{#swaggerAnnotations}}
|
{{^isReadOnly}}@get:NotNull{{/isReadOnly}} {{/required}}{{>beanValidationModel}}{{/useBeanValidation}}{{#swaggerAnnotations}}
|
||||||
@ApiModelProperty({{#example}}example = "{{{example}}}", {{/example}}{{#required}}required = {{required}}, {{/required}}{{#isReadOnly}}readOnly = {{{isReadOnly}}}, {{/isReadOnly}}value = "{{{description}}}"){{/swaggerAnnotations}}
|
@ApiModelProperty({{#example}}example = "{{{example}}}", {{/example}}{{#required}}required = {{required}}, {{/required}}{{#isReadOnly}}readOnly = {{{isReadOnly}}}, {{/isReadOnly}}value = "{{{description}}}"){{/swaggerAnnotations}}
|
||||||
@JsonProperty("{{{baseName}}}"){{#isInherited}} override{{/isInherited}} val {{{name}}}: {{#isEnum}}{{classname}}.{{nameInCamelCase}}{{/isEnum}}{{^isEnum}}{{{dataType}}}{{/isEnum}}? = {{#defaultvalue}}{{defaultvalue}}{{/defaultvalue}}{{^defaultvalue}}null{{/defaultvalue}}
|
@JsonProperty("{{{baseName}}}"){{#isInherited}} override{{/isInherited}} {{>modelMutable}} {{{name}}}: {{#isEnum}}{{classname}}.{{nameInCamelCase}}{{/isEnum}}{{^isEnum}}{{{dataType}}}{{/isEnum}}? = {{#defaultvalue}}{{defaultvalue}}{{/defaultvalue}}{{^defaultvalue}}null{{/defaultvalue}}
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
{{#useBeanValidation}}{{#required}}
|
{{#useBeanValidation}}{{#required}}
|
||||||
{{^isReadOnly}}@get:NotNull{{/isReadOnly}} {{/required}}{{>beanValidationModel}}{{/useBeanValidation}}{{#swaggerAnnotations}}
|
{{^isReadOnly}}@get:NotNull{{/isReadOnly}} {{/required}}{{>beanValidationModel}}{{/useBeanValidation}}{{#swaggerAnnotations}}
|
||||||
@ApiModelProperty({{#example}}example = "{{{example}}}", {{/example}}{{#required}}required = {{required}}, {{/required}}{{#isReadOnly}}readOnly = {{{isReadOnly}}}, {{/isReadOnly}}value = "{{{description}}}"){{/swaggerAnnotations}}
|
@ApiModelProperty({{#example}}example = "{{{example}}}", {{/example}}{{#required}}required = {{required}}, {{/required}}{{#isReadOnly}}readOnly = {{{isReadOnly}}}, {{/isReadOnly}}value = "{{{description}}}"){{/swaggerAnnotations}}
|
||||||
@JsonProperty("{{{baseName}}}"){{#isInherited}} override{{/isInherited}} val {{{name}}}: {{#isEnum}}{{classname}}.{{nameInCamelCase}}{{/isEnum}}{{^isEnum}}{{{dataType}}}{{/isEnum}}{{#isReadOnly}}? = {{#defaultvalue}}{{defaultvalue}}{{/defaultvalue}}{{^defaultvalue}}null{{/defaultvalue}}{{/isReadOnly}}
|
@JsonProperty("{{{baseName}}}"){{#isInherited}} override{{/isInherited}} {{>modelMutable}} {{{name}}}: {{#isEnum}}{{classname}}.{{nameInCamelCase}}{{/isEnum}}{{^isEnum}}{{{dataType}}}{{/isEnum}}{{#isReadOnly}}? = {{#defaultvalue}}{{defaultvalue}}{{/defaultvalue}}{{^defaultvalue}}null{{/defaultvalue}}{{/isReadOnly}}
|
||||||
@@ -1,3 +1,3 @@
|
|||||||
{{#swaggerAnnotations}}
|
{{#swaggerAnnotations}}
|
||||||
@ApiModelProperty({{#example}}example = "{{{example}}}", {{/example}}{{#required}}required = {{required}}, {{/required}}{{#isReadOnly}}readOnly = {{{isReadOnly}}}, {{/isReadOnly}}value = "{{{description}}}"){{/swaggerAnnotations}}
|
@ApiModelProperty({{#example}}example = "{{{example}}}", {{/example}}{{#required}}required = {{required}}, {{/required}}{{#isReadOnly}}readOnly = {{{isReadOnly}}}, {{/isReadOnly}}value = "{{{description}}}"){{/swaggerAnnotations}}
|
||||||
val {{{name}}}: {{#isEnum}}{{classname}}.{{nameInCamelCase}}{{/isEnum}}{{^isEnum}}{{{dataType}}}{{/isEnum}}? {{^discriminator}}= {{#defaultvalue}}{{defaultvalue}}{{/defaultvalue}}{{^defaultvalue}}null{{/defaultvalue}}{{/discriminator}}
|
{{>modelMutable}} {{{name}}}: {{#isEnum}}{{classname}}.{{nameInCamelCase}}{{/isEnum}}{{^isEnum}}{{{dataType}}}{{/isEnum}}? {{^discriminator}}= {{#defaultvalue}}{{defaultvalue}}{{/defaultvalue}}{{^defaultvalue}}null{{/defaultvalue}}{{/discriminator}}
|
||||||
@@ -1,3 +1,3 @@
|
|||||||
{{#swaggerAnnotations}}
|
{{#swaggerAnnotations}}
|
||||||
@ApiModelProperty({{#example}}example = "{{{example}}}", {{/example}}{{#required}}required = {{required}}, {{/required}}{{#isReadOnly}}readOnly = {{{isReadOnly}}}, {{/isReadOnly}}value = "{{{description}}}"){{/swaggerAnnotations}}
|
@ApiModelProperty({{#example}}example = "{{{example}}}", {{/example}}{{#required}}required = {{required}}, {{/required}}{{#isReadOnly}}readOnly = {{{isReadOnly}}}, {{/isReadOnly}}value = "{{{description}}}"){{/swaggerAnnotations}}
|
||||||
val {{{name}}}: {{#isEnum}}{{classname}}.{{nameInCamelCase}}{{/isEnum}}{{^isEnum}}{{{dataType}}}{{/isEnum}}
|
{{>modelMutable}} {{{name}}}: {{#isEnum}}{{classname}}.{{nameInCamelCase}}{{/isEnum}}{{^isEnum}}{{{dataType}}}{{/isEnum}}
|
||||||
1
modules/openapi-generator/src/main/resources/kotlin-spring/modelMutable.mustache
vendored
Normal file
1
modules/openapi-generator/src/main/resources/kotlin-spring/modelMutable.mustache
vendored
Normal file
@@ -0,0 +1 @@
|
|||||||
|
{{#modelMutable}}var{{/modelMutable}}{{^modelMutable}}val{{/modelMutable}}
|
||||||
@@ -36,7 +36,7 @@ data class {{classname}} (
|
|||||||
}
|
}
|
||||||
{{/isEnum}}{{/vars}}{{/hasEnums}}
|
{{/isEnum}}{{/vars}}{{/hasEnums}}
|
||||||
{{#requiredVars}}
|
{{#requiredVars}}
|
||||||
var {{{name}}} get() = _{{{name}}} ?: throw IllegalArgumentException("{{{name}}} is required")
|
{{>modelMutable}} {{{name}}} get() = _{{{name}}} ?: throw IllegalArgumentException("{{{name}}} is required")
|
||||||
set(value){ _{{{name}}} = value }
|
{{#modelMutable}}set(value){ _{{{name}}} = value }{{/modelMutable}}
|
||||||
{{/requiredVars}}
|
{{/requiredVars}}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
{{#description}}
|
{{#description}}
|
||||||
/* {{{description}}} */
|
/* {{{description}}} */
|
||||||
{{/description}}
|
{{/description}}
|
||||||
var {{{name}}}: {{#isEnum}}{{classname}}.{{nameInCamelCase}}{{/isEnum}}{{^isEnum}}{{{dataType}}}{{/isEnum}}? = {{#defaultvalue}}{{defaultvalue}}{{/defaultvalue}}{{^defaultvalue}}null{{/defaultvalue}}
|
{{>modelMutable}} {{{name}}}: {{#isEnum}}{{classname}}.{{nameInCamelCase}}{{/isEnum}}{{^isEnum}}{{{dataType}}}{{/isEnum}}? = {{#defaultvalue}}{{defaultvalue}}{{/defaultvalue}}{{^defaultvalue}}null{{/defaultvalue}}
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
{{#description}}
|
{{#description}}
|
||||||
/* {{{description}}} */
|
/* {{{description}}} */
|
||||||
{{/description}}
|
{{/description}}
|
||||||
@SerializedName("{{{name}}}") private var _{{{name}}}: {{#isEnum}}{{classname}}.{{nameInCamelCase}}{{/isEnum}}{{^isEnum}}{{{dataType}}}{{/isEnum}}?
|
@SerializedName("{{{name}}}") private {{>modelMutable}} _{{{name}}}: {{#isEnum}}{{classname}}.{{nameInCamelCase}}{{/isEnum}}{{^isEnum}}{{{dataType}}}{{/isEnum}}?
|
||||||
1
modules/openapi-generator/src/main/resources/kotlin-vertx-server/modelMutable.mustache
vendored
Normal file
1
modules/openapi-generator/src/main/resources/kotlin-vertx-server/modelMutable.mustache
vendored
Normal file
@@ -0,0 +1 @@
|
|||||||
|
{{#modelMutable}}var{{/modelMutable}}{{^modelMutable}}val{{/modelMutable}}
|
||||||
@@ -1,5 +1,6 @@
|
|||||||
package org.openapitools.codegen;
|
package org.openapitools.codegen;
|
||||||
|
|
||||||
|
import static org.testng.Assert.assertNotNull;
|
||||||
import static org.testng.Assert.fail;
|
import static org.testng.Assert.fail;
|
||||||
import static org.testng.Assert.assertTrue;
|
import static org.testng.Assert.assertTrue;
|
||||||
import static org.testng.Assert.assertFalse;
|
import static org.testng.Assert.assertFalse;
|
||||||
@@ -104,4 +105,27 @@ public class TestUtils {
|
|||||||
fail("Java parse problem: " + filename, ex);
|
fail("Java parse problem: " + filename, ex);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public static void assertFileContains(MockDefaultGenerator generator, String path, String... lines) {
|
||||||
|
final String generatedFile = generator.getFiles().get(path);
|
||||||
|
if (null == generatedFile) {
|
||||||
|
fail("File " + path + " not found in " + generator.getFiles().keySet());
|
||||||
|
}
|
||||||
|
String file = linearize(generatedFile);
|
||||||
|
assertNotNull(file);
|
||||||
|
for (String line : lines)
|
||||||
|
assertTrue(file.contains(linearize(line)));
|
||||||
|
}
|
||||||
|
|
||||||
|
private static String linearize(String target) {
|
||||||
|
return target.replaceAll("\r?\n", "").replaceAll("\\s+", "\\s");
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void assertFileNotContains(MockDefaultGenerator generator, String path, String... lines) {
|
||||||
|
String file = linearize(generator.getFiles().get(path));
|
||||||
|
assertNotNull(file);
|
||||||
|
for (String line : lines)
|
||||||
|
assertFalse(file.contains(linearize(line)));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -14,9 +14,8 @@ import java.io.File;
|
|||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.nio.file.Files;
|
import java.nio.file.Files;
|
||||||
|
|
||||||
import static org.testng.Assert.assertFalse;
|
import static org.openapitools.codegen.TestUtils.assertFileContains;
|
||||||
import static org.testng.Assert.assertNotNull;
|
import static org.openapitools.codegen.TestUtils.assertFileNotContains;
|
||||||
import static org.testng.Assert.assertTrue;
|
|
||||||
|
|
||||||
public abstract class JavaJaxrsBaseTest {
|
public abstract class JavaJaxrsBaseTest {
|
||||||
|
|
||||||
@@ -34,9 +33,9 @@ public abstract class JavaJaxrsBaseTest {
|
|||||||
|
|
||||||
codegen.additionalProperties().put(CXFServerFeatures.LOAD_TEST_DATA_FROM_FILE, "true");
|
codegen.additionalProperties().put(CXFServerFeatures.LOAD_TEST_DATA_FROM_FILE, "true");
|
||||||
|
|
||||||
ClientOptInput input = new ClientOptInput();
|
ClientOptInput input = new ClientOptInput()
|
||||||
input.setOpenAPI(openAPI);
|
.openAPI(openAPI)
|
||||||
input.setConfig(codegen);
|
.config(codegen);
|
||||||
|
|
||||||
MockDefaultGenerator generator = new MockDefaultGenerator();
|
MockDefaultGenerator generator = new MockDefaultGenerator();
|
||||||
generator.opts(input).generate();
|
generator.opts(input).generate();
|
||||||
@@ -47,19 +46,9 @@ public abstract class JavaJaxrsBaseTest {
|
|||||||
" @JsonSubTypes.Type(value = Dog.class, name = \"Dog\"),\n" +
|
" @JsonSubTypes.Type(value = Dog.class, name = \"Dog\"),\n" +
|
||||||
" @JsonSubTypes.Type(value = Cat.class, name = \"Cat\"),\n" +
|
" @JsonSubTypes.Type(value = Cat.class, name = \"Cat\"),\n" +
|
||||||
"})";
|
"})";
|
||||||
checkFileContains(generator, outputPath + "/src/gen/java/org/openapitools/model/Animal.java", jsonTypeInfo, jsonSubType);
|
assertFileContains(generator, outputPath + "/src/gen/java/org/openapitools/model/Animal.java", jsonTypeInfo, jsonSubType);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void checkFileContains(MockDefaultGenerator generator, String path, String... lines) {
|
|
||||||
String file = linearize(generator.getFiles().get(path));
|
|
||||||
assertNotNull(file);
|
|
||||||
for (String line : lines)
|
|
||||||
assertTrue(file.contains(linearize(line)));
|
|
||||||
}
|
|
||||||
|
|
||||||
private String linearize(String target) {
|
|
||||||
return target.replaceAll("\r?\n", "").replaceAll("\\s+", "\\s");
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void doNotGenerateJsonAnnotationForPolymorphismIfJsonExclude() throws IOException {
|
public void doNotGenerateJsonAnnotationForPolymorphismIfJsonExclude() throws IOException {
|
||||||
@@ -74,9 +63,9 @@ public abstract class JavaJaxrsBaseTest {
|
|||||||
|
|
||||||
codegen.additionalProperties().put(CXFServerFeatures.LOAD_TEST_DATA_FROM_FILE, "true");
|
codegen.additionalProperties().put(CXFServerFeatures.LOAD_TEST_DATA_FROM_FILE, "true");
|
||||||
|
|
||||||
ClientOptInput input = new ClientOptInput();
|
ClientOptInput input = new ClientOptInput()
|
||||||
input.setOpenAPI(openAPI);
|
.openAPI(openAPI)
|
||||||
input.setConfig(codegen);
|
.config(codegen);
|
||||||
|
|
||||||
MockDefaultGenerator generator = new MockDefaultGenerator();
|
MockDefaultGenerator generator = new MockDefaultGenerator();
|
||||||
generator.opts(input).generate();
|
generator.opts(input).generate();
|
||||||
@@ -87,15 +76,9 @@ public abstract class JavaJaxrsBaseTest {
|
|||||||
" @JsonSubTypes.Type(value = Dog.class, name = \"Dog\"),\n" +
|
" @JsonSubTypes.Type(value = Dog.class, name = \"Dog\"),\n" +
|
||||||
" @JsonSubTypes.Type(value = Cat.class, name = \"Cat\"),\n" +
|
" @JsonSubTypes.Type(value = Cat.class, name = \"Cat\"),\n" +
|
||||||
"})";
|
"})";
|
||||||
checkFileNotContains(generator, outputPath + "/src/gen/java/org/openapitools/model/Animal.java", jsonTypeInfo, jsonSubType);
|
assertFileNotContains(generator, outputPath + "/src/gen/java/org/openapitools/model/Animal.java", jsonTypeInfo, jsonSubType);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void checkFileNotContains(MockDefaultGenerator generator, String path, String... lines) {
|
|
||||||
String file = linearize(generator.getFiles().get(path));
|
|
||||||
assertNotNull(file);
|
|
||||||
for (String line : lines)
|
|
||||||
assertFalse(file.contains(linearize(line)));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void doNotAddDefaultValueDocumentationForContainers() throws IOException {
|
public void doNotAddDefaultValueDocumentationForContainers() throws IOException {
|
||||||
@@ -109,14 +92,14 @@ public abstract class JavaJaxrsBaseTest {
|
|||||||
|
|
||||||
codegen.additionalProperties().put(CXFServerFeatures.LOAD_TEST_DATA_FROM_FILE, "true");
|
codegen.additionalProperties().put(CXFServerFeatures.LOAD_TEST_DATA_FROM_FILE, "true");
|
||||||
|
|
||||||
ClientOptInput input = new ClientOptInput();
|
ClientOptInput input = new ClientOptInput()
|
||||||
input.setOpenAPI(openAPI);
|
.openAPI(openAPI)
|
||||||
input.setConfig(codegen);
|
.config(codegen);
|
||||||
|
|
||||||
MockDefaultGenerator generator = new MockDefaultGenerator();
|
MockDefaultGenerator generator = new MockDefaultGenerator();
|
||||||
generator.opts(input).generate();
|
generator.opts(input).generate();
|
||||||
|
|
||||||
checkFileNotContains(generator, outputPath + "/src/gen/java/org/openapitools/api/ExamplesApi.java", "DefaultValue");
|
assertFileNotContains(generator, outputPath + "/src/gen/java/org/openapitools/api/ExamplesApi.java", "DefaultValue");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -133,13 +116,13 @@ public abstract class JavaJaxrsBaseTest {
|
|||||||
|
|
||||||
codegen.additionalProperties().put(CXFServerFeatures.LOAD_TEST_DATA_FROM_FILE, "true");
|
codegen.additionalProperties().put(CXFServerFeatures.LOAD_TEST_DATA_FROM_FILE, "true");
|
||||||
|
|
||||||
ClientOptInput input = new ClientOptInput();
|
ClientOptInput input = new ClientOptInput()
|
||||||
input.setOpenAPI(openAPI);
|
.openAPI(openAPI)
|
||||||
input.setConfig(codegen);
|
.config(codegen);
|
||||||
|
|
||||||
MockDefaultGenerator generator = new MockDefaultGenerator();
|
MockDefaultGenerator generator = new MockDefaultGenerator();
|
||||||
generator.opts(input).generate();
|
generator.opts(input).generate();
|
||||||
|
|
||||||
checkFileContains(generator, outputPath + "/src/gen/java/org/openapitools/api/ExamplesApi.java", "DefaultValue");
|
assertFileContains(generator, outputPath + "/src/gen/java/org/openapitools/api/ExamplesApi.java", "DefaultValue");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,72 @@
|
|||||||
|
package org.openapitools.codegen.kotlin;
|
||||||
|
|
||||||
|
import io.swagger.parser.OpenAPIParser;
|
||||||
|
import io.swagger.v3.oas.models.OpenAPI;
|
||||||
|
import io.swagger.v3.parser.core.models.ParseOptions;
|
||||||
|
import org.openapitools.codegen.ClientOptInput;
|
||||||
|
import org.openapitools.codegen.CodegenConstants;
|
||||||
|
import org.openapitools.codegen.MockDefaultGenerator;
|
||||||
|
import org.openapitools.codegen.languages.AbstractKotlinCodegen;
|
||||||
|
import org.openapitools.codegen.languages.KotlinClientCodegen;
|
||||||
|
import org.openapitools.codegen.languages.KotlinServerCodegen;
|
||||||
|
import org.openapitools.codegen.languages.KotlinSpringServerCodegen;
|
||||||
|
import org.openapitools.codegen.languages.KotlinVertxServerCodegen;
|
||||||
|
import org.testng.annotations.DataProvider;
|
||||||
|
import org.testng.annotations.Test;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.nio.file.Files;
|
||||||
|
|
||||||
|
import static org.openapitools.codegen.TestUtils.assertFileContains;
|
||||||
|
|
||||||
|
public class KotlinModelCodegenTest {
|
||||||
|
|
||||||
|
@DataProvider(name = "generators")
|
||||||
|
public Object[][] client() {
|
||||||
|
return new Object[][]{
|
||||||
|
{new KotlinClientCodegen()},
|
||||||
|
{new KotlinServerCodegen()},
|
||||||
|
{new KotlinSpringServerCodegen()},
|
||||||
|
{new KotlinVertxServerCodegen()},
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test(dataProvider = "generators")
|
||||||
|
public void modelAsValues(AbstractKotlinCodegen codegen) throws IOException {
|
||||||
|
String classNameProp = "val className";
|
||||||
|
String colorProp = "val color";
|
||||||
|
|
||||||
|
checkModel(codegen, false, classNameProp, colorProp);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test(dataProvider = "generators")
|
||||||
|
private void modelMutable(AbstractKotlinCodegen codegen) throws IOException {
|
||||||
|
String classNameProp = "var className";
|
||||||
|
String colorProp = "var color";
|
||||||
|
|
||||||
|
checkModel(codegen, true, classNameProp, colorProp);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void checkModel(AbstractKotlinCodegen codegen, boolean mutable, String... props) throws IOException {
|
||||||
|
File output = Files.createTempDirectory("test").toFile().getCanonicalFile();
|
||||||
|
output.deleteOnExit();
|
||||||
|
String outputPath = output.getAbsolutePath().replace('\\', '/');
|
||||||
|
|
||||||
|
OpenAPI openAPI = new OpenAPIParser()
|
||||||
|
.readLocation("src/test/resources/3_0/generic.yaml", null, new ParseOptions()).getOpenAPI();
|
||||||
|
codegen.setOutputDir(output.getAbsolutePath());
|
||||||
|
|
||||||
|
codegen.additionalProperties().put(CodegenConstants.MODEL_PACKAGE, "models");
|
||||||
|
codegen.additionalProperties().put(AbstractKotlinCodegen.MODEL_MUTABLE, mutable);
|
||||||
|
|
||||||
|
ClientOptInput input = new ClientOptInput()
|
||||||
|
.openAPI(openAPI)
|
||||||
|
.config(codegen);
|
||||||
|
|
||||||
|
MockDefaultGenerator generator = new MockDefaultGenerator();
|
||||||
|
generator.opts(input).generate();
|
||||||
|
|
||||||
|
assertFileContains(generator, outputPath + "/src/main/kotlin/models/Animal.kt", props);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,23 @@
|
|||||||
|
# OpenAPI Generator Ignore
|
||||||
|
# Generated by openapi-generator https://github.com/openapitools/openapi-generator
|
||||||
|
|
||||||
|
# Use this file to prevent files from being overwritten by the generator.
|
||||||
|
# The patterns follow closely to .gitignore or .dockerignore.
|
||||||
|
|
||||||
|
# As an example, the C# client generator defines ApiClient.cs.
|
||||||
|
# You can make changes and tell OpenAPI Generator to ignore just this file by uncommenting the following line:
|
||||||
|
#ApiClient.cs
|
||||||
|
|
||||||
|
# You can match any string of characters against a directory, file or extension with a single asterisk (*):
|
||||||
|
#foo/*/qux
|
||||||
|
# The above matches foo/bar/qux and foo/baz/qux, but not foo/bar/baz/qux
|
||||||
|
|
||||||
|
# You can recursively match patterns against a directory, file or extension with a double asterisk (**):
|
||||||
|
#foo/**/qux
|
||||||
|
# This matches foo/bar/qux, foo/baz/qux, and foo/bar/baz/qux
|
||||||
|
|
||||||
|
# You can also negate patterns with an exclamation (!).
|
||||||
|
# For example, you can ignore all files in a docs folder with the file extension .md:
|
||||||
|
#docs/*.md
|
||||||
|
# Then explicitly reverse the ignore rule for a single file:
|
||||||
|
#!docs/README.md
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
4.2.1-SNAPSHOT
|
||||||
@@ -0,0 +1,21 @@
|
|||||||
|
# openAPIPetstore
|
||||||
|
|
||||||
|
This Kotlin based [Spring Boot](https://spring.io/projects/spring-boot) application has been generated using the [OpenAPI Generator](https://github.com/OpenAPITools/openapi-generator).
|
||||||
|
|
||||||
|
## Getting Started
|
||||||
|
|
||||||
|
This document assumes you have either maven or gradle available, either via the wrapper or otherwise. This does not come with a gradle / maven wrapper checked in.
|
||||||
|
|
||||||
|
By default a [`pom.xml`](pom.xml) file will be generated. If you specified `gradleBuildFile=true` when generating this project, a `build.gradle.kts` will also be generated. Note this uses [Gradle Kotlin DSL](https://github.com/gradle/kotlin-dsl).
|
||||||
|
|
||||||
|
To build the project using maven, run:
|
||||||
|
```bash
|
||||||
|
mvn package && java -jar target/openapi-spring-1.0.0.jar
|
||||||
|
```
|
||||||
|
|
||||||
|
To build the project using gradle, run:
|
||||||
|
```bash
|
||||||
|
gradle build && java -jar build/libs/openapi-spring-1.0.0.jar
|
||||||
|
```
|
||||||
|
|
||||||
|
If all builds successfully, the server should run on [http://localhost:8080/](http://localhost:8080/)
|
||||||
@@ -0,0 +1,54 @@
|
|||||||
|
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
|
||||||
|
|
||||||
|
buildscript {
|
||||||
|
repositories {
|
||||||
|
jcenter()
|
||||||
|
mavenCentral()
|
||||||
|
}
|
||||||
|
dependencies {
|
||||||
|
classpath("org.springframework.boot:spring-boot-gradle-plugin:2.2.0.M3")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
group = "org.openapitools"
|
||||||
|
version = "1.0.0"
|
||||||
|
|
||||||
|
repositories {
|
||||||
|
jcenter()
|
||||||
|
mavenCentral()
|
||||||
|
}
|
||||||
|
|
||||||
|
tasks.withType<KotlinCompile> {
|
||||||
|
kotlinOptions.jvmTarget = "1.8"
|
||||||
|
}
|
||||||
|
|
||||||
|
plugins {
|
||||||
|
val kotlinVersion = "1.3.30"
|
||||||
|
id("org.jetbrains.kotlin.jvm") version kotlinVersion
|
||||||
|
id("org.jetbrains.kotlin.plugin.jpa") version kotlinVersion
|
||||||
|
id("org.jetbrains.kotlin.plugin.spring") version kotlinVersion
|
||||||
|
id("org.springframework.boot") version "2.2.0.M3"
|
||||||
|
id("io.spring.dependency-management") version "1.0.5.RELEASE"
|
||||||
|
}
|
||||||
|
|
||||||
|
dependencies {
|
||||||
|
val kotlinxCoroutinesVersion="1.2.0"
|
||||||
|
compile("org.jetbrains.kotlin:kotlin-stdlib-jdk8")
|
||||||
|
compile("org.jetbrains.kotlin:kotlin-reflect")
|
||||||
|
compile("org.springframework.boot:spring-boot-starter-web")
|
||||||
|
compile("io.swagger:swagger-annotations:1.5.21")
|
||||||
|
compile("com.fasterxml.jackson.dataformat:jackson-dataformat-yaml")
|
||||||
|
compile("com.fasterxml.jackson.dataformat:jackson-dataformat-xml")
|
||||||
|
compile("com.fasterxml.jackson.module:jackson-module-kotlin")
|
||||||
|
|
||||||
|
testCompile("org.jetbrains.kotlin:kotlin-test-junit5")
|
||||||
|
testCompile("org.springframework.boot:spring-boot-starter-test") {
|
||||||
|
exclude(module = "junit")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
repositories {
|
||||||
|
mavenCentral()
|
||||||
|
maven { url = uri("https://repo.spring.io/snapshot") }
|
||||||
|
maven { url = uri("https://repo.spring.io/milestone") }
|
||||||
|
}
|
||||||
153
samples/server/petstore/kotlin-springboot-modelMutable/pom.xml
Normal file
153
samples/server/petstore/kotlin-springboot-modelMutable/pom.xml
Normal file
@@ -0,0 +1,153 @@
|
|||||||
|
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
|
||||||
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
<groupId>org.openapitools</groupId>
|
||||||
|
<artifactId>openapi-spring</artifactId>
|
||||||
|
<packaging>jar</packaging>
|
||||||
|
<name>openapi-spring</name>
|
||||||
|
<version>1.0.0</version>
|
||||||
|
<properties>
|
||||||
|
<kotlin.version>1.3.30</kotlin.version>
|
||||||
|
<kotlinx-coroutines.version>1.2.0</kotlinx-coroutines.version>
|
||||||
|
</properties>
|
||||||
|
<parent>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-starter-parent</artifactId>
|
||||||
|
<version>2.2.0.M3</version>
|
||||||
|
</parent>
|
||||||
|
<build>
|
||||||
|
<sourceDirectory>${project.basedir}/src/main/kotlin</sourceDirectory>
|
||||||
|
<testSourceDirectory>${project.basedir}/src/test/kotlin</testSourceDirectory>
|
||||||
|
<plugins>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-maven-plugin</artifactId>
|
||||||
|
<executions>
|
||||||
|
<execution>
|
||||||
|
<goals>
|
||||||
|
<goal>repackage</goal>
|
||||||
|
</goals>
|
||||||
|
</execution>
|
||||||
|
</executions>
|
||||||
|
</plugin>
|
||||||
|
<plugin>
|
||||||
|
<artifactId>kotlin-maven-plugin</artifactId>
|
||||||
|
<groupId>org.jetbrains.kotlin</groupId>
|
||||||
|
<version>${kotlin.version}</version>
|
||||||
|
<configuration>
|
||||||
|
<compilerPlugins>
|
||||||
|
<plugin>spring</plugin>
|
||||||
|
</compilerPlugins>
|
||||||
|
<jvmTarget>1.8</jvmTarget>
|
||||||
|
</configuration>
|
||||||
|
<executions>
|
||||||
|
<execution>
|
||||||
|
<id>compile</id>
|
||||||
|
<phase>compile</phase>
|
||||||
|
<goals>
|
||||||
|
<goal>compile</goal>
|
||||||
|
</goals>
|
||||||
|
</execution>
|
||||||
|
<execution>
|
||||||
|
<id>test-compile</id>
|
||||||
|
<phase>test-compile</phase>
|
||||||
|
<goals>
|
||||||
|
<goal>test-compile</goal>
|
||||||
|
</goals>
|
||||||
|
</execution>
|
||||||
|
</executions>
|
||||||
|
<dependencies>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.jetbrains.kotlin</groupId>
|
||||||
|
<artifactId>kotlin-maven-allopen</artifactId>
|
||||||
|
<version>${kotlin.version}</version>
|
||||||
|
</dependency>
|
||||||
|
</dependencies>
|
||||||
|
</plugin>
|
||||||
|
</plugins>
|
||||||
|
</build>
|
||||||
|
<dependencies>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.jetbrains.kotlin</groupId>
|
||||||
|
<artifactId>kotlin-stdlib-jdk8</artifactId>
|
||||||
|
<version>${kotlin.version}</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.jetbrains.kotlin</groupId>
|
||||||
|
<artifactId>kotlin-reflect</artifactId>
|
||||||
|
<version>${kotlin.version}</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-starter-web</artifactId>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>io.swagger</groupId>
|
||||||
|
<artifactId>swagger-annotations</artifactId>
|
||||||
|
<version>1.5.21</version>
|
||||||
|
</dependency>
|
||||||
|
<!-- @Nullable annotation -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.google.code.findbugs</groupId>
|
||||||
|
<artifactId>jsr305</artifactId>
|
||||||
|
<version>3.0.2</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.fasterxml.jackson.dataformat</groupId>
|
||||||
|
<artifactId>jackson-dataformat-yaml</artifactId>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.fasterxml.jackson.dataformat</groupId>
|
||||||
|
<artifactId>jackson-dataformat-xml</artifactId>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.fasterxml.jackson.datatype</groupId>
|
||||||
|
<artifactId>jackson-datatype-jsr310</artifactId>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.fasterxml.jackson.module</groupId>
|
||||||
|
<artifactId>jackson-module-kotlin</artifactId>
|
||||||
|
</dependency>
|
||||||
|
<!-- Bean Validation API support -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>javax.validation</groupId>
|
||||||
|
<artifactId>validation-api</artifactId>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.jetbrains.kotlin</groupId>
|
||||||
|
<artifactId>kotlin-test-junit5</artifactId>
|
||||||
|
<version>1.3.31</version>
|
||||||
|
<scope>test</scope>
|
||||||
|
</dependency>
|
||||||
|
</dependencies>
|
||||||
|
<repositories>
|
||||||
|
<repository>
|
||||||
|
<id>spring-snapshots</id>
|
||||||
|
<name>Spring Snapshots</name>
|
||||||
|
<url>https://repo.spring.io/snapshot</url>
|
||||||
|
<snapshots>
|
||||||
|
<enabled>true</enabled>
|
||||||
|
</snapshots>
|
||||||
|
</repository>
|
||||||
|
<repository>
|
||||||
|
<id>spring-milestones</id>
|
||||||
|
<name>Spring Milestones</name>
|
||||||
|
<url>https://repo.spring.io/milestone</url>
|
||||||
|
</repository>
|
||||||
|
</repositories>
|
||||||
|
<pluginRepositories>
|
||||||
|
<pluginRepository>
|
||||||
|
<id>spring-snapshots</id>
|
||||||
|
<name>Spring Snapshots</name>
|
||||||
|
<url>https://repo.spring.io/snapshot</url>
|
||||||
|
<snapshots>
|
||||||
|
<enabled>true</enabled>
|
||||||
|
</snapshots>
|
||||||
|
</pluginRepository>
|
||||||
|
<pluginRepository>
|
||||||
|
<id>spring-milestones</id>
|
||||||
|
<name>Spring Milestones</name>
|
||||||
|
<url>https://repo.spring.io/milestone</url>
|
||||||
|
</pluginRepository>
|
||||||
|
</pluginRepositories>
|
||||||
|
</project>
|
||||||
@@ -0,0 +1,15 @@
|
|||||||
|
pluginManagement {
|
||||||
|
repositories {
|
||||||
|
maven { url = uri("https://repo.spring.io/snapshot") }
|
||||||
|
maven { url = uri("https://repo.spring.io/milestone") }
|
||||||
|
gradlePluginPortal()
|
||||||
|
}
|
||||||
|
resolutionStrategy {
|
||||||
|
eachPlugin {
|
||||||
|
if (requested.id.id == "org.springframework.boot") {
|
||||||
|
useModule("org.springframework.boot:spring-boot-gradle-plugin:${requested.version}")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
rootProject.name = "openapi-spring"
|
||||||
@@ -0,0 +1,14 @@
|
|||||||
|
package org.openapitools
|
||||||
|
|
||||||
|
import org.springframework.boot.runApplication
|
||||||
|
import org.springframework.context.annotation.ComponentScan
|
||||||
|
import org.springframework.boot.autoconfigure.SpringBootApplication
|
||||||
|
|
||||||
|
|
||||||
|
@SpringBootApplication
|
||||||
|
@ComponentScan(basePackages = ["org.openapitools", "org.openapitools.api", "org.openapitools.model"])
|
||||||
|
class Application
|
||||||
|
|
||||||
|
fun main(args: Array<String>) {
|
||||||
|
runApplication<Application>(*args)
|
||||||
|
}
|
||||||
@@ -0,0 +1,29 @@
|
|||||||
|
package org.openapitools.api
|
||||||
|
|
||||||
|
import org.springframework.http.HttpStatus
|
||||||
|
import org.springframework.web.bind.annotation.ControllerAdvice
|
||||||
|
import org.springframework.web.bind.annotation.ExceptionHandler
|
||||||
|
import javax.servlet.http.HttpServletResponse
|
||||||
|
import javax.validation.ConstraintViolationException
|
||||||
|
|
||||||
|
// TODO Extend ApiException for custom exception handling, e.g. the below NotFound exception
|
||||||
|
sealed class ApiException(msg: String, val code: Int) : Exception(msg)
|
||||||
|
|
||||||
|
class NotFoundException(msg: String, code: Int = HttpStatus.NOT_FOUND.value()) : ApiException(msg, code)
|
||||||
|
|
||||||
|
|
||||||
|
@ControllerAdvice
|
||||||
|
class DefaultExceptionHandler {
|
||||||
|
|
||||||
|
@ExceptionHandler(value = [ApiException::class])
|
||||||
|
fun onApiException(ex: ApiException, response: HttpServletResponse): Unit =
|
||||||
|
response.sendError(ex.code, ex.message)
|
||||||
|
|
||||||
|
@ExceptionHandler(value = [NotImplementedError::class])
|
||||||
|
fun onNotImplemented(ex: NotImplementedError, response: HttpServletResponse): Unit =
|
||||||
|
response.sendError(HttpStatus.NOT_IMPLEMENTED.value())
|
||||||
|
|
||||||
|
@ExceptionHandler(value = [ConstraintViolationException::class])
|
||||||
|
fun onConstraintViolation(ex: ConstraintViolationException, response: HttpServletResponse): Unit =
|
||||||
|
response.sendError(HttpStatus.BAD_REQUEST.value(), ex.constraintViolations.joinToString(", ") { it.message })
|
||||||
|
}
|
||||||
@@ -0,0 +1,184 @@
|
|||||||
|
package org.openapitools.api
|
||||||
|
|
||||||
|
import org.openapitools.model.ModelApiResponse
|
||||||
|
import org.openapitools.model.Pet
|
||||||
|
import io.swagger.annotations.Api
|
||||||
|
import io.swagger.annotations.ApiOperation
|
||||||
|
import io.swagger.annotations.ApiParam
|
||||||
|
import io.swagger.annotations.ApiResponse
|
||||||
|
import io.swagger.annotations.ApiResponses
|
||||||
|
import io.swagger.annotations.Authorization
|
||||||
|
import io.swagger.annotations.AuthorizationScope
|
||||||
|
import org.springframework.http.HttpStatus
|
||||||
|
import org.springframework.http.MediaType
|
||||||
|
import org.springframework.http.ResponseEntity
|
||||||
|
|
||||||
|
import org.springframework.web.bind.annotation.RequestBody
|
||||||
|
import org.springframework.web.bind.annotation.RequestPart
|
||||||
|
import org.springframework.web.bind.annotation.RequestParam
|
||||||
|
import org.springframework.web.bind.annotation.PathVariable
|
||||||
|
import org.springframework.web.bind.annotation.RequestHeader
|
||||||
|
import org.springframework.web.bind.annotation.RequestMethod
|
||||||
|
import org.springframework.web.bind.annotation.RequestMapping
|
||||||
|
import org.springframework.web.bind.annotation.RestController
|
||||||
|
import org.springframework.validation.annotation.Validated
|
||||||
|
import org.springframework.web.context.request.NativeWebRequest
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired
|
||||||
|
|
||||||
|
import javax.validation.Valid
|
||||||
|
import javax.validation.constraints.DecimalMax
|
||||||
|
import javax.validation.constraints.DecimalMin
|
||||||
|
import javax.validation.constraints.Max
|
||||||
|
import javax.validation.constraints.Min
|
||||||
|
import javax.validation.constraints.NotNull
|
||||||
|
import javax.validation.constraints.Pattern
|
||||||
|
import javax.validation.constraints.Size
|
||||||
|
|
||||||
|
import kotlin.collections.List
|
||||||
|
import kotlin.collections.Map
|
||||||
|
|
||||||
|
@RestController
|
||||||
|
@Validated
|
||||||
|
@Api(value = "Pet", description = "The Pet API")
|
||||||
|
@RequestMapping("\${api.base-path:/v2}")
|
||||||
|
class PetApiController(@Autowired(required = true) val service: PetApiService) {
|
||||||
|
|
||||||
|
@ApiOperation(
|
||||||
|
value = "Add a new pet to the store",
|
||||||
|
nickname = "addPet",
|
||||||
|
notes = "",
|
||||||
|
authorizations = [Authorization(value = "petstore_auth", scopes = [AuthorizationScope(scope = "write:pets", description = "modify pets in your account"), AuthorizationScope(scope = "read:pets", description = "read your pets")])])
|
||||||
|
@ApiResponses(
|
||||||
|
value = [ApiResponse(code = 405, message = "Invalid input")])
|
||||||
|
@RequestMapping(
|
||||||
|
value = ["/pet"],
|
||||||
|
consumes = ["application/json", "application/xml"],
|
||||||
|
method = [RequestMethod.POST])
|
||||||
|
fun addPet(@ApiParam(value = "Pet object that needs to be added to the store" ,required=true ) @Valid @RequestBody body: Pet
|
||||||
|
): ResponseEntity<Unit> {
|
||||||
|
return ResponseEntity(service.addPet(body), HttpStatus.valueOf(405))
|
||||||
|
}
|
||||||
|
|
||||||
|
@ApiOperation(
|
||||||
|
value = "Deletes a pet",
|
||||||
|
nickname = "deletePet",
|
||||||
|
notes = "",
|
||||||
|
authorizations = [Authorization(value = "petstore_auth", scopes = [AuthorizationScope(scope = "write:pets", description = "modify pets in your account"), AuthorizationScope(scope = "read:pets", description = "read your pets")])])
|
||||||
|
@ApiResponses(
|
||||||
|
value = [ApiResponse(code = 400, message = "Invalid pet value")])
|
||||||
|
@RequestMapping(
|
||||||
|
value = ["/pet/{petId}"],
|
||||||
|
method = [RequestMethod.DELETE])
|
||||||
|
fun deletePet(@ApiParam(value = "Pet id to delete", required=true) @PathVariable("petId") petId: kotlin.Long
|
||||||
|
,@ApiParam(value = "" ) @RequestHeader(value="api_key", required=false) apiKey: kotlin.String?
|
||||||
|
): ResponseEntity<Unit> {
|
||||||
|
return ResponseEntity(service.deletePet(petId, apiKey), HttpStatus.valueOf(400))
|
||||||
|
}
|
||||||
|
|
||||||
|
@ApiOperation(
|
||||||
|
value = "Finds Pets by status",
|
||||||
|
nickname = "findPetsByStatus",
|
||||||
|
notes = "Multiple status values can be provided with comma separated strings",
|
||||||
|
response = Pet::class,
|
||||||
|
responseContainer = "List",
|
||||||
|
authorizations = [Authorization(value = "petstore_auth", scopes = [AuthorizationScope(scope = "write:pets", description = "modify pets in your account"), AuthorizationScope(scope = "read:pets", description = "read your pets")])])
|
||||||
|
@ApiResponses(
|
||||||
|
value = [ApiResponse(code = 200, message = "successful operation", response = Pet::class, responseContainer = "List"),ApiResponse(code = 400, message = "Invalid status value")])
|
||||||
|
@RequestMapping(
|
||||||
|
value = ["/pet/findByStatus"],
|
||||||
|
produces = ["application/xml", "application/json"],
|
||||||
|
method = [RequestMethod.GET])
|
||||||
|
fun findPetsByStatus(@NotNull @ApiParam(value = "Status values that need to be considered for filter", required = true, allowableValues = "available, pending, sold") @Valid @RequestParam(value = "status", required = true) status: kotlin.collections.List<kotlin.String>
|
||||||
|
): ResponseEntity<List<Pet>> {
|
||||||
|
return ResponseEntity(service.findPetsByStatus(status), HttpStatus.valueOf(200))
|
||||||
|
}
|
||||||
|
|
||||||
|
@ApiOperation(
|
||||||
|
value = "Finds Pets by tags",
|
||||||
|
nickname = "findPetsByTags",
|
||||||
|
notes = "Multiple tags can be provided with comma separated strings. Use tag1, tag2, tag3 for testing.",
|
||||||
|
response = Pet::class,
|
||||||
|
responseContainer = "List",
|
||||||
|
authorizations = [Authorization(value = "petstore_auth", scopes = [AuthorizationScope(scope = "write:pets", description = "modify pets in your account"), AuthorizationScope(scope = "read:pets", description = "read your pets")])])
|
||||||
|
@ApiResponses(
|
||||||
|
value = [ApiResponse(code = 200, message = "successful operation", response = Pet::class, responseContainer = "List"),ApiResponse(code = 400, message = "Invalid tag value")])
|
||||||
|
@RequestMapping(
|
||||||
|
value = ["/pet/findByTags"],
|
||||||
|
produces = ["application/xml", "application/json"],
|
||||||
|
method = [RequestMethod.GET])
|
||||||
|
fun findPetsByTags(@NotNull @ApiParam(value = "Tags to filter by", required = true) @Valid @RequestParam(value = "tags", required = true) tags: kotlin.collections.List<kotlin.String>
|
||||||
|
): ResponseEntity<List<Pet>> {
|
||||||
|
return ResponseEntity(service.findPetsByTags(tags), HttpStatus.valueOf(200))
|
||||||
|
}
|
||||||
|
|
||||||
|
@ApiOperation(
|
||||||
|
value = "Find pet by ID",
|
||||||
|
nickname = "getPetById",
|
||||||
|
notes = "Returns a single pet",
|
||||||
|
response = Pet::class,
|
||||||
|
authorizations = [Authorization(value = "api_key")])
|
||||||
|
@ApiResponses(
|
||||||
|
value = [ApiResponse(code = 200, message = "successful operation", response = Pet::class),ApiResponse(code = 400, message = "Invalid ID supplied"),ApiResponse(code = 404, message = "Pet not found")])
|
||||||
|
@RequestMapping(
|
||||||
|
value = ["/pet/{petId}"],
|
||||||
|
produces = ["application/xml", "application/json"],
|
||||||
|
method = [RequestMethod.GET])
|
||||||
|
fun getPetById(@ApiParam(value = "ID of pet to return", required=true) @PathVariable("petId") petId: kotlin.Long
|
||||||
|
): ResponseEntity<Pet> {
|
||||||
|
return ResponseEntity(service.getPetById(petId), HttpStatus.valueOf(200))
|
||||||
|
}
|
||||||
|
|
||||||
|
@ApiOperation(
|
||||||
|
value = "Update an existing pet",
|
||||||
|
nickname = "updatePet",
|
||||||
|
notes = "",
|
||||||
|
authorizations = [Authorization(value = "petstore_auth", scopes = [AuthorizationScope(scope = "write:pets", description = "modify pets in your account"), AuthorizationScope(scope = "read:pets", description = "read your pets")])])
|
||||||
|
@ApiResponses(
|
||||||
|
value = [ApiResponse(code = 400, message = "Invalid ID supplied"),ApiResponse(code = 404, message = "Pet not found"),ApiResponse(code = 405, message = "Validation exception")])
|
||||||
|
@RequestMapping(
|
||||||
|
value = ["/pet"],
|
||||||
|
consumes = ["application/json", "application/xml"],
|
||||||
|
method = [RequestMethod.PUT])
|
||||||
|
fun updatePet(@ApiParam(value = "Pet object that needs to be added to the store" ,required=true ) @Valid @RequestBody body: Pet
|
||||||
|
): ResponseEntity<Unit> {
|
||||||
|
return ResponseEntity(service.updatePet(body), HttpStatus.valueOf(400))
|
||||||
|
}
|
||||||
|
|
||||||
|
@ApiOperation(
|
||||||
|
value = "Updates a pet in the store with form data",
|
||||||
|
nickname = "updatePetWithForm",
|
||||||
|
notes = "",
|
||||||
|
authorizations = [Authorization(value = "petstore_auth", scopes = [AuthorizationScope(scope = "write:pets", description = "modify pets in your account"), AuthorizationScope(scope = "read:pets", description = "read your pets")])])
|
||||||
|
@ApiResponses(
|
||||||
|
value = [ApiResponse(code = 405, message = "Invalid input")])
|
||||||
|
@RequestMapping(
|
||||||
|
value = ["/pet/{petId}"],
|
||||||
|
consumes = ["application/x-www-form-urlencoded"],
|
||||||
|
method = [RequestMethod.POST])
|
||||||
|
fun updatePetWithForm(@ApiParam(value = "ID of pet that needs to be updated", required=true) @PathVariable("petId") petId: kotlin.Long
|
||||||
|
,@ApiParam(value = "Updated name of the pet") @RequestParam(value="name", required=false) name: kotlin.String?
|
||||||
|
,@ApiParam(value = "Updated status of the pet") @RequestParam(value="status", required=false) status: kotlin.String?
|
||||||
|
): ResponseEntity<Unit> {
|
||||||
|
return ResponseEntity(service.updatePetWithForm(petId, name, status), HttpStatus.valueOf(405))
|
||||||
|
}
|
||||||
|
|
||||||
|
@ApiOperation(
|
||||||
|
value = "uploads an image",
|
||||||
|
nickname = "uploadFile",
|
||||||
|
notes = "",
|
||||||
|
response = ModelApiResponse::class,
|
||||||
|
authorizations = [Authorization(value = "petstore_auth", scopes = [AuthorizationScope(scope = "write:pets", description = "modify pets in your account"), AuthorizationScope(scope = "read:pets", description = "read your pets")])])
|
||||||
|
@ApiResponses(
|
||||||
|
value = [ApiResponse(code = 200, message = "successful operation", response = ModelApiResponse::class)])
|
||||||
|
@RequestMapping(
|
||||||
|
value = ["/pet/{petId}/uploadImage"],
|
||||||
|
produces = ["application/json"],
|
||||||
|
consumes = ["multipart/form-data"],
|
||||||
|
method = [RequestMethod.POST])
|
||||||
|
fun uploadFile(@ApiParam(value = "ID of pet to update", required=true) @PathVariable("petId") petId: kotlin.Long
|
||||||
|
,@ApiParam(value = "Additional data to pass to server") @RequestParam(value="additionalMetadata", required=false) additionalMetadata: kotlin.String?
|
||||||
|
,@ApiParam(value = "file detail") @Valid @RequestPart("file") file: org.springframework.core.io.Resource?
|
||||||
|
): ResponseEntity<ModelApiResponse> {
|
||||||
|
return ResponseEntity(service.uploadFile(petId, additionalMetadata, file), HttpStatus.valueOf(200))
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,22 @@
|
|||||||
|
package org.openapitools.api
|
||||||
|
|
||||||
|
import org.openapitools.model.ModelApiResponse
|
||||||
|
import org.openapitools.model.Pet
|
||||||
|
interface PetApiService {
|
||||||
|
|
||||||
|
fun addPet(body: Pet): Unit
|
||||||
|
|
||||||
|
fun deletePet(petId: kotlin.Long, apiKey: kotlin.String?): Unit
|
||||||
|
|
||||||
|
fun findPetsByStatus(status: kotlin.collections.List<kotlin.String>): List<Pet>
|
||||||
|
|
||||||
|
fun findPetsByTags(tags: kotlin.collections.List<kotlin.String>): List<Pet>
|
||||||
|
|
||||||
|
fun getPetById(petId: kotlin.Long): Pet
|
||||||
|
|
||||||
|
fun updatePet(body: Pet): Unit
|
||||||
|
|
||||||
|
fun updatePetWithForm(petId: kotlin.Long, name: kotlin.String?, status: kotlin.String?): Unit
|
||||||
|
|
||||||
|
fun uploadFile(petId: kotlin.Long, additionalMetadata: kotlin.String?, file: org.springframework.core.io.Resource?): ModelApiResponse
|
||||||
|
}
|
||||||
@@ -0,0 +1,40 @@
|
|||||||
|
package org.openapitools.api
|
||||||
|
|
||||||
|
import org.openapitools.model.ModelApiResponse
|
||||||
|
import org.openapitools.model.Pet
|
||||||
|
import org.springframework.stereotype.Service
|
||||||
|
@Service
|
||||||
|
class PetApiServiceImpl : PetApiService {
|
||||||
|
|
||||||
|
override fun addPet(body: Pet): Unit {
|
||||||
|
TODO("Implement me")
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun deletePet(petId: kotlin.Long, apiKey: kotlin.String?): Unit {
|
||||||
|
TODO("Implement me")
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun findPetsByStatus(status: kotlin.collections.List<kotlin.String>): List<Pet> {
|
||||||
|
TODO("Implement me")
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun findPetsByTags(tags: kotlin.collections.List<kotlin.String>): List<Pet> {
|
||||||
|
TODO("Implement me")
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun getPetById(petId: kotlin.Long): Pet {
|
||||||
|
TODO("Implement me")
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun updatePet(body: Pet): Unit {
|
||||||
|
TODO("Implement me")
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun updatePetWithForm(petId: kotlin.Long, name: kotlin.String?, status: kotlin.String?): Unit {
|
||||||
|
TODO("Implement me")
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun uploadFile(petId: kotlin.Long, additionalMetadata: kotlin.String?, file: org.springframework.core.io.Resource?): ModelApiResponse {
|
||||||
|
TODO("Implement me")
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,107 @@
|
|||||||
|
package org.openapitools.api
|
||||||
|
|
||||||
|
import org.openapitools.model.Order
|
||||||
|
import io.swagger.annotations.Api
|
||||||
|
import io.swagger.annotations.ApiOperation
|
||||||
|
import io.swagger.annotations.ApiParam
|
||||||
|
import io.swagger.annotations.ApiResponse
|
||||||
|
import io.swagger.annotations.ApiResponses
|
||||||
|
import io.swagger.annotations.Authorization
|
||||||
|
import io.swagger.annotations.AuthorizationScope
|
||||||
|
import org.springframework.http.HttpStatus
|
||||||
|
import org.springframework.http.MediaType
|
||||||
|
import org.springframework.http.ResponseEntity
|
||||||
|
|
||||||
|
import org.springframework.web.bind.annotation.RequestBody
|
||||||
|
import org.springframework.web.bind.annotation.RequestPart
|
||||||
|
import org.springframework.web.bind.annotation.RequestParam
|
||||||
|
import org.springframework.web.bind.annotation.PathVariable
|
||||||
|
import org.springframework.web.bind.annotation.RequestHeader
|
||||||
|
import org.springframework.web.bind.annotation.RequestMethod
|
||||||
|
import org.springframework.web.bind.annotation.RequestMapping
|
||||||
|
import org.springframework.web.bind.annotation.RestController
|
||||||
|
import org.springframework.validation.annotation.Validated
|
||||||
|
import org.springframework.web.context.request.NativeWebRequest
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired
|
||||||
|
|
||||||
|
import javax.validation.Valid
|
||||||
|
import javax.validation.constraints.DecimalMax
|
||||||
|
import javax.validation.constraints.DecimalMin
|
||||||
|
import javax.validation.constraints.Max
|
||||||
|
import javax.validation.constraints.Min
|
||||||
|
import javax.validation.constraints.NotNull
|
||||||
|
import javax.validation.constraints.Pattern
|
||||||
|
import javax.validation.constraints.Size
|
||||||
|
|
||||||
|
import kotlin.collections.List
|
||||||
|
import kotlin.collections.Map
|
||||||
|
|
||||||
|
@RestController
|
||||||
|
@Validated
|
||||||
|
@Api(value = "Store", description = "The Store API")
|
||||||
|
@RequestMapping("\${api.base-path:/v2}")
|
||||||
|
class StoreApiController(@Autowired(required = true) val service: StoreApiService) {
|
||||||
|
|
||||||
|
@ApiOperation(
|
||||||
|
value = "Delete purchase order by ID",
|
||||||
|
nickname = "deleteOrder",
|
||||||
|
notes = "For valid response try integer IDs with value < 1000. Anything above 1000 or nonintegers will generate API errors")
|
||||||
|
@ApiResponses(
|
||||||
|
value = [ApiResponse(code = 400, message = "Invalid ID supplied"),ApiResponse(code = 404, message = "Order not found")])
|
||||||
|
@RequestMapping(
|
||||||
|
value = ["/store/order/{orderId}"],
|
||||||
|
method = [RequestMethod.DELETE])
|
||||||
|
fun deleteOrder(@ApiParam(value = "ID of the order that needs to be deleted", required=true) @PathVariable("orderId") orderId: kotlin.String
|
||||||
|
): ResponseEntity<Unit> {
|
||||||
|
return ResponseEntity(service.deleteOrder(orderId), HttpStatus.valueOf(400))
|
||||||
|
}
|
||||||
|
|
||||||
|
@ApiOperation(
|
||||||
|
value = "Returns pet inventories by status",
|
||||||
|
nickname = "getInventory",
|
||||||
|
notes = "Returns a map of status codes to quantities",
|
||||||
|
response = kotlin.Int::class,
|
||||||
|
responseContainer = "Map",
|
||||||
|
authorizations = [Authorization(value = "api_key")])
|
||||||
|
@ApiResponses(
|
||||||
|
value = [ApiResponse(code = 200, message = "successful operation", response = kotlin.collections.Map::class, responseContainer = "Map")])
|
||||||
|
@RequestMapping(
|
||||||
|
value = ["/store/inventory"],
|
||||||
|
produces = ["application/json"],
|
||||||
|
method = [RequestMethod.GET])
|
||||||
|
fun getInventory(): ResponseEntity<Map<String, kotlin.Int>> {
|
||||||
|
return ResponseEntity(service.getInventory(), HttpStatus.valueOf(200))
|
||||||
|
}
|
||||||
|
|
||||||
|
@ApiOperation(
|
||||||
|
value = "Find purchase order by ID",
|
||||||
|
nickname = "getOrderById",
|
||||||
|
notes = "For valid response try integer IDs with value <= 5 or > 10. Other values will generated exceptions",
|
||||||
|
response = Order::class)
|
||||||
|
@ApiResponses(
|
||||||
|
value = [ApiResponse(code = 200, message = "successful operation", response = Order::class),ApiResponse(code = 400, message = "Invalid ID supplied"),ApiResponse(code = 404, message = "Order not found")])
|
||||||
|
@RequestMapping(
|
||||||
|
value = ["/store/order/{orderId}"],
|
||||||
|
produces = ["application/xml", "application/json"],
|
||||||
|
method = [RequestMethod.GET])
|
||||||
|
fun getOrderById(@Min(1L) @Max(5L) @ApiParam(value = "ID of pet that needs to be fetched", required=true) @PathVariable("orderId") orderId: kotlin.Long
|
||||||
|
): ResponseEntity<Order> {
|
||||||
|
return ResponseEntity(service.getOrderById(orderId), HttpStatus.valueOf(200))
|
||||||
|
}
|
||||||
|
|
||||||
|
@ApiOperation(
|
||||||
|
value = "Place an order for a pet",
|
||||||
|
nickname = "placeOrder",
|
||||||
|
notes = "",
|
||||||
|
response = Order::class)
|
||||||
|
@ApiResponses(
|
||||||
|
value = [ApiResponse(code = 200, message = "successful operation", response = Order::class),ApiResponse(code = 400, message = "Invalid Order")])
|
||||||
|
@RequestMapping(
|
||||||
|
value = ["/store/order"],
|
||||||
|
produces = ["application/xml", "application/json"],
|
||||||
|
method = [RequestMethod.POST])
|
||||||
|
fun placeOrder(@ApiParam(value = "order placed for purchasing the pet" ,required=true ) @Valid @RequestBody body: Order
|
||||||
|
): ResponseEntity<Order> {
|
||||||
|
return ResponseEntity(service.placeOrder(body), HttpStatus.valueOf(200))
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,13 @@
|
|||||||
|
package org.openapitools.api
|
||||||
|
|
||||||
|
import org.openapitools.model.Order
|
||||||
|
interface StoreApiService {
|
||||||
|
|
||||||
|
fun deleteOrder(orderId: kotlin.String): Unit
|
||||||
|
|
||||||
|
fun getInventory(): Map<String, kotlin.Int>
|
||||||
|
|
||||||
|
fun getOrderById(orderId: kotlin.Long): Order
|
||||||
|
|
||||||
|
fun placeOrder(body: Order): Order
|
||||||
|
}
|
||||||
@@ -0,0 +1,23 @@
|
|||||||
|
package org.openapitools.api
|
||||||
|
|
||||||
|
import org.openapitools.model.Order
|
||||||
|
import org.springframework.stereotype.Service
|
||||||
|
@Service
|
||||||
|
class StoreApiServiceImpl : StoreApiService {
|
||||||
|
|
||||||
|
override fun deleteOrder(orderId: kotlin.String): Unit {
|
||||||
|
TODO("Implement me")
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun getInventory(): Map<String, kotlin.Int> {
|
||||||
|
TODO("Implement me")
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun getOrderById(orderId: kotlin.Long): Order {
|
||||||
|
TODO("Implement me")
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun placeOrder(body: Order): Order {
|
||||||
|
TODO("Implement me")
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,161 @@
|
|||||||
|
package org.openapitools.api
|
||||||
|
|
||||||
|
import org.openapitools.model.User
|
||||||
|
import io.swagger.annotations.Api
|
||||||
|
import io.swagger.annotations.ApiOperation
|
||||||
|
import io.swagger.annotations.ApiParam
|
||||||
|
import io.swagger.annotations.ApiResponse
|
||||||
|
import io.swagger.annotations.ApiResponses
|
||||||
|
import io.swagger.annotations.Authorization
|
||||||
|
import io.swagger.annotations.AuthorizationScope
|
||||||
|
import org.springframework.http.HttpStatus
|
||||||
|
import org.springframework.http.MediaType
|
||||||
|
import org.springframework.http.ResponseEntity
|
||||||
|
|
||||||
|
import org.springframework.web.bind.annotation.RequestBody
|
||||||
|
import org.springframework.web.bind.annotation.RequestPart
|
||||||
|
import org.springframework.web.bind.annotation.RequestParam
|
||||||
|
import org.springframework.web.bind.annotation.PathVariable
|
||||||
|
import org.springframework.web.bind.annotation.RequestHeader
|
||||||
|
import org.springframework.web.bind.annotation.RequestMethod
|
||||||
|
import org.springframework.web.bind.annotation.RequestMapping
|
||||||
|
import org.springframework.web.bind.annotation.RestController
|
||||||
|
import org.springframework.validation.annotation.Validated
|
||||||
|
import org.springframework.web.context.request.NativeWebRequest
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired
|
||||||
|
|
||||||
|
import javax.validation.Valid
|
||||||
|
import javax.validation.constraints.DecimalMax
|
||||||
|
import javax.validation.constraints.DecimalMin
|
||||||
|
import javax.validation.constraints.Max
|
||||||
|
import javax.validation.constraints.Min
|
||||||
|
import javax.validation.constraints.NotNull
|
||||||
|
import javax.validation.constraints.Pattern
|
||||||
|
import javax.validation.constraints.Size
|
||||||
|
|
||||||
|
import kotlin.collections.List
|
||||||
|
import kotlin.collections.Map
|
||||||
|
|
||||||
|
@RestController
|
||||||
|
@Validated
|
||||||
|
@Api(value = "User", description = "The User API")
|
||||||
|
@RequestMapping("\${api.base-path:/v2}")
|
||||||
|
class UserApiController(@Autowired(required = true) val service: UserApiService) {
|
||||||
|
|
||||||
|
@ApiOperation(
|
||||||
|
value = "Create user",
|
||||||
|
nickname = "createUser",
|
||||||
|
notes = "This can only be done by the logged in user.")
|
||||||
|
@ApiResponses(
|
||||||
|
value = [ApiResponse(code = 200, message = "successful operation")])
|
||||||
|
@RequestMapping(
|
||||||
|
value = ["/user"],
|
||||||
|
method = [RequestMethod.POST])
|
||||||
|
fun createUser(@ApiParam(value = "Created user object" ,required=true ) @Valid @RequestBody body: User
|
||||||
|
): ResponseEntity<Unit> {
|
||||||
|
return ResponseEntity(service.createUser(body), HttpStatus.valueOf(200))
|
||||||
|
}
|
||||||
|
|
||||||
|
@ApiOperation(
|
||||||
|
value = "Creates list of users with given input array",
|
||||||
|
nickname = "createUsersWithArrayInput",
|
||||||
|
notes = "")
|
||||||
|
@ApiResponses(
|
||||||
|
value = [ApiResponse(code = 200, message = "successful operation")])
|
||||||
|
@RequestMapping(
|
||||||
|
value = ["/user/createWithArray"],
|
||||||
|
method = [RequestMethod.POST])
|
||||||
|
fun createUsersWithArrayInput(@ApiParam(value = "List of user object" ,required=true ) @Valid @RequestBody body: kotlin.collections.List<User>
|
||||||
|
): ResponseEntity<Unit> {
|
||||||
|
return ResponseEntity(service.createUsersWithArrayInput(body), HttpStatus.valueOf(200))
|
||||||
|
}
|
||||||
|
|
||||||
|
@ApiOperation(
|
||||||
|
value = "Creates list of users with given input array",
|
||||||
|
nickname = "createUsersWithListInput",
|
||||||
|
notes = "")
|
||||||
|
@ApiResponses(
|
||||||
|
value = [ApiResponse(code = 200, message = "successful operation")])
|
||||||
|
@RequestMapping(
|
||||||
|
value = ["/user/createWithList"],
|
||||||
|
method = [RequestMethod.POST])
|
||||||
|
fun createUsersWithListInput(@ApiParam(value = "List of user object" ,required=true ) @Valid @RequestBody body: kotlin.collections.List<User>
|
||||||
|
): ResponseEntity<Unit> {
|
||||||
|
return ResponseEntity(service.createUsersWithListInput(body), HttpStatus.valueOf(200))
|
||||||
|
}
|
||||||
|
|
||||||
|
@ApiOperation(
|
||||||
|
value = "Delete user",
|
||||||
|
nickname = "deleteUser",
|
||||||
|
notes = "This can only be done by the logged in user.")
|
||||||
|
@ApiResponses(
|
||||||
|
value = [ApiResponse(code = 400, message = "Invalid username supplied"),ApiResponse(code = 404, message = "User not found")])
|
||||||
|
@RequestMapping(
|
||||||
|
value = ["/user/{username}"],
|
||||||
|
method = [RequestMethod.DELETE])
|
||||||
|
fun deleteUser(@ApiParam(value = "The name that needs to be deleted", required=true) @PathVariable("username") username: kotlin.String
|
||||||
|
): ResponseEntity<Unit> {
|
||||||
|
return ResponseEntity(service.deleteUser(username), HttpStatus.valueOf(400))
|
||||||
|
}
|
||||||
|
|
||||||
|
@ApiOperation(
|
||||||
|
value = "Get user by user name",
|
||||||
|
nickname = "getUserByName",
|
||||||
|
notes = "",
|
||||||
|
response = User::class)
|
||||||
|
@ApiResponses(
|
||||||
|
value = [ApiResponse(code = 200, message = "successful operation", response = User::class),ApiResponse(code = 400, message = "Invalid username supplied"),ApiResponse(code = 404, message = "User not found")])
|
||||||
|
@RequestMapping(
|
||||||
|
value = ["/user/{username}"],
|
||||||
|
produces = ["application/xml", "application/json"],
|
||||||
|
method = [RequestMethod.GET])
|
||||||
|
fun getUserByName(@ApiParam(value = "The name that needs to be fetched. Use user1 for testing.", required=true) @PathVariable("username") username: kotlin.String
|
||||||
|
): ResponseEntity<User> {
|
||||||
|
return ResponseEntity(service.getUserByName(username), HttpStatus.valueOf(200))
|
||||||
|
}
|
||||||
|
|
||||||
|
@ApiOperation(
|
||||||
|
value = "Logs user into the system",
|
||||||
|
nickname = "loginUser",
|
||||||
|
notes = "",
|
||||||
|
response = kotlin.String::class)
|
||||||
|
@ApiResponses(
|
||||||
|
value = [ApiResponse(code = 200, message = "successful operation", response = kotlin.String::class),ApiResponse(code = 400, message = "Invalid username/password supplied")])
|
||||||
|
@RequestMapping(
|
||||||
|
value = ["/user/login"],
|
||||||
|
produces = ["application/xml", "application/json"],
|
||||||
|
method = [RequestMethod.GET])
|
||||||
|
fun loginUser(@NotNull @ApiParam(value = "The user name for login", required = true) @Valid @RequestParam(value = "username", required = true) username: kotlin.String
|
||||||
|
,@NotNull @ApiParam(value = "The password for login in clear text", required = true) @Valid @RequestParam(value = "password", required = true) password: kotlin.String
|
||||||
|
): ResponseEntity<kotlin.String> {
|
||||||
|
return ResponseEntity(service.loginUser(username, password), HttpStatus.valueOf(200))
|
||||||
|
}
|
||||||
|
|
||||||
|
@ApiOperation(
|
||||||
|
value = "Logs out current logged in user session",
|
||||||
|
nickname = "logoutUser",
|
||||||
|
notes = "")
|
||||||
|
@ApiResponses(
|
||||||
|
value = [ApiResponse(code = 200, message = "successful operation")])
|
||||||
|
@RequestMapping(
|
||||||
|
value = ["/user/logout"],
|
||||||
|
method = [RequestMethod.GET])
|
||||||
|
fun logoutUser(): ResponseEntity<Unit> {
|
||||||
|
return ResponseEntity(service.logoutUser(), HttpStatus.valueOf(200))
|
||||||
|
}
|
||||||
|
|
||||||
|
@ApiOperation(
|
||||||
|
value = "Updated user",
|
||||||
|
nickname = "updateUser",
|
||||||
|
notes = "This can only be done by the logged in user.")
|
||||||
|
@ApiResponses(
|
||||||
|
value = [ApiResponse(code = 400, message = "Invalid user supplied"),ApiResponse(code = 404, message = "User not found")])
|
||||||
|
@RequestMapping(
|
||||||
|
value = ["/user/{username}"],
|
||||||
|
method = [RequestMethod.PUT])
|
||||||
|
fun updateUser(@ApiParam(value = "name that need to be deleted", required=true) @PathVariable("username") username: kotlin.String
|
||||||
|
,@ApiParam(value = "Updated user object" ,required=true ) @Valid @RequestBody body: User
|
||||||
|
): ResponseEntity<Unit> {
|
||||||
|
return ResponseEntity(service.updateUser(username, body), HttpStatus.valueOf(400))
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,21 @@
|
|||||||
|
package org.openapitools.api
|
||||||
|
|
||||||
|
import org.openapitools.model.User
|
||||||
|
interface UserApiService {
|
||||||
|
|
||||||
|
fun createUser(body: User): Unit
|
||||||
|
|
||||||
|
fun createUsersWithArrayInput(body: kotlin.collections.List<User>): Unit
|
||||||
|
|
||||||
|
fun createUsersWithListInput(body: kotlin.collections.List<User>): Unit
|
||||||
|
|
||||||
|
fun deleteUser(username: kotlin.String): Unit
|
||||||
|
|
||||||
|
fun getUserByName(username: kotlin.String): User
|
||||||
|
|
||||||
|
fun loginUser(username: kotlin.String, password: kotlin.String): kotlin.String
|
||||||
|
|
||||||
|
fun logoutUser(): Unit
|
||||||
|
|
||||||
|
fun updateUser(username: kotlin.String, body: User): Unit
|
||||||
|
}
|
||||||
@@ -0,0 +1,39 @@
|
|||||||
|
package org.openapitools.api
|
||||||
|
|
||||||
|
import org.openapitools.model.User
|
||||||
|
import org.springframework.stereotype.Service
|
||||||
|
@Service
|
||||||
|
class UserApiServiceImpl : UserApiService {
|
||||||
|
|
||||||
|
override fun createUser(body: User): Unit {
|
||||||
|
TODO("Implement me")
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun createUsersWithArrayInput(body: kotlin.collections.List<User>): Unit {
|
||||||
|
TODO("Implement me")
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun createUsersWithListInput(body: kotlin.collections.List<User>): Unit {
|
||||||
|
TODO("Implement me")
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun deleteUser(username: kotlin.String): Unit {
|
||||||
|
TODO("Implement me")
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun getUserByName(username: kotlin.String): User {
|
||||||
|
TODO("Implement me")
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun loginUser(username: kotlin.String, password: kotlin.String): kotlin.String {
|
||||||
|
TODO("Implement me")
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun logoutUser(): Unit {
|
||||||
|
TODO("Implement me")
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun updateUser(username: kotlin.String, body: User): Unit {
|
||||||
|
TODO("Implement me")
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,29 @@
|
|||||||
|
package org.openapitools.model
|
||||||
|
|
||||||
|
import java.util.Objects
|
||||||
|
import com.fasterxml.jackson.annotation.JsonProperty
|
||||||
|
import javax.validation.constraints.DecimalMax
|
||||||
|
import javax.validation.constraints.DecimalMin
|
||||||
|
import javax.validation.constraints.Max
|
||||||
|
import javax.validation.constraints.Min
|
||||||
|
import javax.validation.constraints.NotNull
|
||||||
|
import javax.validation.constraints.Pattern
|
||||||
|
import javax.validation.constraints.Size
|
||||||
|
import io.swagger.annotations.ApiModelProperty
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A category for a pet
|
||||||
|
* @param id
|
||||||
|
* @param name
|
||||||
|
*/
|
||||||
|
data class Category (
|
||||||
|
|
||||||
|
@ApiModelProperty(example = "null", value = "")
|
||||||
|
@JsonProperty("id") var id: kotlin.Long? = null,
|
||||||
|
|
||||||
|
@ApiModelProperty(example = "null", value = "")
|
||||||
|
@JsonProperty("name") var name: kotlin.String? = null
|
||||||
|
) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
@@ -0,0 +1,33 @@
|
|||||||
|
package org.openapitools.model
|
||||||
|
|
||||||
|
import java.util.Objects
|
||||||
|
import com.fasterxml.jackson.annotation.JsonProperty
|
||||||
|
import javax.validation.constraints.DecimalMax
|
||||||
|
import javax.validation.constraints.DecimalMin
|
||||||
|
import javax.validation.constraints.Max
|
||||||
|
import javax.validation.constraints.Min
|
||||||
|
import javax.validation.constraints.NotNull
|
||||||
|
import javax.validation.constraints.Pattern
|
||||||
|
import javax.validation.constraints.Size
|
||||||
|
import io.swagger.annotations.ApiModelProperty
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Describes the result of uploading an image resource
|
||||||
|
* @param code
|
||||||
|
* @param type
|
||||||
|
* @param message
|
||||||
|
*/
|
||||||
|
data class ModelApiResponse (
|
||||||
|
|
||||||
|
@ApiModelProperty(example = "null", value = "")
|
||||||
|
@JsonProperty("code") var code: kotlin.Int? = null,
|
||||||
|
|
||||||
|
@ApiModelProperty(example = "null", value = "")
|
||||||
|
@JsonProperty("type") var type: kotlin.String? = null,
|
||||||
|
|
||||||
|
@ApiModelProperty(example = "null", value = "")
|
||||||
|
@JsonProperty("message") var message: kotlin.String? = null
|
||||||
|
) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
@@ -0,0 +1,60 @@
|
|||||||
|
package org.openapitools.model
|
||||||
|
|
||||||
|
import java.util.Objects
|
||||||
|
import com.fasterxml.jackson.annotation.JsonProperty
|
||||||
|
import com.fasterxml.jackson.annotation.JsonValue
|
||||||
|
import javax.validation.constraints.DecimalMax
|
||||||
|
import javax.validation.constraints.DecimalMin
|
||||||
|
import javax.validation.constraints.Max
|
||||||
|
import javax.validation.constraints.Min
|
||||||
|
import javax.validation.constraints.NotNull
|
||||||
|
import javax.validation.constraints.Pattern
|
||||||
|
import javax.validation.constraints.Size
|
||||||
|
import io.swagger.annotations.ApiModelProperty
|
||||||
|
|
||||||
|
/**
|
||||||
|
* An order for a pets from the pet store
|
||||||
|
* @param id
|
||||||
|
* @param petId
|
||||||
|
* @param quantity
|
||||||
|
* @param shipDate
|
||||||
|
* @param status Order Status
|
||||||
|
* @param complete
|
||||||
|
*/
|
||||||
|
data class Order (
|
||||||
|
|
||||||
|
@ApiModelProperty(example = "null", value = "")
|
||||||
|
@JsonProperty("id") var id: kotlin.Long? = null,
|
||||||
|
|
||||||
|
@ApiModelProperty(example = "null", value = "")
|
||||||
|
@JsonProperty("petId") var petId: kotlin.Long? = null,
|
||||||
|
|
||||||
|
@ApiModelProperty(example = "null", value = "")
|
||||||
|
@JsonProperty("quantity") var quantity: kotlin.Int? = null,
|
||||||
|
|
||||||
|
@ApiModelProperty(example = "null", value = "")
|
||||||
|
@JsonProperty("shipDate") var shipDate: java.time.OffsetDateTime? = null,
|
||||||
|
|
||||||
|
@ApiModelProperty(example = "null", value = "Order Status")
|
||||||
|
@JsonProperty("status") var status: Order.Status? = null,
|
||||||
|
|
||||||
|
@ApiModelProperty(example = "null", value = "")
|
||||||
|
@JsonProperty("complete") var complete: kotlin.Boolean? = null
|
||||||
|
) {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Order Status
|
||||||
|
* Values: placed,approved,delivered
|
||||||
|
*/
|
||||||
|
enum class Status(val value: kotlin.String) {
|
||||||
|
|
||||||
|
@JsonProperty("placed") placed("placed"),
|
||||||
|
|
||||||
|
@JsonProperty("approved") approved("approved"),
|
||||||
|
|
||||||
|
@JsonProperty("delivered") delivered("delivered");
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
@@ -0,0 +1,64 @@
|
|||||||
|
package org.openapitools.model
|
||||||
|
|
||||||
|
import java.util.Objects
|
||||||
|
import com.fasterxml.jackson.annotation.JsonProperty
|
||||||
|
import com.fasterxml.jackson.annotation.JsonValue
|
||||||
|
import org.openapitools.model.Category
|
||||||
|
import org.openapitools.model.Tag
|
||||||
|
import javax.validation.constraints.DecimalMax
|
||||||
|
import javax.validation.constraints.DecimalMin
|
||||||
|
import javax.validation.constraints.Max
|
||||||
|
import javax.validation.constraints.Min
|
||||||
|
import javax.validation.constraints.NotNull
|
||||||
|
import javax.validation.constraints.Pattern
|
||||||
|
import javax.validation.constraints.Size
|
||||||
|
import io.swagger.annotations.ApiModelProperty
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A pet for sale in the pet store
|
||||||
|
* @param id
|
||||||
|
* @param category
|
||||||
|
* @param name
|
||||||
|
* @param photoUrls
|
||||||
|
* @param tags
|
||||||
|
* @param status pet status in the store
|
||||||
|
*/
|
||||||
|
data class Pet (
|
||||||
|
|
||||||
|
@get:NotNull
|
||||||
|
@ApiModelProperty(example = "doggie", required = true, value = "")
|
||||||
|
@JsonProperty("name") var name: kotlin.String,
|
||||||
|
|
||||||
|
@get:NotNull
|
||||||
|
@ApiModelProperty(example = "null", required = true, value = "")
|
||||||
|
@JsonProperty("photoUrls") var photoUrls: kotlin.collections.List<kotlin.String>,
|
||||||
|
|
||||||
|
@ApiModelProperty(example = "null", value = "")
|
||||||
|
@JsonProperty("id") var id: kotlin.Long? = null,
|
||||||
|
|
||||||
|
@ApiModelProperty(example = "null", value = "")
|
||||||
|
@JsonProperty("category") var category: Category? = null,
|
||||||
|
|
||||||
|
@ApiModelProperty(example = "null", value = "")
|
||||||
|
@JsonProperty("tags") var tags: kotlin.collections.List<Tag>? = null,
|
||||||
|
|
||||||
|
@ApiModelProperty(example = "null", value = "pet status in the store")
|
||||||
|
@JsonProperty("status") var status: Pet.Status? = null
|
||||||
|
) {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* pet status in the store
|
||||||
|
* Values: available,pending,sold
|
||||||
|
*/
|
||||||
|
enum class Status(val value: kotlin.String) {
|
||||||
|
|
||||||
|
@JsonProperty("available") available("available"),
|
||||||
|
|
||||||
|
@JsonProperty("pending") pending("pending"),
|
||||||
|
|
||||||
|
@JsonProperty("sold") sold("sold");
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
@@ -0,0 +1,29 @@
|
|||||||
|
package org.openapitools.model
|
||||||
|
|
||||||
|
import java.util.Objects
|
||||||
|
import com.fasterxml.jackson.annotation.JsonProperty
|
||||||
|
import javax.validation.constraints.DecimalMax
|
||||||
|
import javax.validation.constraints.DecimalMin
|
||||||
|
import javax.validation.constraints.Max
|
||||||
|
import javax.validation.constraints.Min
|
||||||
|
import javax.validation.constraints.NotNull
|
||||||
|
import javax.validation.constraints.Pattern
|
||||||
|
import javax.validation.constraints.Size
|
||||||
|
import io.swagger.annotations.ApiModelProperty
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A tag for a pet
|
||||||
|
* @param id
|
||||||
|
* @param name
|
||||||
|
*/
|
||||||
|
data class Tag (
|
||||||
|
|
||||||
|
@ApiModelProperty(example = "null", value = "")
|
||||||
|
@JsonProperty("id") var id: kotlin.Long? = null,
|
||||||
|
|
||||||
|
@ApiModelProperty(example = "null", value = "")
|
||||||
|
@JsonProperty("name") var name: kotlin.String? = null
|
||||||
|
) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
@@ -0,0 +1,53 @@
|
|||||||
|
package org.openapitools.model
|
||||||
|
|
||||||
|
import java.util.Objects
|
||||||
|
import com.fasterxml.jackson.annotation.JsonProperty
|
||||||
|
import javax.validation.constraints.DecimalMax
|
||||||
|
import javax.validation.constraints.DecimalMin
|
||||||
|
import javax.validation.constraints.Max
|
||||||
|
import javax.validation.constraints.Min
|
||||||
|
import javax.validation.constraints.NotNull
|
||||||
|
import javax.validation.constraints.Pattern
|
||||||
|
import javax.validation.constraints.Size
|
||||||
|
import io.swagger.annotations.ApiModelProperty
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A User who is purchasing from the pet store
|
||||||
|
* @param id
|
||||||
|
* @param username
|
||||||
|
* @param firstName
|
||||||
|
* @param lastName
|
||||||
|
* @param email
|
||||||
|
* @param password
|
||||||
|
* @param phone
|
||||||
|
* @param userStatus User Status
|
||||||
|
*/
|
||||||
|
data class User (
|
||||||
|
|
||||||
|
@ApiModelProperty(example = "null", value = "")
|
||||||
|
@JsonProperty("id") var id: kotlin.Long? = null,
|
||||||
|
|
||||||
|
@ApiModelProperty(example = "null", value = "")
|
||||||
|
@JsonProperty("username") var username: kotlin.String? = null,
|
||||||
|
|
||||||
|
@ApiModelProperty(example = "null", value = "")
|
||||||
|
@JsonProperty("firstName") var firstName: kotlin.String? = null,
|
||||||
|
|
||||||
|
@ApiModelProperty(example = "null", value = "")
|
||||||
|
@JsonProperty("lastName") var lastName: kotlin.String? = null,
|
||||||
|
|
||||||
|
@ApiModelProperty(example = "null", value = "")
|
||||||
|
@JsonProperty("email") var email: kotlin.String? = null,
|
||||||
|
|
||||||
|
@ApiModelProperty(example = "null", value = "")
|
||||||
|
@JsonProperty("password") var password: kotlin.String? = null,
|
||||||
|
|
||||||
|
@ApiModelProperty(example = "null", value = "")
|
||||||
|
@JsonProperty("phone") var phone: kotlin.String? = null,
|
||||||
|
|
||||||
|
@ApiModelProperty(example = "null", value = "User Status")
|
||||||
|
@JsonProperty("userStatus") var userStatus: kotlin.Int? = null
|
||||||
|
) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
@@ -0,0 +1,10 @@
|
|||||||
|
spring:
|
||||||
|
application:
|
||||||
|
name: openAPIPetstore
|
||||||
|
|
||||||
|
jackson:
|
||||||
|
serialization:
|
||||||
|
WRITE_DATES_AS_TIMESTAMPS: false
|
||||||
|
|
||||||
|
server:
|
||||||
|
port: 8080
|
||||||
@@ -0,0 +1,148 @@
|
|||||||
|
package org.openapitools.api
|
||||||
|
|
||||||
|
import org.openapitools.model.ModelApiResponse
|
||||||
|
import org.openapitools.model.Pet
|
||||||
|
import org.junit.jupiter.api.Test
|
||||||
|
|
||||||
|
import org.springframework.http.ResponseEntity
|
||||||
|
|
||||||
|
class PetApiTest {
|
||||||
|
|
||||||
|
private val service: PetApiService = PetApiServiceImpl()
|
||||||
|
private val api: PetApiController = PetApiController(service)
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add a new pet to the store
|
||||||
|
*
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* @throws ApiException
|
||||||
|
* if the Api call fails
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
fun addPetTest() {
|
||||||
|
val body:Pet? = null
|
||||||
|
val response: ResponseEntity<Unit> = api.addPet(body!!)
|
||||||
|
|
||||||
|
// TODO: test validations
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Deletes a pet
|
||||||
|
*
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* @throws ApiException
|
||||||
|
* if the Api call fails
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
fun deletePetTest() {
|
||||||
|
val petId:kotlin.Long? = null
|
||||||
|
val apiKey:kotlin.String? = null
|
||||||
|
val response: ResponseEntity<Unit> = api.deletePet(petId!!, apiKey!!)
|
||||||
|
|
||||||
|
// TODO: test validations
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Finds Pets by status
|
||||||
|
*
|
||||||
|
* Multiple status values can be provided with comma separated strings
|
||||||
|
*
|
||||||
|
* @throws ApiException
|
||||||
|
* if the Api call fails
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
fun findPetsByStatusTest() {
|
||||||
|
val status:kotlin.collections.List<kotlin.String>? = null
|
||||||
|
val response: ResponseEntity<List<Pet>> = api.findPetsByStatus(status!!)
|
||||||
|
|
||||||
|
// TODO: test validations
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Finds Pets by tags
|
||||||
|
*
|
||||||
|
* Multiple tags can be provided with comma separated strings. Use tag1, tag2, tag3 for testing.
|
||||||
|
*
|
||||||
|
* @throws ApiException
|
||||||
|
* if the Api call fails
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
fun findPetsByTagsTest() {
|
||||||
|
val tags:kotlin.collections.List<kotlin.String>? = null
|
||||||
|
val response: ResponseEntity<List<Pet>> = api.findPetsByTags(tags!!)
|
||||||
|
|
||||||
|
// TODO: test validations
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Find pet by ID
|
||||||
|
*
|
||||||
|
* Returns a single pet
|
||||||
|
*
|
||||||
|
* @throws ApiException
|
||||||
|
* if the Api call fails
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
fun getPetByIdTest() {
|
||||||
|
val petId:kotlin.Long? = null
|
||||||
|
val response: ResponseEntity<Pet> = api.getPetById(petId!!)
|
||||||
|
|
||||||
|
// TODO: test validations
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Update an existing pet
|
||||||
|
*
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* @throws ApiException
|
||||||
|
* if the Api call fails
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
fun updatePetTest() {
|
||||||
|
val body:Pet? = null
|
||||||
|
val response: ResponseEntity<Unit> = api.updatePet(body!!)
|
||||||
|
|
||||||
|
// TODO: test validations
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Updates a pet in the store with form data
|
||||||
|
*
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* @throws ApiException
|
||||||
|
* if the Api call fails
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
fun updatePetWithFormTest() {
|
||||||
|
val petId:kotlin.Long? = null
|
||||||
|
val name:kotlin.String? = null
|
||||||
|
val status:kotlin.String? = null
|
||||||
|
val response: ResponseEntity<Unit> = api.updatePetWithForm(petId!!, name!!, status!!)
|
||||||
|
|
||||||
|
// TODO: test validations
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* uploads an image
|
||||||
|
*
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* @throws ApiException
|
||||||
|
* if the Api call fails
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
fun uploadFileTest() {
|
||||||
|
val petId:kotlin.Long? = null
|
||||||
|
val additionalMetadata:kotlin.String? = null
|
||||||
|
val file:org.springframework.core.io.Resource? = null
|
||||||
|
val response: ResponseEntity<ModelApiResponse> = api.uploadFile(petId!!, additionalMetadata!!, file!!)
|
||||||
|
|
||||||
|
// TODO: test validations
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,77 @@
|
|||||||
|
package org.openapitools.api
|
||||||
|
|
||||||
|
import org.openapitools.model.Order
|
||||||
|
import org.junit.jupiter.api.Test
|
||||||
|
|
||||||
|
import org.springframework.http.ResponseEntity
|
||||||
|
|
||||||
|
class StoreApiTest {
|
||||||
|
|
||||||
|
private val service: StoreApiService = StoreApiServiceImpl()
|
||||||
|
private val api: StoreApiController = StoreApiController(service)
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Delete purchase order by ID
|
||||||
|
*
|
||||||
|
* For valid response try integer IDs with value < 1000. Anything above 1000 or nonintegers will generate API errors
|
||||||
|
*
|
||||||
|
* @throws ApiException
|
||||||
|
* if the Api call fails
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
fun deleteOrderTest() {
|
||||||
|
val orderId:kotlin.String? = null
|
||||||
|
val response: ResponseEntity<Unit> = api.deleteOrder(orderId!!)
|
||||||
|
|
||||||
|
// TODO: test validations
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns pet inventories by status
|
||||||
|
*
|
||||||
|
* Returns a map of status codes to quantities
|
||||||
|
*
|
||||||
|
* @throws ApiException
|
||||||
|
* if the Api call fails
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
fun getInventoryTest() {
|
||||||
|
val response: ResponseEntity<Map<String, kotlin.Int>> = api.getInventory()
|
||||||
|
|
||||||
|
// TODO: test validations
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Find purchase order by ID
|
||||||
|
*
|
||||||
|
* For valid response try integer IDs with value <= 5 or > 10. Other values will generated exceptions
|
||||||
|
*
|
||||||
|
* @throws ApiException
|
||||||
|
* if the Api call fails
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
fun getOrderByIdTest() {
|
||||||
|
val orderId:kotlin.Long? = null
|
||||||
|
val response: ResponseEntity<Order> = api.getOrderById(orderId!!)
|
||||||
|
|
||||||
|
// TODO: test validations
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Place an order for a pet
|
||||||
|
*
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* @throws ApiException
|
||||||
|
* if the Api call fails
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
fun placeOrderTest() {
|
||||||
|
val body:Order? = null
|
||||||
|
val response: ResponseEntity<Order> = api.placeOrder(body!!)
|
||||||
|
|
||||||
|
// TODO: test validations
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,143 @@
|
|||||||
|
package org.openapitools.api
|
||||||
|
|
||||||
|
import org.openapitools.model.User
|
||||||
|
import org.junit.jupiter.api.Test
|
||||||
|
|
||||||
|
import org.springframework.http.ResponseEntity
|
||||||
|
|
||||||
|
class UserApiTest {
|
||||||
|
|
||||||
|
private val service: UserApiService = UserApiServiceImpl()
|
||||||
|
private val api: UserApiController = UserApiController(service)
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create user
|
||||||
|
*
|
||||||
|
* This can only be done by the logged in user.
|
||||||
|
*
|
||||||
|
* @throws ApiException
|
||||||
|
* if the Api call fails
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
fun createUserTest() {
|
||||||
|
val body:User? = null
|
||||||
|
val response: ResponseEntity<Unit> = api.createUser(body!!)
|
||||||
|
|
||||||
|
// TODO: test validations
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates list of users with given input array
|
||||||
|
*
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* @throws ApiException
|
||||||
|
* if the Api call fails
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
fun createUsersWithArrayInputTest() {
|
||||||
|
val body:kotlin.collections.List<User>? = null
|
||||||
|
val response: ResponseEntity<Unit> = api.createUsersWithArrayInput(body!!)
|
||||||
|
|
||||||
|
// TODO: test validations
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates list of users with given input array
|
||||||
|
*
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* @throws ApiException
|
||||||
|
* if the Api call fails
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
fun createUsersWithListInputTest() {
|
||||||
|
val body:kotlin.collections.List<User>? = null
|
||||||
|
val response: ResponseEntity<Unit> = api.createUsersWithListInput(body!!)
|
||||||
|
|
||||||
|
// TODO: test validations
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Delete user
|
||||||
|
*
|
||||||
|
* This can only be done by the logged in user.
|
||||||
|
*
|
||||||
|
* @throws ApiException
|
||||||
|
* if the Api call fails
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
fun deleteUserTest() {
|
||||||
|
val username:kotlin.String? = null
|
||||||
|
val response: ResponseEntity<Unit> = api.deleteUser(username!!)
|
||||||
|
|
||||||
|
// TODO: test validations
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get user by user name
|
||||||
|
*
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* @throws ApiException
|
||||||
|
* if the Api call fails
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
fun getUserByNameTest() {
|
||||||
|
val username:kotlin.String? = null
|
||||||
|
val response: ResponseEntity<User> = api.getUserByName(username!!)
|
||||||
|
|
||||||
|
// TODO: test validations
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Logs user into the system
|
||||||
|
*
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* @throws ApiException
|
||||||
|
* if the Api call fails
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
fun loginUserTest() {
|
||||||
|
val username:kotlin.String? = null
|
||||||
|
val password:kotlin.String? = null
|
||||||
|
val response: ResponseEntity<kotlin.String> = api.loginUser(username!!, password!!)
|
||||||
|
|
||||||
|
// TODO: test validations
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Logs out current logged in user session
|
||||||
|
*
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* @throws ApiException
|
||||||
|
* if the Api call fails
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
fun logoutUserTest() {
|
||||||
|
val response: ResponseEntity<Unit> = api.logoutUser()
|
||||||
|
|
||||||
|
// TODO: test validations
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Updated user
|
||||||
|
*
|
||||||
|
* This can only be done by the logged in user.
|
||||||
|
*
|
||||||
|
* @throws ApiException
|
||||||
|
* if the Api call fails
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
fun updateUserTest() {
|
||||||
|
val username:kotlin.String? = null
|
||||||
|
val body:User? = null
|
||||||
|
val response: ResponseEntity<Unit> = api.updateUser(username!!, body!!)
|
||||||
|
|
||||||
|
// TODO: test validations
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user