fix(core,gen): UseStateForUnknown для Optional+Computed + live-dосылка без тихого fallback (R1+R3+A/B)
This commit is contained in:
@@ -132,6 +132,7 @@ func LoadSpecs(dir string) ([]types.GenResource, []types.GenSubresource, []types
|
||||
HasDomainParam: hasDomainParam,
|
||||
}
|
||||
params.Analyze(&gr.UsesBool, &gr.UsesInt64, &gr.UsesString, &gr.HasDefaults, &gr.NeedsBoolDefault, &gr.NeedsInt64Default, &gr.NeedsStringDefault, gr.SchemaParams)
|
||||
gr.NeedsBoolUseStateForUnknown, gr.NeedsInt64UseStateForUnknown = analyzeUseStateForUnknown(gr.SchemaParams)
|
||||
// Анализируем nested sub-params для default-импортов
|
||||
if params.AnalyzeNestedDefaults(&gr.NeedsBoolDefault, &gr.NeedsInt64Default, &gr.NeedsStringDefault, gr.SchemaParams) {
|
||||
gr.NeedsFmtImport = true
|
||||
@@ -452,3 +453,21 @@ func validateModifierOperation(i int, op *lib.OperationSpec) error {
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// analyzeUseStateForUnknown определяет, нужны ли импорты boolplanmodifier/int64planmodifier:
|
||||
// есть ли среди SchemaParams скалярный Optional+Computed (без Default) параметр
|
||||
// соответствующего типа, для которого генерируется UseStateForUnknown().
|
||||
func analyzeUseStateForUnknown(schemaParams []types.Param) (needsBool, needsInt64 bool) {
|
||||
for _, p := range schemaParams {
|
||||
if p.IsJson || p.Required || p.RefSvcId != 0 || p.Default != "" {
|
||||
continue
|
||||
}
|
||||
switch strings.ToLower(p.Type) {
|
||||
case "bool":
|
||||
needsBool = true
|
||||
case "int", "int64", "number":
|
||||
needsInt64 = true
|
||||
}
|
||||
}
|
||||
return needsBool, needsInt64
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user