@@ -117,48 +117,20 @@ func ImportModelEndpoint(cl *config.ModelConfigLoader, appConfig *config.Applica
117117 return c .JSON (http .StatusBadRequest , response )
118118 }
119119
120- // Check content type to determine how to parse
120+ // Detect format once and reuse for both typed and map parsing
121121 contentType := c .Request ().Header .Get ("Content-Type" )
122- var modelConfig config.ModelConfig
122+ trimmed := strings .TrimSpace (string (body ))
123+ isJSON := strings .Contains (contentType , "application/json" ) ||
124+ (! strings .Contains (contentType , "yaml" ) && len (trimmed ) > 0 && trimmed [0 ] == '{' )
123125
124- if strings . Contains ( contentType , "application/json" ) {
125- // Parse JSON
126+ var modelConfig config. ModelConfig
127+ if isJSON {
126128 if err := json .Unmarshal (body , & modelConfig ); err != nil {
127- response := ModelResponse {
128- Success : false ,
129- Error : "Failed to parse JSON: " + err .Error (),
130- }
131- return c .JSON (http .StatusBadRequest , response )
132- }
133- } else if strings .Contains (contentType , "application/x-yaml" ) || strings .Contains (contentType , "text/yaml" ) {
134- // Parse YAML
135- if err := yaml .Unmarshal (body , & modelConfig ); err != nil {
136- response := ModelResponse {
137- Success : false ,
138- Error : "Failed to parse YAML: " + err .Error (),
139- }
140- return c .JSON (http .StatusBadRequest , response )
129+ return c .JSON (http .StatusBadRequest , ModelResponse {Success : false , Error : "Failed to parse JSON: " + err .Error ()})
141130 }
142131 } else {
143- // Try to auto-detect format
144- if len (body ) > 0 && strings .TrimSpace (string (body ))[0 ] == '{' {
145- // Looks like JSON
146- if err := json .Unmarshal (body , & modelConfig ); err != nil {
147- response := ModelResponse {
148- Success : false ,
149- Error : "Failed to parse JSON: " + err .Error (),
150- }
151- return c .JSON (http .StatusBadRequest , response )
152- }
153- } else {
154- // Assume YAML
155- if err := yaml .Unmarshal (body , & modelConfig ); err != nil {
156- response := ModelResponse {
157- Success : false ,
158- Error : "Failed to parse YAML: " + err .Error (),
159- }
160- return c .JSON (http .StatusBadRequest , response )
161- }
132+ if err := yaml .Unmarshal (body , & modelConfig ); err != nil {
133+ return c .JSON (http .StatusBadRequest , ModelResponse {Success : false , Error : "Failed to parse YAML: " + err .Error ()})
162134 }
163135 }
164136
@@ -171,10 +143,9 @@ func ImportModelEndpoint(cl *config.ModelConfigLoader, appConfig *config.Applica
171143 return c .JSON (http .StatusBadRequest , response )
172144 }
173145
174- // Set defaults
175- modelConfig .SetDefaults (appConfig .ToConfigLoaderOptions ()... )
176-
177- // Validate the configuration
146+ // Validate without calling SetDefaults() — runtime defaults should not
147+ // be persisted to disk. SetDefaults() is called when loading configs
148+ // for inference via LoadModelConfigsFromPath().
178149 if valid , _ := modelConfig .Validate (); ! valid {
179150 response := ModelResponse {
180151 Success : false ,
@@ -193,8 +164,21 @@ func ImportModelEndpoint(cl *config.ModelConfigLoader, appConfig *config.Applica
193164 return c .JSON (http .StatusBadRequest , response )
194165 }
195166
196- // Marshal to YAML for storage
197- yamlData , err := yaml .Marshal (& modelConfig )
167+ // Write only the user-provided fields to disk by parsing the original
168+ // body into a map (not the typed struct, which includes Go zero values).
169+ var bodyMap map [string ]any
170+ if isJSON {
171+ _ = json .Unmarshal (body , & bodyMap )
172+ } else {
173+ _ = yaml .Unmarshal (body , & bodyMap )
174+ }
175+
176+ var yamlData []byte
177+ if bodyMap != nil {
178+ yamlData , err = yaml .Marshal (bodyMap )
179+ } else {
180+ yamlData , err = yaml .Marshal (& modelConfig )
181+ }
198182 if err != nil {
199183 response := ModelResponse {
200184 Success : false ,
0 commit comments