Skip to content

Commit c3c2aaa

Browse files
committed
feat(ogen): parse Server variables
1 parent c6a4a52 commit c3c2aaa

File tree

2 files changed

+30
-9
lines changed

2 files changed

+30
-9
lines changed

dsl_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -102,8 +102,8 @@ func TestBuilder(t *testing.T) {
102102
Version: "0.1.0",
103103
},
104104
Servers: []ogen.Server{
105-
{"staging", "staging.api.com"},
106-
{"production", "api.com"},
105+
{"staging", "staging.api.com", nil},
106+
{"production", "api.com", nil},
107107
},
108108
Paths: map[string]*ogen.PathItem{
109109
pathWithID: {
@@ -327,7 +327,7 @@ func TestBuilder(t *testing.T) {
327327
SetHead(ogen.NewOperation().SetOperationID("head").SetResponses(ogen.Responses{"resp": ogen.NewResponse()})).
328328
SetPatch(ogen.NewOperation().SetOperationID("patch").AddParameters(ogen.NewParameter().InHeader().SetDeprecated(true))).
329329
SetTrace(ogen.NewOperation().SetOperationID("trace")).
330-
SetServers([]ogen.Server{{"desc1", "url1"}}).
330+
SetServers([]ogen.Server{{"url1", "desc1", nil}}).
331331
AddServers(ogen.NewServer().SetDescription("desc2").SetURL("url2")).
332332
SetParameters([]*ogen.Parameter{_queryParam.Parameter})
333333
assert.Equal(t, &ogen.PathItem{
@@ -337,7 +337,7 @@ func TestBuilder(t *testing.T) {
337337
Head: &ogen.Operation{OperationID: "head", Responses: ogen.Responses{"resp": &ogen.Response{}}},
338338
Patch: &ogen.Operation{OperationID: "patch", Parameters: []*ogen.Parameter{{In: "header", Deprecated: true}}},
339339
Trace: &ogen.Operation{OperationID: "trace"},
340-
Servers: []ogen.Server{{"desc1", "url1"}, {"desc2", "url2"}},
340+
Servers: []ogen.Server{{"url1", "desc1", nil}, {"url2", "desc2", nil}},
341341
Parameters: []*ogen.Parameter{_queryParam.Parameter},
342342
}, pi)
343343

spec.go

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -94,8 +94,8 @@ type Example struct {
9494
//
9595
// https://swagger.io/specification/#tag-object
9696
type Tag struct {
97-
Name string `json:"name"`
98-
Description string `json:"description,omitempty"`
97+
Name string `json:"name"`
98+
Description string `json:"description,omitempty"`
9999
ExternalDocs *ExternalDocumentation `json:"externalDocs,omitempty"`
100100
}
101101

@@ -136,7 +136,28 @@ type License struct {
136136

137137
// Server represents a Server.
138138
type Server struct {
139-
URL string `json:"url"`
139+
// REQUIRED. A URL to the target host. This URL supports Server Variables and MAY be relative,
140+
// to indicate that the host location is relative to the location where the OpenAPI document is being served.
141+
// Variable substitutions will be made when a variable is named in {brackets}.
142+
URL string `json:"url"`
143+
// An optional string describing the host designated by the URL.
144+
// CommonMark syntax MAY be used for rich text representation.
145+
Description string `json:"description,omitempty"`
146+
// A map between a variable name and its value. The value is used for substitution in the server's URL template.
147+
Variables map[string]ServerVariable `json:"variables,omitempty"`
148+
}
149+
150+
// ServerVariable describes an object representing a Server Variable for server URL template substitution.
151+
type ServerVariable struct {
152+
// An enumeration of string values to be used if the substitution options are from a limited set.
153+
//
154+
// The array MUST NOT be empty.
155+
Enum []string `json:"enum,omitempty"`
156+
// REQUIRED. The default value to use for substitution, which SHALL be sent if an alternate value is not supplied.
157+
// Note this behavior is different than the Schema Object’s treatment of default values, because in those
158+
// cases parameter values are optional. If the enum is defined, the value MUST exist in the enum’s values.
159+
Default string `json:"default"`
160+
// An optional description for the server variable. CommonMark syntax MAY be used for rich text representation.
140161
Description string `json:"description,omitempty"`
141162
}
142163

@@ -190,8 +211,8 @@ type Operation struct {
190211
// Tags can be used for logical grouping of operations by resources or any other qualifier.
191212
Tags []string `json:"tags,omitempty"`
192213

193-
Summary string `json:"summary,omitempty"`
194-
Description string `json:"description,omitempty"`
214+
Summary string `json:"summary,omitempty"`
215+
Description string `json:"description,omitempty"`
195216
ExternalDocs *ExternalDocumentation `json:"externalDocs,omitempty"`
196217

197218
OperationID string `json:"operationId,omitempty"`

0 commit comments

Comments
 (0)