Skip to content
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -2589,6 +2589,10 @@ public CodegenParameter fromParameter(Parameter parameter, Set<String> imports)
codegenParameter.getVendorExtensions().put(CodegenConstants.HAS_VALIDATION_EXT_NAME, Boolean.TRUE);
}

Object defaultValue = parameterSchema.getDefault();
if (defaultValue != null) {
codegenParameter.defaultValue = defaultValue.toString();
}
}

// Issue #2561 (neilotoole) : Set the is<TYPE>Param flags.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,32 @@ public void testFromOperation_BodyParamsUnique() {
Assert.assertEquals(true, codegenOperation.bodyParams.get(0).getVendorExtensions().get("x-has-more"));
}

@Test
public void testFromParameter_DefaultValue() {
PathItem dummyPath = new PathItem()
.get(new Operation());
OpenAPI openAPI = new OpenAPI()
.path("dummy", dummyPath);

DefaultCodegenConfig codegen = new P_DefaultCodegenConfig();

Operation operation = new Operation();
Parameter param = new Parameter()
.in("query")
.name("testParameter");
operation.addParametersItem(param);

CodegenOperation codegenOperation = codegen.fromOperation("/path", "GET", operation, null, openAPI);
Assert.assertNull(codegenOperation.allParams.get(0).getDefaultValue());

Schema schema = new Schema();
schema.setDefault("myDefaultValue");
param.setSchema(schema);

codegenOperation = codegen.fromOperation("/path", "GET", operation, null, openAPI);
Assert.assertEquals(codegenOperation.allParams.get(0).getDefaultValue(), "myDefaultValue");
}

@Test(dataProvider = "testGetCollectionFormatProvider")
public void testGetCollectionFormat(Parameter.StyleEnum style, Boolean explode, String expectedCollectionFormat) {
final DefaultCodegenConfig codegen = new P_DefaultCodegenConfig();
Expand Down