Skip to content

Commit 8818b83

Browse files
authored
fix: Makes specified fields optional in their respective schemas (#557)
1 parent b7f91e1 commit 8818b83

File tree

7 files changed

+59
-15
lines changed

7 files changed

+59
-15
lines changed

admin/model_stream_processor_metric_threshold.go

+20-12
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ package admin
55
// StreamProcessorMetricThreshold Threshold for the metric that, when exceeded, triggers an alert. The metric threshold pertains to event types which reflects changes of measurements and metrics in stream processors.
66
type StreamProcessorMetricThreshold struct {
77
// Human-readable label that identifies the metric against which MongoDB Cloud checks the configured **metricThreshold.threshold**.
8-
MetricName string `json:"metricName"`
8+
MetricName *string `json:"metricName,omitempty"`
99
// MongoDB Cloud computes the current metric value as an average.
1010
Mode *string `json:"mode,omitempty"`
1111
// Comparison operator to apply when checking the current metric value.
@@ -20,9 +20,8 @@ type StreamProcessorMetricThreshold struct {
2020
// This constructor will assign default values to properties that have it defined,
2121
// and makes sure properties required by API are set, but the set of arguments
2222
// will change when the set of required properties is changed
23-
func NewStreamProcessorMetricThreshold(metricName string) *StreamProcessorMetricThreshold {
23+
func NewStreamProcessorMetricThreshold() *StreamProcessorMetricThreshold {
2424
this := StreamProcessorMetricThreshold{}
25-
this.MetricName = metricName
2625
var units string = "RAW"
2726
this.Units = &units
2827
return &this
@@ -38,28 +37,37 @@ func NewStreamProcessorMetricThresholdWithDefaults() *StreamProcessorMetricThres
3837
return &this
3938
}
4039

41-
// GetMetricName returns the MetricName field value
40+
// GetMetricName returns the MetricName field value if set, zero value otherwise
4241
func (o *StreamProcessorMetricThreshold) GetMetricName() string {
43-
if o == nil {
42+
if o == nil || IsNil(o.MetricName) {
4443
var ret string
4544
return ret
4645
}
47-
48-
return o.MetricName
46+
return *o.MetricName
4947
}
5048

51-
// GetMetricNameOk returns a tuple with the MetricName field value
49+
// GetMetricNameOk returns a tuple with the MetricName field value if set, nil otherwise
5250
// and a boolean to check if the value has been set.
5351
func (o *StreamProcessorMetricThreshold) GetMetricNameOk() (*string, bool) {
54-
if o == nil {
52+
if o == nil || IsNil(o.MetricName) {
5553
return nil, false
5654
}
57-
return &o.MetricName, true
55+
56+
return o.MetricName, true
57+
}
58+
59+
// HasMetricName returns a boolean if a field has been set.
60+
func (o *StreamProcessorMetricThreshold) HasMetricName() bool {
61+
if o != nil && !IsNil(o.MetricName) {
62+
return true
63+
}
64+
65+
return false
5866
}
5967

60-
// SetMetricName sets field value
68+
// SetMetricName gets a reference to the given string and assigns it to the MetricName field.
6169
func (o *StreamProcessorMetricThreshold) SetMetricName(v string) {
62-
o.MetricName = v
70+
o.MetricName = &v
6371
}
6472

6573
// GetMode returns the Mode field value if set, zero value otherwise

internal/core/version.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ package core
55
// For more information please see: https://github.com/mongodb/atlas-sdk-go/blob/main/docs/doc_1_concepts.md
66
const (
77
// SDK release tag version.
8-
Version = "v20250312001.0.0"
8+
Version = "v20250312001.1.0"
99
// Resource Version.
1010
Resource = "20250312"
1111
)

openapi/atlas-api-transformed.yaml

-2
Original file line numberDiff line numberDiff line change
@@ -15349,8 +15349,6 @@ components:
1534915349
$ref: "#/components/schemas/RawMetricUnits"
1535015350
description: Element used to express the quantity. This can be an element of
1535115351
time, storage capacity, and the like.
15352-
required:
15353-
- metricName
1535415352
title: Stream Processor Metric Threshold
1535515353
type: object
1535615354
StreamsAWSConnectionConfig:

tools/transformer/src/atlasTransformations.js

+2
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ const {
99
applyRemoveNullableTransformations,
1010
removeRefsFromParameters,
1111
reorderResponseBodies,
12+
applyFieldTransformations,
1213
} = require("./transformations");
1314
const { resolveOpenAPIReference } = require("./engine/transformers");
1415

@@ -29,6 +30,7 @@ module.exports = function runTransformations(openapi) {
2930
openapi = applyRemoveNullableTransformations(openapi);
3031
openapi = applyRemoveObjectAdditionalProperties(openapi);
3132
openapi = reorderResponseBodies(openapi);
33+
openapi = applyFieldTransformations(openapi);
3234

3335
openapi = applyModelNameTransformations(
3436
openapi,
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"optionalFields": {
3+
"StreamProcessorMetricThreshold": ["metricName"]
4+
}
5+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
const fieldTransformations = require("../field.transformations.json");
2+
3+
/**
4+
* Makes specified fields optional in their respective schemas
5+
* @param {*} api OpenAPI JSON File
6+
* @returns OpenAPI JSON File
7+
*/
8+
function applyFieldTransformations(api) {
9+
const { optionalFields } = fieldTransformations;
10+
11+
// Make specified fields optional in their schemas
12+
for (const [schemaName, fields] of Object.entries(optionalFields)) {
13+
const schema = api.components.schemas[schemaName];
14+
if (schema && schema.required) {
15+
schema.required = schema.required.filter(
16+
(field) => !fields.includes(field),
17+
);
18+
if (schema.required.length === 0) {
19+
delete schema.required;
20+
}
21+
}
22+
}
23+
24+
return api;
25+
}
26+
27+
module.exports = {
28+
applyFieldTransformations,
29+
};

tools/transformer/src/transformations/index.js

+2
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ const { applyAnyOfTransformations } = require("./anyOf");
1515
const { applyRemoveNullableTransformations } = require("./removeNullable");
1616
const { removeRefsFromParameters } = require("./removeInvalidParams");
1717
const { reorderResponseBodies } = require("./reorderResponseBodies");
18+
const { applyFieldTransformations } = require("./fields");
1819

1920
module.exports = {
2021
applyModelNameTransformations,
@@ -31,4 +32,5 @@ module.exports = {
3132
applyRemoveNullableTransformations,
3233
removeRefsFromParameters,
3334
reorderResponseBodies,
35+
applyFieldTransformations,
3436
};

0 commit comments

Comments
 (0)