Skip to content

Commit

Permalink
fix(expand): fix missing server url
Browse files Browse the repository at this point in the history
  • Loading branch information
max107 committed Oct 25, 2023
1 parent ee69a99 commit cd6a7cc
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 0 deletions.
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 cd6a7cc

Please sign in to comment.