From 37a3369cea8ed5af34e8324a291a7d7dba0eb43a Mon Sep 17 00:00:00 2001 From: hackerman <3372410+aeneasr@users.noreply.github.com> Date: Fri, 13 May 2022 17:21:35 +0200 Subject: [PATCH] fix: openapi regression (#2465) Co-authored-by: Patrik --- internal/httpclient/api/openapi.yaml | 30 ------------------- spec/api.json | 35 ---------------------- spec/swagger.json | 45 ++++------------------------ ui/node/attributes.go | 30 +++++++++---------- ui/node/node.go | 20 ++++++------- 5 files changed, 30 insertions(+), 130 deletions(-) diff --git a/internal/httpclient/api/openapi.yaml b/internal/httpclient/api/openapi.yaml index 68ae6e705d7..b9e242f4a40 100644 --- a/internal/httpclient/api/openapi.yaml +++ b/internal/httpclient/api/openapi.yaml @@ -5124,12 +5124,6 @@ components: description: |- NodeType represents this node's types. It is a mirror of `node.type` and is primarily used to allow compatibility with OpenAPI 3.0. - enum: - - text - - input - - img - - a - - script type: string title: $ref: '#/components/schemas/uiText' @@ -5169,12 +5163,6 @@ components: description: |- NodeType represents this node's types. It is a mirror of `node.type` and is primarily used to allow compatibility with OpenAPI 3.0. - enum: - - text - - input - - img - - a - - script type: string src: description: |- @@ -5211,12 +5199,6 @@ components: description: |- NodeType represents this node's types. It is a mirror of `node.type` and is primarily used to allow compatibility with OpenAPI 3.0. - enum: - - text - - input - - img - - a - - script type: string onclick: description: |- @@ -5273,12 +5255,6 @@ components: description: |- NodeType represents this node's types. It is a mirror of `node.type` and is primarily used to allow compatibility with OpenAPI 3.0. - enum: - - text - - input - - img - - a - - script type: string nonce: description: |- @@ -5318,12 +5294,6 @@ components: description: |- NodeType represents this node's types. It is a mirror of `node.type` and is primarily used to allow compatibility with OpenAPI 3.0. - enum: - - text - - input - - img - - a - - script type: string text: $ref: '#/components/schemas/uiText' diff --git a/spec/api.json b/spec/api.json index 3bb775b9de8..f44119102bb 100755 --- a/spec/api.json +++ b/spec/api.json @@ -1899,13 +1899,6 @@ }, "node_type": { "description": "NodeType represents this node's types. It is a mirror of `node.type` and\nis primarily used to allow compatibility with OpenAPI 3.0.", - "enum": [ - "text", - "input", - "img", - "a", - "script" - ], "type": "string" }, "title": { @@ -1964,13 +1957,6 @@ }, "node_type": { "description": "NodeType represents this node's types. It is a mirror of `node.type` and\nis primarily used to allow compatibility with OpenAPI 3.0.", - "enum": [ - "text", - "input", - "img", - "a", - "script" - ], "type": "string" }, "src": { @@ -2012,13 +1998,6 @@ }, "node_type": { "description": "NodeType represents this node's types. It is a mirror of `node.type` and\nis primarily used to allow compatibility with OpenAPI 3.0.", - "enum": [ - "text", - "input", - "img", - "a", - "script" - ], "type": "string" }, "onclick": { @@ -2079,13 +2058,6 @@ }, "node_type": { "description": "NodeType represents this node's types. It is a mirror of `node.type` and\nis primarily used to allow compatibility with OpenAPI 3.0.", - "enum": [ - "text", - "input", - "img", - "a", - "script" - ], "type": "string" }, "nonce": { @@ -2127,13 +2099,6 @@ }, "node_type": { "description": "NodeType represents this node's types. It is a mirror of `node.type` and\nis primarily used to allow compatibility with OpenAPI 3.0.", - "enum": [ - "text", - "input", - "img", - "a", - "script" - ], "type": "string" }, "text": { diff --git a/spec/swagger.json b/spec/swagger.json index 0b07a3bf30d..07efd53d9bb 100755 --- a/spec/swagger.json +++ b/spec/swagger.json @@ -4111,14 +4111,7 @@ }, "node_type": { "description": "NodeType represents this node's types. It is a mirror of `node.type` and\nis primarily used to allow compatibility with OpenAPI 3.0.", - "type": "string", - "enum": [ - "text", - "input", - "img", - "a", - "script" - ] + "type": "string" }, "title": { "$ref": "#/definitions/uiText" @@ -4151,14 +4144,7 @@ }, "node_type": { "description": "NodeType represents this node's types. It is a mirror of `node.type` and\nis primarily used to allow compatibility with OpenAPI 3.0.", - "type": "string", - "enum": [ - "text", - "input", - "img", - "a", - "script" - ] + "type": "string" }, "src": { "description": "The image's source URL.\n\nformat: uri", @@ -4197,14 +4183,7 @@ }, "node_type": { "description": "NodeType represents this node's types. It is a mirror of `node.type` and\nis primarily used to allow compatibility with OpenAPI 3.0.", - "type": "string", - "enum": [ - "text", - "input", - "img", - "a", - "script" - ] + "type": "string" }, "onclick": { "description": "OnClick may contain javascript which should be executed on click. This is primarily\nused for WebAuthn.", @@ -4270,14 +4249,7 @@ }, "node_type": { "description": "NodeType represents this node's types. It is a mirror of `node.type` and\nis primarily used to allow compatibility with OpenAPI 3.0.", - "type": "string", - "enum": [ - "text", - "input", - "img", - "a", - "script" - ] + "type": "string" }, "nonce": { "description": "Nonce for CSP\n\nA nonce you may want to use to improve your Content Security Policy.\nYou do not have to use this value but if you want to improve your CSP\npolicies you may use it. You can also choose to use your own nonce value!", @@ -4312,14 +4284,7 @@ }, "node_type": { "description": "NodeType represents this node's types. It is a mirror of `node.type` and\nis primarily used to allow compatibility with OpenAPI 3.0.", - "type": "string", - "enum": [ - "text", - "input", - "img", - "a", - "script" - ] + "type": "string" }, "text": { "$ref": "#/definitions/uiText" diff --git a/ui/node/attributes.go b/ui/node/attributes.go index f59135f50f5..a1e96416e31 100644 --- a/ui/node/attributes.go +++ b/ui/node/attributes.go @@ -75,10 +75,10 @@ type InputAttributes struct { OnClick string `json:"onclick,omitempty"` // NodeType represents this node's types. It is a mirror of `node.type` and - // is primarily used to allow compatibility with OpenAPI 3.0. + // is primarily used to allow compatibility with OpenAPI 3.0. In this struct it technically always is "input". // // required: true - NodeType UiNodeType `json:"node_type"` + NodeType string `json:"node_type"` } // ImageAttributes represents the attributes of an image node. @@ -107,10 +107,10 @@ type ImageAttributes struct { Height int `json:"height"` // NodeType represents this node's types. It is a mirror of `node.type` and - // is primarily used to allow compatibility with OpenAPI 3.0. + // is primarily used to allow compatibility with OpenAPI 3.0. In this struct it technically always is "img". // // required: true - NodeType UiNodeType `json:"node_type"` + NodeType string `json:"node_type"` } // AnchorAttributes represents the attributes of an anchor node. @@ -134,10 +134,10 @@ type AnchorAttributes struct { Identifier string `json:"id"` // NodeType represents this node's types. It is a mirror of `node.type` and - // is primarily used to allow compatibility with OpenAPI 3.0. + // is primarily used to allow compatibility with OpenAPI 3.0. In this struct it technically always is "a". // // required: true - NodeType UiNodeType `json:"node_type"` + NodeType string `json:"node_type"` } // TextAttributes represents the attributes of a text node. @@ -156,10 +156,10 @@ type TextAttributes struct { Identifier string `json:"id"` // NodeType represents this node's types. It is a mirror of `node.type` and - // is primarily used to allow compatibility with OpenAPI 3.0. + // is primarily used to allow compatibility with OpenAPI 3.0. In this struct it technically always is "text". // // required: true - NodeType UiNodeType `json:"node_type"` + NodeType string `json:"node_type"` } // ScriptAttributes represent script nodes which load javascript. @@ -211,10 +211,10 @@ type ScriptAttributes struct { Nonce string `json:"nonce"` // NodeType represents this node's types. It is a mirror of `node.type` and - // is primarily used to allow compatibility with OpenAPI 3.0. + // is primarily used to allow compatibility with OpenAPI 3.0. In this struct it technically always is "script". // // required: true - NodeType UiNodeType `json:"node_type"` + NodeType string `json:"node_type"` } var ( @@ -302,21 +302,21 @@ func (a *ScriptAttributes) Reset() { } func (a *InputAttributes) GetNodeType() UiNodeType { - return a.NodeType + return UiNodeType(a.NodeType) } func (a *ImageAttributes) GetNodeType() UiNodeType { - return a.NodeType + return UiNodeType(a.NodeType) } func (a *AnchorAttributes) GetNodeType() UiNodeType { - return a.NodeType + return UiNodeType(a.NodeType) } func (a *TextAttributes) GetNodeType() UiNodeType { - return a.NodeType + return UiNodeType(a.NodeType) } func (a *ScriptAttributes) GetNodeType() UiNodeType { - return a.NodeType + return UiNodeType(a.NodeType) } diff --git a/ui/node/node.go b/ui/node/node.go index edc38c6c248..4856f6d8e9e 100644 --- a/ui/node/node.go +++ b/ui/node/node.go @@ -353,23 +353,23 @@ func (n *Node) UnmarshalJSON(data []byte) error { switch t := gjson.GetBytes(data, "type").String(); UiNodeType(t) { case Text: attr = &TextAttributes{ - NodeType: Text, + NodeType: string(Text), } case Input: attr = &InputAttributes{ - NodeType: Input, + NodeType: string(Input), } case Anchor: attr = &AnchorAttributes{ - NodeType: Anchor, + NodeType: string(Anchor), } case Image: attr = &ImageAttributes{ - NodeType: Image, + NodeType: string(Image), } case Script: attr = &ScriptAttributes{ - NodeType: Script, + NodeType: string(Script), } default: return fmt.Errorf("unexpected node type: %s", t) @@ -396,19 +396,19 @@ func (n *Node) MarshalJSON() ([]byte, error) { switch attr := n.Attributes.(type) { case *TextAttributes: t = Text - attr.NodeType = Text + attr.NodeType = string(Text) case *InputAttributes: t = Input - attr.NodeType = Input + attr.NodeType = string(Input) case *AnchorAttributes: t = Anchor - attr.NodeType = Anchor + attr.NodeType = string(Anchor) case *ImageAttributes: t = Image - attr.NodeType = Image + attr.NodeType = string(Image) case *ScriptAttributes: t = Script - attr.NodeType = Script + attr.NodeType = string(Script) default: return nil, errors.WithStack(fmt.Errorf("unknown node type: %T", n.Attributes)) }