Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use type's default for default stub map key #76

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,9 @@ internal extension ServiceModelCodeGenerator {
return fieldValue
}

private func getMapFieldValue(lengthConstraint: LengthRangeConstraint<Int>, valueType: String,
private func getMapFieldValue(lengthConstraint: LengthRangeConstraint<Int>,
keyType: String,
valueType: String,
fileBuilder: FileBuilder) -> String {
let fieldValue: String

Expand All @@ -173,8 +175,14 @@ internal extension ServiceModelCodeGenerator {
// create a map that satifies at least the minimum constraint
var mapConstructor: [String] = []
let defaultValue = getDefaultValue(type: valueType, fileBuilder: fileBuilder)
for index in 0..<requiredSize {
mapConstructor.append("\"Entry_\(index)\": \(defaultValue)")

if requiredSize == 1 {
let defaultKeyValue = getDefaultValue(type: keyType, fileBuilder: fileBuilder)
mapConstructor.append("\(defaultKeyValue): \(defaultValue)")
} else {
for index in 0..<requiredSize {
mapConstructor.append("\"Entry_\(index)\": \(defaultValue)")
}
}

fieldValue = "[\(mapConstructor.joined(separator: ", "))]"
Expand Down Expand Up @@ -211,9 +219,10 @@ internal extension ServiceModelCodeGenerator {
fieldValue = overrideDefaultValue ?? "\"\(exampleDateString)\""
case .list(type: let listType, lengthConstraint: let lengthConstraint):
fieldValue = getListFieldValue(lengthConstraint: lengthConstraint, listType: listType, fileBuilder: fileBuilder)
case .map(keyType: _, valueType: let valueType,
case .map(keyType: let keyType,
valueType: let valueType,
lengthConstraint: let lengthConstraint):
fieldValue = getMapFieldValue(lengthConstraint: lengthConstraint, valueType: valueType, fileBuilder: fileBuilder)
fieldValue = getMapFieldValue(lengthConstraint: lengthConstraint, keyType: keyType, valueType: valueType, fileBuilder: fileBuilder)
}

return fieldValue
Expand Down
Loading