From d94f7f43cc8ead819778f1bbb6efd5a41835f841 Mon Sep 17 00:00:00 2001 From: tarilabs Date: Thu, 22 Feb 2024 15:34:12 +0100 Subject: [PATCH] introduce openapi defaults Signed-off-by: Matteo Mortari --- api/openapi/model-registry.yaml | 6 ++++++ .../converter/mlmd_openapi_converter_util.go | 20 ++++++++++++++----- pkg/openapi/model_metadata_bool_value.go | 2 ++ pkg/openapi/model_metadata_double_value.go | 2 ++ pkg/openapi/model_metadata_proto_value.go | 2 ++ pkg/openapi/model_metadata_string_value.go | 2 ++ pkg/openapi/model_metadata_struct_value.go | 2 ++ 7 files changed, 31 insertions(+), 5 deletions(-) diff --git a/api/openapi/model-registry.yaml b/api/openapi/model-registry.yaml index ba900228..70a82544 100644 --- a/api/openapi/model-registry.yaml +++ b/api/openapi/model-registry.yaml @@ -1125,6 +1125,7 @@ components: metadataType: type: string example: MetadataIntValue + default: MetadataIntValue MetadataDoubleValue: description: A double property value. type: object @@ -1138,6 +1139,7 @@ components: metadataType: type: string example: MetadataDoubleValue + default: MetadataDoubleValue MetadataStringValue: description: A string property value. type: object @@ -1150,6 +1152,7 @@ components: metadataType: type: string example: MetadataStringValue + default: MetadataStringValue MetadataStructValue: description: A struct property value. type: object @@ -1163,6 +1166,7 @@ components: metadataType: type: string example: MetadataStructValue + default: MetadataStructValue MetadataProtoValue: description: A proto property value. type: object @@ -1180,6 +1184,7 @@ components: metadataType: type: string example: MetadataProtoValue + default: MetadataProtoValue MetadataBoolValue: description: A bool property value. type: object @@ -1192,6 +1197,7 @@ components: metadataType: type: string example: MetadataBoolValue + default: MetadataBoolValue BaseResource: allOf: - $ref: "#/components/schemas/BaseResourceCreate" diff --git a/internal/converter/mlmd_openapi_converter_util.go b/internal/converter/mlmd_openapi_converter_util.go index 4e89ccd8..7c02c8ee 100644 --- a/internal/converter/mlmd_openapi_converter_util.go +++ b/internal/converter/mlmd_openapi_converter_util.go @@ -13,23 +13,33 @@ import ( ) func NewMetadataStringValue(value string) *openapi.MetadataStringValue { - return openapi.NewMetadataStringValue(value, "MetadataStringValue") + result := openapi.NewMetadataStringValueWithDefaults() + result.StringValue = value + return result } func NewMetadataBoolValue(value bool) *openapi.MetadataBoolValue { - return openapi.NewMetadataBoolValue(value, "MetadataBoolValue") + result := openapi.NewMetadataBoolValueWithDefaults() + result.BoolValue = value + return result } func NewMetadataDoubleValue(value float64) *openapi.MetadataDoubleValue { - return openapi.NewMetadataDoubleValue(value, "MetadataDoubleValue") + result := openapi.NewMetadataDoubleValueWithDefaults() + result.DoubleValue = value + return result } func NewMetadataIntValue(value string) *openapi.MetadataIntValue { - return openapi.NewMetadataIntValue(value, "MetadataIntValue") + result := openapi.NewMetadataIntValueWithDefaults() + result.IntValue = value + return result } func NewMetadataStructValue(value string) *openapi.MetadataStructValue { - return openapi.NewMetadataStructValue(value, "MetadataStructValue") + result := openapi.NewMetadataStructValueWithDefaults() + result.StructValue = value + return result } // MapMLMDCustomProperties maps MLMD custom properties model to OpenAPI one diff --git a/pkg/openapi/model_metadata_bool_value.go b/pkg/openapi/model_metadata_bool_value.go index 5a4e1712..41fbc1c1 100644 --- a/pkg/openapi/model_metadata_bool_value.go +++ b/pkg/openapi/model_metadata_bool_value.go @@ -39,6 +39,8 @@ func NewMetadataBoolValue(boolValue bool, metadataType string) *MetadataBoolValu // but it doesn't guarantee that properties required by API are set func NewMetadataBoolValueWithDefaults() *MetadataBoolValue { this := MetadataBoolValue{} + var metadataType string = "MetadataBoolValue" + this.MetadataType = metadataType return &this } diff --git a/pkg/openapi/model_metadata_double_value.go b/pkg/openapi/model_metadata_double_value.go index f5e9ddf2..eb761cf4 100644 --- a/pkg/openapi/model_metadata_double_value.go +++ b/pkg/openapi/model_metadata_double_value.go @@ -39,6 +39,8 @@ func NewMetadataDoubleValue(doubleValue float64, metadataType string) *MetadataD // but it doesn't guarantee that properties required by API are set func NewMetadataDoubleValueWithDefaults() *MetadataDoubleValue { this := MetadataDoubleValue{} + var metadataType string = "MetadataDoubleValue" + this.MetadataType = metadataType return &this } diff --git a/pkg/openapi/model_metadata_proto_value.go b/pkg/openapi/model_metadata_proto_value.go index ad30808d..6538b9d0 100644 --- a/pkg/openapi/model_metadata_proto_value.go +++ b/pkg/openapi/model_metadata_proto_value.go @@ -43,6 +43,8 @@ func NewMetadataProtoValue(type_ string, protoValue string, metadataType string) // but it doesn't guarantee that properties required by API are set func NewMetadataProtoValueWithDefaults() *MetadataProtoValue { this := MetadataProtoValue{} + var metadataType string = "MetadataProtoValue" + this.MetadataType = metadataType return &this } diff --git a/pkg/openapi/model_metadata_string_value.go b/pkg/openapi/model_metadata_string_value.go index fa037adf..f9a9be5f 100644 --- a/pkg/openapi/model_metadata_string_value.go +++ b/pkg/openapi/model_metadata_string_value.go @@ -39,6 +39,8 @@ func NewMetadataStringValue(stringValue string, metadataType string) *MetadataSt // but it doesn't guarantee that properties required by API are set func NewMetadataStringValueWithDefaults() *MetadataStringValue { this := MetadataStringValue{} + var metadataType string = "MetadataStringValue" + this.MetadataType = metadataType return &this } diff --git a/pkg/openapi/model_metadata_struct_value.go b/pkg/openapi/model_metadata_struct_value.go index 6695135d..363be387 100644 --- a/pkg/openapi/model_metadata_struct_value.go +++ b/pkg/openapi/model_metadata_struct_value.go @@ -40,6 +40,8 @@ func NewMetadataStructValue(structValue string, metadataType string) *MetadataSt // but it doesn't guarantee that properties required by API are set func NewMetadataStructValueWithDefaults() *MetadataStructValue { this := MetadataStructValue{} + var metadataType string = "MetadataStructValue" + this.MetadataType = metadataType return &this }