mirror of
https://github.com/OpenAPITools/openapi-generator.git
synced 2025-07-03 06:00:52 +00:00
Co-authored-by: Eric Durand-Tremblay <etremblay@kronostechnologies.com>
This commit is contained in:
parent
c148539ce3
commit
f9fa62a79e
@ -631,7 +631,7 @@ public abstract class AbstractPhpCodegen extends DefaultCodegen implements Codeg
|
||||
|
||||
@Override
|
||||
public String toEnumDefaultValue(String value, String datatype) {
|
||||
return datatype + "_" + value;
|
||||
return "self::" + datatype + "_" + value;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -32,6 +32,7 @@ import org.testng.annotations.DataProvider;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
|
||||
public class AbstractPhpCodegenTest {
|
||||
@ -146,6 +147,26 @@ public class AbstractPhpCodegenTest {
|
||||
Assert.assertTrue(cp1.isPrimitiveType);
|
||||
}
|
||||
|
||||
@Test(description = "Issue #10244")
|
||||
public void testEnumPropertyWithDefaultValue() {
|
||||
final OpenAPI openAPI = TestUtils.parseFlattenSpec("src/test/resources/3_0/php/issue_10244.yaml");
|
||||
final AbstractPhpCodegen codegen = new P_AbstractPhpCodegen();
|
||||
|
||||
Schema test1 = openAPI.getComponents().getSchemas().get("ModelWithEnumPropertyHavingDefault");
|
||||
CodegenModel cm1 = codegen.fromModel("ModelWithEnumPropertyHavingDefault", test1);
|
||||
|
||||
// Make sure we got the container object.
|
||||
Assert.assertEquals(cm1.getDataType(), "object");
|
||||
Assert.assertEquals(codegen.getTypeDeclaration("MyResponse"), "\\php\\Model\\MyResponse");
|
||||
|
||||
// We need to postProcess the model for enums to be processed
|
||||
codegen.postProcessModels(Collections.singletonMap("models", Collections.singletonList(Collections.singletonMap("model", cm1))));
|
||||
|
||||
// Assert the enum default value is properly generated
|
||||
CodegenProperty cp1 = cm1.vars.get(0);
|
||||
Assert.assertEquals(cp1.getDefaultValue(), "self::PROPERTY_NAME_VALUE");
|
||||
}
|
||||
|
||||
private static class P_AbstractPhpCodegen extends AbstractPhpCodegen {
|
||||
@Override
|
||||
public CodegenType getTag() {
|
||||
|
@ -0,0 +1,26 @@
|
||||
openapi: 3.0.0
|
||||
info:
|
||||
title: 'Issue 10224 Enum default value'
|
||||
version: latest
|
||||
paths:
|
||||
'/':
|
||||
get:
|
||||
operationId: operation
|
||||
responses:
|
||||
'200':
|
||||
description: Success
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
$ref: '#/components/schemas/ModelWithEnumPropertyHavingDefault'
|
||||
components:
|
||||
schemas:
|
||||
ModelWithEnumPropertyHavingDefault:
|
||||
required:
|
||||
- propertyName
|
||||
properties:
|
||||
propertyName:
|
||||
type: string
|
||||
default: VALUE
|
||||
enum:
|
||||
- VALUE
|
Loading…
x
Reference in New Issue
Block a user