forked from loafle/openapi-generator-original
* [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>
This commit is contained in:
parent
78bf3adc4a
commit
b680d7cd7f
@ -6,6 +6,8 @@
|
||||
"templateDir": "modules/openapi-generator/src/main/resources/kotlin-client",
|
||||
"additionalProperties": {
|
||||
"dateLibrary": "string",
|
||||
"serializableModel": "true"
|
||||
"serializableModel": "true",
|
||||
"sortParamsByRequiredFlag": "false",
|
||||
"sortModelPropertiesByRequiredFlag": "false"
|
||||
}
|
||||
}
|
@ -675,9 +675,11 @@ public abstract class AbstractKotlinCodegen extends DefaultCodegen implements Co
|
||||
private String getArrayTypeDeclaration(ArraySchema arr) {
|
||||
// TODO: collection type here should be fully qualified namespace to avoid model conflicts
|
||||
// This supports arrays of arrays.
|
||||
String arrayType = typeMapping.get("array");
|
||||
String arrayType;
|
||||
if (ModelUtils.isSet(arr)) {
|
||||
arrayType = typeMapping.get("set");
|
||||
} else {
|
||||
arrayType = typeMapping.get("array");
|
||||
}
|
||||
StringBuilder instantiationType = new StringBuilder(arrayType);
|
||||
Schema items = arr.getItems();
|
||||
|
@ -25,7 +25,7 @@
|
||||
* {{{description}}}
|
||||
* 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}}
|
||||
@JsonProperty({{{value}}}) {{{name}}}({{{value}}}){{^-last}},{{/-last}}{{#-last}};{{/-last}}
|
||||
{{/enumVars}}{{/allowableValues}}
|
||||
|
@ -1,4 +1,4 @@
|
||||
{{#useBeanValidation}}{{#required}}
|
||||
{{^isReadOnly}}@get:NotNull{{/isReadOnly}} {{/required}}{{>beanValidationModel}}{{/useBeanValidation}}{{#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}}
|
||||
{{^isReadOnly}}@get:NotNull{{/isReadOnly}} {{/required}}{{>beanValidationModel}}{{/useBeanValidation}}{{#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;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import io.swagger.parser.OpenAPIParser;
|
||||
import io.swagger.v3.oas.models.OpenAPI;
|
||||
import io.swagger.v3.oas.models.info.Info;
|
||||
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.SpringCodegen;
|
||||
import org.openapitools.codegen.languages.features.CXFServerFeatures;
|
||||
import org.testng.Assert;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import java.io.File;
|
||||
import java.nio.file.Files;
|
||||
import java.util.Collections;
|
||||
|
||||
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
|
||||
public void testInitialConfigValues() throws Exception {
|
||||
final KotlinSpringServerCodegen codegen = new KotlinSpringServerCodegen();
|
||||
@ -34,6 +68,7 @@ public class KotlinSpringServerCodegenTest {
|
||||
Assert.assertEquals(codegen.additionalProperties().get(KotlinSpringServerCodegen.SERVER_PORT), "8080");
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testSettersForConfigValues() throws Exception {
|
||||
final KotlinSpringServerCodegen codegen = new KotlinSpringServerCodegen();
|
||||
|
@ -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
|
Loading…
x
Reference in New Issue
Block a user