@@ -119,48 +119,20 @@ func ImportModelEndpoint(cl *config.ModelConfigLoader, appConfig *config.Applica
119119 return c .JSON (http .StatusBadRequest , response )
120120 }
121121
122- // Check content type to determine how to parse
122+ // Detect format once and reuse for both typed and map parsing
123123 contentType := c .Request ().Header .Get ("Content-Type" )
124- var modelConfig config.ModelConfig
124+ trimmed := strings .TrimSpace (string (body ))
125+ isJSON := strings .Contains (contentType , "application/json" ) ||
126+ (! strings .Contains (contentType , "yaml" ) && len (trimmed ) > 0 && trimmed [0 ] == '{' )
125127
126- if strings . Contains ( contentType , "application/json" ) {
127- // Parse JSON
128+ var modelConfig config. ModelConfig
129+ if isJSON {
128130 if err := json .Unmarshal (body , & modelConfig ); err != nil {
129- response := ModelResponse {
130- Success : false ,
131- Error : "Failed to parse JSON: " + err .Error (),
132- }
133- return c .JSON (http .StatusBadRequest , response )
134- }
135- } else if strings .Contains (contentType , "application/x-yaml" ) || strings .Contains (contentType , "text/yaml" ) {
136- // Parse YAML
137- if err := yaml .Unmarshal (body , & modelConfig ); err != nil {
138- response := ModelResponse {
139- Success : false ,
140- Error : "Failed to parse YAML: " + err .Error (),
141- }
142- return c .JSON (http .StatusBadRequest , response )
131+ return c .JSON (http .StatusBadRequest , ModelResponse {Success : false , Error : "Failed to parse JSON: " + err .Error ()})
143132 }
144133 } else {
145- // Try to auto-detect format
146- if len (body ) > 0 && strings .TrimSpace (string (body ))[0 ] == '{' {
147- // Looks like JSON
148- if err := json .Unmarshal (body , & modelConfig ); err != nil {
149- response := ModelResponse {
150- Success : false ,
151- Error : "Failed to parse JSON: " + err .Error (),
152- }
153- return c .JSON (http .StatusBadRequest , response )
154- }
155- } else {
156- // Assume YAML
157- if err := yaml .Unmarshal (body , & modelConfig ); err != nil {
158- response := ModelResponse {
159- Success : false ,
160- Error : "Failed to parse YAML: " + err .Error (),
161- }
162- return c .JSON (http .StatusBadRequest , response )
163- }
134+ if err := yaml .Unmarshal (body , & modelConfig ); err != nil {
135+ return c .JSON (http .StatusBadRequest , ModelResponse {Success : false , Error : "Failed to parse YAML: " + err .Error ()})
164136 }
165137 }
166138
@@ -173,10 +145,9 @@ func ImportModelEndpoint(cl *config.ModelConfigLoader, appConfig *config.Applica
173145 return c .JSON (http .StatusBadRequest , response )
174146 }
175147
176- // Set defaults
177- modelConfig .SetDefaults (appConfig .ToConfigLoaderOptions ()... )
178-
179- // Validate the configuration
148+ // Validate without calling SetDefaults() — runtime defaults should not
149+ // be persisted to disk. SetDefaults() is called when loading configs
150+ // for inference via LoadModelConfigsFromPath().
180151 if valid , _ := modelConfig .Validate (); ! valid {
181152 response := ModelResponse {
182153 Success : false ,
@@ -195,8 +166,21 @@ func ImportModelEndpoint(cl *config.ModelConfigLoader, appConfig *config.Applica
195166 return c .JSON (http .StatusBadRequest , response )
196167 }
197168
198- // Marshal to YAML for storage
199- yamlData , err := yaml .Marshal (& modelConfig )
169+ // Write only the user-provided fields to disk by parsing the original
170+ // body into a map (not the typed struct, which includes Go zero values).
171+ var bodyMap map [string ]any
172+ if isJSON {
173+ _ = json .Unmarshal (body , & bodyMap )
174+ } else {
175+ _ = yaml .Unmarshal (body , & bodyMap )
176+ }
177+
178+ var yamlData []byte
179+ if bodyMap != nil {
180+ yamlData , err = yaml .Marshal (bodyMap )
181+ } else {
182+ yamlData , err = yaml .Marshal (& modelConfig )
183+ }
200184 if err != nil {
201185 response := ModelResponse {
202186 Success : false ,
0 commit comments