Works offline. Open this file directly in a browser after extracting the ZIP. API execution is disabled in this reference bundle; calling the live API requires a running backend and appropriate authorization.
`
// Build returns a bundle in memory. Specifications are embedded in the HTML to avoid file:// fetch/CORS restrictions.
func Build() (map[string][]byte, error) {
files := map[string][]byte{"index.html": []byte(indexTemplate), "THIRD_PARTY_LICENSE.txt": thirdPartyLicense}
for _, asset := range []string{"swagger-ui.css", "swagger-ui-bundle.js"} {
content, err := swaggerFiles.ReadFile(asset)
if err != nil {
return nil, fmt.Errorf("load Swagger UI asset %s: %w", asset, err)
}
files["assets/"+asset] = content
}
page, err := template.New("swagger").Parse(pageTemplate)
if err != nil {
return nil, err
}
for _, audience := range []string{"admin", "client", "all"} {
spec, err := apidocs.Specification(audience)
if err != nil {
return nil, err
}
raw, err := json.MarshalIndent(spec, "", " ")
if err != nil {
return nil, err
}
yamlSpec, err := yaml.Marshal(spec)
if err != nil {
return nil, err
}
name := audience
if audience == "client" {
name = "customer"
}
files["specs/"+name+".json"] = append(raw, '\n')
files["specs/"+name+".yaml"] = yamlSpec
title := "Rezina API"
if info, ok := spec["info"].(map[string]any); ok {
if value, ok := info["title"].(string); ok {
title = value
}
}
count := 0
if paths, ok := spec["paths"].(map[string]any); ok {
for _, value := range paths {
if operations, ok := value.(map[string]any); ok {
for method := range operations {
switch method {
case "get", "post", "put", "patch", "delete", "head", "options":
count++
}
}
}
}
}
var html bytes.Buffer
// encoding/json escapes HTML metacharacters, so the JSON cannot terminate the surrounding script element.
data := struct {
Title, Name string
Count int
Spec template.JS
}{title, name, count, template.JS(raw)}
if err := page.Execute(&html, data); err != nil {
return nil, err
}
files[name+".html"] = html.Bytes()
}
files["README.txt"] = []byte("Rezina offline API documentation\n\nExtract the ZIP completely, then open index.html in a modern browser.\nAdmin and customer pages use the same audience-specific specifications as the running application.\nAll JavaScript, CSS, and API specifications are local. No server, CDN, or internet connection is needed to read the documentation.\nAPI execution is disabled. Use the live Swagger pages to call a running API.\nJSON and YAML files for admin, customer, and all APIs are in specs/.\nRegenerate with: go run ./cmd/swagger-export -out exports/swagger-offline\n")
return files, nil
}
// Export writes the folder and a ZIP beside it, without removing existing unrelated files.
func Export(output string) (string, error) {
files, err := Build()
if err != nil {
return "", err
}
output, err = filepath.Abs(output)
if err != nil {
return "", err
}
if err := os.MkdirAll(output, 0755); err != nil {
return "", err
}
names := make([]string, 0, len(files))
for name := range files {
names = append(names, name)
}
sort.Strings(names)
for _, name := range names {
target := filepath.Join(output, filepath.FromSlash(name))
if err := os.MkdirAll(filepath.Dir(target), 0755); err != nil {
return "", err
}
if err := os.WriteFile(target, files[name], 0644); err != nil {
return "", err
}
}
var archive bytes.Buffer
writer := zip.NewWriter(&archive)
for _, name := range names {
header := &zip.FileHeader{Name: filepath.Base(output) + "/" + strings.ReplaceAll(name, "\\", "/"), Method: zip.Deflate}
file, err := writer.CreateHeader(header)
if err != nil {
return "", err
}
if _, err := file.Write(files[name]); err != nil {
return "", err
}
}
if err := writer.Close(); err != nil {
return "", err
}
zipPath := output + ".zip"
if err := os.WriteFile(zipPath, archive.Bytes(), 0644); err != nil {
return "", err
}
return zipPath, nil
}