Skip to content

Commit

Permalink
fix: add deprecated field to openapi2.Operation (getkin#559)
Browse files Browse the repository at this point in the history
  • Loading branch information
FrimIdan committed Jun 12, 2022
1 parent 648d6b9 commit 3244585
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 0 deletions.
1 change: 1 addition & 0 deletions openapi2/openapi2.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ type Operation struct {
openapi3.ExtensionProps
Summary string `json:"summary,omitempty" yaml:"summary,omitempty"`
Description string `json:"description,omitempty" yaml:"description,omitempty"`
Deprecated bool `json:"deprecated,omitempty" yaml:"deprecated,omitempty"`
ExternalDocs *openapi3.ExternalDocs `json:"externalDocs,omitempty" yaml:"externalDocs,omitempty"`
Tags []string `json:"tags,omitempty" yaml:"tags,omitempty"`
OperationID string `json:"operationId,omitempty" yaml:"operationId,omitempty"`
Expand Down
37 changes: 37 additions & 0 deletions openapi2conv/issue558_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package openapi2conv

import (
"testing"

"github.com/invopop/yaml"
"github.com/stretchr/testify/require"
)

func TestPR558(t *testing.T) {
spec := `
swagger: '2.0'
info:
version: 1.0.0
title: title
paths:
/test:
get:
deprecated: true
parameters:
- in: body
schema:
type: object
responses:
'200':
description: description
`
doc3, err := v2v3YAML([]byte(spec))
require.NoError(t, err)
require.NotEmpty(t, doc3.Paths["/test"].Get.Deprecated)
_, err = yaml.Marshal(doc3)
require.NoError(t, err)

doc2, err := FromV3(doc3)
require.NoError(t, err)
require.NotEmpty(t, doc2.Paths["/test"].Get.Deprecated)
}
2 changes: 2 additions & 0 deletions openapi2conv/openapi2_conv.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@ func ToV3Operation(doc2 *openapi2.T, components *openapi3.Components, pathItem *
OperationID: operation.OperationID,
Summary: operation.Summary,
Description: operation.Description,
Deprecated: operation.Deprecated,
Tags: operation.Tags,
ExtensionProps: operation.ExtensionProps,
}
Expand Down Expand Up @@ -922,6 +923,7 @@ func FromV3Operation(doc3 *openapi3.T, operation *openapi3.Operation) (*openapi2
OperationID: operation.OperationID,
Summary: operation.Summary,
Description: operation.Description,
Deprecated: operation.Deprecated,
Tags: operation.Tags,
ExtensionProps: operation.ExtensionProps,
}
Expand Down

0 comments on commit 3244585

Please sign in to comment.