Skip to content

Commit

Permalink
chore: change api bundle
Browse files Browse the repository at this point in the history
  • Loading branch information
katallaxie authored May 6, 2024
1 parent 804c0c3 commit 0a522cd
Show file tree
Hide file tree
Showing 9 changed files with 1,559 additions and 46 deletions.
15 changes: 6 additions & 9 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
BASE_DIR ?= $(CURDIR)
OUTPUT_DIR ?= $(BASE_DIR)/dist

GO ?= go
GO ?= go
GO_RUN_TOOLS ?= $(GO) run -modfile ./tools/go.mod
GO_TEST ?= $(GO_RUN_TOOLS) gotest.tools/gotestsum --format pkgname
GO_TEST ?= $(GO_RUN_TOOLS) gotest.tools/gotestsum --format pkgname
GO_RELEASER ?= $(GO_RUN_TOOLS) github.com/goreleaser/goreleaser
GO_KO ?= $(GO_RUN_TOOLS) github.com/google/ko
GO_MOD ?= $(shell ${GO} list -m)
GO_KO ?= $(GO_RUN_TOOLS) github.com/google/ko
GO_MOD ?= $(shell ${GO} list -m)

COMMANDS := $(notdir $(wildcard cmd/*))

Expand All @@ -20,14 +20,11 @@ KOFLAGS ?=
build: $(COMMANDS) ## Build the application.

$(filter-out $(CUSTOM_BUILD_BINARIES), $(COMMANDS)): ## Build artifact
$(GO) build -ldflags "$(LDFLAGS_STATIC)" -o $(BIN_OUTPUT_DIR)/$@ ./cmd/$@
$(GO) build -ldflags "$(LDFLAGS_STATIC)" -o $(BIN_OUTPUT_DIR)/$@ ./cmd/$@

.PHONY: generate
generate: ## Generate code.
$(GO) generate ./...
$(GO_RUN_TOOLS) github.com/deepmap/oapi-codegen/v2/cmd/oapi-codegen -config ./api/config.models.yml ./api/api.yml
$(GO_RUN_TOOLS) github.com/deepmap/oapi-codegen/v2/cmd/oapi-codegen -config ./api/config.client.yml ./api/api.yml
$(GO_RUN_TOOLS) github.com/deepmap/oapi-codegen/v2/cmd/oapi-codegen -config ./api/config.server.yml ./api/api.yml

.PHONY: fmt
fmt: ## Run go fmt against code.
Expand Down Expand Up @@ -76,4 +73,4 @@ help: ## Display this help screen.
include hack/inc.codegen.mk

# dev
include hack/inc.dev.mk
include hack/inc.dev.mk
39 changes: 7 additions & 32 deletions api/api.yml
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ paths:
content:
application/json:
schema:
$ref: "#/components/schemas/Version"
$ref: "./schemas/version.yml#/components/schemas/Version"
"500":
$ref: "#/components/responses/InternalError"
"501":
Expand Down Expand Up @@ -1008,37 +1008,37 @@ components:
content:
application/json:
schema:
$ref: "#/components/schemas/Error"
$ref: "./schemas/error.yml#/components/schemas/Error"
NotFound:
description: The requested resource was not found.
content:
application/json:
schema:
$ref: "#/components/schemas/Error"
$ref: "./schemas/error.yml#/components/schemas/Error"
Unauthorized:
description: The request was not authorized.
content:
application/json:
schema:
$ref: "#/components/schemas/Error"
$ref: "./schemas/error.yml#/components/schemas/Error"
BadRequest:
description: The request was not valid.
content:
application/json:
schema:
$ref: "#/components/schemas/Error"
$ref: "./schemas/error.yml#/components/schemas/Error"
Unimplemented:
description: The requested resource was not implemented.
content:
application/json:
schema:
$ref: "#/components/schemas/Error"
$ref: "./schemas/error.yml#/components/schemas/Error"
Duplicate:
description: The requested resource was a duplicate.
content:
application/json:
schema:
$ref: "#/components/schemas/Error"
$ref: "./schemas/error.yml#/components/schemas/Error"

requestBodies:
# Body for creating a system
Expand Down Expand Up @@ -1142,20 +1142,6 @@ components:
name: X-API-Key

schemas:
Error:
type: object
required:
- code
- message
properties:
code:
type: integer
format: int32
ref:
type: string
message:
type: string

NKey:
description: |
An NKey is the private key of a NATS account.
Expand Down Expand Up @@ -1517,17 +1503,6 @@ components:
items:
$ref: "#/components/schemas/JWTExport"

Version:
type: object
required:
- version
- date
properties:
version:
type: string
date:
type: string

Clusters:
type: array
maxItems: 100
Expand Down
3 changes: 2 additions & 1 deletion api/config.client.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# yaml-language-server: $schema=https://raw.githubusercontent.com/deepmap/oapi-codegen/HEAD/configuration-schema.json
package: apis
generate:
client: true
output: pkg/apis/client.gen.go
output: ../pkg/apis/client.gen.go
output-options:
skip-prune: true
3 changes: 2 additions & 1 deletion api/config.models.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
# yaml-language-server: $schema=https://raw.githubusercontent.com/deepmap/oapi-codegen/HEAD/configuration-schema.json
package: apis
generate:
models: true
embedded-spec: true
output: pkg/apis/models.gen.go
output: ../pkg/apis/models.gen.go
output-options:
skip-prune: true
7 changes: 4 additions & 3 deletions api/config.server.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
# yaml-language-server: $schema=https://raw.githubusercontent.com/deepmap/oapi-codegen/HEAD/configuration-schema.json
package: apis
generate:
fiber-server: true
strict-server: true
output: pkg/apis/server.gen.go
output: ../pkg/apis/server.gen.go
output-options:
skip-prune: true


import-mapping:
./schemas/version.yml: github.com/zeiss/typhoon/api/schemas
9 changes: 9 additions & 0 deletions api/gen.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
//go:build generate
// +build generate

package api

//go:generate npx -y @redocly/openapi-cli@latest bundle api.yml -o out.yml
//go:generate go run -modfile ../tools/go.mod github.com/deepmap/oapi-codegen/v2/cmd/oapi-codegen -config config.client.yml out.yml
//go:generate go run -modfile ../tools/go.mod github.com/deepmap/oapi-codegen/v2/cmd/oapi-codegen -config config.server.yml out.yml
//go:generate go run -modfile ../tools/go.mod github.com/deepmap/oapi-codegen/v2/cmd/oapi-codegen -config config.models.yml out.yml
Loading

0 comments on commit 0a522cd

Please sign in to comment.