forked from loafle/openapi-generator-original
feat: x-enum-description support added to kotlin-server code generator (#19041)
This commit is contained in:
parent
21d3cfe924
commit
c9da04cb65
@ -4,6 +4,11 @@
|
||||
*/
|
||||
enum class {{classname}}(val value: {{dataType}}) {
|
||||
{{#allowableValues}}{{#enumVars}}
|
||||
{{#enumDescription}}
|
||||
/**
|
||||
* {{.}}
|
||||
*/
|
||||
{{/enumDescription}}
|
||||
{{&name}}({{{value}}}){{^-last}},{{/-last}}{{#-last}};{{/-last}}
|
||||
{{/enumVars}}{{/allowableValues}}
|
||||
}
|
||||
|
@ -13,6 +13,12 @@ import kotlinx.serialization.Serializable
|
||||
{{>additionalModelTypeAnnotations}}
|
||||
{{#nonPublicApi}}internal {{/nonPublicApi}}enum class {{classname}}(val value: {{{dataType}}}) {
|
||||
{{#allowableValues}}{{#enumVars}}
|
||||
|
||||
{{#enumDescription}}
|
||||
/**
|
||||
* {{.}}
|
||||
*/
|
||||
{{/enumDescription}}
|
||||
@JsonProperty(value = {{^isString}}"{{/isString}}{{{value}}}{{^isString}}"{{/isString}})
|
||||
{{#kotlinx_serialization}}
|
||||
@SerialName(value = {{^isString}}"{{/isString}}{{{value}}}{{^isString}}"{{/isString}})
|
||||
|
@ -23,6 +23,38 @@ import static org.openapitools.codegen.languages.features.BeanValidationFeatures
|
||||
|
||||
public class KotlinServerCodegenTest {
|
||||
|
||||
|
||||
@Test
|
||||
public void enumDescription() throws IOException {
|
||||
File output = Files.createTempDirectory("test").toFile().getCanonicalFile();
|
||||
output.deleteOnExit();
|
||||
|
||||
KotlinServerCodegen codegen = new KotlinServerCodegen();
|
||||
codegen.setOutputDir(output.getAbsolutePath());
|
||||
codegen.additionalProperties().put(LIBRARY, JAXRS_SPEC);
|
||||
|
||||
new DefaultGenerator().opts(new ClientOptInput()
|
||||
.openAPI(TestUtils.parseSpec("src/test/resources/3_0/enum-description.yaml"))
|
||||
.config(codegen))
|
||||
.generate();
|
||||
|
||||
String outputPath = output.getAbsolutePath() + "/src/main/kotlin/org/openapitools/server";
|
||||
Path petApi = Paths.get(outputPath + "/models/Type.kt");
|
||||
assertFileNotContains(
|
||||
petApi,
|
||||
"import jakarta.ws.rs.*",
|
||||
"import jakarta.ws.rs.core.Response",
|
||||
"@jakarta.annotation.Generated(value = arrayOf(\"org.openapitools.codegen.languages.KotlinServerCodegen\")"
|
||||
);
|
||||
// assert, that all enum values have a description comment
|
||||
assertFileContains(
|
||||
petApi,
|
||||
"Pegasi b is a gas giant exoplanet that orbits a G-type star",
|
||||
"Mercury is the first planet from the Sun and the smallest in the Solar System",
|
||||
"The planet we all live on"
|
||||
);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void javaxImports() throws IOException {
|
||||
File output = Files.createTempDirectory("test").toFile().getCanonicalFile();
|
||||
|
@ -0,0 +1,36 @@
|
||||
openapi: 3.0.0
|
||||
info:
|
||||
title: Sample API
|
||||
description: API description in Markdown.
|
||||
version: 1.0.0
|
||||
paths:
|
||||
/ponies:
|
||||
get:
|
||||
summary: Returns all animals.
|
||||
description: Optional extended description in Markdown.
|
||||
responses:
|
||||
200:
|
||||
description: OK
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
type: array
|
||||
items:
|
||||
$ref: '#/components/schemas/Pony'
|
||||
components:
|
||||
schemas:
|
||||
Pony:
|
||||
type: object
|
||||
properties:
|
||||
type:
|
||||
$ref: '#/components/schemas/Type'
|
||||
Type:
|
||||
type: string
|
||||
enum:
|
||||
- Earth
|
||||
- Pegasi
|
||||
- Mercury
|
||||
x-enum-descriptions:
|
||||
- The planet we all live on
|
||||
- Pegasi b is a gas giant exoplanet that orbits a G-type star
|
||||
- Mercury is the first planet from the Sun and the smallest in the Solar System
|
Loading…
x
Reference in New Issue
Block a user