-
Notifications
You must be signed in to change notification settings - Fork 205
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
376 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package spec3 | ||
|
||
import ( | ||
"encoding/json" | ||
|
||
"github.com/go-openapi/spec" | ||
"github.com/go-openapi/swag" | ||
) | ||
|
||
// Example https://swagger.io/specification/#example-object | ||
|
||
type Example struct { | ||
spec.Refable | ||
ExampleProps | ||
spec.VendorExtensible | ||
} | ||
|
||
// MarshalJSON is a custom marshal function that knows how to encode RequestBody as JSON | ||
func (e *Example) MarshalJSON() ([]byte, error) { | ||
b1, err := json.Marshal(e.Refable) | ||
if err != nil { | ||
return nil, err | ||
} | ||
b2, err := json.Marshal(e.ExampleProps) | ||
if err != nil { | ||
return nil, err | ||
} | ||
b3, err := json.Marshal(e.VendorExtensible) | ||
if err != nil { | ||
return nil, err | ||
} | ||
return swag.ConcatJSON(b1, b2, b3), nil | ||
} | ||
|
||
type ExampleProps struct { | ||
// Summary holds a short description of the example | ||
Summary string `json:"summary,omitempty"` | ||
// Description holds a long description of the example | ||
Description string `json:"description,omitempty"` | ||
// Embedded literal example. | ||
Value interface{} `json:"value,omitempty"` | ||
// A URL that points to the literal example. This provides the capability to reference examples that cannot easily be included in JSON or YAML documents. | ||
ExternalValue string `json:"externalValue,omitempty"` | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
package spec3 | ||
|
||
import ( | ||
"encoding/json" | ||
|
||
"github.com/go-openapi/swag" | ||
"k8s.io/kube-openapi/pkg/validation/spec" | ||
) | ||
|
||
// Header a struct that describes a single operation parameter, more at https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.0.0.md#parameterObject | ||
// | ||
// Note that this struct is actually a thin wrapper around HeaderProps to make it referable and extensible | ||
type Header struct { | ||
spec.Refable | ||
HeaderProps | ||
spec.VendorExtensible | ||
} | ||
|
||
// MarshalJSON is a custom marshal function that knows how to encode Header as JSON | ||
func (h *Header) MarshalJSON() ([]byte, error) { | ||
b1, err := json.Marshal(h.Refable) | ||
if err != nil { | ||
return nil, err | ||
} | ||
b2, err := json.Marshal(h.HeaderProps) | ||
if err != nil { | ||
return nil, err | ||
} | ||
b3, err := json.Marshal(h.VendorExtensible) | ||
if err != nil { | ||
return nil, err | ||
} | ||
return swag.ConcatJSON(b1, b2, b3), nil | ||
} | ||
|
||
func (h *Header) UnmarshalJSON(data []byte) error { | ||
if err := json.Unmarshal(data, &h.Refable); err != nil { | ||
return err | ||
} | ||
if err := json.Unmarshal(data, &h.HeaderProps); err != nil { | ||
return err | ||
} | ||
if err := json.Unmarshal(data, &h.VendorExtensible); err != nil { | ||
return err | ||
} | ||
|
||
return nil | ||
} | ||
|
||
// HeaderProps a struct that describes a header object | ||
type HeaderProps struct { | ||
// Description holds a brief description of the parameter | ||
Description string `json:"description,omitempty"` | ||
// Required determines whether this parameter is mandatory | ||
Required bool `json:"required,omitempty"` | ||
// Deprecated declares this operation to be deprecated | ||
Deprecated bool `json:"deprecated,omitempty"` | ||
// AllowEmptyValue sets the ability to pass empty-valued parameters | ||
AllowEmptyValue bool `json:"allowEmptyValue,omitempty"` | ||
// Style describes how the parameter value will be serialized depending on the type of the parameter value | ||
Style string `json:"style,omitempty"` | ||
// Explode when true, parameter values of type array or object generate separate parameters for each value of the array or key-value pair of the map | ||
Explode bool `json:"explode,omitempty"` | ||
// AllowReserved determines whether the parameter value SHOULD allow reserved characters, as defined by RFC3986 | ||
AllowReserved bool `json:"allowReserved,omitempty"` | ||
// Schema holds the schema defining the type used for the parameter | ||
Schema *spec.Schema `json:"schema,omitempty"` | ||
// Content holds a map containing the representations for the parameter | ||
Content map[string]*MediaType `json:"content,omitempty"` | ||
// the following fields are missing: | ||
// TODO: Example field is missing - (example Any Example of the media type. The example SHOULD match the specified schema and encoding properties if present. The example object is mutually exclusive of the examples object. Furthermore, if referencing a schema which contains an example, the example value SHALL override the example provided by the schema. To represent examples of media types that cannot naturally be represented in JSON or YAML, a string value can contain the example with escaping where necessary.) | ||
// TODO: Examples field is missing - (examples Map[ string, Example Object | Reference Object] Examples of the media type. Each example SHOULD contain a value in the correct format as specified in the parameter encoding. The examples object is mutually exclusive of the example object. Furthermore, if referencing a schema which contains an example, the examples value SHALL override the example provided by the schema.) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.