forked from loafle/openapi-generator-original
		
	[kotlin-server][ktor2] fix isKtor, update samples (#20327)
* fix isKtor, update samples * fi dockerfile * fix dataclass * add new files * fix template * regenerate samples
This commit is contained in:
		
							parent
							
								
									f766f445da
								
							
						
					
					
						commit
						b16144094d
					
				@ -288,13 +288,13 @@ public class KotlinServerCodegen extends AbstractKotlinCodegen implements BeanVa
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
        supportingFiles.add(new SupportingFile("README.mustache", "", "README.md"));
 | 
					        supportingFiles.add(new SupportingFile("README.mustache", "", "README.md"));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        if (isKtor()) {
 | 
					        if (isKtor2Or3()) {
 | 
				
			||||||
            supportingFiles.add(new SupportingFile("Dockerfile.mustache", "", "Dockerfile"));
 | 
					            supportingFiles.add(new SupportingFile("Dockerfile.mustache", "", "Dockerfile"));
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        String gradleBuildFile = "build.gradle";
 | 
					        String gradleBuildFile = "build.gradle";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        if (isJavalin() || isKtor()) {
 | 
					        if (isJavalin() || isKtor2Or3()) {
 | 
				
			||||||
            gradleBuildFile = "build.gradle.kts";
 | 
					            gradleBuildFile = "build.gradle.kts";
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -302,7 +302,7 @@ public class KotlinServerCodegen extends AbstractKotlinCodegen implements BeanVa
 | 
				
			|||||||
        supportingFiles.add(new SupportingFile("settings.gradle.mustache", "", "settings.gradle"));
 | 
					        supportingFiles.add(new SupportingFile("settings.gradle.mustache", "", "settings.gradle"));
 | 
				
			||||||
        supportingFiles.add(new SupportingFile("gradle.properties", "", "gradle.properties"));
 | 
					        supportingFiles.add(new SupportingFile("gradle.properties", "", "gradle.properties"));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        if (isKtor()) {
 | 
					        if (isKtor2Or3()) {
 | 
				
			||||||
            additionalProperties.put(Constants.IS_KTOR, true);
 | 
					            additionalProperties.put(Constants.IS_KTOR, true);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            supportingFiles.add(new SupportingFile("AppMain.kt.mustache", packageFolder, "AppMain.kt"));
 | 
					            supportingFiles.add(new SupportingFile("AppMain.kt.mustache", packageFolder, "AppMain.kt"));
 | 
				
			||||||
@ -445,7 +445,20 @@ public class KotlinServerCodegen extends AbstractKotlinCodegen implements BeanVa
 | 
				
			|||||||
        return Constants.JAVALIN5.equals(library) || Constants.JAVALIN6.equals(library);
 | 
					        return Constants.JAVALIN5.equals(library) || Constants.JAVALIN6.equals(library);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    private boolean isKtor() {
 | 
					    private boolean isKtor2Or3() {
 | 
				
			||||||
        return Constants.KTOR.equals(library) || Constants.KTOR2.equals(library);
 | 
					        return Constants.KTOR.equals(library) || Constants.KTOR2.equals(library);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    /**
 | 
				
			||||||
 | 
					     * Returns true if latest version of ktor is used.
 | 
				
			||||||
 | 
					     *
 | 
				
			||||||
 | 
					     * @return true if latest veresion of ktor is used.
 | 
				
			||||||
 | 
					     */
 | 
				
			||||||
 | 
					    private boolean isKtor() {
 | 
				
			||||||
 | 
					        return Constants.KTOR.equals(library);
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    private boolean isKtor2() {
 | 
				
			||||||
 | 
					        return Constants.KTOR2.equals(library);
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
				
			|||||||
@ -1,5 +1,5 @@
 | 
				
			|||||||
{{#hasAuthMethods}}
 | 
					{{#hasAuthMethods}}
 | 
				
			||||||
{{>libraries/ktor/_principal}}
 | 
					{{>libraries/ktor2/_principal}}
 | 
				
			||||||
{{#examples}}
 | 
					{{#examples}}
 | 
				
			||||||
{{#-first}}
 | 
					{{#-first}}
 | 
				
			||||||
{{#lambda.indented}}{{>_response}}{{/lambda.indented}}
 | 
					{{#lambda.indented}}{{>_response}}{{/lambda.indented}}
 | 
				
			||||||
@ -12,7 +12,7 @@ call.respond(HttpStatusCode.NotImplemented)
 | 
				
			|||||||
{{^hasAuthMethods}}
 | 
					{{^hasAuthMethods}}
 | 
				
			||||||
{{#examples}}
 | 
					{{#examples}}
 | 
				
			||||||
{{#-first}}
 | 
					{{#-first}}
 | 
				
			||||||
{{>libraries/ktor/_response}}
 | 
					{{>libraries/ktor2/_response}}
 | 
				
			||||||
{{/-first}}
 | 
					{{/-first}}
 | 
				
			||||||
{{/examples}}
 | 
					{{/examples}}
 | 
				
			||||||
{{^examples}}
 | 
					{{^examples}}
 | 
				
			||||||
 | 
				
			|||||||
@ -35,13 +35,13 @@ fun Route.{{classname}}() {
 | 
				
			|||||||
    {{^featureResources}}
 | 
					    {{^featureResources}}
 | 
				
			||||||
    route("{{path}}") {
 | 
					    route("{{path}}") {
 | 
				
			||||||
        {{#lambda.lowercase}}{{httpMethod}}{{/lambda.lowercase}} {
 | 
					        {{#lambda.lowercase}}{{httpMethod}}{{/lambda.lowercase}} {
 | 
				
			||||||
            {{#lambda.indented_12}}{{>libraries/ktor/_api_body}}{{/lambda.indented_12}}
 | 
					            {{#lambda.indented_12}}{{>libraries/ktor2/_api_body}}{{/lambda.indented_12}}
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    {{/featureResources}}
 | 
					    {{/featureResources}}
 | 
				
			||||||
    {{#featureResources}}
 | 
					    {{#featureResources}}
 | 
				
			||||||
    {{#lambda.lowercase}}{{httpMethod}}{{/lambda.lowercase}}<Paths.{{operationId}}> {
 | 
					    {{#lambda.lowercase}}{{httpMethod}}{{/lambda.lowercase}}<Paths.{{operationId}}> {
 | 
				
			||||||
        {{#lambda.indented_8}}{{>libraries/ktor/_api_body}}{{/lambda.indented_8}}
 | 
					        {{#lambda.indented_8}}{{>libraries/ktor2/_api_body}}{{/lambda.indented_8}}
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    {{/featureResources}}
 | 
					    {{/featureResources}}
 | 
				
			||||||
    {{#hasAuthMethods}}
 | 
					    {{#hasAuthMethods}}
 | 
				
			||||||
 | 
				
			|||||||
							
								
								
									
										52
									
								
								modules/openapi-generator/src/main/resources/kotlin-server/libraries/ktor2/data_class.mustache
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										52
									
								
								modules/openapi-generator/src/main/resources/kotlin-server/libraries/ktor2/data_class.mustache
									
									
									
									
										vendored
									
									
										Normal file
									
								
							@ -0,0 +1,52 @@
 | 
				
			|||||||
 | 
					{{#parcelizeModels}}
 | 
				
			||||||
 | 
					import android.os.Parcelable
 | 
				
			||||||
 | 
					import kotlinx.parcelize.Parcelize
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					{{/parcelizeModels}}
 | 
				
			||||||
 | 
					{{#serializableModel}}
 | 
				
			||||||
 | 
					import java.io.Serializable
 | 
				
			||||||
 | 
					{{/serializableModel}}
 | 
				
			||||||
 | 
					/**
 | 
				
			||||||
 | 
					 * {{{description}}}
 | 
				
			||||||
 | 
					{{#vars}}
 | 
				
			||||||
 | 
					 * @param {{{name}}} {{{description}}}
 | 
				
			||||||
 | 
					{{/vars}}
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					{{#parcelizeModels}}
 | 
				
			||||||
 | 
					@Parcelize
 | 
				
			||||||
 | 
					{{/parcelizeModels}}
 | 
				
			||||||
 | 
					{{#hasVars}}data {{/hasVars}}class {{classname}}(
 | 
				
			||||||
 | 
					{{#requiredVars}}
 | 
				
			||||||
 | 
					{{>data_class_req_var}}{{^-last}},
 | 
				
			||||||
 | 
					{{/-last}}{{/requiredVars}}{{#hasRequired}}{{#hasOptional}},
 | 
				
			||||||
 | 
					{{/hasOptional}}{{/hasRequired}}{{#optionalVars}}{{>data_class_opt_var}}{{^-last}},
 | 
				
			||||||
 | 
					{{/-last}}{{/optionalVars}}
 | 
				
			||||||
 | 
					) {{^serializableModel}}{{#parcelizeModels}} : Parcelable{{/parcelizeModels}}{{/serializableModel}}{{^parcelizeModels}}{{#serializableModel}}: Serializable {{/serializableModel}}{{/parcelizeModels}}{{#parcelizeModels}}{{#serializableModel}} : Parcelable, Serializable {{/serializableModel}}{{/parcelizeModels}}
 | 
				
			||||||
 | 
					{{#vendorExtensions.x-has-data-class-body}}
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					{{/vendorExtensions.x-has-data-class-body}}
 | 
				
			||||||
 | 
					{{#serializableModel}}
 | 
				
			||||||
 | 
					    companion object {
 | 
				
			||||||
 | 
					        private const val serialVersionUID: Long = 123
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					{{/serializableModel}}
 | 
				
			||||||
 | 
					{{#hasEnums}}
 | 
				
			||||||
 | 
					    {{#vars}}
 | 
				
			||||||
 | 
					    {{#isEnum}}
 | 
				
			||||||
 | 
					    /**
 | 
				
			||||||
 | 
					    * {{{description}}}
 | 
				
			||||||
 | 
					    * Values: {{#allowableValues}}{{#enumVars}}{{&name}}{{^-last}},{{/-last}}{{/enumVars}}{{/allowableValues}}
 | 
				
			||||||
 | 
					    */
 | 
				
			||||||
 | 
					    enum class {{{nameInPascalCase}}}(val value: {{{dataType}}}){
 | 
				
			||||||
 | 
					    {{#allowableValues}}
 | 
				
			||||||
 | 
					    {{#enumVars}}
 | 
				
			||||||
 | 
					        {{&name}}({{{value}}}){{^-last}},{{/-last}}{{#-last}};{{/-last}}
 | 
				
			||||||
 | 
					    {{/enumVars}}
 | 
				
			||||||
 | 
					    {{/allowableValues}}
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					{{/isEnum}}
 | 
				
			||||||
 | 
					{{/vars}}
 | 
				
			||||||
 | 
					{{/hasEnums}}
 | 
				
			||||||
 | 
					{{#vendorExtensions.x-has-data-class-body}}
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					{{/vendorExtensions.x-has-data-class-body}}
 | 
				
			||||||
@ -0,0 +1,4 @@
 | 
				
			|||||||
 | 
					{{#description}}
 | 
				
			||||||
 | 
					    /* {{{.}}} */
 | 
				
			||||||
 | 
					{{/description}}
 | 
				
			||||||
 | 
					    {{>modelMutable}} {{{name}}}: {{#isEnum}}{{{classname}}}.{{{nameInPascalCase}}}{{/isEnum}}{{^isEnum}}{{{dataType}}}{{/isEnum}}? = {{{defaultValue}}}{{^defaultValue}}null{{/defaultValue}}
 | 
				
			||||||
@ -0,0 +1,5 @@
 | 
				
			|||||||
 | 
					{{#description}}
 | 
				
			||||||
 | 
					    /* {{{.}}} */
 | 
				
			||||||
 | 
					{{/description}}
 | 
				
			||||||
 | 
					    {{! Note that required properties may be nullable according to the OpenAPI specification. }}
 | 
				
			||||||
 | 
					    {{>modelMutable}} {{{name}}}: {{#isEnum}}{{{classname}}}.{{{nameInPascalCase}}}{{/isEnum}}{{^isEnum}}{{{dataType}}}{{/isEnum}}{{#isNullable}}?{{/isNullable}}{{#defaultValue}} = {{^isNumber}}{{{defaultValue}}}{{/isNumber}}{{#isNumber}}{{{dataType}}}("{{{defaultValue}}}"){{/isNumber}}{{/defaultValue}}
 | 
				
			||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user