Skip to content

Commit

Permalink
Merge branch 'master' into chore/golangci-lint
Browse files Browse the repository at this point in the history
  • Loading branch information
deepmap-marcinr committed Oct 27, 2022
2 parents 17280e5 + e5ee43d commit 8cec783
Show file tree
Hide file tree
Showing 71 changed files with 1,819 additions and 240 deletions.
2 changes: 1 addition & 1 deletion README.md
Expand Up @@ -112,7 +112,7 @@ type ServerInterface interface {
These are the functions which you will implement yourself in order to create
a server conforming to the API specification. Normally, all the arguments and
parameters are stored on the `echo.Context` in handlers, so we do the tedious
work of of unmarshaling the JSON automatically, simply passing values into
work of unmarshalling the JSON automatically, simply passing values into
your handlers.

Notice that `FindPetById` takes a parameter `id int64`. All path arguments
Expand Down
23 changes: 23 additions & 0 deletions examples/custom-client-type/api.yaml
@@ -0,0 +1,23 @@
openapi: "3.0.0"
info:
version: 1.0.0
title: Custom Client Type Example
paths:
/client:
get:
operationId: getClient
responses:
200:
content:
application/json:
schema:
$ref: "#/components/schemas/Client"
components:
schemas:
Client:
type: object
required:
- name
properties:
name:
type: string
7 changes: 7 additions & 0 deletions examples/custom-client-type/cfg.yaml
@@ -0,0 +1,7 @@
package: customclienttype
output: custom-client-type.gen.go
generate:
models: true
client: true
output-options:
client-type-name: CustomClientType
239 changes: 239 additions & 0 deletions 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.

6 changes: 6 additions & 0 deletions examples/custom-client-type/doc.go
@@ -0,0 +1,6 @@
package customclienttype

// This is an example of how to add a prefix to the name of the generated Client struct
// See https://github.com/deepmap/oapi-codegen/issues/785 for why this might be necessary

//go:generate go run github.com/deepmap/oapi-codegen/cmd/oapi-codegen -config cfg.yaml api.yaml
8 changes: 4 additions & 4 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.

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

// 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) {
func sendPetStoreError(w http.ResponseWriter, code int, message string) {
petErr := Error{
Code: int32(code),
Message: message,
Expand Down Expand Up @@ -74,7 +74,7 @@ func (p *PetStore) AddPet(w http.ResponseWriter, r *http.Request) {
// We expect a NewPet object in the request body.
var newPet NewPet
if err := json.NewDecoder(r.Body).Decode(&newPet); err != nil {
sendPetstoreError(w, http.StatusBadRequest, "Invalid format for NewPet")
sendPetStoreError(w, http.StatusBadRequest, "Invalid format for NewPet")
return
}

Expand Down Expand Up @@ -105,7 +105,7 @@ func (p *PetStore) FindPetByID(w http.ResponseWriter, r *http.Request, id int64)

pet, found := p.Pets[id]
if !found {
sendPetstoreError(w, http.StatusNotFound, fmt.Sprintf("Could not find pet with ID %d", id))
sendPetStoreError(w, http.StatusNotFound, fmt.Sprintf("Could not find pet with ID %d", id))
return
}

Expand All @@ -119,7 +119,7 @@ func (p *PetStore) DeletePet(w http.ResponseWriter, r *http.Request, id int64) {

_, found := p.Pets[id]
if !found {
sendPetstoreError(w, http.StatusNotFound, fmt.Sprintf("Could not find pet with ID %d", id))
sendPetStoreError(w, http.StatusNotFound, fmt.Sprintf("Could not find pet with ID %d", id))
return
}
delete(p.Pets, id)
Expand Down
4 changes: 2 additions & 2 deletions examples/petstore-expanded/chi/petstore_test.go
Expand Up @@ -53,7 +53,7 @@ func TestPetStore(t *testing.T) {

var resultPet api.Pet
err = json.NewDecoder(rr.Body).Decode(&resultPet)
assert.NoError(t, err, "error unmarshaling response")
assert.NoError(t, err, "error unmarshalling response")
assert.Equal(t, newPet.Name, resultPet.Name)
assert.Equal(t, *newPet.Tag, *resultPet.Tag)
})
Expand Down Expand Up @@ -146,7 +146,7 @@ func TestPetStore(t *testing.T) {

var petError api.Error
err = json.NewDecoder(rr.Body).Decode(&petError)
assert.NoError(t, err, "error unmarshaling PetError")
assert.NoError(t, err, "error unmarshalling PetError")
assert.Equal(t, int32(http.StatusNotFound), petError.Code)

// Now, delete both real pets
Expand Down
8 changes: 4 additions & 4 deletions examples/petstore-expanded/echo/api/petstore.go
Expand Up @@ -41,7 +41,7 @@ func NewPetStore() *PetStore {

// This function wraps sending of an error in the Error format, and
// handling the failure to marshal that.
func sendPetstoreError(ctx echo.Context, code int, message string) error {
func sendPetStoreError(ctx echo.Context, code int, message string) error {
petErr := models.Error{
Code: int32(code),
Message: message,
Expand Down Expand Up @@ -86,7 +86,7 @@ func (p *PetStore) AddPet(ctx echo.Context) error {
var newPet models.NewPet
err := ctx.Bind(&newPet)
if err != nil {
return sendPetstoreError(ctx, http.StatusBadRequest, "Invalid format for NewPet")
return sendPetStoreError(ctx, http.StatusBadRequest, "Invalid format for NewPet")
}
// We now have a pet, let's add it to our "database".

Expand Down Expand Up @@ -126,7 +126,7 @@ func (p *PetStore) FindPetByID(ctx echo.Context, petId int64) error {

pet, found := p.Pets[petId]
if !found {
return sendPetstoreError(ctx, http.StatusNotFound,
return sendPetStoreError(ctx, http.StatusNotFound,
fmt.Sprintf("Could not find pet with ID %d", petId))
}
return ctx.JSON(http.StatusOK, pet)
Expand All @@ -138,7 +138,7 @@ func (p *PetStore) DeletePet(ctx echo.Context, id int64) error {

_, found := p.Pets[id]
if !found {
return sendPetstoreError(ctx, http.StatusNotFound,
return sendPetStoreError(ctx, http.StatusNotFound,
fmt.Sprintf("Could not find pet with ID %d", id))
}
delete(p.Pets, id)
Expand Down

0 comments on commit 8cec783

Please sign in to comment.