Skip to content

Commit

Permalink
Merge branch 'main' into feat/valid-receiver
Browse files Browse the repository at this point in the history
  • Loading branch information
sashamelentyev authored Oct 28, 2023
2 parents 2da6dbf + f604144 commit 893026c
Show file tree
Hide file tree
Showing 10 changed files with 74 additions and 9 deletions.
2 changes: 1 addition & 1 deletion examples/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ go 1.20
require (
github.com/go-faster/errors v0.6.1
github.com/go-faster/jx v1.1.0
github.com/google/uuid v1.3.1
github.com/google/uuid v1.4.0
github.com/ogen-go/ogen v0.0.0
github.com/stretchr/testify v1.8.4
go.opentelemetry.io/otel v1.19.0
Expand Down
4 changes: 2 additions & 2 deletions examples/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ github.com/go-logr/logr v1.2.4/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbV
github.com/go-logr/stdr v1.2.2 h1:hSWxHoqTgW2S2qGc0LTAI563KZ5YKYRhT3MFKZMbjag=
github.com/go-logr/stdr v1.2.2/go.mod h1:mMo/vtBO5dYbehREoey6XUKy/eSumjCCveDpRre4VKE=
github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38=
github.com/google/uuid v1.3.1 h1:KjJaJ9iWZ3jOFZIf1Lqf4laDRCasjl0BCmnEGxkdLb4=
github.com/google/uuid v1.3.1/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/google/uuid v1.4.0 h1:MtMxsa51/r9yyhkyLsVeVt0B+BGQZzpQiTQ4eHZ8bc4=
github.com/google/uuid v1.4.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE=
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA=
Expand Down
4 changes: 3 additions & 1 deletion gen/ir/json.go
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,8 @@ func (j JSON) SumTypes() string {
return strings.Join(sortedTypes, ",")
}

const arraySuffix = "Array"

func jsonType(t *Type) string {
if t.IsNumeric() {
if s := t.Schema; s != nil && s.Type == "string" {
Expand All @@ -207,7 +209,7 @@ func jsonType(t *Type) string {
return "Number"
}
if t.Is(KindArray) {
return "Array"
return arraySuffix
}
if t.Is(KindStruct, KindMap) {
return "Object"
Expand Down
2 changes: 1 addition & 1 deletion gen/ir/template_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (

func (t *Type) EncodeFn() string {
if t.Is(KindArray) && t.Item.EncodeFn() != "" {
return t.Item.EncodeFn() + "Array"
return t.Item.EncodeFn() + arraySuffix
}
switch t.Primitive {
case ByteSlice:
Expand Down
2 changes: 1 addition & 1 deletion gen/ir/type.go
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ func (t *Type) NamePostfix() string {
return t.Primitive.String()
}
case KindArray:
return t.Item.NamePostfix() + "Array"
return t.Item.NamePostfix() + arraySuffix
case KindAny:
return "Any"
case KindPointer:
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ require (
github.com/go-faster/errors v0.6.1
github.com/go-faster/jx v1.1.0
github.com/go-faster/yaml v0.4.6
github.com/google/uuid v1.3.1
github.com/google/uuid v1.4.0
github.com/mattn/go-isatty v0.0.20
github.com/stretchr/testify v1.8.4
github.com/valyala/fasthttp v1.50.0
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ github.com/go-logr/logr v1.2.4/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbV
github.com/go-logr/stdr v1.2.2 h1:hSWxHoqTgW2S2qGc0LTAI563KZ5YKYRhT3MFKZMbjag=
github.com/go-logr/stdr v1.2.2/go.mod h1:mMo/vtBO5dYbehREoey6XUKy/eSumjCCveDpRre4VKE=
github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38=
github.com/google/uuid v1.3.1 h1:KjJaJ9iWZ3jOFZIf1Lqf4laDRCasjl0BCmnEGxkdLb4=
github.com/google/uuid v1.3.1/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/google/uuid v1.4.0 h1:MtMxsa51/r9yyhkyLsVeVt0B+BGQZzpQiTQ4eHZ8bc4=
github.com/google/uuid v1.4.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/klauspost/compress v1.16.3 h1:XuJt9zzcnaz6a16/OU53ZjWp/v7/42WcR5t2a0PcNQY=
github.com/klauspost/compress v1.16.3/go.mod h1:ntbaceVETuRiXiv4DpjP66DpAtAGkEQskQzEyD//IeE=
github.com/kr/pretty v0.2.1/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI=
Expand Down
5 changes: 5 additions & 0 deletions middleware/middleware.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,11 @@ type Request struct {
Raw *http.Request
}

// SetContext sets Context in Request.
func (r *Request) SetContext(ctx context.Context) {
r.Context = ctx
}

// Response is response type for middleware.
type Response struct {
// Type is the operation response type.
Expand Down
1 change: 1 addition & 0 deletions openapi/parser/expand.go
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@ func (e *expander) Server(s openapi.Server) (expanded ogen.Server, err error) {
Description: param.Description,
}
}
expanded.URL = template.String()
if len(vars) > 0 {
expanded.Variables = vars
}
Expand Down
57 changes: 57 additions & 0 deletions openapi/parser/parse_server_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
package parser_test

import (
"testing"

"github.com/ogen-go/ogen"
"github.com/ogen-go/ogen/openapi/parser"
"github.com/stretchr/testify/require"
)

func TestServerURL(t *testing.T) {
data := `
info:
description: test
title: test
version: 1.0.0
openapi: "3.0.0"
servers:
- url: "{protocol}://{host}:{port}"
variables:
host:
default: localhost
port:
default: "4000"
protocol:
default: http
enum:
- http
- https
`
spec, err := ogen.Parse([]byte(data))
require.NoError(t, err)

api, err := parser.Parse(spec, parser.Settings{})
require.NoError(t, err)

expandSpec, err := parser.Expand(api)
require.NoError(t, err)

require.Equal(t, []ogen.Server{
{
URL: "{protocol}://{host}:{port}",
Variables: map[string]ogen.ServerVariable{
"host": {
Default: "localhost",
},
"protocol": {
Enum: []string{"http", "https"},
Default: "http",
},
"port": {
Default: "4000",
},
},
},
}, expandSpec.Servers)
}

0 comments on commit 893026c

Please sign in to comment.