Skip to content

Commit f9825a1

Browse files
authored
Merge pull request #1385 from max107/fix_info_todo
fix(expand): copy full info from spec
2 parents a1fb175 + c245c62 commit f9825a1

File tree

5 files changed

+122
-6
lines changed

5 files changed

+122
-6
lines changed

openapi/Info.go

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
package openapi
2+
3+
import "github.com/ogen-go/ogen/jsonschema"
4+
5+
type (
6+
// Extensions is a map of OpenAPI extensions.
7+
//
8+
// See https://spec.openapis.org/oas/v3.1.0#specification-extensions.
9+
Extensions = jsonschema.Extensions
10+
)
11+
12+
// Info provides metadata about the API.
13+
//
14+
// The metadata MAY be used by the clients if needed,
15+
// and MAY be presented in editing or documentation generation tools for convenience.
16+
//
17+
// See https://spec.openapis.org/oas/v3.1.0#info-object.
18+
type Info struct {
19+
// REQUIRED. The title of the API.
20+
Title string `json:"title" yaml:"title"`
21+
// A short summary of the API.
22+
Summary string `json:"summary,omitempty" yaml:"summary,omitempty"`
23+
// A short description of the API.
24+
// CommonMark syntax MAY be used for rich text representation.
25+
Description string `json:"description,omitempty" yaml:"description,omitempty"`
26+
// A URL to the Terms of Service for the API. MUST be in the format of a URL.
27+
TermsOfService string `json:"termsOfService,omitempty" yaml:"termsOfService,omitempty"`
28+
// The contact information for the exposed API.
29+
Contact *Contact `json:"contact,omitempty" yaml:"contact,omitempty"`
30+
// The license information for the exposed API.
31+
License *License `json:"license,omitempty" yaml:"license,omitempty"`
32+
// REQUIRED. The version of the OpenAPI document.
33+
Version string `json:"version" yaml:"version"`
34+
35+
// Specification extensions.
36+
Extensions Extensions `json:"-" yaml:",inline"`
37+
}
38+
39+
// Contact information for the exposed API.
40+
//
41+
// See https://spec.openapis.org/oas/v3.1.0#contact-object.
42+
type Contact struct {
43+
// The identifying name of the contact person/organization.
44+
Name string `json:"name,omitempty" yaml:"name,omitempty"`
45+
// The URL pointing to the contact information.
46+
URL string `json:"url,omitempty" yaml:"url,omitempty"`
47+
// The email address of the contact person/organization.
48+
Email string `json:"email,omitempty" yaml:"email,omitempty"`
49+
50+
// Specification extensions.
51+
Extensions Extensions `json:"-" yaml:",inline"`
52+
}
53+
54+
// License information for the exposed API.
55+
//
56+
// See https://spec.openapis.org/oas/v3.1.0#license-object.
57+
type License struct {
58+
// REQUIRED. The license name used for the API.
59+
Name string `json:"name" yaml:"name"`
60+
// An SPDX license expression for the API.
61+
Identifier string `json:"identifier,omitempty" yaml:"identifier,omitempty"`
62+
// A URL to the license used for the API.
63+
URL string `json:"url,omitempty" yaml:"url,omitempty"`
64+
65+
// Specification extensions.
66+
Extensions Extensions `json:"-" yaml:",inline"`
67+
}

openapi/api.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ type API struct {
1717
Operations []*Operation
1818
Webhooks []Webhook
1919
Components *Components
20+
Info Info
2021
}
2122

2223
// Components represent parsed components of OpenAPI spec.

openapi/parser/expand.go

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -47,12 +47,7 @@ func (e *expander) Spec(api *openapi.API) (spec *ogen.Spec, err error) {
4747
}
4848
}
4949
spec.Tags = tags
50-
51-
// FIXME(tdakkota): store actual information
52-
spec.Info = ogen.Info{
53-
Title: "Expanded spec",
54-
Version: "v0.1.0",
55-
}
50+
spec.Info = fromOpenapiInfo(api.Info)
5651

5752
if servers := api.Servers; len(servers) > 0 {
5853
expanded := make([]ogen.Server, len(servers))

openapi/parser/parse_info.go

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
package parser
2+
3+
import (
4+
"github.com/ogen-go/ogen"
5+
"github.com/ogen-go/ogen/openapi"
6+
)
7+
8+
func fromOpenapiInfo(info openapi.Info) ogen.Info {
9+
result := ogen.Info{
10+
Title: info.Title,
11+
Summary: info.Title,
12+
Description: info.Description,
13+
TermsOfService: info.TermsOfService,
14+
Version: info.Version,
15+
Extensions: info.Extensions,
16+
}
17+
18+
if info.Contact != nil {
19+
val := ogen.Contact(*info.Contact)
20+
result.Contact = &val
21+
}
22+
23+
if info.License != nil {
24+
val := ogen.License(*info.License)
25+
result.License = &val
26+
}
27+
28+
return result
29+
}
30+
31+
func fromOgenInfo(info ogen.Info) openapi.Info {
32+
result := openapi.Info{
33+
Title: info.Title,
34+
Summary: info.Title,
35+
Description: info.Description,
36+
TermsOfService: info.TermsOfService,
37+
Version: info.Version,
38+
Extensions: info.Extensions,
39+
}
40+
41+
if info.Contact != nil {
42+
val := openapi.Contact(*info.Contact)
43+
result.Contact = &val
44+
}
45+
46+
if info.License != nil {
47+
val := openapi.License(*info.License)
48+
result.License = &val
49+
}
50+
51+
return result
52+
}

openapi/parser/parser.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,7 @@ func Parse(spec *ogen.Spec, s Settings) (_ *openapi.API, rerr error) {
146146
Operations: p.operations,
147147
Webhooks: webhooks,
148148
Components: components,
149+
Info: fromOgenInfo(p.spec.Info),
149150
}, nil
150151
}
151152

0 commit comments

Comments
 (0)