File tree Expand file tree Collapse file tree
modules/openapi-generator/src
main/resources/kotlin-server
java/org/openapitools/codegen/kotlin Expand file tree Collapse file tree Original file line number Diff line number Diff line change 44*/
55enum class { {classname} }(val value: { {dataType} }) {
66{{#allowableValues} }{ {#enumVars} }
7+ { {#enumDescription} }
8+ /**
9+ * { {.} }
10+ */
11+ { {/enumDescription} }
712 { {&name} }({ {{value} }}){ {^-last} },{ {/-last} }{ {#-last} };{ {/-last} }
813{ {/enumVars} }{ {/allowableValues} }
914}
Original file line number Diff line number Diff line change @@ -13,6 +13,12 @@ import kotlinx.serialization.Serializable
1313{ {> additionalModelTypeAnnotations} }
1414{ {#nonPublicApi} }internal { {/nonPublicApi} }enum class { {classname} }(val value: { {{dataType} }}) {
1515{{#allowableValues} }{ {#enumVars} }
16+
17+ { {#enumDescription} }
18+ /**
19+ * { {.} }
20+ */
21+ { {/enumDescription} }
1622 @JsonProperty(value = { {^isString} }"{ {/isString} }{ {{value} }}{ {^isString} }"{ {/isString} })
1723 { {#kotlinx_serialization} }
1824 @SerialName(value = { {^isString} }"{ {/isString} }{ {{value} }}{ {^isString} }"{ {/isString} })
Original file line number Diff line number Diff line change 2323
2424public class KotlinServerCodegenTest {
2525
26+
27+ @ Test
28+ public void enumDescription () throws IOException {
29+ File output = Files .createTempDirectory ("test" ).toFile ().getCanonicalFile ();
30+ output .deleteOnExit ();
31+
32+ KotlinServerCodegen codegen = new KotlinServerCodegen ();
33+ codegen .setOutputDir (output .getAbsolutePath ());
34+ codegen .additionalProperties ().put (LIBRARY , JAXRS_SPEC );
35+
36+ new DefaultGenerator ().opts (new ClientOptInput ()
37+ .openAPI (TestUtils .parseSpec ("src/test/resources/3_0/enum-description.yaml" ))
38+ .config (codegen ))
39+ .generate ();
40+
41+ String outputPath = output .getAbsolutePath () + "/src/main/kotlin/org/openapitools/server" ;
42+ Path petApi = Paths .get (outputPath + "/models/Type.kt" );
43+ assertFileNotContains (
44+ petApi ,
45+ "import jakarta.ws.rs.*" ,
46+ "import jakarta.ws.rs.core.Response" ,
47+ "@jakarta.annotation.Generated(value = arrayOf(\" org.openapitools.codegen.languages.KotlinServerCodegen\" )"
48+ );
49+ // assert, that all enum values have a description comment
50+ assertFileContains (
51+ petApi ,
52+ "Pegasi b is a gas giant exoplanet that orbits a G-type star" ,
53+ "Mercury is the first planet from the Sun and the smallest in the Solar System" ,
54+ "The planet we all live on"
55+ );
56+ }
57+
2658 @ Test
2759 public void javaxImports () throws IOException {
2860 File output = Files .createTempDirectory ("test" ).toFile ().getCanonicalFile ();
Original file line number Diff line number Diff line change 1+ openapi : 3.0.0
2+ info :
3+ title : Sample API
4+ description : API description in Markdown.
5+ version : 1.0.0
6+ paths :
7+ /ponies :
8+ get :
9+ summary : Returns all animals.
10+ description : Optional extended description in Markdown.
11+ responses :
12+ 200 :
13+ description : OK
14+ content :
15+ application/json :
16+ schema :
17+ type : array
18+ items :
19+ $ref : ' #/components/schemas/Pony'
20+ components :
21+ schemas :
22+ Pony :
23+ type : object
24+ properties :
25+ type :
26+ $ref : ' #/components/schemas/Type'
27+ Type :
28+ type : string
29+ enum :
30+ - Earth
31+ - Pegasi
32+ - Mercury
33+ x-enum-descriptions :
34+ - The planet we all live on
35+ - Pegasi b is a gas giant exoplanet that orbits a G-type star
36+ - Mercury is the first planet from the Sun and the smallest in the Solar System
You can’t perform that action at this time.
0 commit comments