Skip to content

Commit 1704429

Browse files
author
Marco
committed
Issue 21890: added test (first draft)
1 parent c58f058 commit 1704429

2 files changed

Lines changed: 72 additions & 4 deletions

File tree

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

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,7 @@
2525
import io.swagger.v3.parser.core.models.ParseOptions;
2626
import org.mockito.Answers;
2727
import org.mockito.Mockito;
28-
import org.openapitools.codegen.CodegenConstants;
29-
import org.openapitools.codegen.CodegenModel;
30-
import org.openapitools.codegen.CodegenParameter;
31-
import org.openapitools.codegen.TestUtils;
28+
import org.openapitools.codegen.*;
3229
import org.openapitools.codegen.languages.AbstractJavaCodegen;
3330
import org.openapitools.codegen.testutils.ConfigAssert;
3431
import org.openapitools.codegen.utils.ModelUtils;
@@ -755,6 +752,20 @@ public void nullDefaultValueForModelWithDynamicProperties() {
755752
Assert.assertEquals(defaultValue, "null");
756753
}
757754

755+
@Test
756+
public void defaultEmptyListForModelWithAdditionalPropertyDefaultToEmptyContainer() {
757+
final OpenAPI openAPI = TestUtils.parseFlattenSpec("src/test/resources/3_1/java/issue_21890.yaml");
758+
codegen.additionalProperties().put(CodegenConstants.DEFAULT_TO_EMPTY_CONTAINER, "map");
759+
codegen.processOpts();
760+
codegen.setOpenAPI(openAPI);
761+
762+
Schema<?> schema = openAPI.getComponents().getSchemas().get("Pet_parents");
763+
764+
CodegenProperty parents = codegen.fromProperty("parents", schema, true);
765+
String defaultValue = codegen.toDefaultValue(parents, schema);
766+
Assert.assertEquals(defaultValue, "new HashMap()");
767+
}
768+
758769
@Test
759770
public void maplikeDefaultValueForModelWithStringToStringMapping() {
760771
final OpenAPI openAPI = FLATTENED_SPEC.get("3_0/mapSchemas");
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
openapi: 3.1.0
2+
servers:
3+
- url: 'http://petstore.swagger.io/v2'
4+
info:
5+
description: >-
6+
This is a sample server Petstore server. For this sample, you can use the api key
7+
`special-key` to test the authorization filters.
8+
version: 1.0.0
9+
title: OpenAPI Petstore
10+
license:
11+
name: Apache-2.0
12+
url: 'https://www.apache.org/licenses/LICENSE-2.0.html'
13+
paths:
14+
'/pet/{petId}':
15+
get:
16+
tags:
17+
- pet
18+
summary: Find pet by ID
19+
description: Returns a single pet
20+
operationId: getPetById
21+
parameters:
22+
- name: petId
23+
in: path
24+
description: ID of pet to return
25+
required: true
26+
schema:
27+
type: integer
28+
format: int64
29+
responses:
30+
'200':
31+
description: successful operation
32+
content:
33+
application/json:
34+
schema:
35+
$ref: '#/components/schemas/Pet'
36+
'400':
37+
description: Invalid ID supplied
38+
'404':
39+
description: Pet not found
40+
components:
41+
schemas:
42+
Pet:
43+
title: a Pet
44+
description: A pet for sale in the pet store
45+
type: object
46+
properties:
47+
parents:
48+
type: object
49+
properties:
50+
mother:
51+
type: string
52+
father:
53+
type: string
54+
required:
55+
- parents
56+
57+

0 commit comments

Comments
 (0)