Skip to content

Commit e9cd8cf

Browse files
committed
fix: address review feedback on OpenAPI converter
- Add build/generate-openapi.go as Makefile prerequisite so changes to the converter trigger spec regeneration - Remove leftover `_ = key` no-op statement - Add top-of-file comment explaining what the converter does and why - Document why knownEnumTypes mapping is needed Co-Authored-By: Claude Opus 4 (claude-opus-4-6)
1 parent 2a62a21 commit e9cd8cf

File tree

2 files changed

+21
-3
lines changed

2 files changed

+21
-3
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,7 @@ swagger-validate: ## check if the swagger spec is valid
260260
.PHONY: generate-openapi3
261261
generate-openapi3: $(OPENAPI3_SPEC) ## generate the OpenAPI 3.0 spec from the Swagger 2.0 spec
262262

263-
$(OPENAPI3_SPEC): $(SWAGGER_SPEC)
263+
$(OPENAPI3_SPEC): $(SWAGGER_SPEC) build/generate-openapi.go
264264
$(GO) run build/generate-openapi.go
265265

266266
.PHONY: openapi3-check

build/generate-openapi.go

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,17 @@
11
// Copyright 2026 The Gitea Authors. All rights reserved.
22
// SPDX-License-Identifier: MIT
33

4+
// generate-openapi converts Gitea's Swagger 2.0 spec into an OpenAPI 3.0 spec.
5+
//
6+
// Gitea generates a Swagger 2.0 spec from code annotations (make generate-swagger).
7+
// This tool converts it to OAS3 so that SDK generators and tools that require
8+
// OAS3 (e.g. progenitor for Rust) can consume it directly. The conversion also
9+
// deduplicates inline enum definitions into named schema components, producing
10+
// cleaner SDK output with proper enum types instead of anonymous strings.
11+
//
12+
// Usage: go run build/generate-openapi.go
13+
// Output: templates/swagger/v1_openapi3_json.tmpl
14+
415
//go:build ignore
516

617
package main
@@ -272,8 +283,6 @@ func extractSharedEnums(doc *openapi3.T) {
272283
}
273284
}
274285
}
275-
276-
_ = key
277286
}
278287
}
279288

@@ -286,6 +295,15 @@ func enumKey(values []any) string {
286295
return strings.Join(strs, "|")
287296
}
288297

298+
// knownEnumTypes maps constant-name prefixes to their Go type names.
299+
// SDK generators (e.g. progenitor for Rust) need named enum types to produce
300+
// good code — without them you get duplicate anonymous string types on every
301+
// field instead of a shared enum like StateType.
302+
//
303+
// deriveEnumName extracts a prefix by stripping the enum value from the
304+
// constant name (e.g. "StateClosed" minus "closed" = "State"), but that
305+
// prefix doesn't always match the Go type (State → StateType,
306+
// CommitStatus → CommitStatusState). This map bridges the gap.
289307
var knownEnumTypes = map[string]string{
290308
"CommitStatus": "CommitStatusState",
291309
"State": "StateType",

0 commit comments

Comments
 (0)