Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix info tags #1408

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions openapi/parser/_testdata/expand/info_tags.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
openapi: 3.1.0
info:
version: 1.0.0
title: info_test
tags:
- name: Order
description: orders
- name: Invoice
description: invoices
- name: Product
description: products
32 changes: 32 additions & 0 deletions openapi/parser/expand_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package parser_test

import (
"os"
"testing"

"github.com/stretchr/testify/require"

"github.com/ogen-go/ogen"
"github.com/ogen-go/ogen/openapi/parser"
)

func TestExpand(t *testing.T) {
f, err := os.ReadFile("_testdata/expand/info_tags.yaml")
require.NoError(t, err)

spec, err := ogen.Parse(f)
require.NoError(t, err)
require.NotEmpty(t, spec.Tags)
require.Len(t, spec.Tags, 3)

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

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

require.Equal(t, "info_test", expandSpec.Info.Title)
require.Equal(t, "1.0.0", expandSpec.Info.Version)
require.Empty(t, expandSpec.Info.Summary)
require.Len(t, expandSpec.Tags, 3)
}
4 changes: 2 additions & 2 deletions openapi/parser/parse_info.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
func fromOpenapiInfo(info openapi.Info) ogen.Info {
result := ogen.Info{
Title: info.Title,
Summary: info.Title,
Summary: info.Summary,
Description: info.Description,
TermsOfService: info.TermsOfService,
Version: info.Version,
Expand All @@ -31,7 +31,7 @@ func fromOpenapiInfo(info openapi.Info) ogen.Info {
func fromOgenInfo(info ogen.Info) openapi.Info {
result := openapi.Info{
Title: info.Title,
Summary: info.Title,
Summary: info.Summary,
Description: info.Description,
TermsOfService: info.TermsOfService,
Version: info.Version,
Expand Down
9 changes: 9 additions & 0 deletions openapi/parser/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,16 @@ func Parse(spec *ogen.Spec, s Settings) (_ *openapi.API, rerr error) {
return nil, errors.Wrap(err, "parse webhooks")
}

tags := make([]openapi.Tag, len(spec.Tags))
for i, tag := range spec.Tags {
tags[i] = openapi.Tag{
Name: tag.Name,
Description: tag.Description,
}
}

return &openapi.API{
Tags: tags,
Version: p.version,
Servers: servers,
Operations: p.operations,
Expand Down
Loading