mirror of
https://github.com/hanzoai/forge.git
synced 2026-10-30 15:00:39 +00:00
Storage buckets, indexer names, the bleve analyzer, the lock prefix, SSH host keys, the markdown front-matter key, the container data paths, the RPM repo id and the API security scheme all read as this product now, and app.example.ini matches the code again. The upstream maintainer list and the changelog generator config went with the release history they belonged to, and the citation comments state the fact rather than link the issue. Three inert rules turn out to have been inert because they named a module path this tree does not use: gci grouped no first-party imports under prefix(), and depguard let models/migrations import models and modules/structs. They now name github.com/hanzoai/git. The config example also documented .gitea/workflows while the code has read .hanzo/workflows for some time. The authorized_keys marker follows the delegate-hook precedent: the new name is written and the old one is still recognised, because a marker we do not know is copied through as a hand-added key and leaves a revoked key authorized. The stored user_setting key keeps its value; only a migration may change that. Co-authored-by: Hanzo Dev <[email protected]>
98 lines
2.6 KiB
Go
98 lines
2.6 KiB
Go
// Copyright 2026 Hanzo AI, Inc. All rights reserved.
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
// generate-openapi converts the Swagger 2.0 spec into an OpenAPI 3.0 spec.
|
|
//
|
|
// The Swagger 2.0 spec is generated from code annotations (make generate-swagger).
|
|
// This tool converts it to OAS3 so that SDK generators and tools that require
|
|
// OAS3 (e.g. progenitor for Rust) can consume it directly. The conversion also
|
|
// deduplicates inline enum definitions into named schema components, producing
|
|
// cleaner SDK output with proper enum types instead of anonymous strings.
|
|
//
|
|
// Run: go run build/generate-openapi.go
|
|
// Output: templates/swagger/v1_openapi3_json.tmpl
|
|
|
|
//go:build ignore
|
|
|
|
package main
|
|
|
|
import (
|
|
"encoding/json"
|
|
"fmt"
|
|
"log"
|
|
"os"
|
|
"regexp"
|
|
"sort"
|
|
"strings"
|
|
|
|
"github.com/hanzoai/git/build/openapi3gen"
|
|
|
|
"github.com/getkin/kin-openapi/openapi3"
|
|
)
|
|
|
|
const (
|
|
swaggerSpecPath = "templates/swagger/v1_json.tmpl"
|
|
openapi3OutPath = "templates/swagger/v1_openapi3_json.tmpl"
|
|
|
|
appSubUrlVar = "{{.SwaggerAppSubUrl}}"
|
|
appVerVar = "{{.SwaggerAppVer}}"
|
|
|
|
appSubUrlPlaceholder = "GIT_APP_SUB_URL_PLACEHOLDER"
|
|
appVerPlaceholder = "0.0.0-placeholder"
|
|
)
|
|
|
|
var (
|
|
appSubUrlRe = regexp.MustCompile(regexp.QuoteMeta(appSubUrlVar))
|
|
appVerRe = regexp.MustCompile(regexp.QuoteMeta(appVerVar))
|
|
|
|
enumScanDirs = []string{
|
|
"modules/structs",
|
|
"modules/commitstatus",
|
|
}
|
|
)
|
|
|
|
func main() {
|
|
astEnumMap, err := openapi3gen.ScanSwaggerEnumTypes(enumScanDirs)
|
|
if err != nil {
|
|
log.Fatalf("scanning swagger:enum annotations: %v", err)
|
|
}
|
|
names := make([]string, 0, len(astEnumMap))
|
|
for _, ns := range astEnumMap {
|
|
names = append(names, ns...)
|
|
}
|
|
sort.Strings(names)
|
|
fmt.Fprintf(os.Stderr, "discovered %d swagger:enum types: %s\n", len(names), strings.Join(names, ", "))
|
|
|
|
data, err := os.ReadFile(swaggerSpecPath)
|
|
if err != nil {
|
|
log.Fatalf("reading swagger spec: %v", err)
|
|
}
|
|
|
|
cleaned := appSubUrlRe.ReplaceAll(data, []byte(appSubUrlPlaceholder))
|
|
cleaned = appVerRe.ReplaceAll(cleaned, []byte(appVerPlaceholder))
|
|
|
|
oas3, err := openapi3gen.Convert(cleaned, astEnumMap)
|
|
if err != nil {
|
|
log.Fatalf("converting to openapi 3.0: %v", err)
|
|
}
|
|
|
|
oas3.Servers = openapi3.Servers{
|
|
{URL: appSubUrlPlaceholder + "/v1"},
|
|
}
|
|
|
|
out, err := json.MarshalIndent(oas3, "", " ")
|
|
if err != nil {
|
|
log.Fatalf("marshaling openapi 3.0: %v", err)
|
|
}
|
|
|
|
result := strings.ReplaceAll(string(out), appSubUrlPlaceholder, appSubUrlVar)
|
|
result = strings.ReplaceAll(result, appVerPlaceholder, appVerVar)
|
|
result = strings.TrimSpace(result)
|
|
|
|
if err := os.WriteFile(openapi3OutPath, []byte(result), 0o644); err != nil {
|
|
log.Fatalf("writing openapi 3.0 spec: %v", err)
|
|
}
|
|
|
|
fmt.Printf("Generated %s\n", openapi3OutPath)
|
|
}
|