Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: x-enum-description support added to kotlin-server code generator #19041

Merged
merged 1 commit into from
Jul 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
feat: x-enum-description support added to kotlin-server code generator
  • Loading branch information
deicon committed Jul 1, 2024
commit 503158f8d15c1b814a798ec116206e5851f713f5
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@
*/
enum class {{classname}}(val value: {{dataType}}) {
{{#allowableValues}}{{#enumVars}}
{{#enumDescription}}
/**
* {{.}}
*/
{{/enumDescription}}
{{&name}}({{{value}}}){{^-last}},{{/-last}}{{#-last}};{{/-last}}
{{/enumVars}}{{/allowableValues}}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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}})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,38 @@

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();
Expand Down
Original file line number Diff line number Diff line change
@@ -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