Skip to content

Commit 37834cd

Browse files
authored
Revert "merge master to v2 (#1903)" (#1906)
This reverts commit 7b50e07.
1 parent 7b50e07 commit 37834cd

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

68 files changed

+721
-4141
lines changed

.github/workflows/ci.yml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ jobs:
1010
test:
1111
strategy:
1212
matrix:
13-
go: [ '1.19.x', '1.20.x', '1.21.x', '1.22.x' ]
13+
go: [ '1.18.x', '1.19.x', '1.20.x' ]
1414
platform: [ubuntu-latest, macos-latest]
1515
runs-on: ${{ matrix.platform }}
1616
steps:
@@ -22,7 +22,8 @@ jobs:
2222
- name: deps
2323
run: make deps
2424
- name: static program analysis
25-
run: make fmt-check vet
25+
run: |
26+
make fmt-check lint vet
2627
- name: build
2728
run: make build
2829
- name: test

.github/workflows/docker.yml

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,44 +5,38 @@ on:
55
tags:
66
- 'v*'
77

8-
permissions:
9-
contents: read
10-
packages: write
11-
128
jobs:
139
docker-build:
1410
runs-on: ubuntu-latest
1511
steps:
1612
- name: Checkout code
17-
uses: actions/checkout@v4
13+
uses: actions/checkout@v3
1814

1915
- name: Set up Docker Buildx
2016
id: buildx
21-
uses: docker/setup-buildx-action@v3
17+
uses: docker/setup-buildx-action@v2
2218

2319
- name: Login to Github Packages
24-
uses: docker/login-action@v3
20+
uses: docker/login-action@v2
2521
with:
2622
registry: ghcr.io
2723
username: ${{ github.actor }}
2824
password: ${{ secrets.GITHUB_TOKEN }}
2925

3026
- name: Docker meta
3127
id: meta
32-
uses: docker/metadata-action@v5
28+
uses: docker/metadata-action@v4
3329
with:
3430
images: ghcr.io/swaggo/swag
3531

3632
- name: Build image and push to GitHub Container Registry
37-
id: docker_build
38-
uses: docker/build-push-action@v5
33+
uses: docker/build-push-action@v2
3934
with:
4035
context: .
41-
platforms: linux/amd64,linux/arm64
4236
push: true
4337
tags: |
44-
ghcr.io/${{ github.repository }}:latest
45-
ghcr.io/${{ github.repository }}:${{github.ref_name}}
38+
ghcr.io/swaggo/swag:latest
39+
ghcr.io/swaggo/swag:${{github.ref_name}}
4640
labels: ${{ steps.meta.outputs.labels }}
4741

4842
- name: Image digest

Dockerfile

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# Dockerfile References: https://docs.docker.com/engine/reference/builder/
22

33
# Start from the latest golang base image
4-
FROM --platform=$BUILDPLATFORM golang:1.21-alpine as builder
4+
FROM golang:1.18.3-alpine as builder
55

66
# Set the Current Working Directory inside the container
77
WORKDIR /app
@@ -15,22 +15,14 @@ RUN go mod download
1515
# Copy the source from the current directory to the Working Directory inside the container
1616
COPY . .
1717

18-
# Configure go compiler target platform
19-
ARG TARGETOS
20-
ARG TARGETARCH
21-
ENV GOARCH=$TARGETARCH \
22-
GOOS=$TARGETOS
23-
2418
# Build the Go app
2519
RUN CGO_ENABLED=0 GOOS=linux go build -v -a -installsuffix cgo -o swag cmd/swag/main.go
2620

2721

2822
######## Start a new stage from scratch #######
29-
FROM --platform=$TARGETPLATFORM scratch
23+
FROM scratch
3024

31-
WORKDIR /code/
25+
WORKDIR /root/
3226

3327
# Copy the Pre-built binary file from the previous stage
34-
COPY --from=builder /app/swag /bin/swag
35-
36-
ENTRYPOINT ["/bin/swag"]
28+
COPY --from=builder /app/swag .

Makefile

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ GOBUILD:=$(GOCMD) build
66
GOINSTALL:=$(GOCMD) install
77
GOCLEAN:=$(GOCMD) clean
88
GOTEST:=$(GOCMD) test
9-
GOMODTIDY:=$(GOCMD) mod tidy
109
GOGET:=$(GOCMD) get
1110
GOLIST:=$(GOCMD) list
1211
GOVET:=$(GOCMD) vet
@@ -17,6 +16,8 @@ BINARY_NAME:=swag
1716
PACKAGES:=$(shell $(GOLIST) github.com/swaggo/swag/v2 github.com/swaggo/swag/v2/cmd/swag github.com/swaggo/swag/v2/gen github.com/swaggo/swag/v2/format)
1817
GOFILES:=$(shell find . -name "*.go" -type f)
1918

19+
export GO111MODULE := on
20+
2021
all: test build
2122

2223
.PHONY: build
@@ -53,10 +54,25 @@ clean:
5354

5455
.PHONY: deps
5556
deps:
56-
$(GOMODTIDY)
57+
$(GOGET) github.com/swaggo/cli
58+
$(GOGET) sigs.k8s.io/yaml
59+
$(GOGET) github.com/KyleBanks/depth
60+
$(GOGET) github.com/go-openapi/jsonreference
61+
$(GOGET) github.com/go-openapi/spec
62+
$(GOGET) github.com/stretchr/testify/assert
63+
$(GOGET) golang.org/x/tools/go/loader
64+
65+
.PHONY: devel-deps
66+
devel-deps:
67+
GO111MODULE=off $(GOGET) -v -u \
68+
golang.org/x/lint/golint
69+
70+
.PHONY: lint
71+
lint: devel-deps
72+
for PKG in $(PACKAGES); do golint -set_exit_status $$PKG || exit 1; done;
5773

5874
.PHONY: vet
59-
vet: deps
75+
vet: deps devel-deps
6076
$(GOVET) $(PACKAGES)
6177

6278
.PHONY: fmt

README.md

Lines changed: 23 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,7 @@ Swag converts Go annotations to Swagger Documentation 2.0. We've created a varie
4242
- [User defined structure with an array type](#user-defined-structure-with-an-array-type)
4343
- [Function scoped struct declaration](#function-scoped-struct-declaration)
4444
- [Model composition in response](#model-composition-in-response)
45-
- [Add headers in request](#add-request-headers)
46-
- [Add headers in response](#add-a-headers-in-response)
45+
- [Add a headers in response](#add-a-headers-in-response)
4746
- [Use multiple path params](#use-multiple-path-params)
4847
- [Add multiple paths](#add-multiple-paths)
4948
- [Example value of struct](#example-value-of-struct)
@@ -57,7 +56,6 @@ Swag converts Go annotations to Swagger Documentation 2.0. We've created a varie
5756
- [How to use security annotations](#how-to-use-security-annotations)
5857
- [Add a description for enum items](#add-a-description-for-enum-items)
5958
- [Generate only specific docs file types](#generate-only-specific-docs-file-types)
60-
- [How to use Go generic types](#how-to-use-generics)
6159
- [Change the default Go Template action delimiters](#change-the-default-go-template-action-delimiters)
6260
- [About the Project](#about-the-project)
6361
- [Contributors](#contributors)
@@ -69,16 +67,11 @@ Swag converts Go annotations to Swagger Documentation 2.0. We've created a varie
6967

7068
1. Add comments to your API source code, See [Declarative Comments Format](#declarative-comments-format).
7169

72-
2. Install swag by using:
70+
2. Download swag by using:
7371
```sh
7472
go install github.com/swaggo/swag/v2/cmd/swag@latest
7573
```
76-
To build from source you need [Go](https://golang.org/dl/) (1.19 or newer).
77-
78-
Alternatively you can run the docker image:
79-
```sh
80-
docker run --rm -v $(pwd):/code ghcr.io/swaggo/swag:latest
81-
```
74+
To build from source you need [Go](https://golang.org/dl/) (1.18 or newer).
8275

8376
Or download a pre-compiled binary from the [release page](https://github.com/swaggo/swag/releases).
8477

@@ -88,9 +81,6 @@ swag init
8881
```
8982

9083
Make sure to import the generated `docs/docs.go` so that your specific configuration gets `init`'ed. If your General API annotations do not live in `main.go`, you can let swag know with `-g` flag.
91-
```go
92-
import _ "example-module-name/docs"
93-
```
9484
```sh
9585
swag init -g http/api.go
9686
```
@@ -122,7 +112,6 @@ OPTIONS:
122112
--outputTypes value, --ot value Output types of generated files (docs.go, swagger.json, swagger.yaml) like go,json,yaml (default: "go,json,yaml")
123113
--parseVendor Parse go files in 'vendor' folder, disabled by default (default: false)
124114
--parseDependency, --pd Parse go files inside dependency folder, disabled by default (default: false)
125-
--parseDependencyLevel, --pdl Enhancement of '--parseDependency', parse go files inside dependency folder, 0 disabled, 1 only parse models, 2 only parse operations, 3 parse all (default: 0)
126115
--markdownFiles value, --md value Parse folder containing markdown files to use as description, disabled by default
127116
--codeExampleFiles value, --cef value Parse folder containing code example files to use for the x-codeSamples extension, disabled by default
128117
--parseInternal Parse go files in internal packages, disabled by default (default: false)
@@ -136,9 +125,6 @@ OPTIONS:
136125
--tags value, -t value A comma-separated list of tags to filter the APIs for which the documentation is generated.Special case if the tag is prefixed with the '!' character then the APIs with that tag will be excluded
137126
--v3.1 Generate OpenAPI V3.1 spec (default: false)
138127
--templateDelims value, --td value Provide custom delimeters for Go template generation. The format is leftDelim,rightDelim. For example: "[[,]]"
139-
--collectionFormat value, --cf value Set default collection format (default: "csv")
140-
--state value Initial state for the state machine (default: ""), @HostState in root file, @State in other files
141-
--parseFuncBody Parse API info within body of functions in go files, disabled by default (default: false)
142128
--packageName --output A package name of docs.go, using output directory name by default (check --output option)
143129
--collectionFormat value, --cf value Set default collection format (default: "csv")
144130
--help, -h show help
@@ -177,7 +163,6 @@ OPTIONS:
177163
178164
Find the example source code [here](https://github.com/swaggo/swag/tree/master/example/celler).
179165
180-
Finish the steps in [Getting started](#getting-started)
181166
1. After using `swag init` to generate Swagger 2.0 docs, import the following packages:
182167
```go
183168
import "github.com/swaggo/gin-swagger" // gin-swagger middleware
@@ -458,26 +443,25 @@ The following annotations are only available if you set the -v3.1 flag in the CL
458443
[celler/controller](https://github.com/swaggo/swag/tree/master/example/celler/controller)
459444
460445
461-
| annotation | description |
462-
|----------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
463-
| description | A verbose explanation of the operation behavior. |
464-
| description.markdown | A short description of the application. The description will be read from a file. E.g. `@description.markdown details` will load `details.md` | // @description.file endpoint.description.markdown |
465-
| id | A unique string used to identify the operation. Must be unique among all API operations. |
466-
| tags | A list of tags to each API operation that separated by commas. |
467-
| summary | A short summary of what the operation does. |
468-
| accept | A list of MIME types the APIs can consume. Note that Accept only affects operations with a request body, such as POST, PUT and PATCH. Value MUST be as described under [Mime Types](#mime-types). |
469-
| produce | A list of MIME types the APIs can produce. Value MUST be as described under [Mime Types](#mime-types). |
470-
| param | Parameters that separated by spaces. `param name`,`param type`,`data type`,`is mandatory?`,`comment` `attribute(optional)` |
471-
| security | [Security](#security) to each API operation. |
472-
| success | Success response that separated by spaces. `return code or default`,`{param type}`,`data type`,`comment` |
473-
| failure | Failure response that separated by spaces. `return code or default`,`{param type}`,`data type`,`comment` |
474-
| response | As same as `success` and `failure` |
475-
| header | Header in response that separated by spaces. `return code`,`{param type}`,`data type`,`comment` |
476-
| router | Path definition that separated by spaces. `path`,`[httpMethod]` |
477-
| deprecatedrouter | As same as router, but deprecated. |
478-
| x-name | The extension key, must be start by x- and take only json value. |
479-
| x-codeSample | Optional Markdown usage. take `file` as parameter. This will then search for a file named like the summary in the given folder. |
480-
| deprecated | Mark endpoint as deprecated. |
446+
| annotation | description |
447+
|-------------|----------------------------------------------------------------------------------------------------------------------------|
448+
| description | A verbose explanation of the operation behavior. |
449+
| description.markdown | A short description of the application. The description will be read from a file. E.g. `@description.markdown details` will load `details.md`| // @description.file endpoint.description.markdown |
450+
| id | A unique string used to identify the operation. Must be unique among all API operations. |
451+
| tags | A list of tags to each API operation that separated by commas. |
452+
| summary | A short summary of what the operation does. |
453+
| accept | A list of MIME types the APIs can consume. Note that Accept only affects operations with a request body, such as POST, PUT and PATCH. Value MUST be as described under [Mime Types](#mime-types). |
454+
| produce | A list of MIME types the APIs can produce. Value MUST be as described under [Mime Types](#mime-types). |
455+
| param | Parameters that separated by spaces. `param name`,`param type`,`data type`,`is mandatory?`,`comment` `attribute(optional)` |
456+
| security | [Security](#security) to each API operation. |
457+
| success | Success response that separated by spaces. `return code or default`,`{param type}`,`data type`,`comment` |
458+
| failure | Failure response that separated by spaces. `return code or default`,`{param type}`,`data type`,`comment` |
459+
| response | As same as `success` and `failure` |
460+
| header | Header in response that separated by spaces. `return code`,`{param type}`,`data type`,`comment` |
461+
| router | Path definition that separated by spaces. `path`,`[httpMethod]` |
462+
| x-name | The extension key, must be start by x- and take only json value. |
463+
| x-codeSample | Optional Markdown usage. take `file` as parameter. This will then search for a file named like the summary in the given folder. |
464+
| deprecated | Mark endpoint as deprecated. |
481465
482466
483467
@@ -679,14 +663,7 @@ type DeepObject struct { //in `proto` package
679663
}
680664
@success 200 {object} jsonresult.JSONResult{data1=proto.Order{data=proto.DeepObject},data2=[]proto.Order{data=[]proto.DeepObject}} "desc"
681665
```
682-
### Add response request
683-
684-
```go
685-
// @Param X-MyHeader header string true "MyHeader must be set for valid response"
686-
// @Param X-API-VERSION header string true "API version eg.: 1.0"
687-
```
688-
689-
### Add response headers
666+
### Add a headers in response
690667
691668
```go
692669
// @Success 200 {string} string "ok"
@@ -962,19 +939,6 @@ By default `swag` command generates Swagger specification in three different fil
962939
963940
If you would like to limit a set of file types which should be generated you can use `--outputTypes` (short `-ot`) flag. Default value is `go,json,yaml` - output types separated with comma. To limit output only to `go` and `yaml` files, you would write `go,yaml`. With complete command that would be `swag init --outputTypes go,yaml`.
964941
965-
### How to use Generics
966-
967-
```go
968-
// @Success 200 {object} web.GenericNestedResponse[types.Post]
969-
// @Success 204 {object} web.GenericNestedResponse[types.Post, Types.AnotherOne]
970-
// @Success 201 {object} web.GenericNestedResponse[web.GenericInnerType[types.Post]]
971-
func GetPosts(w http.ResponseWriter, r *http.Request) {
972-
_ = web.GenericNestedResponse[types.Post]{}
973-
}
974-
```
975-
See [this file](https://github.com/swaggo/swag/blob/master/testdata/generics_nested/api/api.go) for more details
976-
and other examples.
977-
978942
### Change the default Go Template action delimiters
979943
[#980](https://github.com/swaggo/swag/issues/980)
980944
[#1177](https://github.com/swaggo/swag/issues/1177)
@@ -987,17 +951,6 @@ swag init -g http/api.go -td "[[,]]"
987951
```
988952
The new delimiter is a string with the format "`<left delimiter>`,`<right delimiter>`".
989953
990-
### Parse Internal and Dependency Packages
991-
992-
If the struct is defined in a dependency package, use `--parseDependency`.
993-
994-
If the struct is defined in your main project, use `--parseInternal`.
995-
996-
if you want to include both internal and from dependencies use both flags
997-
```
998-
swag init --parseDependency --parseInternal
999-
```
1000-
1001954
## About the Project
1002955
This project was inspired by [yvasiyarov/swagger](https://github.com/yvasiyarov/swagger) but we simplified the usage and added support a variety of [web frameworks](#supported-web-frameworks). Gopher image source is [tenntenn/gopher-stickers](https://github.com/tenntenn/gopher-stickers). It has licenses [creative commons licensing](http://creativecommons.org/licenses/by/3.0/deed.en).
1003956
## Contributors

0 commit comments

Comments
 (0)