Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implementing OpenAPI 3.1.0 spec #1513

Merged
merged 88 commits into from
Apr 5, 2023
Merged
Changes from 1 commit
Commits
Show all changes
88 commits
Select commit Hold shift + click to select a range
aa5a215
fix x-tagGroups
Jan 13, 2021
54bd4bc
Merge pull request #1 from Nerzal/fix-x-tagGroups
Nerzal Jan 13, 2021
96eee75
fix module name
Jan 13, 2021
f0b8625
change paths
Jan 13, 2021
9580174
refactoring
Feb 8, 2021
83a6083
update dependencies
Feb 8, 2021
1147eb4
stuff
Feb 8, 2021
0a23f2e
add log
Feb 8, 2021
73b57c7
fix finding of main file
Feb 8, 2021
98b6b59
fix broken type resolution
Feb 8, 2021
c40dc23
fix bug
Feb 8, 2021
4eccc19
clean deps
Feb 8, 2021
886e6d2
Merge remote-tracking branch 'original/master'
Dec 27, 2021
858f1d9
fix tool after merging upstream
Dec 27, 2021
e8e2bda
use json-iterator to marshal json
Dec 27, 2021
81f1d52
fix generating of json examples
Dec 27, 2021
1dfdb3b
update config used by jsoniter
Dec 27, 2021
4aa902e
bump version
Feb 14, 2022
fe64ddb
update dependencies
Feb 22, 2023
81a16c8
Merge remote-tracking branch 'original/master'
Mar 17, 2023
3a99229
resolve merge conflicts
Mar 17, 2023
473c027
use newest go in docker
Mar 17, 2023
d927e96
yep
Mar 17, 2023
72c5980
fix gen
Mar 17, 2023
d12dabb
fix gen
Mar 17, 2023
e67eeba
Merge pull request #4 from Nerzal/update
Nerzal Mar 17, 2023
0241617
update swag version
Mar 17, 2023
62d6ff8
yep
Mar 17, 2023
d0485ad
fix parser
Mar 17, 2023
f224910
fix some tests
Mar 17, 2023
7452c8e
fix all tests
Mar 17, 2023
1ea654a
parse most of general api description
Mar 17, 2023
d73aa63
implement security scheme parsing
Mar 17, 2023
1f830f5
parse oauth2 specs
Mar 17, 2023
31b3743
parse scopes and extensions in security schemes
Mar 20, 2023
20df8ef
extend parsing security stuff
Mar 20, 2023
5bf301f
process v3 routes
Mar 20, 2023
945d27a
meh
Mar 20, 2023
58e12ac
find unimported types
Mar 20, 2023
215a455
parse basic operation info
Mar 21, 2023
c50add5
parse primitive and object parameters
Mar 21, 2023
ca4d32a
generate openapi spec
Mar 21, 2023
24fb27b
fix module name
Mar 23, 2023
7c46c69
cleanup
Mar 23, 2023
2360bad
update version to 2.0
Mar 23, 2023
a720c2d
Merge remote-tracking branch 'original/master' into v2
Mar 23, 2023
a2fe9e4
fix issues that appread after merging
Mar 23, 2023
626b69e
cleanup after merge conflicts
Mar 23, 2023
d7e81dd
fix all tests
Mar 23, 2023
8295590
add go 1.19 to workflows
Mar 23, 2023
94b9ee9
pin dockerfile to 1.19.7
Mar 23, 2023
b7c4572
Set minimum supported Go version to 1.18.x
Mar 23, 2023
ab124a1
parse response headers
Mar 23, 2023
4c4d6e0
copy readme
Mar 23, 2023
abc2f72
started to implement field parser
Mar 24, 2023
f38d587
Refactor: use RefOrSpec instead of Spec
Mar 24, 2023
6029f39
start to add tests for operationv3
Mar 24, 2023
27f62ff
fix tests
Mar 24, 2023
7cabc5f
implement allOf with primitive types
Mar 27, 2023
86a243e
Add NestedPrimitiveArrayType test
Mar 27, 2023
020e074
implement TestParseResponseCommentWithNestedFieldsV3
Mar 27, 2023
c794db3
add more tests
Mar 27, 2023
7a0bcc3
parse arrays and maps
Mar 28, 2023
d27ee31
fix implementation of map types
Mar 28, 2023
d5da469
implement more tests
Mar 28, 2023
85002f8
fix example docs
Mar 28, 2023
2f858ed
adjust example
Mar 28, 2023
8332a60
fix example jsons
Mar 28, 2023
7659574
support array types in Parameters
Mar 29, 2023
d04f558
implement more tests, implement correct collectionFormat handling
Mar 29, 2023
bcf2021
finish implementation of operationv3 tests
Mar 30, 2023
407063b
all tests green
Mar 30, 2023
2b137af
fix parsing of security definitions
Mar 30, 2023
4ce39e9
add test for generalAPI info
Mar 30, 2023
803f803
end of day checkin
Mar 30, 2023
8e1fcdc
Update example.json
Nerzal Mar 30, 2023
241f88a
fix codeSamples from file and fix creation of operations
Mar 31, 2023
ae4ecdc
fix resolving of schema ref errors
Mar 31, 2023
dff93ec
fix tests that broke due to fixes on model parsing
Apr 5, 2023
39e6fc4
Fix creating schemes of array types of custom objects
Apr 5, 2023
bb41478
Fix resolution of refSchemas
Apr 5, 2023
53453fc
cleanup
Apr 5, 2023
32244b1
update dependencies
Apr 5, 2023
84b5327
cleanup
Apr 5, 2023
fa3a0b9
Update README.md
Nerzal Apr 5, 2023
42d47ca
Update README_zh-CN.md
Nerzal Apr 5, 2023
1281122
update dependency
Apr 5, 2023
a99131d
reset test file
Apr 5, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Merge remote-tracking branch 'original/master'
Tobias Theel committed Mar 17, 2023

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
commit 81a16c842cd583daa73e2d66cdd6ceb8b6cc94da
6 changes: 3 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -10,15 +10,15 @@ jobs:
test:
strategy:
matrix:
go: [ '1.14.x', '1.15.x', '1.16.x', '1.17.x' ]
go: [ '1.16.x', '1.17.x', '1.18.x' ]
platform: [ubuntu-latest, macos-latest]
runs-on: ${{ matrix.platform }}
steps:
- uses: actions/checkout@master
- uses: actions/checkout@v3
with:
path: ./src/github.com/${{ github.repository }}
- name: Set up Go
uses: actions/setup-go@v1
uses: actions/setup-go@v3
with:
go-version: ${{ matrix.go }}
- name: deps
43 changes: 43 additions & 0 deletions .github/workflows/docker.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
name: docker

on:
push:
tags:
- 'v*'

jobs:
docker-build:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v3

- name: Set up Docker Buildx
id: buildx
uses: docker/setup-buildx-action@v2

- name: Login to Github Packages
uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Docker meta
id: meta
uses: docker/metadata-action@v4
with:
images: ghcr.io/swaggo/swag

- name: Build image and push to GitHub Container Registry
uses: docker/build-push-action@v2
with:
context: .
push: true
tags: |
ghcr.io/swaggo/swag:latest
ghcr.io/swaggo/swag:${{github.ref_name}}
labels: ${{ steps.meta.outputs.labels }}

- name: Image digest
run: echo ${{ steps.docker_build.outputs.digest }}
21 changes: 10 additions & 11 deletions .goreleaser.yml
Original file line number Diff line number Diff line change
@@ -7,18 +7,17 @@ build:
- amd64
- arm64
- 386
ignore:
- goos: darwin
goarch: arm64
env:
- CGO_ENABLED=0

archives:
-
replacements:
darwin: Darwin
linux: Linux
windows: Windows
386: i386
amd64: x86_64
arm64: aarch64
- id: foo
name_template: >-
{{ .ProjectName }}_
{{- .Version }}_
{{- if eq .Os "linux"}}Linux{{ else if eq .Os "darwin"}}Darwin{{ else }}{{ .Os }}{{ end }}_
{{- if eq .Arch "386" }}i386{{ else if eq .Arch "amd64" }}x86_64{{ else }}{{ .Arch }}{{ end }}

checksum:
name_template: 'checksums.txt'
snapshot:
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Dockerfile References: https://docs.docker.com/engine/reference/builder/

# Start from the latest golang base image
FROM golang:1.17-alpine as builder
FROM golang:1.18.3-alpine as builder

# Set the Current Working Directory inside the container
WORKDIR /app
6 changes: 3 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
@@ -63,9 +63,9 @@ deps:
$(GOGET) golang.org/x/tools/go/loader

.PHONY: devel-deps
devel-deps:
devel-deps:
GO111MODULE=off $(GOGET) -v -u \
golang.org/x/lint/golint
golang.org/x/lint/golint

.PHONY: lint
lint: devel-deps
@@ -91,4 +91,4 @@ fmt-check:
.PHONY: view-covered
view-covered:
$(GOTEST) -coverprofile=cover.out $(TARGET)
$(GOCMD) tool cover -html=cover.out
$(GOCMD) tool cover -html=cover.out
187 changes: 149 additions & 38 deletions README.md

Large diffs are not rendered by default.

118 changes: 86 additions & 32 deletions cmd/swag/main.go
Original file line number Diff line number Diff line change
@@ -2,8 +2,10 @@ package main

import (
"fmt"
"io"
"log"
"os"
"strings"

"github.com/Nerzal/swag"
"github.com/Nerzal/swag/format"
@@ -13,23 +15,34 @@ import (
)

const (
searchDirFlag = "dir"
excludeFlag = "exclude"
generalInfoFlag = "generalInfo"
propertyStrategyFlag = "propertyStrategy"
outputFlag = "output"
parseVendorFlag = "parseVendor"
parseDependencyFlag = "parseDependency"
markdownFilesFlag = "markdownFiles"
codeExampleFilesFlag = "codeExampleFiles"
parseInternalFlag = "parseInternal"
generatedTimeFlag = "generatedTime"
parseDepthFlag = "parseDepth"
instanceNameFlag = "instanceName"
overridesFileFlag = "overridesFile"
searchDirFlag = "dir"
excludeFlag = "exclude"
generalInfoFlag = "generalInfo"
propertyStrategyFlag = "propertyStrategy"
outputFlag = "output"
outputTypesFlag = "outputTypes"
parseVendorFlag = "parseVendor"
parseDependencyFlag = "parseDependency"
markdownFilesFlag = "markdownFiles"
codeExampleFilesFlag = "codeExampleFiles"
parseInternalFlag = "parseInternal"
generatedTimeFlag = "generatedTime"
requiredByDefaultFlag = "requiredByDefault"
parseDepthFlag = "parseDepth"
instanceNameFlag = "instanceName"
overridesFileFlag = "overridesFile"
parseGoListFlag = "parseGoList"
quietFlag = "quiet"
tagsFlag = "tags"
parseExtensionFlag = "parseExtension"
)

var initFlags = []cli.Flag{
&cli.BoolFlag{
Name: quietFlag,
Aliases: []string{"q"},
Usage: "Make the logger quiet.",
},
&cli.StringFlag{
Name: generalInfoFlag,
Aliases: []string{"g"},
@@ -56,7 +69,13 @@ var initFlags = []cli.Flag{
Name: outputFlag,
Aliases: []string{"o"},
Value: "./docs",
Usage: "Output directory for all the generated files(swagger.json, swagger.yaml and doc.go)",
Usage: "Output directory for all the generated files(swagger.json, swagger.yaml and docs.go)",
},
&cli.StringFlag{
Name: outputTypesFlag,
Aliases: []string{"ot"},
Value: "go,json,yaml",
Usage: "Output types of generated files (docs.go, swagger.json, swagger.yaml) like go,json,yaml",
},
&cli.BoolFlag{
Name: parseVendorFlag,
@@ -92,6 +111,10 @@ var initFlags = []cli.Flag{
Value: 100,
Usage: "Dependency parse depth",
},
&cli.BoolFlag{
Name: requiredByDefaultFlag,
Usage: "Set validation required for all fields by default",
},
&cli.StringFlag{
Name: instanceNameFlag,
Value: "",
@@ -102,32 +125,63 @@ var initFlags = []cli.Flag{
Value: gen.DefaultOverridesFile,
Usage: "File to read global type overrides from.",
},
&cli.BoolFlag{
Name: parseGoListFlag,
Value: true,
Usage: "Parse dependency via 'go list'",
},
&cli.StringFlag{
Name: parseExtensionFlag,
Value: "",
Usage: "Parse only those operations that match given extension",
},
&cli.StringFlag{
Name: tagsFlag,
Aliases: []string{"t"},
Value: "",
Usage: "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",
},
}

func initAction(c *cli.Context) error {
strategy := c.String(propertyStrategyFlag)
func initAction(ctx *cli.Context) error {
strategy := ctx.String(propertyStrategyFlag)

switch strategy {
case swag.CamelCase, swag.SnakeCase, swag.PascalCase:
default:
return fmt.Errorf("not supported %s propertyStrategy", strategy)
}

outputTypes := strings.Split(ctx.String(outputTypesFlag), ",")
if len(outputTypes) == 0 {
return fmt.Errorf("no output types specified")
}
logger := log.New(os.Stdout, "", log.LstdFlags)
if ctx.Bool(quietFlag) {
logger = log.New(io.Discard, "", log.LstdFlags)
}

return gen.New().Build(&gen.Config{
SearchDir: c.String(searchDirFlag),
Excludes: c.String(excludeFlag),
MainAPIFile: c.String(generalInfoFlag),
SearchDir: ctx.String(searchDirFlag),
Excludes: ctx.String(excludeFlag),
ParseExtension: ctx.String(parseExtensionFlag),
MainAPIFile: ctx.String(generalInfoFlag),
PropNamingStrategy: strategy,
OutputDir: c.String(outputFlag),
ParseVendor: c.Bool(parseVendorFlag),
ParseDependency: c.Bool(parseDependencyFlag),
MarkdownFilesDir: c.String(markdownFilesFlag),
ParseInternal: c.Bool(parseInternalFlag),
GeneratedTime: c.Bool(generatedTimeFlag),
CodeExampleFilesDir: c.String(codeExampleFilesFlag),
ParseDepth: c.Int(parseDepthFlag),
InstanceName: c.String(instanceNameFlag),
OverridesFile: c.String(overridesFileFlag),
OutputDir: ctx.String(outputFlag),
OutputTypes: outputTypes,
ParseVendor: ctx.Bool(parseVendorFlag),
ParseDependency: ctx.Bool(parseDependencyFlag),
MarkdownFilesDir: ctx.String(markdownFilesFlag),
ParseInternal: ctx.Bool(parseInternalFlag),
GeneratedTime: ctx.Bool(generatedTimeFlag),
RequiredByDefault: ctx.Bool(requiredByDefaultFlag),
CodeExampleFilesDir: ctx.String(codeExampleFilesFlag),
ParseDepth: ctx.Int(parseDepthFlag),
InstanceName: ctx.String(instanceNameFlag),
OverridesFile: ctx.String(overridesFileFlag),
ParseGoList: ctx.Bool(parseGoListFlag),
Tags: ctx.String(tagsFlag),
Debugger: logger,
})
}

@@ -179,8 +233,8 @@ func main() {
},
},
}
err := app.Run(os.Args)
if err != nil {

if err := app.Run(os.Args); err != nil {
log.Fatal(err)
}
}
Loading
You are viewing a condensed version of this merge commit. You can view the full changes here.