Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
7 changes: 7 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,15 @@ linters:
- dupl # generated code has a lot of duplication
- err113 # generated code does not wrap errors
- exhaustruct # generated code does not initialize all fields
- forbidigo # in examples, we have a lot of printing and logging on purpose
- funlen # generated code produces long functions
- gochecknoglobals # generated code uses globals
- gochecknoinits # generated code uses init()
- gocognit # generated code has high cognitive complexity
- gocyclo # generated code has high cyclomatic complexity
- godox # allow TODOs
- gomodguard # deprecated
- gomodguard_v2 # we don't use this
- ireturn # generated code returns interfaces
- lll # generated code has long lines
- maintidx # generated code has low maintainability index
Expand All @@ -26,6 +29,7 @@ linters:
- noinlineerr # unclear added value
- paralleltest # no test files
- recvcheck # disagree
- tagalign # generated tags for jesssevdk CLI trigger this. To be investigated further (non-blocking)
- tagliatelle # false positives on generated tags
- testpackage # no test files
- thelper # no test files
Expand All @@ -46,6 +50,9 @@ linters:
goconst:
min-len: 2
min-occurrences: 3
gosec:
excludes:
- G706 # logs in examples are deliberately verbose and revealing of the internals
exclusions:
warn-unused: false
generated: lax
Expand Down
14 changes: 8 additions & 6 deletions 2.0/petstore/server/api/petstore.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

//nolint:forcetypeassert // type assertions left unchecked for brevity
package api

import (
Expand All @@ -26,10 +27,10 @@ import (
"github.com/go-openapi/runtime"
"github.com/go-openapi/runtime/middleware"
"github.com/go-openapi/runtime/middleware/untyped"
"github.com/go-openapi/swag"
"github.com/go-openapi/swag/jsonutils"
)

// NewPetstore creates a new petstore api handler
// NewPetstore creates a new petstore api handler.
func NewPetstore() (http.Handler, error) {
spec, err := loads.Analyzed(json.RawMessage([]byte(swaggerJSON)), "")
if err != nil {
Expand All @@ -56,7 +57,7 @@ var createPet = runtime.OperationHandlerFunc(func(data any) (any, error) {
fmt.Printf("%#v\n", data)
body := data.(map[string]any)["pet"]
var pet Pet
if err := swag.FromDynamicJSON(body, &pet); err != nil {
if err := jsonutils.FromDynamicJSON(body, &pet); err != nil {
return nil, err
}
addPet(pet)
Expand All @@ -68,7 +69,8 @@ var deletePet = runtime.OperationHandlerFunc(func(data any) (any, error) {
fmt.Printf("%#v\n", data)
id := data.(map[string]any)["id"].(int64)
removePet(id)
return nil, nil

return nil, nil //nolint:nilnil // for demo purpose we don't return any response
})

var getPetByID = runtime.OperationHandlerFunc(func(data any) (any, error) {
Expand All @@ -78,13 +80,13 @@ var getPetByID = runtime.OperationHandlerFunc(func(data any) (any, error) {
return petByID(id)
})

// Tag the tag model
// Tag the tag model.
type Tag struct {
ID int64
Name string
}

// Pet the pet model
// Pet the pet model.
type Pet struct {
ID int64 `json:"id"`
Name string `json:"name"`
Expand Down
16 changes: 16 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,22 @@ This software ships under the [SPDX-License-Identifier: Apache-2.0](./LICENSE).
* [Contributing guidelines](.github/CONTRIBUTING.md)
* [Code style](docs/STYLE.md)

## Regenerating all examples

```
go run ./hack/tools regen
```

To run examples, some of these require some auth material (not committed to this repo):
```
go run ./hack/tools gencerts
go run ./hack/tools gentokens
```

## Cutting a new release

This repository is deliberately left unreleased: examples follow the code generation on go-swagger/go-swagger@master.

<!-- Badges: status -->
[test-badge]: https://github.com/go-swagger/examples/actions/workflows/go-test.yml/badge.svg
[test-url]: https://github.com/go-swagger/examples/actions/workflows/go-test.yml
Expand Down
8 changes: 4 additions & 4 deletions alias-compatibility/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,13 @@
// swagger:meta
package demo

// Identifier represents a unique identifier
// Identifier represents a unique identifier.
type Identifier string

// UserID is an alias to Identifier for user-specific IDs
// UserID is an alias to Identifier for user-specific IDs.
type UserID = Identifier

// User represents a user in the system
// User represents a user in the system.
type User struct {
ID UserID `json:"id"`
Name string `json:"name"`
Expand All @@ -60,4 +60,4 @@ type UserResponse struct {
// Responses:
//
// 200: UserResponse
func getUser() {}
func getUser() {} //nolint:unused // left here to demonstrate what we get from an unexported symbol
1 change: 0 additions & 1 deletion authentication/client/auth_sample_client.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion authentication/client/customers/create_parameters.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion authentication/client/customers/create_responses.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion authentication/client/customers/get_id_parameters.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion authentication/client/customers/get_id_responses.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions authentication/models/customer.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions authentication/models/error.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions authentication/models/social_id.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion authentication/restapi/configure_auth_sample.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import (
//go:generate swagger generate server --target ../../authentication --name AuthSample --spec ../swagger.yml --principal models.Principal

func configureFlags(api *operations.AuthSampleAPI) {
// api.CommandLineOptionsGroups = []swag.CommandLineOptionsGroup{ ... }
// api.CommandLineOptionsGroups = []cmdutils.CommandLineOptionsGroup{ ... }
_ = api
}

Expand Down
4 changes: 2 additions & 2 deletions authentication/restapi/operations/auth_sample_api.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions authentication/restapi/server.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion auto-configure/implementation/auth_impl.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@ func (i *AuthImpl) KeyAuth(token string) (any, error) {
return nil, errors.New("wrong token")
}

// if return nil, nil, will cause 401 error
// if return nil value, will cause 401 error
return true, nil
}
4 changes: 2 additions & 2 deletions auto-configure/implementation/configure_impl.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"log"
"net/http"

"github.com/go-openapi/swag"
"github.com/go-openapi/swag/cmdutils"

"github.com/go-swagger/examples/auto-configure/restapi/operations"
)
Expand All @@ -20,7 +20,7 @@ type Flags struct {
}

func (i *ConfigureImpl) ConfigureFlags(api *operations.AToDoListApplicationAPI) {
api.CommandLineOptionsGroups = []swag.CommandLineOptionsGroup{
api.CommandLineOptionsGroups = []cmdutils.CommandLineOptionsGroup{
{
ShortDescription: "Example Flags",
LongDescription: "",
Expand Down
2 changes: 1 addition & 1 deletion auto-configure/implementation/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
)

// HandlerImpl implements all required configuration and api handling
// functionalities for todo list server backend
// functionalities for todo list server backend.
type HandlerImpl struct {
TodosHandlerImpl
ConfigureImpl
Expand Down
4 changes: 2 additions & 2 deletions auto-configure/implementation/todos_impl.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"sync"

"github.com/go-openapi/runtime/middleware"
"github.com/go-openapi/swag"
"github.com/go-openapi/swag/conv"

"github.com/go-swagger/examples/auto-configure/models"
"github.com/go-swagger/examples/auto-configure/restapi/operations/todos"
Expand Down Expand Up @@ -63,7 +63,7 @@ func (i *TodosHandlerImpl) FindTodos(params todos.FindTodosParams, principal any
i.lock.Lock()
defer i.lock.Unlock()
mergedParams := todos.NewFindTodosParams()
mergedParams.Since = swag.Int64(0)
mergedParams.Since = conv.Pointer(int64(0))
if params.Since != nil {
mergedParams.Since = params.Since
}
Expand Down
6 changes: 3 additions & 3 deletions auto-configure/models/error.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading