Skip to content

Commit 410182e

Browse files
committed
chore: import codescan fixtures from go-swagger/go-swagger with full history
2 parents 1250a36 + 452f80e commit 410182e

67 files changed

Lines changed: 5616 additions & 0 deletions

Some content is hidden

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

fixtures/bugs/2540/foo/examples.go

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
// Package docs SwagTest
2+
//
3+
// Test Swagger
4+
//
5+
// Schemes: https
6+
// Version: 1.0.0
7+
// BasePath: /test/
8+
//
9+
// Consumes:
10+
// - application/json
11+
//
12+
// Produces:
13+
// - application/json
14+
//
15+
// swagger:meta
16+
package foo
17+
18+
// swagger:route GET /book book
19+
// Get book
20+
// responses:
21+
// 200: getBook
22+
23+
type Author struct {
24+
Name string
25+
}
26+
27+
// Book holds all relevant information about a book.
28+
//
29+
// At this moment, a book is only described by its publishing date
30+
// and author.
31+
//
32+
// example: { "Published": 2026, "Author": "Fred" }
33+
//
34+
// default: { "Published": 1900, "Author": "Unknown" }
35+
//
36+
// swagger:model
37+
type Book struct {
38+
// min: 0
39+
//
40+
// example: 2021
41+
Published int
42+
// example: { "Name": "Tolkien" }
43+
Author Author
44+
}
45+
46+
// OK.
47+
// swagger:response getBook
48+
type response struct {
49+
// in:body
50+
Body Book
51+
}

fixtures/bugs/3125/full/api/api.go

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
//go:build testintegration
2+
3+
package api
4+
5+
import (
6+
"encoding/json"
7+
"fmt"
8+
"net/http"
9+
"strconv"
10+
)
11+
12+
type User struct {
13+
Name string `json:"name"`
14+
Age int `json:"age"`
15+
}
16+
17+
// FooBarRequest represents body of FooBar request.
18+
type FooBarRequest struct {
19+
// Foo param
20+
Foo string `json:"foo"`
21+
// Bar params
22+
Bar []int `json:"bar"`
23+
// User param
24+
User User `json:"user"`
25+
}
26+
27+
// FooBarResponse represents body of FooBar response.
28+
type FooBarResponse struct {
29+
Baz struct {
30+
Prop string `json:"prop"`
31+
} `json:"baz"`
32+
}
33+
34+
// FooBarHandler handles incoming foobar requests
35+
func FooBarHandler(w http.ResponseWriter, req *http.Request) {
36+
if err := req.ParseForm(); err != nil {
37+
http.Error(w, fmt.Sprintf("%s: %v", http.StatusText(http.StatusBadRequest), err), http.StatusBadRequest)
38+
return
39+
}
40+
raw := req.FormValue("age")
41+
age, err := strconv.Atoi(raw)
42+
if err != nil {
43+
http.Error(w, fmt.Sprintf("%s: %v", http.StatusText(http.StatusBadRequest), err), http.StatusBadRequest)
44+
return
45+
}
46+
47+
r := FooBarRequest{
48+
Foo: req.FormValue("foo"),
49+
User: User{
50+
Name: req.FormValue("name"),
51+
Age: age,
52+
},
53+
}
54+
55+
resp := doSthWithRequest(r)
56+
57+
enc := json.NewEncoder(w)
58+
err = enc.Encode(resp)
59+
if err != nil {
60+
http.Error(w, fmt.Sprintf("%s: %v", http.StatusText(http.StatusInternalServerError), err), http.StatusInternalServerError)
61+
return
62+
}
63+
}
64+
65+
func doSthWithRequest(req FooBarRequest) FooBarResponse {
66+
return FooBarResponse{}
67+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
//go:build testintegration
2+
3+
// Package classification awesome.
4+
//
5+
// Documentation of our awesome API.
6+
//
7+
// Schemes: http
8+
// BasePath: /
9+
// Version: 1.0.0
10+
// Host: some-url.com
11+
//
12+
// Consumes:
13+
// - application/json
14+
//
15+
// Produces:
16+
// - application/json
17+
//
18+
// Security:
19+
// - basic
20+
//
21+
// SecurityDefinitions:
22+
// basic:
23+
// type: basic
24+
//
25+
// swagger:meta
26+
package docs
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
//go:build testintegration
2+
3+
package docs
4+
5+
import "swagger/api"
6+
7+
// swagger:route POST /foobar foobar-tag idOfFoobarEndpoint
8+
// Foobar does some amazing stuff.
9+
// responses:
10+
// 200: foobarResponse
11+
12+
// This text will appear as description of your response body.
13+
// swagger:response foobarResponse
14+
type foobarResponseWrapper struct {
15+
// in:body
16+
Body api.FooBarResponse
17+
}
18+
19+
// swagger:parameters idOfFoobarEndpoint
20+
type foobarParamsWrapper struct {
21+
// This text will appear as description of your request body.
22+
// in:body
23+
Body api.FooBarRequest
24+
}
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
basePath: /
2+
consumes:
3+
- application/json
4+
definitions:
5+
FooBarRequest:
6+
properties:
7+
bar:
8+
description: Bar params
9+
items:
10+
format: int64
11+
type: integer
12+
type: array
13+
x-go-name: Bar
14+
foo:
15+
description: Foo param
16+
type: string
17+
x-go-name: Foo
18+
user:
19+
description: User param
20+
$ref: '#/definitions/User'
21+
title: FooBarRequest represents body of FooBar request.
22+
type: object
23+
x-go-package: swagger/api
24+
FooBarResponse:
25+
properties:
26+
baz:
27+
properties:
28+
prop:
29+
type: string
30+
x-go-name: Prop
31+
type: object
32+
x-go-name: Baz
33+
title: FooBarResponse represents body of FooBar response.
34+
type: object
35+
x-go-package: swagger/api
36+
User:
37+
properties:
38+
age:
39+
format: int64
40+
type: integer
41+
x-go-name: Age
42+
name:
43+
type: string
44+
x-go-name: Name
45+
type: object
46+
x-go-package: swagger/api
47+
host: some-url.com
48+
info:
49+
description: Documentation of our awesome API.
50+
title: awesome.
51+
version: 1.0.0
52+
paths:
53+
/foobar:
54+
post:
55+
operationId: idOfFoobarEndpoint
56+
parameters:
57+
- description: This text will appear as description of your request body.
58+
in: body
59+
name: Body
60+
schema:
61+
$ref: '#/definitions/FooBarRequest'
62+
responses:
63+
"200":
64+
$ref: '#/responses/foobarResponse'
65+
summary: Foobar does some amazing stuff.
66+
tags:
67+
- foobar-tag
68+
produces:
69+
- application/json
70+
responses:
71+
foobarResponse:
72+
description: This text will appear as description of your response body.
73+
schema:
74+
$ref: '#/definitions/FooBarResponse'
75+
schemes:
76+
- http
77+
securityDefinitions:
78+
basic:
79+
type: basic
80+
swagger: "2.0"
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
basePath: /
2+
consumes:
3+
- application/json
4+
definitions:
5+
FooBarRequest:
6+
properties:
7+
bar:
8+
description: Bar params
9+
items:
10+
format: int64
11+
type: integer
12+
type: array
13+
x-go-name: Bar
14+
foo:
15+
description: Foo param
16+
type: string
17+
x-go-name: Foo
18+
user:
19+
$ref: '#/definitions/User'
20+
title: FooBarRequest represents body of FooBar request.
21+
type: object
22+
x-go-package: swagger/api
23+
FooBarResponse:
24+
properties:
25+
baz:
26+
properties:
27+
prop:
28+
type: string
29+
x-go-name: Prop
30+
type: object
31+
x-go-name: Baz
32+
title: FooBarResponse represents body of FooBar response.
33+
type: object
34+
x-go-package: swagger/api
35+
User:
36+
properties:
37+
age:
38+
format: int64
39+
type: integer
40+
x-go-name: Age
41+
name:
42+
type: string
43+
x-go-name: Name
44+
type: object
45+
x-go-package: swagger/api
46+
host: some-url.com
47+
info:
48+
description: Documentation of our awesome API.
49+
title: awesome.
50+
version: 1.0.0
51+
paths:
52+
/foobar:
53+
post:
54+
operationId: idOfFoobarEndpoint
55+
parameters:
56+
- description: This text will appear as description of your request body.
57+
in: body
58+
name: Body
59+
schema:
60+
$ref: '#/definitions/FooBarRequest'
61+
responses:
62+
"200":
63+
$ref: '#/responses/foobarResponse'
64+
summary: Foobar does some amazing stuff.
65+
tags:
66+
- foobar-tag
67+
produces:
68+
- application/json
69+
responses:
70+
foobarResponse:
71+
description: This text will appear as description of your response body.
72+
schema:
73+
$ref: '#/definitions/FooBarResponse'
74+
schemes:
75+
- http
76+
securityDefinitions:
77+
basic:
78+
type: basic
79+
swagger: "2.0"

fixtures/bugs/3125/full/main.go

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
//go:build testintegration
2+
3+
package main
4+
5+
import (
6+
"log"
7+
"net"
8+
"net/http"
9+
10+
"swagger/api"
11+
)
12+
13+
func main() {
14+
// Route => handler
15+
http.HandleFunc("POST /foobar", api.FooBarHandler)
16+
17+
// Start server
18+
listener, err := net.Listen("tcp", ":1323")
19+
if err != nil {
20+
log.Fatal(err)
21+
}
22+
23+
err = http.Serve(listener, nil)
24+
if err != nil {
25+
log.Fatal(err)
26+
}
27+
}

fixtures/bugs/3125/minimal/item.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package minimal
2+
3+
// swagger:model Item
4+
type Item struct {
5+
// Nullable value
6+
// required: true
7+
// Extensions:
8+
// ---
9+
// x-nullable: true
10+
Value1 *ValueStruct `json:"value1"`
11+
12+
// Non-nullable value
13+
// required: true
14+
// example: {"value": 42}
15+
Value2 ValueStruct `json:"value2"`
16+
}
17+
18+
type ValueStruct struct {
19+
Value int `json:"value"`
20+
}

0 commit comments

Comments
 (0)