Skip to content

Commit

Permalink
small fixes
Browse files Browse the repository at this point in the history
* SingleOrArray and BoolOrSchema had methods on both value and pointer receivers
* Fix comments with markdown links and unpaired parentheses
  • Loading branch information
SVilgelm committed Sep 21, 2023
1 parent 23eee6e commit f698b70
Show file tree
Hide file tree
Showing 9 changed files with 25 additions and 18 deletions.
2 changes: 1 addition & 1 deletion spec/bool_or_schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ func (o *BoolOrSchema) UnmarshalYAML(node *yaml.Node) error {
}

// MarshalYAML implements yaml.Marshaler interface.
func (o BoolOrSchema) MarshalYAML() (any, error) {
func (o *BoolOrSchema) MarshalYAML() (any, error) {
var v any
if o.Schema != nil {
v = o.Schema
Expand Down
4 changes: 3 additions & 1 deletion spec/callback_test.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
package spec_test

import (
"testing"

"github.com/stretchr/testify/require"

"github.com/sv-tools/openapi/spec"
"testing"
)

func TestCallback_WithPathItem(t *testing.T) {
Expand Down
4 changes: 3 additions & 1 deletion spec/components_test.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
package spec_test

import (
"testing"

"github.com/stretchr/testify/require"

"github.com/sv-tools/openapi/spec"
"testing"
)

func TestComponents_WithRefOrSpec(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion spec/json_schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ type JsonSchemaCore struct {
Vocabulary map[string]bool `json:"$vocabulary,omitempty" yaml:"$vocabulary,omitempty"`
DynamicAnchor string `json:"$dynamicAnchor,omitempty" yaml:"dynamicAnchor,omitempty"`
// https://json-schema.org/understanding-json-schema/reference/type.html
Type SingleOrArray[string] `json:"type,omitempty" yaml:"type,omitempty"`
Type *SingleOrArray[string] `json:"type,omitempty" yaml:"type,omitempty"`
}

// JsonSchema fields
Expand Down
4 changes: 2 additions & 2 deletions spec/operation.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ type Operation struct {
// The request body applicable for this operation.
// The requestBody is fully supported in HTTP methods where the HTTP 1.1 specification [RFC7231] has
// explicitly defined semantics for request bodies.
// In other cases where the HTTP spec is vague (such as [GET]section-4.3.1), [HEAD]section-4.3.2) and
// [DELETE]section-4.3.5)), requestBody is permitted but does not have well-defined semantics and SHOULD be avoided if possible.
// In other cases where the HTTP spec is vague (such as [GET](section-4.3.1), [HEAD](section-4.3.2) and
// [DELETE](section-4.3.5)), requestBody is permitted but does not have well-defined semantics and SHOULD be avoided if possible.
RequestBody *RefOrSpec[Extendable[RequestBody]] `json:"requestBody,omitempty" yaml:"requestBody,omitempty"`
// The list of possible responses as they are returned from executing this operation.
Responses *Extendable[Responses] `json:"responses,omitempty" yaml:"responses,omitempty"`
Expand Down
4 changes: 3 additions & 1 deletion spec/paths_test.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
package spec_test

import (
"testing"

"github.com/stretchr/testify/require"

"github.com/sv-tools/openapi/spec"
"testing"
)

func TestPaths_WithPathItem(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion spec/request_body.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ package spec
type RequestBody struct {
// REQUIRED.
// The content of the request body.
// The key is a media type or [media type range]appendix-D) and the value describes it.
// The key is a media type or [media type range](appendix-D) and the value describes it.
// For requests that match multiple keys, only the most specific key is applicable. e.g. text/plain overrides text/*
Content map[string]*Extendable[MediaType] `json:"content,omitempty" yaml:"content,omitempty"`
// A brief description of the request body.
Expand Down
2 changes: 1 addition & 1 deletion spec/response.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ type Response struct {
// If a response header is defined with the name "Content-Type", it SHALL be ignored.
Headers map[string]*RefOrSpec[Extendable[Header]] `json:"headers,omitempty" yaml:"headers,omitempty"`
// A map containing descriptions of potential response payloads.
// The key is a media type or [media type range]appendix-D) and the value describes it.
// The key is a media type or [media type range](appendix-D) and the value describes it.
// For responses that match multiple keys, only the most specific key is applicable. e.g. text/plain overrides text/*
Content map[string]*Extendable[MediaType] `json:"content,omitempty" yaml:"content,omitempty"`
// A map of operations links that can be followed from the response.
Expand Down
19 changes: 10 additions & 9 deletions spec/single_or_array.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ type SingleOrArray[T any] []T

// NewSingleOrArray creates SingleOrArray object.
func NewSingleOrArray[T any](v ...T) SingleOrArray[T] {
return append([]T{}, v...)
a := append(SingleOrArray[T]{}, v...)
return a
}

// UnmarshalJSON implements json.Unmarshaler interface.
Expand All @@ -29,10 +30,10 @@ func (o *SingleOrArray[T]) UnmarshalJSON(data []byte) error {
}

// MarshalJSON implements json.Marshaler interface.
func (o SingleOrArray[T]) MarshalJSON() ([]byte, error) {
var v any = []T(o)
if len(o) == 1 {
v = o[0]
func (o *SingleOrArray[T]) MarshalJSON() ([]byte, error) {
var v any = []T(*o)
if len(*o) == 1 {
v = (*o)[0]
}
return json.Marshal(&v)
}
Expand All @@ -52,10 +53,10 @@ func (o *SingleOrArray[T]) UnmarshalYAML(node *yaml.Node) error {
}

// MarshalYAML implements yaml.Marshaler interface.
func (o SingleOrArray[T]) MarshalYAML() (any, error) {
var v any = []T(o)
if len(o) == 1 {
v = o[0]
func (o *SingleOrArray[T]) MarshalYAML() (any, error) {
var v any = []T(*o)
if len(*o) == 1 {
v = (*o)[0]
}
return v, nil
}

0 comments on commit f698b70

Please sign in to comment.