forked from loafle/openapi-generator-original
* fix missing bean validation annotations on RequestBody * add new line to files * remove new line from files * reformat file
This commit is contained in:
parent
166ebc50b0
commit
ced31f49b3
1
modules/openapi-generator/src/main/resources/kotlin-spring/beanValidationBodyParams.mustache
vendored
Normal file
1
modules/openapi-generator/src/main/resources/kotlin-spring/beanValidationBodyParams.mustache
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
{{! RequestBody required param is responsible for optional and nullability }}{{>beanValidationCore}}
|
@ -1 +1 @@
|
|||||||
{{! PathParam is always required, no @NotNull necessary }}{{>beanValidationPath}}
|
{{! PathParam is always required, no @NotNull necessary }}{{>beanValidationCore}}
|
@ -1 +1 @@
|
|||||||
{{#required}}@NotNull {{/required}}{{>beanValidationPath}}
|
{{#required}}@NotNull {{/required}}{{>beanValidationCore}}
|
@ -1 +1 @@
|
|||||||
{{#isBodyParam}}{{#swagger2AnnotationLibrary}}@Parameter(description = "{{{description}}}"{{#required}}, required = true{{/required}}{{^isContainer}}{{#allowableValues}}{{#defaultValue}}, schema = Schema(allowableValues = ["{{{allowableValues}}}"], defaultValue = {{^isString}}"{{/isString}}{{#isString}}{{#isEnum}}"{{/isEnum}}{{/isString}}{{{defaultValue}}}{{^isString}}"{{/isString}}{{#isString}}{{#isEnum}}"{{/isEnum}}{{/isString}}){{/defaultValue}}{{/allowableValues}}{{^allowableValues}}{{#defaultValue}}, schema = Schema(defaultValue = {{^isString}}"{{/isString}}{{#isString}}{{#isEnum}}"{{/isEnum}}{{/isString}}{{{defaultValue}}}{{^isString}}"{{/isString}}{{#isString}}{{#isEnum}}"{{/isEnum}}{{/isString}}){{/defaultValue}}{{/allowableValues}}{{#allowableValues}}{{^defaultValue}}, schema = Schema(allowableValues = ["{{{allowableValues}}}"]){{/defaultValue}}{{/allowableValues}}{{/isContainer}}){{/swagger2AnnotationLibrary}}{{#swagger1AnnotationLibrary}}@ApiParam(value = "{{{description}}}"{{#required}}, required = true{{/required}}{{^isContainer}}{{#allowableValues}}, allowableValues = "{{{.}}}"{{/allowableValues}}{{/isContainer}}{{#defaultValue}}, defaultValue = "{{{.}}}"{{/defaultValue}}){{/swagger1AnnotationLibrary}} {{#useBeanValidation}}@Valid{{/useBeanValidation}} @RequestBody{{^required}}(required = false){{/required}} {{{paramName}}}: {{^reactive}}{{>optionalDataType}}{{/reactive}}{{#reactive}}{{^isArray}}{{>optionalDataType}}{{/isArray}}{{#isArray}}Flow<{{{baseType}}}>{{/isArray}}{{/reactive}}{{/isBodyParam}}
|
{{#isBodyParam}}{{#swagger2AnnotationLibrary}}@Parameter(description = "{{{description}}}"{{#required}}, required = true{{/required}}{{^isContainer}}{{#allowableValues}}{{#defaultValue}}, schema = Schema(allowableValues = ["{{{allowableValues}}}"], defaultValue = {{^isString}}"{{/isString}}{{#isString}}{{#isEnum}}"{{/isEnum}}{{/isString}}{{{defaultValue}}}{{^isString}}"{{/isString}}{{#isString}}{{#isEnum}}"{{/isEnum}}{{/isString}}){{/defaultValue}}{{/allowableValues}}{{^allowableValues}}{{#defaultValue}}, schema = Schema(defaultValue = {{^isString}}"{{/isString}}{{#isString}}{{#isEnum}}"{{/isEnum}}{{/isString}}{{{defaultValue}}}{{^isString}}"{{/isString}}{{#isString}}{{#isEnum}}"{{/isEnum}}{{/isString}}){{/defaultValue}}{{/allowableValues}}{{#allowableValues}}{{^defaultValue}}, schema = Schema(allowableValues = ["{{{allowableValues}}}"]){{/defaultValue}}{{/allowableValues}}{{/isContainer}}){{/swagger2AnnotationLibrary}}{{#swagger1AnnotationLibrary}}@ApiParam(value = "{{{description}}}"{{#required}}, required = true{{/required}}{{^isContainer}}{{#allowableValues}}, allowableValues = "{{{.}}}"{{/allowableValues}}{{/isContainer}}{{#defaultValue}}, defaultValue = "{{{.}}}"{{/defaultValue}}){{/swagger1AnnotationLibrary}}{{#useBeanValidation}} @Valid{{>beanValidationBodyParams}}{{/useBeanValidation}} @RequestBody{{^required}}(required = false){{/required}} {{{paramName}}}: {{^reactive}}{{>optionalDataType}}{{/reactive}}{{#reactive}}{{^isArray}}{{>optionalDataType}}{{/isArray}}{{#isArray}}Flow<{{{baseType}}}>{{/isArray}}{{/reactive}}{{/isBodyParam}}
|
@ -1 +1 @@
|
|||||||
{{#isHeaderParam}}{{#useBeanValidation}}{{>beanValidationPath}}{{/useBeanValidation}}{{#swagger2AnnotationLibrary}}@Parameter(description = "{{{description}}}", `in` = ParameterIn.HEADER{{#required}}, required = true{{/required}}{{#allowableValues}}{{#defaultValue}}, schema = Schema(allowableValues = [{{#values}}"{{{.}}}"{{^-last}}, {{/-last}}{{/values}}]{{^isContainer}}, defaultValue = {{^isString}}"{{/isString}}{{#isString}}{{#isEnum}}"{{/isEnum}}{{/isString}}{{{defaultValue}}}{{^isString}}"{{/isString}}{{#isString}}{{#isEnum}}"{{/isEnum}}{{/isString}}{{/isContainer}}){{/defaultValue}}{{/allowableValues}}{{#allowableValues}}{{^defaultValue}}, schema = Schema(allowableValues = [{{#values}}"{{{.}}}"{{^-last}}, {{/-last}}{{/values}}]){{/defaultValue}}{{/allowableValues}}{{^allowableValues}}{{#defaultValue}}{{^isContainer}}, schema = Schema(defaultValue = {{^isString}}"{{/isString}}{{#isString}}{{#isEnum}}"{{/isEnum}}{{/isString}}{{{defaultValue}}}{{^isString}}"{{/isString}}{{#isString}}{{#isEnum}}"{{/isEnum}}{{/isString}}){{/isContainer}}{{/defaultValue}}{{/allowableValues}}){{/swagger2AnnotationLibrary}}{{#swagger1AnnotationLibrary}}@ApiParam(value = "{{{description}}}"{{#required}}, required = true{{/required}}{{#allowableValues}}, allowableValues = "{{#values}}{{{.}}}{{^-last}}, {{/-last}}{{/values}}"{{/allowableValues}}{{#defaultValue}}, defaultValue = "{{{.}}}"{{/defaultValue}}){{/swagger1AnnotationLibrary}} @RequestHeader(value = "{{baseName}}", required = {{#required}}true{{/required}}{{^required}}false{{/required}}) {{paramName}}: {{>optionalDataType}}{{/isHeaderParam}}
|
{{#isHeaderParam}}{{#useBeanValidation}}{{>beanValidationCore}}{{/useBeanValidation}}{{#swagger2AnnotationLibrary}}@Parameter(description = "{{{description}}}", `in` = ParameterIn.HEADER{{#required}}, required = true{{/required}}{{#allowableValues}}{{#defaultValue}}, schema = Schema(allowableValues = [{{#values}}"{{{.}}}"{{^-last}}, {{/-last}}{{/values}}]{{^isContainer}}, defaultValue = {{^isString}}"{{/isString}}{{#isString}}{{#isEnum}}"{{/isEnum}}{{/isString}}{{{defaultValue}}}{{^isString}}"{{/isString}}{{#isString}}{{#isEnum}}"{{/isEnum}}{{/isString}}{{/isContainer}}){{/defaultValue}}{{/allowableValues}}{{#allowableValues}}{{^defaultValue}}, schema = Schema(allowableValues = [{{#values}}"{{{.}}}"{{^-last}}, {{/-last}}{{/values}}]){{/defaultValue}}{{/allowableValues}}{{^allowableValues}}{{#defaultValue}}{{^isContainer}}, schema = Schema(defaultValue = {{^isString}}"{{/isString}}{{#isString}}{{#isEnum}}"{{/isEnum}}{{/isString}}{{{defaultValue}}}{{^isString}}"{{/isString}}{{#isString}}{{#isEnum}}"{{/isEnum}}{{/isString}}){{/isContainer}}{{/defaultValue}}{{/allowableValues}}){{/swagger2AnnotationLibrary}}{{#swagger1AnnotationLibrary}}@ApiParam(value = "{{{description}}}"{{#required}}, required = true{{/required}}{{#allowableValues}}, allowableValues = "{{#values}}{{{.}}}{{^-last}}, {{/-last}}{{/values}}"{{/allowableValues}}{{#defaultValue}}, defaultValue = "{{{.}}}"{{/defaultValue}}){{/swagger1AnnotationLibrary}} @RequestHeader(value = "{{baseName}}", required = {{#required}}true{{/required}}{{^required}}false{{/required}}) {{paramName}}: {{>optionalDataType}}{{/isHeaderParam}}
|
@ -25,6 +25,9 @@ import java.nio.file.Files;
|
|||||||
import java.nio.file.Paths;
|
import java.nio.file.Paths;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.function.Function;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
import static org.openapitools.codegen.TestUtils.assertFileContains;
|
import static org.openapitools.codegen.TestUtils.assertFileContains;
|
||||||
import static org.openapitools.codegen.TestUtils.assertFileNotContains;
|
import static org.openapitools.codegen.TestUtils.assertFileNotContains;
|
||||||
@ -87,14 +90,14 @@ public class KotlinSpringServerCodegenTest {
|
|||||||
codegen.setLibrary("spring-cloud");
|
codegen.setLibrary("spring-cloud");
|
||||||
|
|
||||||
new DefaultGenerator().opts(new ClientOptInput()
|
new DefaultGenerator().opts(new ClientOptInput()
|
||||||
.openAPI(TestUtils.parseSpec("src/test/resources/3_0/kotlin/feat13488_use_kotlinSpring_with_springCloud.yaml"))
|
.openAPI(TestUtils.parseSpec("src/test/resources/3_0/kotlin/feat13488_use_kotlinSpring_with_springCloud.yaml"))
|
||||||
.config(codegen))
|
.config(codegen))
|
||||||
.generate();
|
.generate();
|
||||||
|
|
||||||
// Check that the @RequestMapping annotation is not generated in the Api file
|
// Check that the @RequestMapping annotation is not generated in the Api file
|
||||||
assertFileNotContains(
|
assertFileNotContains(
|
||||||
Paths.get(output + "/src/main/kotlin/org/openapitools/api/TestV1Api.kt"),
|
Paths.get(output + "/src/main/kotlin/org/openapitools/api/TestV1Api.kt"),
|
||||||
"@RequestMapping(\"\\${api.base-path"
|
"@RequestMapping(\"\\${api.base-path"
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -214,18 +217,18 @@ public class KotlinSpringServerCodegenTest {
|
|||||||
codegen.additionalProperties().put(KotlinSpringServerCodegen.USE_TAGS, true);
|
codegen.additionalProperties().put(KotlinSpringServerCodegen.USE_TAGS, true);
|
||||||
|
|
||||||
List<File> files = new DefaultGenerator()
|
List<File> files = new DefaultGenerator()
|
||||||
.opts(
|
.opts(
|
||||||
new ClientOptInput()
|
new ClientOptInput()
|
||||||
.openAPI(TestUtils.parseSpec("src/test/resources/3_0/kotlin/issue5497-use-tags-kotlin.yaml"))
|
.openAPI(TestUtils.parseSpec("src/test/resources/3_0/kotlin/issue5497-use-tags-kotlin.yaml"))
|
||||||
.config(codegen)
|
.config(codegen)
|
||||||
)
|
)
|
||||||
.generate();
|
.generate();
|
||||||
|
|
||||||
Helpers.assertContainsAllOf(files,
|
Helpers.assertContainsAllOf(files,
|
||||||
new File(output, "src/main/kotlin/org/openapitools/api/TestV1ApiController.kt"),
|
new File(output, "src/main/kotlin/org/openapitools/api/TestV1ApiController.kt"),
|
||||||
new File(output, "src/main/kotlin/org/openapitools/api/TestV1ApiDelegate.kt"),
|
new File(output, "src/main/kotlin/org/openapitools/api/TestV1ApiDelegate.kt"),
|
||||||
new File(output, "src/main/kotlin/org/openapitools/api/TestV2ApiController.kt"),
|
new File(output, "src/main/kotlin/org/openapitools/api/TestV2ApiController.kt"),
|
||||||
new File(output, "src/main/kotlin/org/openapitools/api/TestV2ApiDelegate.kt")
|
new File(output, "src/main/kotlin/org/openapitools/api/TestV2ApiDelegate.kt")
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -239,51 +242,51 @@ public class KotlinSpringServerCodegenTest {
|
|||||||
codegen.additionalProperties().put(KotlinSpringServerCodegen.USE_TAGS, true);
|
codegen.additionalProperties().put(KotlinSpringServerCodegen.USE_TAGS, true);
|
||||||
|
|
||||||
List<File> files = new DefaultGenerator()
|
List<File> files = new DefaultGenerator()
|
||||||
.opts(
|
.opts(
|
||||||
new ClientOptInput()
|
new ClientOptInput()
|
||||||
.openAPI(TestUtils.parseSpec("src/test/resources/3_0/kotlin/issue7325-use-delegate-reactive-tags-kotlin.yaml"))
|
.openAPI(TestUtils.parseSpec("src/test/resources/3_0/kotlin/issue7325-use-delegate-reactive-tags-kotlin.yaml"))
|
||||||
.config(codegen)
|
.config(codegen)
|
||||||
)
|
)
|
||||||
.generate();
|
.generate();
|
||||||
|
|
||||||
Helpers.assertContainsAllOf(files,
|
Helpers.assertContainsAllOf(files,
|
||||||
new File(output, "src/main/kotlin/org/openapitools/api/TestV1Api.kt"),
|
new File(output, "src/main/kotlin/org/openapitools/api/TestV1Api.kt"),
|
||||||
new File(output, "src/main/kotlin/org/openapitools/api/TestV1ApiController.kt"),
|
new File(output, "src/main/kotlin/org/openapitools/api/TestV1ApiController.kt"),
|
||||||
new File(output, "src/main/kotlin/org/openapitools/api/TestV1ApiDelegate.kt"),
|
new File(output, "src/main/kotlin/org/openapitools/api/TestV1ApiDelegate.kt"),
|
||||||
new File(output, "src/main/kotlin/org/openapitools/api/TestV2Api.kt"),
|
new File(output, "src/main/kotlin/org/openapitools/api/TestV2Api.kt"),
|
||||||
new File(output, "src/main/kotlin/org/openapitools/api/TestV2ApiController.kt"),
|
new File(output, "src/main/kotlin/org/openapitools/api/TestV2ApiController.kt"),
|
||||||
new File(output, "src/main/kotlin/org/openapitools/api/TestV2ApiDelegate.kt"),
|
new File(output, "src/main/kotlin/org/openapitools/api/TestV2ApiDelegate.kt"),
|
||||||
new File(output, "src/main/kotlin/org/openapitools/api/TestV3Api.kt"),
|
new File(output, "src/main/kotlin/org/openapitools/api/TestV3Api.kt"),
|
||||||
new File(output, "src/main/kotlin/org/openapitools/api/TestV3ApiController.kt"),
|
new File(output, "src/main/kotlin/org/openapitools/api/TestV3ApiController.kt"),
|
||||||
new File(output, "src/main/kotlin/org/openapitools/api/TestV3ApiDelegate.kt")
|
new File(output, "src/main/kotlin/org/openapitools/api/TestV3ApiDelegate.kt")
|
||||||
);
|
);
|
||||||
|
|
||||||
assertFileContains(Paths.get(output + "/src/main/kotlin/org/openapitools/api/TestV1Api.kt"),
|
assertFileContains(Paths.get(output + "/src/main/kotlin/org/openapitools/api/TestV1Api.kt"),
|
||||||
"suspend fun");
|
"suspend fun");
|
||||||
assertFileNotContains(Paths.get(output + "/src/main/kotlin/org/openapitools/api/TestV1Api.kt"),
|
assertFileNotContains(Paths.get(output + "/src/main/kotlin/org/openapitools/api/TestV1Api.kt"),
|
||||||
"exchange");
|
"exchange");
|
||||||
assertFileContains(Paths.get(output + "/src/main/kotlin/org/openapitools/api/TestV1ApiDelegate.kt"),
|
assertFileContains(Paths.get(output + "/src/main/kotlin/org/openapitools/api/TestV1ApiDelegate.kt"),
|
||||||
"suspend fun");
|
"suspend fun");
|
||||||
assertFileNotContains(Paths.get(output + "/src/main/kotlin/org/openapitools/api/TestV1ApiDelegate.kt"),
|
assertFileNotContains(Paths.get(output + "/src/main/kotlin/org/openapitools/api/TestV1ApiDelegate.kt"),
|
||||||
"ApiUtil");
|
"ApiUtil");
|
||||||
|
|
||||||
assertFileContains(Paths.get(output + "/src/main/kotlin/org/openapitools/api/TestV2Api.kt"),
|
assertFileContains(Paths.get(output + "/src/main/kotlin/org/openapitools/api/TestV2Api.kt"),
|
||||||
"import kotlinx.coroutines.flow.Flow", "ResponseEntity<Flow<kotlin.String>>");
|
"import kotlinx.coroutines.flow.Flow", "ResponseEntity<Flow<kotlin.String>>");
|
||||||
assertFileNotContains(Paths.get(output + "/src/main/kotlin/org/openapitools/api/TestV2Api.kt"),
|
assertFileNotContains(Paths.get(output + "/src/main/kotlin/org/openapitools/api/TestV2Api.kt"),
|
||||||
"exchange");
|
"exchange");
|
||||||
assertFileContains(Paths.get(output + "/src/main/kotlin/org/openapitools/api/TestV2ApiDelegate.kt"),
|
assertFileContains(Paths.get(output + "/src/main/kotlin/org/openapitools/api/TestV2ApiDelegate.kt"),
|
||||||
"import kotlinx.coroutines.flow.Flow", "ResponseEntity<Flow<kotlin.String>>");
|
"import kotlinx.coroutines.flow.Flow", "ResponseEntity<Flow<kotlin.String>>");
|
||||||
assertFileNotContains(Paths.get(output + "/src/main/kotlin/org/openapitools/api/TestV2ApiDelegate.kt"),
|
assertFileNotContains(Paths.get(output + "/src/main/kotlin/org/openapitools/api/TestV2ApiDelegate.kt"),
|
||||||
"suspend fun", "ApiUtil");
|
"suspend fun", "ApiUtil");
|
||||||
|
|
||||||
assertFileContains(Paths.get(output + "/src/main/kotlin/org/openapitools/api/TestV3Api.kt"),
|
assertFileContains(Paths.get(output + "/src/main/kotlin/org/openapitools/api/TestV3Api.kt"),
|
||||||
"import kotlinx.coroutines.flow.Flow", "requestBody: Flow<kotlin.Long>");
|
"import kotlinx.coroutines.flow.Flow", "requestBody: Flow<kotlin.Long>");
|
||||||
assertFileNotContains(Paths.get(output + "/src/main/kotlin/org/openapitools/api/TestV3Api.kt"),
|
assertFileNotContains(Paths.get(output + "/src/main/kotlin/org/openapitools/api/TestV3Api.kt"),
|
||||||
"exchange");
|
"exchange");
|
||||||
assertFileContains(Paths.get(output + "/src/main/kotlin/org/openapitools/api/TestV3ApiDelegate.kt"),
|
assertFileContains(Paths.get(output + "/src/main/kotlin/org/openapitools/api/TestV3ApiDelegate.kt"),
|
||||||
"import kotlinx.coroutines.flow.Flow", "suspend fun", "requestBody: Flow<kotlin.Long>");
|
"import kotlinx.coroutines.flow.Flow", "suspend fun", "requestBody: Flow<kotlin.Long>");
|
||||||
assertFileNotContains(Paths.get(output + "/src/main/kotlin/org/openapitools/api/TestV3ApiDelegate.kt"),
|
assertFileNotContains(Paths.get(output + "/src/main/kotlin/org/openapitools/api/TestV3ApiDelegate.kt"),
|
||||||
"ApiUtil");
|
"ApiUtil");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ -293,7 +296,7 @@ public class KotlinSpringServerCodegenTest {
|
|||||||
String outputPath = output.getAbsolutePath().replace('\\', '/');
|
String outputPath = output.getAbsolutePath().replace('\\', '/');
|
||||||
|
|
||||||
OpenAPI openAPI = new OpenAPIParser()
|
OpenAPI openAPI = new OpenAPIParser()
|
||||||
.readLocation("src/test/resources/3_0/objectQueryParam.yaml", null, new ParseOptions()).getOpenAPI();
|
.readLocation("src/test/resources/3_0/objectQueryParam.yaml", null, new ParseOptions()).getOpenAPI();
|
||||||
|
|
||||||
KotlinSpringServerCodegen codegen = new KotlinSpringServerCodegen();
|
KotlinSpringServerCodegen codegen = new KotlinSpringServerCodegen();
|
||||||
codegen.setOutputDir(output.getAbsolutePath());
|
codegen.setOutputDir(output.getAbsolutePath());
|
||||||
@ -323,7 +326,7 @@ public class KotlinSpringServerCodegenTest {
|
|||||||
String outputPath = output.getAbsolutePath().replace('\\', '/');
|
String outputPath = output.getAbsolutePath().replace('\\', '/');
|
||||||
|
|
||||||
OpenAPI openAPI = new OpenAPIParser()
|
OpenAPI openAPI = new OpenAPIParser()
|
||||||
.readLocation("src/test/resources/3_0/issue_3248.yaml", null, new ParseOptions()).getOpenAPI();
|
.readLocation("src/test/resources/3_0/issue_3248.yaml", null, new ParseOptions()).getOpenAPI();
|
||||||
|
|
||||||
KotlinSpringServerCodegen codegen = new KotlinSpringServerCodegen();
|
KotlinSpringServerCodegen codegen = new KotlinSpringServerCodegen();
|
||||||
codegen.setOutputDir(output.getAbsolutePath());
|
codegen.setOutputDir(output.getAbsolutePath());
|
||||||
@ -360,7 +363,7 @@ public class KotlinSpringServerCodegenTest {
|
|||||||
String outputPath = output.getAbsolutePath().replace('\\', '/');
|
String outputPath = output.getAbsolutePath().replace('\\', '/');
|
||||||
|
|
||||||
OpenAPI openAPI = new OpenAPIParser()
|
OpenAPI openAPI = new OpenAPIParser()
|
||||||
.readLocation("src/test/resources/3_0/issue_2053.yaml", null, new ParseOptions()).getOpenAPI();
|
.readLocation("src/test/resources/3_0/issue_2053.yaml", null, new ParseOptions()).getOpenAPI();
|
||||||
|
|
||||||
KotlinSpringServerCodegen codegen = new KotlinSpringServerCodegen();
|
KotlinSpringServerCodegen codegen = new KotlinSpringServerCodegen();
|
||||||
codegen.setOutputDir(output.getAbsolutePath());
|
codegen.setOutputDir(output.getAbsolutePath());
|
||||||
@ -380,12 +383,12 @@ public class KotlinSpringServerCodegenTest {
|
|||||||
generator.opts(input).generate();
|
generator.opts(input).generate();
|
||||||
|
|
||||||
assertFileContains(
|
assertFileContains(
|
||||||
Paths.get(outputPath + "/src/main/kotlin/org/openapitools/api/ElephantsApiController.kt"),
|
Paths.get(outputPath + "/src/main/kotlin/org/openapitools/api/ElephantsApiController.kt"),
|
||||||
"@org.springframework.format.annotation.DateTimeFormat(iso = org.springframework.format.annotation.DateTimeFormat.ISO.DATE)"
|
"@org.springframework.format.annotation.DateTimeFormat(iso = org.springframework.format.annotation.DateTimeFormat.ISO.DATE)"
|
||||||
);
|
);
|
||||||
assertFileContains(
|
assertFileContains(
|
||||||
Paths.get(outputPath + "/src/main/kotlin/org/openapitools/api/ZebrasApiController.kt"),
|
Paths.get(outputPath + "/src/main/kotlin/org/openapitools/api/ZebrasApiController.kt"),
|
||||||
"@org.springframework.format.annotation.DateTimeFormat(iso = org.springframework.format.annotation.DateTimeFormat.ISO.DATE_TIME)"
|
"@org.springframework.format.annotation.DateTimeFormat(iso = org.springframework.format.annotation.DateTimeFormat.ISO.DATE_TIME)"
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -400,13 +403,13 @@ public class KotlinSpringServerCodegenTest {
|
|||||||
codegen.additionalProperties().put(KotlinSpringServerCodegen.BEAN_QUALIFIERS, true);
|
codegen.additionalProperties().put(KotlinSpringServerCodegen.BEAN_QUALIFIERS, true);
|
||||||
|
|
||||||
new DefaultGenerator().opts(new ClientOptInput()
|
new DefaultGenerator().opts(new ClientOptInput()
|
||||||
.openAPI(TestUtils.parseSpec("src/test/resources/3_0/kotlin/bean-qualifiers.yaml"))
|
.openAPI(TestUtils.parseSpec("src/test/resources/3_0/kotlin/bean-qualifiers.yaml"))
|
||||||
.config(codegen))
|
.config(codegen))
|
||||||
.generate();
|
.generate();
|
||||||
|
|
||||||
assertFileContains(
|
assertFileContains(
|
||||||
Paths.get(outputPath + "/src/main/kotlin/org/openapitools/api/PingApiController.kt"),
|
Paths.get(outputPath + "/src/main/kotlin/org/openapitools/api/PingApiController.kt"),
|
||||||
"@RestController(\"org.openapitools.api.PingApiController\")"
|
"@RestController(\"org.openapitools.api.PingApiController\")"
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -422,13 +425,13 @@ public class KotlinSpringServerCodegenTest {
|
|||||||
codegen.additionalProperties().put(KotlinSpringServerCodegen.SKIP_DEFAULT_INTERFACE, true);
|
codegen.additionalProperties().put(KotlinSpringServerCodegen.SKIP_DEFAULT_INTERFACE, true);
|
||||||
|
|
||||||
new DefaultGenerator().opts(new ClientOptInput()
|
new DefaultGenerator().opts(new ClientOptInput()
|
||||||
.openAPI(TestUtils.parseSpec("src/test/resources/3_0/kotlin/skip-default-interface.yaml"))
|
.openAPI(TestUtils.parseSpec("src/test/resources/3_0/kotlin/skip-default-interface.yaml"))
|
||||||
.config(codegen))
|
.config(codegen))
|
||||||
.generate();
|
.generate();
|
||||||
|
|
||||||
assertFileNotContains(
|
assertFileNotContains(
|
||||||
Paths.get(outputPath + "/src/main/kotlin/org/openapitools/api/PingApi.kt"),
|
Paths.get(outputPath + "/src/main/kotlin/org/openapitools/api/PingApi.kt"),
|
||||||
"return "
|
"return "
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -443,21 +446,21 @@ public class KotlinSpringServerCodegenTest {
|
|||||||
codegen.additionalProperties().put(KotlinSpringServerCodegen.USE_SPRING_BOOT3, true);
|
codegen.additionalProperties().put(KotlinSpringServerCodegen.USE_SPRING_BOOT3, true);
|
||||||
|
|
||||||
new DefaultGenerator().opts(new ClientOptInput()
|
new DefaultGenerator().opts(new ClientOptInput()
|
||||||
.openAPI(TestUtils.parseSpec("src/test/resources/3_0/kotlin/feat13578_use_springboot3_jakarta_extension.yaml"))
|
.openAPI(TestUtils.parseSpec("src/test/resources/3_0/kotlin/feat13578_use_springboot3_jakarta_extension.yaml"))
|
||||||
.config(codegen))
|
.config(codegen))
|
||||||
.generate();
|
.generate();
|
||||||
|
|
||||||
assertFileContains(
|
assertFileContains(
|
||||||
Paths.get(outputPath + "/src/main/kotlin/org/openapitools/api/ApiUtil.kt"),
|
Paths.get(outputPath + "/src/main/kotlin/org/openapitools/api/ApiUtil.kt"),
|
||||||
"import jakarta.servlet.http.HttpServletResponse"
|
"import jakarta.servlet.http.HttpServletResponse"
|
||||||
);
|
);
|
||||||
assertFileContains(
|
assertFileContains(
|
||||||
Paths.get(outputPath + "/src/main/kotlin/org/openapitools/api/Exceptions.kt"),
|
Paths.get(outputPath + "/src/main/kotlin/org/openapitools/api/Exceptions.kt"),
|
||||||
"import jakarta.validation.ConstraintViolationException"
|
"import jakarta.validation.ConstraintViolationException"
|
||||||
);
|
);
|
||||||
assertFileContains(
|
assertFileContains(
|
||||||
Paths.get(outputPath + "/src/main/kotlin/org/openapitools/api/PingApiController.kt"),
|
Paths.get(outputPath + "/src/main/kotlin/org/openapitools/api/PingApiController.kt"),
|
||||||
"import jakarta.validation.Valid"
|
"import jakarta.validation.Valid"
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -515,25 +518,25 @@ public class KotlinSpringServerCodegenTest {
|
|||||||
codegen.setOutputDir(output.getAbsolutePath());
|
codegen.setOutputDir(output.getAbsolutePath());
|
||||||
|
|
||||||
new DefaultGenerator().opts(new ClientOptInput()
|
new DefaultGenerator().opts(new ClientOptInput()
|
||||||
.openAPI(TestUtils.parseSpec("src/test/resources/3_0/kotlin/issue3596-use-correct-get-annotation-target.yaml"))
|
.openAPI(TestUtils.parseSpec("src/test/resources/3_0/kotlin/issue3596-use-correct-get-annotation-target.yaml"))
|
||||||
.config(codegen))
|
.config(codegen))
|
||||||
.generate();
|
.generate();
|
||||||
|
|
||||||
assertFileNotContains(
|
assertFileNotContains(
|
||||||
Paths.get(outputPath + "/src/main/kotlin/org/openapitools/model/Animal.kt"),
|
Paths.get(outputPath + "/src/main/kotlin/org/openapitools/model/Animal.kt"),
|
||||||
"@Schema(example = \"null\", description = \"\")"
|
"@Schema(example = \"null\", description = \"\")"
|
||||||
);
|
);
|
||||||
assertFileContains(
|
assertFileContains(
|
||||||
Paths.get(outputPath + "/src/main/kotlin/org/openapitools/model/Animal.kt"),
|
Paths.get(outputPath + "/src/main/kotlin/org/openapitools/model/Animal.kt"),
|
||||||
"@get:Schema(example = \"null\", description = \"\")"
|
"@get:Schema(example = \"null\", description = \"\")"
|
||||||
);
|
);
|
||||||
assertFileNotContains(
|
assertFileNotContains(
|
||||||
Paths.get(outputPath + "/src/main/kotlin/org/openapitools/model/Animal.kt"),
|
Paths.get(outputPath + "/src/main/kotlin/org/openapitools/model/Animal.kt"),
|
||||||
"@Schema(example = \"null\", requiredMode = Schema.RequiredMode.REQUIRED, description = \"\")"
|
"@Schema(example = \"null\", requiredMode = Schema.RequiredMode.REQUIRED, description = \"\")"
|
||||||
);
|
);
|
||||||
assertFileContains(
|
assertFileContains(
|
||||||
Paths.get(outputPath + "/src/main/kotlin/org/openapitools/model/Animal.kt"),
|
Paths.get(outputPath + "/src/main/kotlin/org/openapitools/model/Animal.kt"),
|
||||||
"@get:Schema(example = \"null\", requiredMode = Schema.RequiredMode.REQUIRED, description = \"\")"
|
"@get:Schema(example = \"null\", requiredMode = Schema.RequiredMode.REQUIRED, description = \"\")"
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -549,25 +552,53 @@ public class KotlinSpringServerCodegenTest {
|
|||||||
codegen.additionalProperties().put(DOCUMENTATION_PROVIDER, DocumentationProvider.SPRINGFOX.toCliOptValue());
|
codegen.additionalProperties().put(DOCUMENTATION_PROVIDER, DocumentationProvider.SPRINGFOX.toCliOptValue());
|
||||||
|
|
||||||
new DefaultGenerator().opts(new ClientOptInput()
|
new DefaultGenerator().opts(new ClientOptInput()
|
||||||
.openAPI(TestUtils.parseSpec("src/test/resources/3_0/kotlin/issue3596-use-correct-get-annotation-target.yaml"))
|
.openAPI(TestUtils.parseSpec("src/test/resources/3_0/kotlin/issue3596-use-correct-get-annotation-target.yaml"))
|
||||||
.config(codegen))
|
.config(codegen))
|
||||||
.generate();
|
.generate();
|
||||||
|
|
||||||
assertFileNotContains(
|
assertFileNotContains(
|
||||||
Paths.get(outputPath + "/src/main/kotlin/org/openapitools/model/Animal.kt"),
|
Paths.get(outputPath + "/src/main/kotlin/org/openapitools/model/Animal.kt"),
|
||||||
"@ApiModelProperty(example = \"null\", value = \"\")"
|
"@ApiModelProperty(example = \"null\", value = \"\")"
|
||||||
);
|
);
|
||||||
assertFileContains(
|
assertFileContains(
|
||||||
Paths.get(outputPath + "/src/main/kotlin/org/openapitools/model/Animal.kt"),
|
Paths.get(outputPath + "/src/main/kotlin/org/openapitools/model/Animal.kt"),
|
||||||
"@get:ApiModelProperty(example = \"null\", value = \"\")"
|
"@get:ApiModelProperty(example = \"null\", value = \"\")"
|
||||||
);
|
);
|
||||||
assertFileNotContains(
|
assertFileNotContains(
|
||||||
Paths.get(outputPath + "/src/main/kotlin/org/openapitools/model/Animal.kt"),
|
Paths.get(outputPath + "/src/main/kotlin/org/openapitools/model/Animal.kt"),
|
||||||
"@ApiModelProperty(example = \"null\", required = true, value = \"\")"
|
"@ApiModelProperty(example = \"null\", required = true, value = \"\")"
|
||||||
);
|
);
|
||||||
assertFileContains(
|
assertFileContains(
|
||||||
Paths.get(outputPath + "/src/main/kotlin/org/openapitools/model/Animal.kt"),
|
Paths.get(outputPath + "/src/main/kotlin/org/openapitools/model/Animal.kt"),
|
||||||
"@get:ApiModelProperty(example = \"null\", required = true, value = \"\")"
|
"@get:ApiModelProperty(example = \"null\", required = true, value = \"\")"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void useBeanValidationGenerateAnnotationsForRequestBody() throws IOException {
|
||||||
|
File output = Files.createTempDirectory("test").toFile().getCanonicalFile();
|
||||||
|
output.deleteOnExit();
|
||||||
|
|
||||||
|
OpenAPI openAPI = new OpenAPIParser()
|
||||||
|
.readLocation("src/test/resources/bugs/issue_13932.yml", null, new ParseOptions()).getOpenAPI();
|
||||||
|
KotlinSpringServerCodegen codegen = new KotlinSpringServerCodegen();
|
||||||
|
codegen.setOutputDir(output.getAbsolutePath());
|
||||||
|
codegen.additionalProperties().put(KotlinSpringServerCodegen.INTERFACE_ONLY, "true");
|
||||||
|
codegen.additionalProperties().put(KotlinSpringServerCodegen.USE_BEANVALIDATION, "true");
|
||||||
|
codegen.additionalProperties().put(CodegenConstants.MODEL_PACKAGE, "xyz.model");
|
||||||
|
codegen.additionalProperties().put(CodegenConstants.API_PACKAGE, "xyz.controller");
|
||||||
|
|
||||||
|
ClientOptInput input = new ClientOptInput()
|
||||||
|
.openAPI(openAPI)
|
||||||
|
.config(codegen);
|
||||||
|
|
||||||
|
DefaultGenerator generator = new DefaultGenerator();
|
||||||
|
Map<String, File> files = generator.opts(input).generate().stream()
|
||||||
|
.collect(Collectors.toMap(File::getName, Function.identity()));
|
||||||
|
|
||||||
|
assertFileContains(
|
||||||
|
Paths.get(files.get("AddApi.kt").getAbsolutePath()),
|
||||||
|
"@Min(2)"
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user