Skip to content

[feature]: Artifact Export and Download Command (microcks export) - #597

Open
aniket866 wants to merge 3 commits into
microcks:masterfrom
aniket866:Feature/Export-artifacts-and-download
Open

aniket866 wants to merge 3 commits into
microcks:masterfrom
aniket866:Feature/Export-artifacts-and-download

Conversation

@aniket866

@aniket866 aniket866 commented Oct 27, 2026 •

Copy link
Copy Markdown
Contributor

Artifact Export and Download Command (microcks export)

Summary

Add a microcks export <service:version> --output <dir> command to download registered API specifications from the Microcks server back to local disk.

User Value

Allows teams to back up or retrieve API contract definitions directly from Microcks when source files are unavailable locally.

Proposed Usage

microcks.exe export "Petstore API:1.0" --output ./specs/

Tested and verified against this mock server verify_server.go

package main

import (
	"encoding/json"
	"fmt"
	"net/http"
)

func main() {
	// 1. Service lookup by name & version
	http.HandleFunc("/api/services", func(w http.ResponseWriter, r *http.Request) {
		w.Header().Set("Content-Type", "application/json")
		json.NewEncoder(w).Encode([]map[string]any{
			{"id": "svc-order-1", "name": "Order API", "version": "1.0", "type": "REST"},
		})
	})

	// 2. Service details
	http.HandleFunc("/api/services/svc-order-1", func(w http.ResponseWriter, r *http.Request) {
		w.Header().Set("Content-Type", "application/json")
		json.NewEncoder(w).Encode(map[string]any{
			"service": map[string]any{"id": "svc-order-1", "name": "Order API", "version": "1.0", "type": "REST"},
		})
	})

	// 3. Raw specification artifacts
	http.HandleFunc("/api/resources/service/svc-order-1", func(w http.ResponseWriter, r *http.Request) {
		w.Header().Set("Content-Type", "application/json")
		json.NewEncoder(w).Encode([]map[string]any{
			{
				"id":        "res-1",
				"name":      "order-api-openapi.yaml",
				"content":   "openapi: 3.0.0\ninfo:\n  title: Order API\n  version: 1.0\npaths:\n  /orders:\n    get:\n      responses:\n        '200':\n          description: list orders",
				"type":      "OPEN_API_SPEC",
				"serviceId": "svc-order-1",
			},
		})
	})

	// 4. Snapshot export
	http.HandleFunc("/api/export", func(w http.ResponseWriter, r *http.Request) {
		w.Header().Set("Content-Type", "application/json")
		fmt.Fprint(w, `{"services":[{"id":"svc-order-1","name":"Order API","version":"1.0"}]}`)
	})

	fmt.Println("Mock Microcks server running on http://localhost:8585...")
	http.ListenAndServe(":8585", nil)
}

run :go run verify_server.go

run : with overwrite safety guard

 .\microcks.exe export "Order API:1.0" --output .\downloaded_specs\ --microcksURL http://localhost:8585/api --overwrite

This will create :

  1. Resolves the Service: Queries Microcks for the service matching "Order API:1.0", retrieving service ID svc-order-1.
  2. Retrieves the Specification Artifacts: Calls /api/resources/service/svc-order-1 to pull the contract file stored on the server.
  3. Applies Overwrite Guard: Detects that downloaded_specs\order-api-openapi.yaml already exists, honors the --overwrite flag, and safely refreshes the file with mode 0600.
  4. Resulting Output File: Creates/updates downloaded_specs/order-api-openapi.yaml
    :
  • AI disclosure : Chatgpt is used to analyze related files and do changes.
image

Closes #596

@aniket866
aniket866 force-pushed the Feature/Export-artifacts-and-download branch from 4101bf1 to 6edaf52 Compare October 27, 2026 18:51

This branch was successfully deployed

1 active deployment
Build — 6edaf524 Deployed Oct 27, 2026 by aniket866 via build-verify-package #829
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.

[Feature]: Artifact Export and Download Command (microcks export)

1 participant