From ee2b8c41192c7b62051d4c46a7a6e7e4764025ed Mon Sep 17 00:00:00 2001 From: Matt Bonnell Date: Wed, 24 Mar 2021 12:35:02 -0400 Subject: [PATCH] add patch models --- client/doc.go | 32 ++++++- .../admin/patch_o_auth2_client_parameters.go | 8 +- internal/httpclient/models/patch_document.go | 96 +++++++++++++++++++ internal/httpclient/models/patch_request.go | 69 +++++++++++++ .../models/plugin_config_interface.go | 3 + internal/httpclient/models/volume.go | 3 +- spec/api.json | 39 +++++++- 7 files changed, 241 insertions(+), 9 deletions(-) create mode 100644 internal/httpclient/models/patch_document.go create mode 100644 internal/httpclient/models/patch_request.go diff --git a/client/doc.go b/client/doc.go index f77646e01df..974ba52077e 100644 --- a/client/doc.go +++ b/client/doc.go @@ -29,8 +29,6 @@ package client -import "encoding/json" - // swagger:parameters createOAuth2Client type swaggerCreateClientPayload struct { // in: body @@ -57,7 +55,35 @@ type swaggerPatchClientPayload struct { // in: body // required: true - Body json.RawMessage + Body patchRequest +} + +// A JSONPatch request +// +// swagger:model patchRequest +type patchRequest []patchDocument + +// A JSONPatch document as defined by RFC 6902 +// +// swagger:model patchDocument +type patchDocument struct { + // The operation to be performed + // + // required: true + // example: "replace" + Op string `json:"op"` + + // A JSON-pointer + // + // required: true + // example: "/name" + Path string `json:"path"` + + // The value to be used within the operations + Value interface{} `json:"value"` + + // A JSON-pointer + From string `json:"from"` } // swagger:parameters listOAuth2Clients diff --git a/internal/httpclient/client/admin/patch_o_auth2_client_parameters.go b/internal/httpclient/client/admin/patch_o_auth2_client_parameters.go index d5c3f0116aa..bb40dbefc65 100644 --- a/internal/httpclient/client/admin/patch_o_auth2_client_parameters.go +++ b/internal/httpclient/client/admin/patch_o_auth2_client_parameters.go @@ -14,6 +14,8 @@ import ( "github.com/go-openapi/runtime" cr "github.com/go-openapi/runtime/client" "github.com/go-openapi/strfmt" + + "github.com/ory/hydra/internal/httpclient/models" ) // NewPatchOAuth2ClientParams creates a new PatchOAuth2ClientParams object, @@ -60,7 +62,7 @@ func NewPatchOAuth2ClientParamsWithHTTPClient(client *http.Client) *PatchOAuth2C type PatchOAuth2ClientParams struct { // Body. - Body interface{} + Body models.PatchRequest // ID. ID string @@ -119,13 +121,13 @@ func (o *PatchOAuth2ClientParams) SetHTTPClient(client *http.Client) { } // WithBody adds the body to the patch o auth2 client params -func (o *PatchOAuth2ClientParams) WithBody(body interface{}) *PatchOAuth2ClientParams { +func (o *PatchOAuth2ClientParams) WithBody(body models.PatchRequest) *PatchOAuth2ClientParams { o.SetBody(body) return o } // SetBody adds the body to the patch o auth2 client params -func (o *PatchOAuth2ClientParams) SetBody(body interface{}) { +func (o *PatchOAuth2ClientParams) SetBody(body models.PatchRequest) { o.Body = body } diff --git a/internal/httpclient/models/patch_document.go b/internal/httpclient/models/patch_document.go new file mode 100644 index 00000000000..0f8b9cac0db --- /dev/null +++ b/internal/httpclient/models/patch_document.go @@ -0,0 +1,96 @@ +// Code generated by go-swagger; DO NOT EDIT. + +package models + +// This file was generated by the swagger tool. +// Editing this file might prove futile when you re-run the swagger generate command + +import ( + "context" + + "github.com/go-openapi/errors" + "github.com/go-openapi/strfmt" + "github.com/go-openapi/swag" + "github.com/go-openapi/validate" +) + +// PatchDocument A JSONPatch document as defined by RFC 6902 +// +// swagger:model patchDocument +type PatchDocument struct { + + // A JSON-pointer + From string `json:"from,omitempty"` + + // The operation to be performed + // Example: \"replace\ + // Required: true + Op *string `json:"op"` + + // A JSON-pointer + // Example: \"/name\ + // Required: true + Path *string `json:"path"` + + // The value to be used within the operations + Value interface{} `json:"value,omitempty"` +} + +// Validate validates this patch document +func (m *PatchDocument) Validate(formats strfmt.Registry) error { + var res []error + + if err := m.validateOp(formats); err != nil { + res = append(res, err) + } + + if err := m.validatePath(formats); err != nil { + res = append(res, err) + } + + if len(res) > 0 { + return errors.CompositeValidationError(res...) + } + return nil +} + +func (m *PatchDocument) validateOp(formats strfmt.Registry) error { + + if err := validate.Required("op", "body", m.Op); err != nil { + return err + } + + return nil +} + +func (m *PatchDocument) validatePath(formats strfmt.Registry) error { + + if err := validate.Required("path", "body", m.Path); err != nil { + return err + } + + return nil +} + +// ContextValidate validates this patch document based on context it is used +func (m *PatchDocument) ContextValidate(ctx context.Context, formats strfmt.Registry) error { + return nil +} + +// MarshalBinary interface implementation +func (m *PatchDocument) MarshalBinary() ([]byte, error) { + if m == nil { + return nil, nil + } + return swag.WriteJSON(m) +} + +// UnmarshalBinary interface implementation +func (m *PatchDocument) UnmarshalBinary(b []byte) error { + var res PatchDocument + if err := swag.ReadJSON(b, &res); err != nil { + return err + } + *m = res + return nil +} diff --git a/internal/httpclient/models/patch_request.go b/internal/httpclient/models/patch_request.go new file mode 100644 index 00000000000..e974c6748e9 --- /dev/null +++ b/internal/httpclient/models/patch_request.go @@ -0,0 +1,69 @@ +// Code generated by go-swagger; DO NOT EDIT. + +package models + +// This file was generated by the swagger tool. +// Editing this file might prove futile when you re-run the swagger generate command + +import ( + "context" + "strconv" + + "github.com/go-openapi/errors" + "github.com/go-openapi/strfmt" + "github.com/go-openapi/swag" +) + +// PatchRequest A JSONPatch request +// +// swagger:model patchRequest +type PatchRequest []*PatchDocument + +// Validate validates this patch request +func (m PatchRequest) Validate(formats strfmt.Registry) error { + var res []error + + for i := 0; i < len(m); i++ { + if swag.IsZero(m[i]) { // not required + continue + } + + if m[i] != nil { + if err := m[i].Validate(formats); err != nil { + if ve, ok := err.(*errors.Validation); ok { + return ve.ValidateName(strconv.Itoa(i)) + } + return err + } + } + + } + + if len(res) > 0 { + return errors.CompositeValidationError(res...) + } + return nil +} + +// ContextValidate validate this patch request based on the context it is used +func (m PatchRequest) ContextValidate(ctx context.Context, formats strfmt.Registry) error { + var res []error + + for i := 0; i < len(m); i++ { + + if m[i] != nil { + if err := m[i].ContextValidate(ctx, formats); err != nil { + if ve, ok := err.(*errors.Validation); ok { + return ve.ValidateName(strconv.Itoa(i)) + } + return err + } + } + + } + + if len(res) > 0 { + return errors.CompositeValidationError(res...) + } + return nil +} diff --git a/internal/httpclient/models/plugin_config_interface.go b/internal/httpclient/models/plugin_config_interface.go index 73a75d00a44..3e77cc86694 100644 --- a/internal/httpclient/models/plugin_config_interface.go +++ b/internal/httpclient/models/plugin_config_interface.go @@ -20,6 +20,9 @@ import ( // swagger:model PluginConfigInterface type PluginConfigInterface struct { + // Protocol to use for clients connecting to the plugin. + ProtocolScheme string `json:"ProtocolScheme,omitempty"` + // socket // Required: true Socket *string `json:"Socket"` diff --git a/internal/httpclient/models/volume.go b/internal/httpclient/models/volume.go index a8a725e2cf8..a27d9734b32 100644 --- a/internal/httpclient/models/volume.go +++ b/internal/httpclient/models/volume.go @@ -42,7 +42,8 @@ type Volume struct { // Required: true Options map[string]string `json:"Options"` - // The level at which the volume exists. Either `global` for cluster-wide, or `local` for machine level. + // The level at which the volume exists. Either `global` for cluster-wide, + // or `local` for machine level. // Required: true Scope *string `json:"Scope"` diff --git a/spec/api.json b/spec/api.json index dc4013cb083..b7035b4ea4e 100755 --- a/spec/api.json +++ b/spec/api.json @@ -365,7 +365,7 @@ "in": "body", "required": true, "schema": { - "type": "object" + "$ref": "#/definitions/patchRequest" } } ], @@ -2499,7 +2499,7 @@ } }, "Scope": { - "description": "The level at which the volume exists. Either `global` for cluster-wide, or `local` for machine level.", + "description": "The level at which the volume exists. Either `global` for cluster-wide,\nor `local` for machine level.", "type": "string" }, "Status": { @@ -3089,6 +3089,41 @@ } } }, + "patchDocument": { + "description": "A JSONPatch document as defined by RFC 6902", + "type": "object", + "required": [ + "op", + "path" + ], + "properties": { + "from": { + "description": "A JSON-pointer", + "type": "string" + }, + "op": { + "description": "The operation to be performed", + "type": "string", + "example": "\"replace\"" + }, + "path": { + "description": "A JSON-pointer", + "type": "string", + "example": "\"/name\"" + }, + "value": { + "description": "The value to be used within the operations", + "type": "object" + } + } + }, + "patchRequest": { + "description": "A JSONPatch request", + "type": "array", + "items": { + "$ref": "#/definitions/patchDocument" + } + }, "rejectRequest": { "type": "object", "title": "The request payload used to accept a login or consent request.",