@@ -2923,6 +2923,7 @@ protected void updateModelForObject(CodegenModel m, Schema schema) {
29232923 }
29242924 // process 'additionalProperties'
29252925 setAddProps (schema , m );
2926+ setPropNames (schema , m );
29262927 addRequiredVarsMap (schema , m );
29272928 }
29282929
@@ -2944,6 +2945,7 @@ protected void updateModelForAnyType(CodegenModel m, Schema schema) {
29442945 }
29452946 // process 'additionalProperties'
29462947 setAddProps (schema , m );
2948+ setPropNames (schema , m );
29472949 addRequiredVarsMap (schema , m );
29482950 }
29492951
@@ -3260,6 +3262,18 @@ protected void SortModelPropertiesByRequiredFlag(CodegenModel model) {
32603262 Collections .sort (model .allVars , comparator );
32613263 }
32623264
3265+ protected void setPropNames (Schema schema , IJsonSchemaValidationProperties property ) {
3266+ if (schema .equals (new Schema ())) {
3267+ return ;
3268+ }
3269+
3270+ if (schema .getPropertyNames () == null ) {
3271+ return ;
3272+ }
3273+ CodegenProperty propNamesProp = fromProperty (getPropertyNamesName (), schema .getPropertyNames (), false , false );
3274+ property .setPropertyNames (propNamesProp );
3275+ }
3276+
32633277 protected void setAddProps (Schema schema , IJsonSchemaValidationProperties property ) {
32643278 if (schema .equals (new Schema ())) {
32653279 // if we are trying to set additionalProperties on an empty schema stop recursing
@@ -3882,7 +3896,7 @@ protected void updatePropertyForObject(CodegenProperty property, Schema p) {
38823896 // an object or anyType composed schema that has additionalProperties set
38833897 updatePropertyForMap (property , p );
38843898 }
3885- addVarsRequiredVarsAdditionalProps (p , property );
3899+ addVarsRequiredVarsAdditionalPropsPropertyNames (p , property );
38863900 }
38873901
38883902 protected void updatePropertyForAnyType (CodegenProperty property , Schema p ) {
@@ -3905,7 +3919,7 @@ protected void updatePropertyForAnyType(CodegenProperty property, Schema p) {
39053919 // even though it should allow in any type and have map constraints for properties
39063920 updatePropertyForMap (property , p );
39073921 }
3908- addVarsRequiredVarsAdditionalProps (p , property );
3922+ addVarsRequiredVarsAdditionalPropsPropertyNames (p , property );
39093923 }
39103924
39113925 protected void updatePropertyForString (CodegenProperty property , Schema p ) {
@@ -5192,9 +5206,9 @@ public CodegenResponse fromResponse(String responseCode, ApiResponse response) {
51925206 r .simpleType = false ;
51935207 r .containerType = cp .containerType ;
51945208 r .containerTypeMapped = cp .containerTypeMapped ;
5195- addVarsRequiredVarsAdditionalProps (responseSchema , r );
5209+ addVarsRequiredVarsAdditionalPropsPropertyNames (responseSchema , r );
51965210 } else if (ModelUtils .isAnyType (responseSchema )) {
5197- addVarsRequiredVarsAdditionalProps (responseSchema , r );
5211+ addVarsRequiredVarsAdditionalPropsPropertyNames (responseSchema , r );
51985212 } else if (!ModelUtils .isBooleanSchema (responseSchema )) {
51995213 // referenced schemas
52005214 LOGGER .debug ("Property type is not primitive: {}" , cp .dataType );
@@ -5505,14 +5519,14 @@ public CodegenParameter fromParameter(Parameter parameter, Set<String> imports)
55055519 if (ModelUtils .isFreeFormObject (parameterSchema , openAPI )) {
55065520 codegenParameter .isFreeFormObject = true ;
55075521 }
5508- addVarsRequiredVarsAdditionalProps (parameterSchema , codegenParameter );
5522+ addVarsRequiredVarsAdditionalPropsPropertyNames (parameterSchema , codegenParameter );
55095523 } else if (ModelUtils .isNullType (parameterSchema )) {
55105524 } else if (ModelUtils .isAnyType (parameterSchema )) {
55115525 // any schema with no type set, composed schemas often do this
55125526 if (ModelUtils .isMapSchema (parameterSchema )) { // for map parameter
55135527 updateParameterForMap (codegenParameter , parameterSchema , imports );
55145528 }
5515- addVarsRequiredVarsAdditionalProps (parameterSchema , codegenParameter );
5529+ addVarsRequiredVarsAdditionalPropsPropertyNames (parameterSchema , codegenParameter );
55165530 } else if (ModelUtils .isArraySchema (parameterSchema )) {
55175531 Schema inner = ModelUtils .getSchemaItems (parameterSchema );
55185532
@@ -7859,7 +7873,7 @@ protected void updateRequestBodyForObject(CodegenParameter codegenParameter, Sch
78597873 // object type schema or composed schema with properties defined
78607874 this .addBodyModelSchema (codegenParameter , name , schema , imports , bodyParameterName , false );
78617875 }
7862- addVarsRequiredVarsAdditionalProps (schema , codegenParameter );
7876+ addVarsRequiredVarsAdditionalPropsPropertyNames (schema , codegenParameter );
78637877 }
78647878
78657879 protected void updateRequestBodyForArray (CodegenParameter codegenParameter , Schema schema , String name , Set <String > imports , String bodyParameterName ) {
@@ -8144,7 +8158,7 @@ public CodegenParameter fromRequestBody(RequestBody body, Set<String> imports, S
81448158 } else {
81458159 updateRequestBodyForPrimitiveType (codegenParameter , schema , bodyParameterName , imports );
81468160 }
8147- addVarsRequiredVarsAdditionalProps (schema , codegenParameter );
8161+ addVarsRequiredVarsAdditionalPropsPropertyNames (schema , codegenParameter );
81488162 } else {
81498163 // referenced schemas
81508164 updateRequestBodyForPrimitiveType (codegenParameter , schema , bodyParameterName , imports );
@@ -8262,12 +8276,13 @@ protected void addRequiredVarsMap(Schema schema, IJsonSchemaValidationProperties
82628276 }
82638277 }
82648278
8265- protected void addVarsRequiredVarsAdditionalProps (Schema schema , IJsonSchemaValidationProperties property ) {
8279+ protected void addVarsRequiredVarsAdditionalPropsPropertyNames (Schema schema , IJsonSchemaValidationProperties property ) {
82668280 setAddProps (schema , property );
82678281 Set <String > mandatory = schema .getRequired () == null ? Collections .emptySet ()
82688282 : new TreeSet <>(schema .getRequired ());
82698283 addVars (property , property .getVars (), schema .getProperties (), mandatory );
82708284 addRequiredVarsMap (schema , property );
8285+ setPropNames (schema , property );
82718286 }
82728287
82738288 protected String getItemsName (Schema containingSchema , String containingSchemaName ) {
@@ -8282,6 +8297,10 @@ protected String getAdditionalPropertiesName() {
82828297 return "additional_properties" ;
82838298 }
82848299
8300+ protected String getPropertyNamesName () {
8301+ return "property_names" ;
8302+ }
8303+
82858304 private void addJsonSchemaForBodyRequestInCaseItsNotPresent (CodegenParameter codegenParameter , RequestBody body ) {
82868305 if (codegenParameter .jsonSchema == null )
82878306 codegenParameter .jsonSchema = Json .pretty (body );
0 commit comments