File tree 4 files changed +79
-0
lines changed
modules/openapi-generator/src
main/resources/kotlin-server
java/org/openapitools/codegen/kotlin
4 files changed +79
-0
lines changed Original file line number Diff line number Diff line change 4
4
*/
5
5
enum class { {classname} }(val value: { {dataType} }) {
6
6
{{#allowableValues} }{ {#enumVars} }
7
+ { {#enumDescription} }
8
+ /**
9
+ * { {.} }
10
+ */
11
+ { {/enumDescription} }
7
12
{ {&name} }({ {{value} }}){ {^-last} },{ {/-last} }{ {#-last} };{ {/-last} }
8
13
{ {/enumVars} }{ {/allowableValues} }
9
14
}
Original file line number Diff line number Diff line change @@ -13,6 +13,12 @@ import kotlinx.serialization.Serializable
13
13
{ {> additionalModelTypeAnnotations} }
14
14
{ {#nonPublicApi} }internal { {/nonPublicApi} }enum class { {classname} }(val value: { {{dataType} }}) {
15
15
{{#allowableValues} }{ {#enumVars} }
16
+
17
+ { {#enumDescription} }
18
+ /**
19
+ * { {.} }
20
+ */
21
+ { {/enumDescription} }
16
22
@JsonProperty(value = { {^isString} }"{ {/isString} }{ {{value} }}{ {^isString} }"{ {/isString} })
17
23
{ {#kotlinx_serialization} }
18
24
@SerialName(value = { {^isString} }"{ {/isString} }{ {{value} }}{ {^isString} }"{ {/isString} })
Original file line number Diff line number Diff line change 23
23
24
24
public class KotlinServerCodegenTest {
25
25
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
+
26
58
@ Test
27
59
public void javaxImports () throws IOException {
28
60
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