Skip to content

Commit 16563f5

Browse files
rienafairefrMatthieu Berthomé
authored andcommitted
spec for testing enum with null/nullable
1 parent 6925ae1 commit 16563f5

File tree

2 files changed

+40
-0
lines changed

2 files changed

+40
-0
lines changed

modules/openapi-generator/src/test/java/org/openapitools/codegen/python/PythonClientCodegenTest.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,18 @@
2020
import io.swagger.parser.OpenAPIParser;
2121
import io.swagger.v3.oas.models.OpenAPI;
2222
import io.swagger.v3.oas.models.Operation;
23+
import io.swagger.v3.oas.models.media.StringSchema;
2324
import io.swagger.v3.parser.core.models.ParseOptions;
2425
import org.openapitools.codegen.CodegenConstants;
2526
import org.openapitools.codegen.CodegenOperation;
27+
import org.openapitools.codegen.CodegenProperty;
2628
import org.openapitools.codegen.languages.PythonClientCodegen;
2729
import org.testng.Assert;
2830
import org.testng.annotations.Test;
2931

32+
import java.util.ArrayList;
33+
import java.util.Arrays;
34+
3035
public class PythonClientCodegenTest {
3136

3237
@Test
@@ -58,6 +63,18 @@ public void testAdditionalPropertiesPutForConfigValues() throws Exception {
5863
Assert.assertEquals(codegen.isHideGenerationTimestamp(), false);
5964
}
6065

66+
@Test(description = "test enum null/nullable patterns")
67+
public void testEnumNull() {
68+
final OpenAPI openAPI = new OpenAPIParser()
69+
.readLocation("src/test/resources/3_0/issue_1997.yaml", null, new ParseOptions()).getOpenAPI();
70+
71+
72+
StringSchema prop = (StringSchema) openAPI.getComponents().getSchemas().get("Type").getProperties().get("prop");
73+
ArrayList<Object> expected = new ArrayList<>(Arrays.asList("A", "B", "C"));
74+
assert prop.getNullable();
75+
assert prop.getEnum().equals(expected);
76+
}
77+
6178
@Test(description = "test regex patterns")
6279
public void testRegularExpressionOpenAPISchemaVersion3() {
6380
final OpenAPI openAPI = new OpenAPIParser()
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
openapi: 3.0.1
2+
paths:
3+
/test:
4+
summary: test
5+
info:
6+
description: test
7+
version: 1.0.0
8+
title: test
9+
components:
10+
schemas:
11+
Type:
12+
properties:
13+
prop:
14+
nullable: true
15+
enum: [A, B, C]
16+
type: string
17+
prop2:
18+
enum: [A, B, C, null]
19+
type: string
20+
prop3:
21+
nullable: true
22+
enum: []
23+
type: string

0 commit comments

Comments
 (0)