Skip to content

Commit

Permalink
[kotlin] Fixing merge conflict and re-running CI for #4565 (#4977)
Browse files Browse the repository at this point in the history
* [fix-kotlinArrayEnumEmbedded] fix embedded enum array
* Add new gen props to bin/ci/kotlin-client-string.json

Co-authored-by: nekkiy <hard-t@mail.ru>
  • Loading branch information
jimschubert and nekkiy committed Jan 12, 2020
1 parent 78bf3ad commit b680d7c
Show file tree
Hide file tree
Showing 7 changed files with 105 additions and 6 deletions.
4 changes: 3 additions & 1 deletion bin/ci/kotlin-client-string.json
Expand Up @@ -6,6 +6,8 @@
"templateDir": "modules/openapi-generator/src/main/resources/kotlin-client", "templateDir": "modules/openapi-generator/src/main/resources/kotlin-client",
"additionalProperties": { "additionalProperties": {
"dateLibrary": "string", "dateLibrary": "string",
"serializableModel": "true" "serializableModel": "true",
"sortParamsByRequiredFlag": "false",
"sortModelPropertiesByRequiredFlag": "false"
} }
} }
Expand Up @@ -675,9 +675,11 @@ public String toModelFilename(String name) {
private String getArrayTypeDeclaration(ArraySchema arr) { private String getArrayTypeDeclaration(ArraySchema arr) {
// TODO: collection type here should be fully qualified namespace to avoid model conflicts // TODO: collection type here should be fully qualified namespace to avoid model conflicts
// This supports arrays of arrays. // This supports arrays of arrays.
String arrayType = typeMapping.get("array"); String arrayType;
if (ModelUtils.isSet(arr)) { if (ModelUtils.isSet(arr)) {
arrayType = typeMapping.get("set"); arrayType = typeMapping.get("set");
} else {
arrayType = typeMapping.get("array");
} }
StringBuilder instantiationType = new StringBuilder(arrayType); StringBuilder instantiationType = new StringBuilder(arrayType);
Schema items = arr.getItems(); Schema items = arr.getItems();
Expand Down
Expand Up @@ -25,7 +25,7 @@
* {{{description}}} * {{{description}}}
* Values: {{#allowableValues}}{{#enumVars}}{{&name}}{{^-last}},{{/-last}}{{/enumVars}}{{/allowableValues}} * Values: {{#allowableValues}}{{#enumVars}}{{&name}}{{^-last}},{{/-last}}{{/enumVars}}{{/allowableValues}}
*/ */
enum class {{nameInCamelCase}}(val value: {{{dataType}}}) { enum class {{nameInCamelCase}}(val value: {{#isContainer}}{{#items}}{{{dataType}}}{{/items}}{{/isContainer}}{{^isContainer}}{{{dataType}}}{{/isContainer}}) {
{{#allowableValues}}{{#enumVars}} {{#allowableValues}}{{#enumVars}}
@JsonProperty({{{value}}}) {{{name}}}({{{value}}}){{^-last}},{{/-last}}{{#-last}};{{/-last}} @JsonProperty({{{value}}}) {{{name}}}({{{value}}}){{^-last}},{{/-last}}{{#-last}};{{/-last}}
{{/enumVars}}{{/allowableValues}} {{/enumVars}}{{/allowableValues}}
Expand Down
@@ -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}} {{>modelMutable}} {{{name}}}: {{#isEnum}}{{classname}}.{{nameInCamelCase}}{{/isEnum}}{{^isEnum}}{{{dataType}}}{{/isEnum}}? = {{#defaultvalue}}{{defaultvalue}}{{/defaultvalue}}{{^defaultvalue}}null{{/defaultvalue}} @JsonProperty("{{{baseName}}}"){{#isInherited}} override{{/isInherited}} {{>modelMutable}} {{{name}}}: {{#isEnum}}{{#isListContainer}}{{baseType}}<{{/isListContainer}}{{classname}}.{{nameInCamelCase}}{{#isListContainer}}>{{/isListContainer}}{{/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}} {{>modelMutable}} {{{name}}}: {{#isEnum}}{{classname}}.{{nameInCamelCase}}{{/isEnum}}{{^isEnum}}{{{dataType}}}{{/isEnum}}{{#isReadOnly}}? = {{#defaultvalue}}{{defaultvalue}}{{/defaultvalue}}{{^defaultvalue}}null{{/defaultvalue}}{{/isReadOnly}} @JsonProperty("{{{baseName}}}"){{#isInherited}} override{{/isInherited}} {{>modelMutable}} {{{name}}}: {{#isEnum}}{{#isListContainer}}{{baseType}}<{{/isListContainer}}{{classname}}.{{nameInCamelCase}}{{#isListContainer}}>{{/isListContainer}}{{/isEnum}}{{^isEnum}}{{{dataType}}}{{/isEnum}}{{#isReadOnly}}? = {{#defaultvalue}}{{defaultvalue}}{{/defaultvalue}}{{^defaultvalue}}null{{/defaultvalue}}{{/isReadOnly}}
@@ -1,15 +1,49 @@
package org.openapitools.codegen.kotlin.spring; package org.openapitools.codegen.kotlin.spring;


import com.fasterxml.jackson.annotation.JsonProperty;
import io.swagger.parser.OpenAPIParser;
import io.swagger.v3.oas.models.OpenAPI; import io.swagger.v3.oas.models.OpenAPI;
import io.swagger.v3.oas.models.info.Info; import io.swagger.v3.oas.models.info.Info;
import io.swagger.v3.oas.models.servers.Server; import io.swagger.v3.oas.models.servers.Server;
import org.openapitools.codegen.CodegenConstants; import io.swagger.v3.parser.core.models.ParseOptions;
import org.apache.commons.io.FileUtils;
import org.openapitools.codegen.*;
import org.openapitools.codegen.config.CodegenConfigurator;
import org.openapitools.codegen.kotlin.KotlinTestUtils;
import org.openapitools.codegen.languages.AbstractJavaCodegen;
import org.openapitools.codegen.languages.JavaClientCodegen;
import org.openapitools.codegen.languages.KotlinSpringServerCodegen; import org.openapitools.codegen.languages.KotlinSpringServerCodegen;
import org.openapitools.codegen.languages.SpringCodegen;
import org.openapitools.codegen.languages.features.CXFServerFeatures;
import org.testng.Assert; import org.testng.Assert;
import org.testng.annotations.Test; import org.testng.annotations.Test;


import java.io.File;
import java.nio.file.Files;
import java.util.Collections;

public class KotlinSpringServerCodegenTest { public class KotlinSpringServerCodegenTest {


@Test(description = "test embedded enum array")
public void embeddedEnumArrayTest() throws Exception {
String baseModelPackage = "zz";
File output = Files.createTempDirectory("test").toFile().getCanonicalFile(); //may be move to /build
OpenAPI openAPI = TestUtils.parseSpec("src/test/resources/3_0/issue______kotlinArrayEnumEmbedded.yaml");
KotlinSpringServerCodegen codegen = new KotlinSpringServerCodegen();
codegen.setOutputDir(output.getAbsolutePath());
codegen.additionalProperties().put(CodegenConstants.MODEL_PACKAGE, baseModelPackage + ".yyyy.model.xxxx");
ClientOptInput input = new ClientOptInput();
input.openAPI(openAPI);
input.config(codegen);
DefaultGenerator generator = new DefaultGenerator();
generator.opts(input).generate();
File resultSourcePath = new File(output, "src/main/kotlin");
File outputModel = Files.createTempDirectory("test").toFile().getCanonicalFile();
FileUtils.copyDirectory(new File(resultSourcePath, baseModelPackage), new File(outputModel, baseModelPackage));
//no exception
ClassLoader cl = KotlinTestUtils.buildModule(Collections.singletonList(outputModel.getAbsolutePath()), Thread.currentThread().getContextClassLoader());
}

@Test @Test
public void testInitialConfigValues() throws Exception { public void testInitialConfigValues() throws Exception {
final KotlinSpringServerCodegen codegen = new KotlinSpringServerCodegen(); final KotlinSpringServerCodegen codegen = new KotlinSpringServerCodegen();
Expand All @@ -34,6 +68,7 @@ public void testInitialConfigValues() throws Exception {
Assert.assertEquals(codegen.additionalProperties().get(KotlinSpringServerCodegen.SERVER_PORT), "8080"); Assert.assertEquals(codegen.additionalProperties().get(KotlinSpringServerCodegen.SERVER_PORT), "8080");
} }



@Test @Test
public void testSettersForConfigValues() throws Exception { public void testSettersForConfigValues() throws Exception {
final KotlinSpringServerCodegen codegen = new KotlinSpringServerCodegen(); final KotlinSpringServerCodegen codegen = new KotlinSpringServerCodegen();
Expand Down
@@ -0,0 +1,60 @@
openapi: "3.0.1"
info:
title: test
version: "1.0"
paths:
/test:
get:
operationId: test
responses:
200:
description: OK
content:
application/json:
schema:
$ref: '#/components/schemas/EmbeddedEnumArray'

components:
schemas:
EmbeddedEnumArray:
type: object
properties:
colors:
type: array
items:
type: string
enum: ['BLACK', 'RED', 'ORANGE', 'YELLOW', 'BLUE', 'GREEN']
reqColors:
type: array
items:
type: string
enum: ['BLACK', 'RED', 'ORANGE', 'YELLOW', 'BLUE', 'GREEN']
required:
- reqColors
NoEmbeddedEnumArray:
type: object
properties:
colors:
type: array
items:
$ref: '#/components/schemas/Colors'
reqColors:
type: array
items:
$ref: '#/components/schemas/Colors'
required:
- reqColors
Colors:
type: string
enum: ['BLACK', 'RED', 'ORANGE', 'YELLOW', 'BLUE', 'GREEN']
SimpleColorContainer:
type: object
properties:
color:
type: string
enum: ['BLACK', 'RED', 'ORANGE', 'YELLOW', 'BLUE', 'GREEN']
reqColor:
type: string
enum: ['BLACK', 'RED', 'ORANGE', 'YELLOW', 'BLUE', 'GREEN']
required:
- reqColor

0 comments on commit b680d7c

Please sign in to comment.