Skip to content

bug: import-dir misclassifies valid primary specifications based on filename #632

Open

Description

@gyanranjanpanda

import-dir decides whether a specification is a primary or secondary artifact based purely on substring matching against the filename, without inspecting the file contents.

Any filename containing words like examples, metadata, collection, or postman is marked as a secondary artifact (mainArtifact=false).

When a valid primary specification has a name matching any of those substrings (for example payments-examples.yaml or user-metadata-api.yaml), it is uploaded with mainArtifact=false. Because Microcks treats secondary artifacts as completion artifacts that require an already-discovered service, the import fails to discover any API if no separate primary artifact exists.

This also prevents importing standalone Postman collections via import-dir, even though Microcks supports them as primary artifacts.

Root cause

cmd/importDir.go lines 305–325:

func detectFileType(filePath string) FileType {
	fileName := strings.ToLower(filepath.Base(filePath))
	ext := filepath.Ext(filePath)

	isPrimary := true

	if strings.Contains(fileName, "postman") || strings.Contains(fileName, "collection") || strings.Contains(fileName, "metadata") || strings.Contains(fileName, "examples") {
		isPrimary = false
	}

	// If there's an OpenAPI file, prefer it as primary
	if strings.Contains(fileName, "openapi") || strings.Contains(fileName, "swagger") {
		isPrimary = true
	}

	return FileType{
		Extension: ext,
		IsPrimary: isPrimary,
	}
}
  1. Substring matching on examples, collection, metadata, or postman forces isPrimary = false on valid specs.
  2. The override at line 317 only checks for openapi or swagger, completely ignoring AsyncAPI, GraphQL, Protobuf, and primary Postman collections.

To reproduce

  1. Put a valid OpenAPI spec in a directory named payments-examples.yaml
  2. Run microcks import-dir .
  3. Notice the CLI reports:
    Microcks has completed '...'
    
    instead of discovered. Because it was uploaded with mainArtifact=false and no prior primary spec exists, the service is not discovered.

Suggested fix

Inspect the file contents (e.g. checking for top-level keys like openapi:, swagger:, asyncapi:, or Postman collection structure) to identify primary artifacts, and only use filename heuristics as a fallback.

this msg drafted with the help of ai

Activity

  1. gyanranjanpanda commented on Nov 19, 2026

    @gyanranjanpanda
    ContributorAuthor

    @Caesarsage @Harsh4902 what is your view on this

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions