mirror of
https://github.com/valitydev/openapi-generator.git
synced 2024-11-08 03:18:53 +00:00
Add default value to Ruby model
This commit is contained in:
parent
a866c7fef4
commit
21bd4fbbc1
@ -6,9 +6,7 @@ import io.swagger.codegen.CodegenConstants;
|
||||
import io.swagger.codegen.CodegenType;
|
||||
import io.swagger.codegen.DefaultCodegen;
|
||||
import io.swagger.codegen.SupportingFile;
|
||||
import io.swagger.models.properties.ArrayProperty;
|
||||
import io.swagger.models.properties.MapProperty;
|
||||
import io.swagger.models.properties.Property;
|
||||
import io.swagger.models.properties.*;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.Arrays;
|
||||
@ -186,6 +184,43 @@ public class RubyClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
return super.getTypeDeclaration(p);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toDefaultValue(Property p) {
|
||||
if (p instanceof IntegerProperty) {
|
||||
IntegerProperty dp = (IntegerProperty) p;
|
||||
if (dp.getDefault() != null) {
|
||||
return dp.getDefault().toString();
|
||||
}
|
||||
} else if (p instanceof LongProperty) {
|
||||
LongProperty dp = (LongProperty) p;
|
||||
if (dp.getDefault() != null) {
|
||||
return dp.getDefault().toString();
|
||||
}
|
||||
} else if (p instanceof DoubleProperty) {
|
||||
DoubleProperty dp = (DoubleProperty) p;
|
||||
if (dp.getDefault() != null) {
|
||||
return dp.getDefault().toString();
|
||||
}
|
||||
} else if (p instanceof FloatProperty) {
|
||||
FloatProperty dp = (FloatProperty) p;
|
||||
if (dp.getDefault() != null) {
|
||||
return dp.getDefault().toString();
|
||||
}
|
||||
} else if (p instanceof BooleanProperty) {
|
||||
BooleanProperty bp = (BooleanProperty) p;
|
||||
if (bp.getDefault() != null) {
|
||||
return bp.getDefault().toString();
|
||||
}
|
||||
} else if (p instanceof StringProperty) {
|
||||
StringProperty sp = (StringProperty) p;
|
||||
if (sp.getDefault() != null) {
|
||||
return "\"" + escapeText(sp.getDefault()) + "\"";
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getSwaggerType(Property p) {
|
||||
String swaggerType = super.getSwaggerType(p);
|
||||
@ -204,10 +239,6 @@ public class RubyClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
return type;
|
||||
}
|
||||
|
||||
public String toDefaultValue(Property p) {
|
||||
return "null";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toVarName(String name) {
|
||||
// sanitize name
|
||||
|
@ -21,7 +21,7 @@ module {{moduleName}}
|
||||
end
|
||||
|
||||
def initialize(attributes = {})
|
||||
return if !attributes.is_a?(Hash) || attributes.empty?
|
||||
return unless attributes.is_a?(Hash)
|
||||
|
||||
# convert string to symbol for hash key
|
||||
attributes = attributes.inject({}){|memo,(k,v)| memo[k.to_sym] = v; memo}
|
||||
@ -30,7 +30,9 @@ module {{moduleName}}
|
||||
if attributes[:'{{{baseName}}}']
|
||||
{{#isContainer}}if (value = attributes[:'{{{baseName}}}']).is_a?(Array)
|
||||
self.{{{name}}} = value
|
||||
end{{/isContainer}}{{^isContainer}}self.{{{name}}} = attributes[:'{{{baseName}}}']{{/isContainer}}
|
||||
end{{/isContainer}}{{^isContainer}}self.{{{name}}} = attributes[:'{{{baseName}}}']{{/isContainer}}{{#defaultValue}}
|
||||
else
|
||||
self.{{{name}}} = {{{defaultValue}}}{{/defaultValue}}
|
||||
end
|
||||
{{/vars}}
|
||||
end
|
||||
|
@ -25,7 +25,7 @@ module Petstore
|
||||
end
|
||||
|
||||
def initialize(attributes = {})
|
||||
return if !attributes.is_a?(Hash) || attributes.empty?
|
||||
return unless attributes.is_a?(Hash)
|
||||
|
||||
# convert string to symbol for hash key
|
||||
attributes = attributes.inject({}){|memo,(k,v)| memo[k.to_sym] = v; memo}
|
||||
|
@ -41,7 +41,7 @@ module Petstore
|
||||
end
|
||||
|
||||
def initialize(attributes = {})
|
||||
return if !attributes.is_a?(Hash) || attributes.empty?
|
||||
return unless attributes.is_a?(Hash)
|
||||
|
||||
# convert string to symbol for hash key
|
||||
attributes = attributes.inject({}){|memo,(k,v)| memo[k.to_sym] = v; memo}
|
||||
|
@ -41,7 +41,7 @@ module Petstore
|
||||
end
|
||||
|
||||
def initialize(attributes = {})
|
||||
return if !attributes.is_a?(Hash) || attributes.empty?
|
||||
return unless attributes.is_a?(Hash)
|
||||
|
||||
# convert string to symbol for hash key
|
||||
attributes = attributes.inject({}){|memo,(k,v)| memo[k.to_sym] = v; memo}
|
||||
|
@ -25,7 +25,7 @@ module Petstore
|
||||
end
|
||||
|
||||
def initialize(attributes = {})
|
||||
return if !attributes.is_a?(Hash) || attributes.empty?
|
||||
return unless attributes.is_a?(Hash)
|
||||
|
||||
# convert string to symbol for hash key
|
||||
attributes = attributes.inject({}){|memo,(k,v)| memo[k.to_sym] = v; memo}
|
||||
|
@ -49,7 +49,7 @@ module Petstore
|
||||
end
|
||||
|
||||
def initialize(attributes = {})
|
||||
return if !attributes.is_a?(Hash) || attributes.empty?
|
||||
return unless attributes.is_a?(Hash)
|
||||
|
||||
# convert string to symbol for hash key
|
||||
attributes = attributes.inject({}){|memo,(k,v)| memo[k.to_sym] = v; memo}
|
||||
|
Loading…
Reference in New Issue
Block a user