forked from loafle/openapi-generator-original
fix max, min for number
This commit is contained in:
parent
adbde2fb61
commit
3b6f280d0b
@ -1678,6 +1678,24 @@ public class DefaultCodegen implements CodegenConfig {
|
||||
property.isNumber = Boolean.TRUE;
|
||||
}
|
||||
|
||||
if (p.getMinimum() != null) {
|
||||
property.minimum = String.valueOf(p.getMinimum().longValue());
|
||||
}
|
||||
if (p.getMaximum() != null) {
|
||||
property.maximum = String.valueOf(p.getMaximum().longValue());
|
||||
}
|
||||
if (p.getExclusiveMinimum() != null) {
|
||||
property.exclusiveMinimum = p.getExclusiveMinimum();
|
||||
}
|
||||
if (p.getExclusiveMaximum() != null) {
|
||||
property.exclusiveMaximum = p.getExclusiveMaximum();
|
||||
}
|
||||
|
||||
// check if any validation rule defined
|
||||
// exclusive* are noop without corresponding min/max
|
||||
if (property.minimum != null || property.maximum != null)
|
||||
property.hasValidation = true;
|
||||
|
||||
if (p.getEnum() != null && !p.getEnum().isEmpty()) {
|
||||
List<Object> _enum = p.getEnum();
|
||||
property._enum = new ArrayList<String>();
|
||||
|
@ -261,7 +261,39 @@ public class RubyClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
// not including base object test as the moment as not all API has model
|
||||
//writeOptional(outputFolder, new SupportingFile("base_object_spec.mustache", specFolder, "base_object_spec.rb"));
|
||||
}
|
||||
|
||||
|
||||
/* TO BE DELETED: replaced with postProcessOperations below
|
||||
@Override
|
||||
public CodegenOperation fromOperation(String path, String httpMethod, Operation operation, Map<String, Schema> schemas, OpenAPI openAPI) {
|
||||
CodegenOperation op = super.fromOperation(path, httpMethod, operation, schemas, openAPI);
|
||||
// Set vendor-extension to be used in template:
|
||||
// x-codegen-hasMoreRequired
|
||||
// x-codegen-hasMoreOptional
|
||||
// x-codegen-hasRequiredParams
|
||||
CodegenParameter lastRequired = null;
|
||||
CodegenParameter lastOptional = null;
|
||||
for (CodegenParameter p : op.allParams) {
|
||||
if (p.required) {
|
||||
lastRequired = p;
|
||||
} else {
|
||||
lastOptional = p;
|
||||
}
|
||||
}
|
||||
for (CodegenParameter p : op.allParams) {
|
||||
if (p == lastRequired) {
|
||||
p.vendorExtensions.put("x-codegen-hasMoreRequired", false);
|
||||
} else if (p == lastOptional) {
|
||||
p.vendorExtensions.put("x-codegen-hasMoreOptional", false);
|
||||
} else {
|
||||
p.vendorExtensions.put("x-codegen-hasMoreRequired", true);
|
||||
p.vendorExtensions.put("x-codegen-hasMoreOptional", true);
|
||||
}
|
||||
}
|
||||
op.vendorExtensions.put("x-codegen-hasRequiredParams", lastRequired != null);
|
||||
return op;
|
||||
}
|
||||
*/
|
||||
|
||||
@Override
|
||||
public Map<String, Object> postProcessOperations(Map<String, Object> objs) {
|
||||
Map<String, Object> operations = (Map<String, Object>) objs.get("operations");
|
||||
|
@ -163,6 +163,30 @@ module Petstore
|
||||
invalid_properties.push('invalid value for "number", number cannot be nil.')
|
||||
end
|
||||
|
||||
if @number > 543
|
||||
invalid_properties.push('invalid value for "number", must be smaller than or equal to 543.')
|
||||
end
|
||||
|
||||
if @number < 32
|
||||
invalid_properties.push('invalid value for "number", must be greater than or equal to 32.')
|
||||
end
|
||||
|
||||
if !@float.nil? && @float > 987
|
||||
invalid_properties.push('invalid value for "float", must be smaller than or equal to 987.')
|
||||
end
|
||||
|
||||
if !@float.nil? && @float < 54
|
||||
invalid_properties.push('invalid value for "float", must be greater than or equal to 54.')
|
||||
end
|
||||
|
||||
if !@double.nil? && @double > 123
|
||||
invalid_properties.push('invalid value for "double", must be smaller than or equal to 123.')
|
||||
end
|
||||
|
||||
if !@double.nil? && @double < 67
|
||||
invalid_properties.push('invalid value for "double", must be greater than or equal to 67.')
|
||||
end
|
||||
|
||||
if !@string.nil? && @string !~ Regexp.new(/[a-z]/i)
|
||||
invalid_properties.push('invalid value for "string", must conform to the pattern /[a-z]/i.')
|
||||
end
|
||||
@ -202,6 +226,12 @@ module Petstore
|
||||
return false if !@int32.nil? && @int32 > 200
|
||||
return false if !@int32.nil? && @int32 < 20
|
||||
return false if @number.nil?
|
||||
return false if @number > 543
|
||||
return false if @number < 32
|
||||
return false if !@float.nil? && @float > 987
|
||||
return false if !@float.nil? && @float < 54
|
||||
return false if !@double.nil? && @double > 123
|
||||
return false if !@double.nil? && @double < 67
|
||||
return false if !@string.nil? && @string !~ Regexp.new(/[a-z]/i)
|
||||
return false if @byte.nil?
|
||||
return false if @byte !~ Regexp.new(/^(?:[A-Za-z0-9+\/]{4})*(?:[A-Za-z0-9+\/]{2}==|[A-Za-z0-9+\/]{3}=)?$/)
|
||||
@ -240,6 +270,52 @@ module Petstore
|
||||
@int32 = int32
|
||||
end
|
||||
|
||||
# Custom attribute writer method with validation
|
||||
# @param [Object] number Value to be assigned
|
||||
def number=(number)
|
||||
if number.nil?
|
||||
fail ArgumentError, 'number cannot be nil'
|
||||
end
|
||||
|
||||
if number > 543
|
||||
fail ArgumentError, 'invalid value for "number", must be smaller than or equal to 543.'
|
||||
end
|
||||
|
||||
if number < 32
|
||||
fail ArgumentError, 'invalid value for "number", must be greater than or equal to 32.'
|
||||
end
|
||||
|
||||
@number = number
|
||||
end
|
||||
|
||||
# Custom attribute writer method with validation
|
||||
# @param [Object] float Value to be assigned
|
||||
def float=(float)
|
||||
if !float.nil? && float > 987
|
||||
fail ArgumentError, 'invalid value for "float", must be smaller than or equal to 987.'
|
||||
end
|
||||
|
||||
if !float.nil? && float < 54
|
||||
fail ArgumentError, 'invalid value for "float", must be greater than or equal to 54.'
|
||||
end
|
||||
|
||||
@float = float
|
||||
end
|
||||
|
||||
# Custom attribute writer method with validation
|
||||
# @param [Object] double Value to be assigned
|
||||
def double=(double)
|
||||
if !double.nil? && double > 123
|
||||
fail ArgumentError, 'invalid value for "double", must be smaller than or equal to 123.'
|
||||
end
|
||||
|
||||
if !double.nil? && double < 67
|
||||
fail ArgumentError, 'invalid value for "double", must be greater than or equal to 67.'
|
||||
end
|
||||
|
||||
@double = double
|
||||
end
|
||||
|
||||
# Custom attribute writer method with validation
|
||||
# @param [Object] string Value to be assigned
|
||||
def string=(string)
|
||||
|
Loading…
x
Reference in New Issue
Block a user