Skip to content

Commit b680f23

Browse files
fix
1 parent def542c commit b680f23

File tree

3 files changed

+9
-13
lines changed

3 files changed

+9
-13
lines changed

marshaller/unmarshaller.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -367,15 +367,16 @@ func unmarshalModel(ctx context.Context, parentName string, node *yaml.Node, str
367367
// Direct field index lookup (eliminates map[string]Field allocation)
368368
fieldIndex, ok := fieldMap.FieldIndexes[key]
369369
if !ok {
370-
if strings.HasPrefix(key, "x-") && extensionsField != nil {
370+
switch {
371+
case strings.HasPrefix(key, "x-") && extensionsField != nil:
371372
// Lock access to extensionsField to prevent concurrent modification
372373
extensionsMutex.Lock()
373374
defer extensionsMutex.Unlock()
374375
err := UnmarshalExtension(keyNode, valueNode, *extensionsField)
375376
if err != nil {
376377
return err
377378
}
378-
} else if embeddedMap != nil {
379+
case embeddedMap != nil:
379380
// Skip alias definitions - these are nodes where:
380381
// 1. The value node has an anchor (e.g., &keyAlias)
381382
// 2. The key is not an alias reference (doesn't start with *)
@@ -385,7 +386,7 @@ func unmarshalModel(ctx context.Context, parentName string, node *yaml.Node, str
385386
return nil
386387
}
387388
jobMapContent[i/2] = append(jobMapContent[i/2], keyNode, valueNode)
388-
} else {
389+
default:
389390
// This is an unknown property (not a recognized field, not an extension, not in embedded map)
390391
unknownPropertiesMutex.Lock()
391392
unknownProperties = append(unknownProperties, key)

openapi/cmd/sanitize.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ func sanitizeOpenAPI(ctx context.Context, processor *OpenAPIProcessor) error {
139139
if err != nil {
140140
return fmt.Errorf("failed to load config file: %w", err)
141141
}
142-
processor.PrintInfo(fmt.Sprintf("Using configuration from %s", sanitizeConfigFile))
142+
processor.PrintInfo("Using configuration from " + sanitizeConfigFile)
143143
}
144144

145145
// Perform the sanitization

openapi/sanitize.go

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ func LoadSanitizeConfig(r io.Reader) (*SanitizeOptions, error) {
142142

143143
// LoadSanitizeConfigFromFile loads sanitize configuration from a YAML file.
144144
func LoadSanitizeConfigFromFile(path string) (*SanitizeOptions, error) {
145-
f, err := os.Open(path)
145+
f, err := os.Open(path) //nolint:gosec
146146
if err != nil {
147147
return nil, fmt.Errorf("failed to open config file: %w", err)
148148
}
@@ -183,8 +183,7 @@ func removeExtensions(ctx context.Context, doc *OpenAPI, opts *SanitizeOptions)
183183
// Collect keys to remove
184184
keysToRemove := []string{}
185185
for key := range ext.All() {
186-
shouldRemove := false
187-
186+
var shouldRemove bool
188187
if removeAll {
189188
// Remove all extensions
190189
shouldRemove = true
@@ -222,12 +221,8 @@ func removeUnknownProperties(ctx context.Context, doc *OpenAPI) error {
222221
// We need specific matchers for wrapped types (Referenced*, JSONSchema)
223222
for item := range Walk(ctx, doc) {
224223
err := item.Match(Matcher{
225-
Any: func(model any) error {
226-
return cleanUnknownPropertiesFromModel(model)
227-
},
228-
Schema: func(schema *oas3.JSONSchema[oas3.Referenceable]) error {
229-
return cleanUnknownPropertiesFromJSONSchema(schema)
230-
},
224+
Any: cleanUnknownPropertiesFromModel,
225+
Schema: cleanUnknownPropertiesFromJSONSchema,
231226
// Handle all Referenced types by extracting their Object
232227
ReferencedResponse: func(ref *ReferencedResponse) error {
233228
if ref != nil && !ref.IsReference() && ref.Object != nil {

0 commit comments

Comments
 (0)