Skip to content

Commit

Permalink
[Gorilla] update the MiddlewareFunc type for compatibility
Browse files Browse the repository at this point in the history
This PR ported the fix deepmap#578
to gorilla/mux, so the gorilla/mux users can have a consistent behaviour
too.

Signed-off-by: Mengnan Gong <namco1992@gmail.com>
  • Loading branch information
namco1992 committed Aug 8, 2023
1 parent d26d251 commit 759311e
Show file tree
Hide file tree
Showing 113 changed files with 678 additions and 3,151 deletions.
42 changes: 0 additions & 42 deletions README.md
Expand Up @@ -28,34 +28,6 @@ something via utility code or reflection, it's probably a better approach than
code generation, which is fragile due to the very dynamic nature of OpenAPI and
the very static nature of Go.

## Contributing

I would like to pre-emptively extend my gratitude to anyone who takes the time
to improve this project.

Oapi-codegen is being actively maintained, however the two people who do so
are very busy, and can only set aside time for this project every once in a while,
so our release cadence is slow and conservative.

Generating code which others depend on, which is based on something as complex
as OpenAPI is fraught with many edge cases, and we prefer to leave things as
they are if there is a reasonable workaround.

If you do find a case where oapi-codegen is broken, and would like to submit a PR,
we are very grateful, and will happily look at it.

Since most commits affect generated code, before sending your PR, please
ensure that all boilerplate has been regenerated. You can do this from the top level
of the repository by running:

go generate ./...

I realize that our code isn't entirely idiomatic with respect to comments, and
variable naming and initialisms, especially the generated code, but I'm reluctant
to merge PR's which change this, due to the breakage they will cause for others. If
you rename anything under `/pkg` or change the names of variables in generated
code, you will break other people's code. It's safe to rename internal names.

## Overview

We're going to use the OpenAPI example of the
Expand Down Expand Up @@ -596,20 +568,6 @@ which help you to use the various OpenAPI 3 Authentication mechanism.
will override any default value. This extended property isn't supported in all parts of
OpenAPI, so please refer to the spec as to where it's allowed. Swagger validation tools will
flag incorrect usage of this property.
- `x-go-type-skip-optional-pointer`: specifies if the Go type should or should not be a pointer
when the property is optional. If set to true, the type will not be a pointer if the field is
optional or nullable. If set to false, the type will be a pointer.

```yaml
properties:
field:
type: string
x-go-type-skip-optional-pointer: true
```

In the example above, the `field` field will be of type `string` instead of `*string`. This is
useful when you want to handle the case of an empty string differently than a null value.

- `x-go-name`: specifies Go field name. It allows you to specify the field name for a schema, and
will override any default value. This extended property isn't supported in all parts of
OpenAPI, so please refer to the spec as to where it's allowed. Swagger validation tools will
Expand Down
4 changes: 2 additions & 2 deletions cmd/oapi-codegen/oapi-codegen.go
Expand Up @@ -269,7 +269,7 @@ func main() {
}

if opts.OutputFile != "" {
err = os.WriteFile(opts.OutputFile, []byte(code), 0o644)
err = os.WriteFile(opts.OutputFile, []byte(code), 0644)
if err != nil {
errExit("error writing generated code to file: %s\n", err)
}
Expand All @@ -279,7 +279,7 @@ func main() {
}

func loadTemplateOverrides(templatesDir string) (map[string]string, error) {
templates := make(map[string]string)
var templates = make(map[string]string)

if templatesDir == "" {
return templates, nil
Expand Down
18 changes: 9 additions & 9 deletions examples/authenticated-api/echo/api/api.gen.go

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

6 changes: 3 additions & 3 deletions examples/authenticated-api/echo/main.go
Expand Up @@ -2,8 +2,8 @@ package main

import (
"flag"
"fmt"
"log"
"net"

"github.com/deepmap/oapi-codegen/examples/authenticated-api/echo/api"
"github.com/deepmap/oapi-codegen/examples/authenticated-api/echo/server"
Expand All @@ -12,7 +12,7 @@ import (
)

func main() {
port := flag.String("port", "8080", "port where to serve traffic")
var port = flag.Int("port", 8080, "port where to serve traffic")

e := echo.New()

Expand Down Expand Up @@ -50,5 +50,5 @@ func main() {
log.Println("Reader token", string(readerJWS))
log.Println("Writer token", string(writerJWS))

e.Logger.Fatal(e.Start(net.JoinHostPort("0.0.0.0", *port)))
e.Logger.Fatal(e.Start(fmt.Sprintf("0.0.0.0:%d", *port)))
}
2 changes: 1 addition & 1 deletion examples/custom-client-type/custom-client-type.gen.go

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

56 changes: 14 additions & 42 deletions examples/petstore-expanded/chi/api/petstore.gen.go

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

4 changes: 2 additions & 2 deletions examples/petstore-expanded/chi/api/petstore.go
Expand Up @@ -26,7 +26,7 @@ func NewPetStore() *PetStore {
}
}

// sendPetStoreError wraps sending of an error in the Error format, and
// This function wraps sending of an error in the Error format, and
// handling the failure to marshal that.
func sendPetStoreError(w http.ResponseWriter, code int, message string) {
petErr := Error{
Expand Down Expand Up @@ -89,7 +89,7 @@ func (p *PetStore) AddPet(w http.ResponseWriter, r *http.Request) {
pet.Name = newPet.Name
pet.Tag = newPet.Tag
pet.Id = p.NextId
p.NextId++
p.NextId = p.NextId + 1

// Insert into map
p.Pets[pet.Id] = pet
Expand Down
5 changes: 2 additions & 3 deletions examples/petstore-expanded/chi/petstore.go
Expand Up @@ -8,7 +8,6 @@ import (
"flag"
"fmt"
"log"
"net"
"net/http"
"os"

Expand All @@ -18,7 +17,7 @@ import (
)

func main() {
port := flag.String("port", "8080", "Port for test HTTP server")
var port = flag.Int("port", 8080, "Port for test HTTP server")
flag.Parse()

swagger, err := api.GetSwagger()
Expand Down Expand Up @@ -46,7 +45,7 @@ func main() {

s := &http.Server{
Handler: r,
Addr: net.JoinHostPort("0.0.0.0", *port),
Addr: fmt.Sprintf("0.0.0.0:%d", *port),
}

// And we serve HTTP until the world ends.
Expand Down
12 changes: 6 additions & 6 deletions examples/petstore-expanded/echo/api/petstore-server.gen.go

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

0 comments on commit 759311e

Please sign in to comment.