Skip to content

Commit 03de496

Browse files
committed
fix(openapi): support any type for additionalProperties
JsonSchema "additionalProperties" is a union type of a boolean and an object. Adding the ability to support both.
1 parent e0b0d84 commit 03de496

File tree

3 files changed

+47
-34
lines changed

3 files changed

+47
-34
lines changed

pkg/api/api.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ func GetAPI(api *openapi.OpenAPI, serverURL, pathPrefix string) (*API, error) {
8989
}
9090
if pathItem.Get != nil {
9191
if resp, ok := pathItem.Get.Responses["200"]; ok {
92-
lroDetails = pathItem.Post.XAEPLongRunningOperation
92+
lroDetails = pathItem.Get.XAEPLongRunningOperation
9393
schema := api.GetSchemaFromResponse(resp, openapi.APPLICATION_JSON)
9494
responseSchema := &openapi.Schema{}
9595
if lroDetails != nil {

pkg/api/operation.go

Lines changed: 41 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,47 @@
11
package api
22

3-
import "github.com/aep-dev/aep-lib-go/pkg/openapi"
3+
import (
4+
"encoding/json"
45

5-
var OperationSchema = openapi.Schema{
6-
Type: "object",
7-
XAEPProtoMessageName: "aep.api.Operation",
8-
Required: []string{
9-
"name",
10-
"done",
11-
},
12-
Properties: map[string]openapi.Schema{
13-
"path": {
14-
Type: "string",
15-
Description: "The server-assigned path of the operation, which is unique within the service.",
16-
},
17-
"metadata": {
18-
Type: "object",
19-
Description: "Service-specific metadata associated with the operation.",
20-
AdditionalProperties: true,
21-
},
22-
"done": {
23-
Type: "boolean",
24-
Description: "If the value is false, it means the operation is still in progress. If true, the operation is completed.",
25-
},
26-
"error": {
27-
Ref: "https://aep.dev/json-schema/type/problems.json",
6+
"github.com/aep-dev/aep-lib-go/pkg/openapi"
7+
)
8+
9+
var additionalPropertiesTrue = json.RawMessage([]byte("true"))
10+
11+
func OperationSchema() openapi.Schema {
12+
// jsonString := `true`
13+
// additionalPropertiesTrue := json.RawMessage([]byte(jsonString))
14+
return openapi.Schema{
15+
Type: "object",
16+
XAEPProtoMessageName: "aep.api.Operation",
17+
Required: []string{
18+
"name",
19+
"done",
2820
},
29-
"response": {
30-
Type: "object",
31-
Description: "The normal response of the operation in case of success.",
32-
AdditionalProperties: true,
21+
Properties: map[string]openapi.Schema{
22+
"path": {
23+
Type: "string",
24+
Description: "The server-assigned path of the operation, which is unique within the service.",
25+
},
26+
"metadata": {
27+
Type: "object",
28+
Description: "Service-specific metadata associated with the operation.",
29+
AdditionalProperties: additionalPropertiesTrue,
30+
},
31+
"done": {
32+
Type: "boolean",
33+
Description: "If the value is false, it means the operation is still in progress. If true, the operation is completed.",
34+
},
35+
"error": {
36+
Ref: "https://aep.dev/json-schema/type/problems.json",
37+
},
38+
"response": {
39+
Type: "object",
40+
Description: "The normal response of the operation in case of success.",
41+
AdditionalProperties: additionalPropertiesTrue,
42+
},
3343
},
34-
},
44+
}
3545
}
3646

3747
func OperationResourceWithDefaults() *Resource {
@@ -42,10 +52,11 @@ func OperationResourceWithDefaults() *Resource {
4252

4353
// Return a longrunningoperation resource
4454
func OperationResource(m Methods, cm []*CustomMethod) *Resource {
55+
schema := OperationSchema()
4556
return &Resource{
4657
Singular: "operation",
4758
Plural: "operations",
48-
Schema: &OperationSchema,
59+
Schema: &schema,
4960
Methods: m,
5061
CustomMethods: cm,
5162
}

pkg/openapi/openapi.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -179,13 +179,15 @@ type Schema struct {
179179
Ref string `json:"$ref,omitempty"`
180180
XAEPResource *XAEPResource `json:"x-aep-resource,omitempty"`
181181
XAEPFieldNumber int `json:"x-aep-field-number,omitempty"`
182-
// Documents the name of the proto message to use for generation.
183-
// If unset, proto generation will create a proto message for this schema.
182+
/// Documents the name of the proto message to use for generation.
183+
/// If unset, proto generation will not create a proto message for this schema.
184184
XAEPProtoMessageName string `json:"x-aep-proto-message-name,omitempty"`
185185
ReadOnly bool `json:"readOnly,omitempty"`
186186
Required []string `json:"required,omitempty"`
187187
Description string `json:"description,omitempty"`
188-
AdditionalProperties bool `json:"additionalProperties,omitempty"`
188+
// AdditionalProperties can be a bool and an object - this allows
189+
// handling for both.
190+
AdditionalProperties json.RawMessage `json:"additionalProperties,omitempty"`
189191
}
190192

191193
type Properties map[string]Schema

0 commit comments

Comments
 (0)