forked from loafle/openapi-generator-original
[PHP] fix numeric value in model enum (#10474)
* fix number value :win model enum * fix tests
This commit is contained in:
parent
d4b8ff60a1
commit
1a50f1f493
@ -804,4 +804,9 @@ public abstract class AbstractPhpCodegen extends DefaultCodegen implements Codeg
|
||||
|
||||
return packageName;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isDataTypeString(String dataType) {
|
||||
return "string".equals(dataType);
|
||||
}
|
||||
}
|
||||
|
@ -3,8 +3,12 @@ class {{classname}}
|
||||
/**
|
||||
* Possible values of this enum
|
||||
*/
|
||||
{{#allowableValues}}{{#enumVars}}const {{{name}}} = {{{value}}};
|
||||
{{/enumVars}}{{/allowableValues}}
|
||||
{{#allowableValues}}
|
||||
{{#enumVars}}
|
||||
const {{^isString}}NUMBER_{{/isString}}{{{name}}} = {{{value}}};
|
||||
|
||||
{{/enumVars}}
|
||||
{{/allowableValues}}
|
||||
/**
|
||||
* Gets allowable values of the enum
|
||||
* @return string[]
|
||||
@ -12,8 +16,13 @@ class {{classname}}
|
||||
public static function getAllowableEnumValues()
|
||||
{
|
||||
return [
|
||||
{{#allowableValues}}{{#enumVars}}self::{{{name}}},{{^-last}}
|
||||
{{/-last}}{{/enumVars}}{{/allowableValues}}
|
||||
{{#allowableValues}}
|
||||
{{#enumVars}}
|
||||
self::{{^isString}}NUMBER_{{/isString}}{{{name}}}{{^-last}},
|
||||
{{/-last}}
|
||||
{{/enumVars}}
|
||||
{{/allowableValues}}
|
||||
|
||||
];
|
||||
}
|
||||
}
|
||||
|
@ -164,7 +164,7 @@ public class AbstractPhpCodegenTest {
|
||||
|
||||
// Assert the enum default value is properly generated
|
||||
CodegenProperty cp1 = cm1.vars.get(0);
|
||||
Assert.assertEquals(cp1.getDefaultValue(), "self::PROPERTY_NAME_VALUE");
|
||||
Assert.assertEquals(cp1.getDefaultValue(), "'VALUE'");
|
||||
}
|
||||
|
||||
private static class P_AbstractPhpCodegen extends AbstractPhpCodegen {
|
||||
|
@ -314,11 +314,11 @@ public class PhpModelTest {
|
||||
HashMap<String, Object> fish= new HashMap<String, Object>();
|
||||
fish.put("name", "FISH");
|
||||
fish.put("value", "\'fish\'");
|
||||
fish.put("isString", false);
|
||||
fish.put("isString", true);
|
||||
HashMap<String, Object> crab= new HashMap<String, Object>();
|
||||
crab.put("name", "CRAB");
|
||||
crab.put("value", "\'crab\'");
|
||||
crab.put("isString", false);
|
||||
crab.put("isString", true);
|
||||
Assert.assertEquals(prope.allowableValues.get("enumVars"), Arrays.asList(fish, crab));
|
||||
|
||||
// assert inner items
|
||||
|
@ -43,9 +43,11 @@ class EnumClass
|
||||
* Possible values of this enum
|
||||
*/
|
||||
const ABC = '_abc';
|
||||
|
||||
const EFG = '-efg';
|
||||
|
||||
const XYZ = '(xyz)';
|
||||
|
||||
|
||||
/**
|
||||
* Gets allowable values of the enum
|
||||
* @return string[]
|
||||
@ -55,7 +57,7 @@ class EnumClass
|
||||
return [
|
||||
self::ABC,
|
||||
self::EFG,
|
||||
self::XYZ,
|
||||
self::XYZ
|
||||
];
|
||||
}
|
||||
}
|
||||
|
@ -43,9 +43,11 @@ class OuterEnum
|
||||
* Possible values of this enum
|
||||
*/
|
||||
const PLACED = 'placed';
|
||||
|
||||
const APPROVED = 'approved';
|
||||
|
||||
const DELIVERED = 'delivered';
|
||||
|
||||
|
||||
/**
|
||||
* Gets allowable values of the enum
|
||||
* @return string[]
|
||||
@ -55,7 +57,7 @@ class OuterEnum
|
||||
return [
|
||||
self::PLACED,
|
||||
self::APPROVED,
|
||||
self::DELIVERED,
|
||||
self::DELIVERED
|
||||
];
|
||||
}
|
||||
}
|
||||
|
@ -43,9 +43,11 @@ class OuterEnumDefaultValue
|
||||
* Possible values of this enum
|
||||
*/
|
||||
const PLACED = 'placed';
|
||||
|
||||
const APPROVED = 'approved';
|
||||
|
||||
const DELIVERED = 'delivered';
|
||||
|
||||
|
||||
/**
|
||||
* Gets allowable values of the enum
|
||||
* @return string[]
|
||||
@ -55,7 +57,7 @@ class OuterEnumDefaultValue
|
||||
return [
|
||||
self::PLACED,
|
||||
self::APPROVED,
|
||||
self::DELIVERED,
|
||||
self::DELIVERED
|
||||
];
|
||||
}
|
||||
}
|
||||
|
@ -42,10 +42,12 @@ class OuterEnumInteger
|
||||
/**
|
||||
* Possible values of this enum
|
||||
*/
|
||||
const 0 = 0;
|
||||
const 1 = 1;
|
||||
const 2 = 2;
|
||||
|
||||
const NUMBER_0 = 0;
|
||||
|
||||
const NUMBER_1 = 1;
|
||||
|
||||
const NUMBER_2 = 2;
|
||||
|
||||
/**
|
||||
* Gets allowable values of the enum
|
||||
* @return string[]
|
||||
@ -53,9 +55,9 @@ class OuterEnumInteger
|
||||
public static function getAllowableEnumValues()
|
||||
{
|
||||
return [
|
||||
self::0,
|
||||
self::1,
|
||||
self::2,
|
||||
self::NUMBER_0,
|
||||
self::NUMBER_1,
|
||||
self::NUMBER_2
|
||||
];
|
||||
}
|
||||
}
|
||||
|
@ -42,10 +42,12 @@ class OuterEnumIntegerDefaultValue
|
||||
/**
|
||||
* Possible values of this enum
|
||||
*/
|
||||
const 0 = 0;
|
||||
const 1 = 1;
|
||||
const 2 = 2;
|
||||
|
||||
const NUMBER_0 = 0;
|
||||
|
||||
const NUMBER_1 = 1;
|
||||
|
||||
const NUMBER_2 = 2;
|
||||
|
||||
/**
|
||||
* Gets allowable values of the enum
|
||||
* @return string[]
|
||||
@ -53,9 +55,9 @@ class OuterEnumIntegerDefaultValue
|
||||
public static function getAllowableEnumValues()
|
||||
{
|
||||
return [
|
||||
self::0,
|
||||
self::1,
|
||||
self::2,
|
||||
self::NUMBER_0,
|
||||
self::NUMBER_1,
|
||||
self::NUMBER_2
|
||||
];
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user