forked from loafle/openapi-generator-original
Co-authored-by: Eric Durand-Tremblay <etremblay@kronostechnologies.com>
This commit is contained in:
parent
c148539ce3
commit
f9fa62a79e
@ -195,7 +195,7 @@ public abstract class AbstractPhpCodegen extends DefaultCodegen implements Codeg
|
|||||||
if (additionalProperties.containsKey(CodegenConstants.GIT_USER_ID)) {
|
if (additionalProperties.containsKey(CodegenConstants.GIT_USER_ID)) {
|
||||||
this.setGitUserId((String) additionalProperties.get(CodegenConstants.GIT_USER_ID));
|
this.setGitUserId((String) additionalProperties.get(CodegenConstants.GIT_USER_ID));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (additionalProperties.containsKey(CodegenConstants.GIT_REPO_ID)) {
|
if (additionalProperties.containsKey(CodegenConstants.GIT_REPO_ID)) {
|
||||||
this.setGitRepoId((String) additionalProperties.get(CodegenConstants.GIT_REPO_ID));
|
this.setGitRepoId((String) additionalProperties.get(CodegenConstants.GIT_REPO_ID));
|
||||||
}
|
}
|
||||||
@ -631,7 +631,7 @@ public abstract class AbstractPhpCodegen extends DefaultCodegen implements Codeg
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toEnumDefaultValue(String value, String datatype) {
|
public String toEnumDefaultValue(String value, String datatype) {
|
||||||
return datatype + "_" + value;
|
return "self::" + datatype + "_" + value;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -32,6 +32,7 @@ import org.testng.annotations.DataProvider;
|
|||||||
import org.testng.annotations.Test;
|
import org.testng.annotations.Test;
|
||||||
|
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
import java.util.Collections;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
|
||||||
public class AbstractPhpCodegenTest {
|
public class AbstractPhpCodegenTest {
|
||||||
@ -146,6 +147,26 @@ public class AbstractPhpCodegenTest {
|
|||||||
Assert.assertTrue(cp1.isPrimitiveType);
|
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 {
|
private static class P_AbstractPhpCodegen extends AbstractPhpCodegen {
|
||||||
@Override
|
@Override
|
||||||
public CodegenType getTag() {
|
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