Skip to content

Commit 9dddc2b

Browse files
committed
Replace "go-swagger" by "openapi-generator".
1 parent ef20eb0 commit 9dddc2b

File tree

9 files changed

+34
-123
lines changed

9 files changed

+34
-123
lines changed

.gitignore

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,2 @@
11
.DS_Store
2-
.env
3-
.gobincache/
2+
/.env

.openapi-generator-ignore

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# Already part of the project
2+
/.gitignore
3+
/api/openapi.yaml
4+
/README.md
5+
6+
# Unwanted
7+
/.travis.yml
8+
/git_push.sh

.openapi-generator/config.yaml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
generatorName: go
2+
3+
gitHost: github.com
4+
gitUserId: netbox-community
5+
gitRepoId: go-netbox/v3
6+
7+
packageName: netbox
8+
9+
additionalProperties:
10+
disallowAdditionalPropertiesIfNotPresent: "false"
11+
packageVersion: "3"

Dockerfile

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
1-
ARG GO_VERSION=1.20.1
2-
ARG ALPINE_VERSION=3.17
3-
ARG GOIMPORTS_VERSION=0.6.0
4-
ARG DELVE_VERSION=1.20.1
5-
ARG SWAGGER_VERSION=0.30.4
1+
ARG GO_VERSION=1.21.0-alpine3.18
2+
ARG GOIMPORTS_VERSION=0.12.0
3+
ARG DELVE_VERSION=1.21.0
64

75

86
## Base image
9-
FROM golang:${GO_VERSION}-alpine${ALPINE_VERSION} AS base
7+
FROM golang:${GO_VERSION} AS base
108

119
WORKDIR /go/src/app
1210

@@ -18,7 +16,6 @@ FROM base AS development
1816

1917
ARG GOIMPORTS_VERSION
2018
ARG DELVE_VERSION
21-
ARG SWAGGER_VERSION
2219

2320
RUN apk add \
2421
bash \
@@ -28,8 +25,7 @@ RUN apk add \
2825
python3 \
2926
zsh \
3027
&& go install golang.org/x/tools/cmd/goimports@v${GOIMPORTS_VERSION} \
31-
&& go install github.com/go-delve/delve/cmd/dlv@v${DELVE_VERSION} \
32-
&& go install github.com/go-swagger/go-swagger/cmd/swagger@v${SWAGGER_VERSION}
28+
&& go install github.com/go-delve/delve/cmd/dlv@v${DELVE_VERSION}
3329

3430
ARG USER_ID=1000
3531
ENV USER_NAME=default

Makefile

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,10 @@ shell:
3333
build:
3434
$(EXEC) ./scripts/set-versions.sh $(NETBOX_VERSION) $(NETBOX_DOCKER_VERSION)
3535
./scripts/fetch-spec.sh $$(cat api/netbox_version) $$(cat api/netbox_docker_version)
36-
$(EXEC) ./scripts/generate-code.sh
36+
./scripts/generate-code.sh
37+
$(EXEC) go mod tidy
38+
$(EXEC) goimports -w .
3739

3840
.PHONY: test
3941
test:
40-
$(EXEC) go test ./... -tags=integration
42+
$(EXEC) go test -v ./...

assets/copyright_header.txt

Lines changed: 0 additions & 13 deletions
This file was deleted.

examples/customhost/customhost.go

Lines changed: 0 additions & 36 deletions
This file was deleted.

examples/debugflag/debugflag.go

Lines changed: 0 additions & 39 deletions
This file was deleted.

scripts/generate-code.sh

Lines changed: 5 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -2,25 +2,8 @@
22

33
set -euo pipefail
44

5-
export SRC_DIR='./netbox'
6-
7-
# Prepare environment
8-
rm -rf netbox/client netbox/models
9-
go mod download
10-
11-
# Run pre-generation hooks
12-
for SCRIPT in scripts/pre-generation/*; do
13-
"${SCRIPT}"
14-
done
15-
16-
# Generate code
17-
swagger generate client -f api/openapi.json --target="${SRC_DIR}" --copyright-file=assets/copyright_header.txt
18-
go mod tidy
19-
20-
# Run post-generation hooks
21-
for SCRIPT in scripts/post-generation/*; do
22-
"${SCRIPT}"
23-
done
24-
25-
# Format generated code and fix imports
26-
goimports -w "${SRC_DIR}"
5+
docker run --rm -v "${PWD}:/local" openapitools/openapi-generator-cli:v6.6.0 generate \
6+
--config /local/.openapi-generator/config.yaml \
7+
--input-spec /local/api/openapi.yaml \
8+
--output /local \
9+
--http-user-agent go-netbox/$(cat api/netbox_version)

0 commit comments

Comments
 (0)