mirror of
https://github.com/OneUptime/oneuptime.git
synced 2026-04-06 00:32:12 +02:00
fix: always import math/big and add helper for converting *big.Float to float64
This commit is contained in:
@@ -59,11 +59,6 @@ export class ResourceGenerator {
|
||||
];
|
||||
|
||||
// Add conditional imports only if they're actually used
|
||||
const hasNumberFields: boolean = Object.values(resource.schema).some(
|
||||
(attr: any) => {
|
||||
return attr.type === "number";
|
||||
},
|
||||
);
|
||||
const hasReadOperation: boolean = Boolean(resource.operations.read);
|
||||
const hasDefaultValues: boolean = Object.values(resource.schema).some(
|
||||
(attr: any) => {
|
||||
@@ -71,9 +66,8 @@ export class ResourceGenerator {
|
||||
},
|
||||
);
|
||||
|
||||
if (hasNumberFields) {
|
||||
imports.push("math/big");
|
||||
}
|
||||
// Always add math/big since the bigFloatToFloat64 helper method uses it
|
||||
imports.push("math/big");
|
||||
|
||||
if (hasReadOperation) {
|
||||
imports.push("net/http");
|
||||
@@ -340,15 +334,24 @@ func (r *${resourceTypeName}Resource) parseJSONField(terraformString types.Strin
|
||||
if terraformString.IsNull() || terraformString.IsUnknown() || terraformString.ValueString() == "" {
|
||||
return nil
|
||||
}
|
||||
|
||||
|
||||
var result interface{}
|
||||
if err := json.Unmarshal([]byte(terraformString.ValueString()), &result); err != nil {
|
||||
// If JSON parsing fails, return the raw string
|
||||
return terraformString.ValueString()
|
||||
}
|
||||
|
||||
|
||||
return result
|
||||
}
|
||||
|
||||
// Helper method to convert *big.Float to float64 for JSON serialization
|
||||
func (r *${resourceTypeName}Resource) bigFloatToFloat64(bf *big.Float) interface{} {
|
||||
if bf == nil {
|
||||
return nil
|
||||
}
|
||||
f, _ := bf.Float64()
|
||||
return f
|
||||
}
|
||||
`;
|
||||
}
|
||||
|
||||
@@ -1417,7 +1420,8 @@ func (r *${resourceTypeName}Resource) Delete(ctx context.Context, req resource.D
|
||||
case "string":
|
||||
return `${fieldRef}.ValueString()`;
|
||||
case "number":
|
||||
return `${fieldRef}.ValueBigFloat()`;
|
||||
// Use helper to convert *big.Float to float64 for proper JSON serialization
|
||||
return `r.bigFloatToFloat64(${fieldRef}.ValueBigFloat())`;
|
||||
case "bool":
|
||||
return `${fieldRef}.ValueBool()`;
|
||||
case "map":
|
||||
|
||||
Reference in New Issue
Block a user