Skip to content

fix(import-dir): detect primary artifacts from file content - #656

Open
Ashish-CodeJourney wants to merge 3 commits into
microcks:masterfrom
Ashish-CodeJourney:fix/import-dir-detect-by-content
Open

Ashish-CodeJourney wants to merge 3 commits into
microcks:masterfrom
Ashish-CodeJourney:fix/import-dir-detect-by-content

Conversation

@Ashish-CodeJourney

Copy link
Copy Markdown

Fixes #632

Problem

import-dir decided whether a file is a primary or secondary artifact only from its filename. A valid spec named payments-examples.yaml or user-metadata-api.json was uploaded with mainArtifact=false, so Microcks treated it as a completion artifact and no service was discovered. The reverse also happened: a Microcks APIExamples file named openapi-examples.yaml was uploaded as primary because the name contains openapi.

Fix

detectFileType now looks at the file content first:

  • a top level openapi, swagger or asyncapi key marks the file as primary
  • an apiVersion starting with mocks.microcks.io/ (APIExamples, APIMetadata) marks it as secondary
  • anything else (unreadable, not YAML/JSON, Postman collections, GraphQL, Protobuf) falls back to the existing filename rules, so current behaviour is kept for those formats

JSON is valid YAML, so a single yaml.v3 parse handles both.

Tests

  • New TestDetectFileTypeUsesFileContent covers misleading filenames for OpenAPI, Swagger and AsyncAPI specs, Microcks examples/metadata files, a Postman collection and an unrelated YAML file using the fallback.
  • Existing TestDetectFileTypeWithLogic still passes unchanged.
  • go test ./... and go vet ./cmd pass.

Signed-off-by: Ashish Vaghela <vaghelaashish111@gmail.com>
Signed-off-by: Ashish Vaghela <vaghelaashish111@gmail.com>
Signed-off-by: Ashish Vaghela <vaghelaashish111@gmail.com>

This branch has not been deployed

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

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

1 participant