@@ -2895,6 +2895,7 @@ protected void updateModelForObject(CodegenModel m, Schema schema) {
28952895 }
28962896 // process 'additionalProperties'
28972897 setAddProps (schema , m );
2898+ setPropNames (schema , m );
28982899 addRequiredVarsMap (schema , m );
28992900 }
29002901
@@ -2916,6 +2917,7 @@ protected void updateModelForAnyType(CodegenModel m, Schema schema) {
29162917 }
29172918 // process 'additionalProperties'
29182919 setAddProps (schema , m );
2920+ setPropNames (schema , m );
29192921 addRequiredVarsMap (schema , m );
29202922 }
29212923
@@ -3232,6 +3234,18 @@ protected void SortModelPropertiesByRequiredFlag(CodegenModel model) {
32323234 Collections .sort (model .allVars , comparator );
32333235 }
32343236
3237+ protected void setPropNames (Schema schema , IJsonSchemaValidationProperties property ) {
3238+ if (schema .equals (new Schema ())) {
3239+ return ;
3240+ }
3241+
3242+ if (schema .getPropertyNames () == null ) {
3243+ return ;
3244+ }
3245+ CodegenProperty propNamesProp = fromProperty (getPropertyNamesName (), schema .getPropertyNames (), false , false );
3246+ property .setPropertyNames (propNamesProp );
3247+ }
3248+
32353249 protected void setAddProps (Schema schema , IJsonSchemaValidationProperties property ) {
32363250 if (schema .equals (new Schema ())) {
32373251 // if we are trying to set additionalProperties on an empty schema stop recursing
@@ -3854,7 +3868,7 @@ protected void updatePropertyForObject(CodegenProperty property, Schema p) {
38543868 // an object or anyType composed schema that has additionalProperties set
38553869 updatePropertyForMap (property , p );
38563870 }
3857- addVarsRequiredVarsAdditionalProps (p , property );
3871+ addVarsRequiredVarsAdditionalPropsPropertyNames (p , property );
38583872 }
38593873
38603874 protected void updatePropertyForAnyType (CodegenProperty property , Schema p ) {
@@ -3877,7 +3891,7 @@ protected void updatePropertyForAnyType(CodegenProperty property, Schema p) {
38773891 // even though it should allow in any type and have map constraints for properties
38783892 updatePropertyForMap (property , p );
38793893 }
3880- addVarsRequiredVarsAdditionalProps (p , property );
3894+ addVarsRequiredVarsAdditionalPropsPropertyNames (p , property );
38813895 }
38823896
38833897 protected void updatePropertyForString (CodegenProperty property , Schema p ) {
@@ -5165,9 +5179,9 @@ public CodegenResponse fromResponse(String responseCode, ApiResponse response) {
51655179 r .simpleType = false ;
51665180 r .containerType = cp .containerType ;
51675181 r .containerTypeMapped = cp .containerTypeMapped ;
5168- addVarsRequiredVarsAdditionalProps (responseSchema , r );
5182+ addVarsRequiredVarsAdditionalPropsPropertyNames (responseSchema , r );
51695183 } else if (ModelUtils .isAnyType (responseSchema )) {
5170- addVarsRequiredVarsAdditionalProps (responseSchema , r );
5184+ addVarsRequiredVarsAdditionalPropsPropertyNames (responseSchema , r );
51715185 } else if (!ModelUtils .isBooleanSchema (responseSchema )) {
51725186 // referenced schemas
51735187 LOGGER .debug ("Property type is not primitive: {}" , cp .dataType );
@@ -5478,14 +5492,14 @@ public CodegenParameter fromParameter(Parameter parameter, Set<String> imports)
54785492 if (ModelUtils .isFreeFormObject (parameterSchema , openAPI )) {
54795493 codegenParameter .isFreeFormObject = true ;
54805494 }
5481- addVarsRequiredVarsAdditionalProps (parameterSchema , codegenParameter );
5495+ addVarsRequiredVarsAdditionalPropsPropertyNames (parameterSchema , codegenParameter );
54825496 } else if (ModelUtils .isNullType (parameterSchema )) {
54835497 } else if (ModelUtils .isAnyType (parameterSchema )) {
54845498 // any schema with no type set, composed schemas often do this
54855499 if (ModelUtils .isMapSchema (parameterSchema )) { // for map parameter
54865500 updateParameterForMap (codegenParameter , parameterSchema , imports );
54875501 }
5488- addVarsRequiredVarsAdditionalProps (parameterSchema , codegenParameter );
5502+ addVarsRequiredVarsAdditionalPropsPropertyNames (parameterSchema , codegenParameter );
54895503 } else if (ModelUtils .isArraySchema (parameterSchema )) {
54905504 Schema inner = ModelUtils .getSchemaItems (parameterSchema );
54915505
@@ -7771,7 +7785,7 @@ protected void updateRequestBodyForObject(CodegenParameter codegenParameter, Sch
77717785 // object type schema or composed schema with properties defined
77727786 this .addBodyModelSchema (codegenParameter , name , schema , imports , bodyParameterName , false );
77737787 }
7774- addVarsRequiredVarsAdditionalProps (schema , codegenParameter );
7788+ addVarsRequiredVarsAdditionalPropsPropertyNames (schema , codegenParameter );
77757789 }
77767790
77777791 protected void updateRequestBodyForArray (CodegenParameter codegenParameter , Schema schema , String name , Set <String > imports , String bodyParameterName ) {
@@ -8056,7 +8070,7 @@ public CodegenParameter fromRequestBody(RequestBody body, Set<String> imports, S
80568070 } else {
80578071 updateRequestBodyForPrimitiveType (codegenParameter , schema , bodyParameterName , imports );
80588072 }
8059- addVarsRequiredVarsAdditionalProps (schema , codegenParameter );
8073+ addVarsRequiredVarsAdditionalPropsPropertyNames (schema , codegenParameter );
80608074 } else {
80618075 // referenced schemas
80628076 updateRequestBodyForPrimitiveType (codegenParameter , schema , bodyParameterName , imports );
@@ -8174,12 +8188,13 @@ protected void addRequiredVarsMap(Schema schema, IJsonSchemaValidationProperties
81748188 }
81758189 }
81768190
8177- protected void addVarsRequiredVarsAdditionalProps (Schema schema , IJsonSchemaValidationProperties property ) {
8191+ protected void addVarsRequiredVarsAdditionalPropsPropertyNames (Schema schema , IJsonSchemaValidationProperties property ) {
81788192 setAddProps (schema , property );
81798193 Set <String > mandatory = schema .getRequired () == null ? Collections .emptySet ()
81808194 : new TreeSet <>(schema .getRequired ());
81818195 addVars (property , property .getVars (), schema .getProperties (), mandatory );
81828196 addRequiredVarsMap (schema , property );
8197+ setPropNames (schema , property );
81838198 }
81848199
81858200 protected String getItemsName (Schema containingSchema , String containingSchemaName ) {
@@ -8194,6 +8209,10 @@ protected String getAdditionalPropertiesName() {
81948209 return "additional_properties" ;
81958210 }
81968211
8212+ protected String getPropertyNamesName () {
8213+ return "property_names" ;
8214+ }
8215+
81978216 private void addJsonSchemaForBodyRequestInCaseItsNotPresent (CodegenParameter codegenParameter , RequestBody body ) {
81988217 if (codegenParameter .jsonSchema == null )
81998218 codegenParameter .jsonSchema = Json .pretty (body );
0 commit comments