Skip to content

Duplicate objects generated from multiple attributes with the same $ref schema #236

@kenny-statsig

Description

@kenny-statsig

tfplugingen-openapi CLI version

v0.3.0

OpenAPI Spec File

"MetricCreationContractDto": {
        "type": "object",
        "properties": {
          "name": {
            "type": "string",
            "maxLength": 200,
            "minLength": 4,
            "pattern": "^[a-zA-Z0-9_.\\-()/ %:]*$",
            "description": "The name of the new metric, which identifies it within the system.",
            "example": "metricName"
          },
          "type": {
            "type": "string",
            "enum": [
              "ratio",
              "sum",
              "composite",
              "mean",
              "event_count_custom",
              "event_user",
              "funnel",
              "undefined",
              "setup_incomplete",
              "composite_sum",
              "import_window",
              "user_warehouse"
            ],
            "description": "The type of the metric. Allowed values include sum, ratio, mean, event_count_sum, composite, composite_sum, undefined, funnel, user_warehouse.",
            "example": "sum"
          },
          "isVerified": {
            "type": "boolean",
            "description": "Marks the metric as verified for internal trustworthiness.",
            "example": false
          },
          "isReadOnly": {
            "type": "boolean",
            "description": "Set to true to make the metric definition editable only from the Console API.",
            "example": false
          },
          "unitTypes": {
            "type": "array",
            "items": {
              "type": "string"
            },
            "description": "Array of unit types associated with the metric, such as stableID or userID.",
            "example": [
              "stableID",
              "userID"
            ]
          },
          "metricEvents": {
            "type": "array",
            "items": {
              "type": "object",
              "properties": {
                "name": {
                  "type": "string",
                  "description": "The name of the metric event."
                },
                "type": {
                  "type": "string",
                  "enum": [
                    "count",
                    "count_distinct",
                    "value",
                    "metadata"
                  ],
                  "nullable": true,
                  "description": "The type of metric event. Allowed values include: count, count_distinct, value, and metadata."
                },
                "metadataKey": {
                  "type": "string",
                  "description": "The key for associated metadata, if applicable."
                },
                "criteria": {
                  "type": "array",
                  "items": {
                    "$ref": "#/components/schemas/MetricEventsCriteriaDto"
                  },
                  "description": "Filtering criteria for the metric event, including conditions and values to refine the event data."
                }
              },
              "required": [
                "name"
              ]
            },
            "description": "An array of event definitions used to compute the metric.",
            "example": [
              {
                "name": "event1",
                "type": "value"
              }
            ]
          },
          "metricComponentMetrics": {
            "type": "array",
            "items": {
              "type": "object",
              "properties": {
                "name": {
                  "type": "string"
                },
                "type": {
                  "type": "string"
                }
              },
              "required": [
                "name",
                "type"
              ]
            },
            "description": "List of input metrics used to calculate the new metric for composite types.",
            "example": []
          },
          "description": {
            "type": "string",
            "maxLength": 1000,
            "description": "A description of the new metric, providing context and purpose."
          },
          "directionality": {
            "default": "increase",
            "type": "string",
            "enum": [
              "increase",
              "decrease"
            ],
            "description": "Indicates the desired change direction for the metric. Use \"increase\" for positive changes and \"decrease\" for negative changes.",
            "example": "increase"
          },
          "tags": {
            "type": "array",
            "items": {
              "type": "string"
            },
            "description": "Tags associated with the metric for categorization and searchability.",
            "example": [
              "tag1",
              "tag2"
            ]
          },
          "isPermanent": {
            "type": "boolean",
            "description": "Indicates whether the metric is permanent and should not be deleted.",
            "example": false
          },
          "rollupTimeWindow": {
            "type": "string",
            "description": "Time window for the metric rollup. Specify \"custom\" for a customized time window.",
            "example": "custom"
          },
          "customRollUpStart": {
            "type": "number",
            "description": "Custom time window start date in days since exposure.",
            "example": 1,
            "format": "double"
          },
          "customRollUpEnd": {
            "type": "number",
            "description": "Custom time window end date in days since exposure.",
            "example": 1,
            "format": "double"
          },
          "funnelEventList": {
            "type": "array",
            "items": {
              "type": "object",
              "properties": {
                "name": {
                  "type": "string",
                  "description": "The name of the funnel event used in the metric.",
                  "example": "event1"
                },
                "type": {
                  "type": "string",
                  "enum": [
                    "event_dau",
                    "event_user",
                    "event_count",
                    "event_count_custom"
                  ],
                  "description": "The type of funnel event, specifying how the event is tracked.",
                  "example": "event_dau"
                }
              },
              "required": [
                "name",
                "type"
              ]
            },
            "description": "List of events used to create funnel metrics."
          },
          "funnelCountDistinct": {
            "type": "string",
            "enum": [
              "events",
              "users"
            ],
            "description": "Specifies whether to count events or distinct users for the funnel metric."
          },
          "warehouseNative": {
            "type": "object",
            "properties": {
              "aggregation": {
                "type": "string",
                "enum": [
                  "count",
                  "sum",
                  "mean",
                  "daily_participation",
                  "ratio",
                  "funnel",
                  "count_distinct",
                  "percentile",
                  "first_value",
                  "latest_value",
                  "retention",
                  "max",
                  "min",
                  ""
                ],
                "description": "Allowed: count┃sum┃mean┃daily_participation┃ratio┃funnel┃count_distinct┃percentile"
              },
              "metricSourceName": {
                "type": "string",
                "description": "For Count, Sum, Mean, User Count aggregation types: the name of metric source"
              },
              "criteria": {
                "type": "array",
                "items": {
                  "$ref": "#/components/schemas/MetricEventsCriteriaDto"
                },
                "description": "Filtering criteria for the metric source"
              },
              "waitForCohortWindow": {
                "type": "boolean"
              },
              "denominatorCriteria": {
                "type": "array",
                "items": {
                  "$ref": "#/components/schemas/MetricEventsCriteriaDto"
                },
                "description": "Filtering criteria for the denominator metric source, if this metric is a ratio"
              },
              "denominatorAggregation": {
                "type": "string",
                "enum": [
                  "count",
                  "sum",
                  "mean",
                  "daily_participation",
                  "ratio",
                  "funnel",
                  "count_distinct",
                  "percentile",
                  "first_value",
                  "latest_value",
                  "retention",
                  "max",
                  "min",
                  ""
                ],
                "description": "Allowed: count┃sum┃mean┃daily_participation┃ratio┃funnel┃count_distinct┃percentile"
              },
              "denominatorCustomRollupEnd": {
                "type": "number",
                "description": "Custom end date for rollup in days since exposure."
              },
              "denominatorCustomRollupStart": {
                "type": "number",
                "description": "Custom start date for rollup in days since exposure."
              },
              "denominatorMetricSourceName": {
                "type": "string",
                "description": "Name of the metric source for the denominator."
              },
              "denominatorRollupTimeWindow": {
                "type": "string",
                "description": "Time window for the denominator metric. Specify \"custom\" for a custom window."
              },
              "denominatorValueColumn": {
                "type": "string",
                "description": "Column name for the denominator’s value."
              },
              "funnelCalculationWindow": {
                "type": "number",
                "description": "Duration for counting funnel events in days."
              },
              "funnelCountDistinct": {
                "type": "string",
                "enum": [
                  "sessions",
                  "users"
                ],
                "description": "Allowed: users┃sessions for distinct count method in funnel events."
              },
              "funnelEvents": {
                "type": "array",
                "items": {
                  "type": "object",
                  "properties": {
                    "criteria": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/MetricEventsCriteriaDto"
                      },
                      "description": "Optional array of criteria to filter the funnel events, defined by various types and conditions."
                    },
                    "metricSourceName": {
                      "type": "string",
                      "description": "Optional name of the metric source associated with the funnel event."
                    },
                    "name": {
                      "type": "string",
                      "nullable": true,
                      "description": "Optional step name for the funnel event, can be null if not specified."
                    },
                    "sessionIdentifierField": {
                      "type": "string",
                      "nullable": true,
                      "description": "Name of column which being used as session identifier. Funnel event with the same metric source"
                    }
                  }
                },
                "description": "List of funnel events with associated criteria and identifiers."
              },
              "funnelStartCriteria": {
                "type": "string",
                "enum": [
                  "start_event",
                  "exposure"
                ],
                "description": "Allowed: start_event┃exposure to determine funnel start criteria."
              },
              "metricDimensionColumns": {
                "type": "array",
                "items": {
                  "type": "string"
                },
                "description": "Specify metadata columns for breaking down metric analysis."
              },
              "metricBakeDays": {
                "type": "number",
                "description": "Number of days for metric baking; specify duration for analysis."
              },
              "numeratorAggregation": {
                "type": "string",
                "enum": [
                  "count",
                  "sum",
                  "mean",
                  "daily_participation",
                  "ratio",
                  "funnel",
                  "count_distinct",
                  "percentile",
                  "first_value",
                  "latest_value",
                  "retention",
                  "max",
                  "min",
                  ""
                ],
                "description": "Aggregation type for numerator; Allowed: count┃sum┃mean┃daily_participation┃ratio┃funnel┃count_distinct┃percentile."
              },
              "valueColumn": {
                "type": "string",
                "description": "Column name representing the metric’s value."
              },
              "winsorizationHigh": {
                "type": "number",
                "maximum": 1,
                "minimum": 0,
                "description": "High threshold for winsorization; must be between 0 and 1."
              },
              "winsorizationLow": {
                "type": "number",
                "maximum": 1,
                "minimum": 0,
                "description": "Low threshold for winsorization; must be between 0 and 1."
              },
              "cupedAttributionWindow": {
                "type": "number",
                "nullable": true,
                "description": "Attribution window for CUPED adjustments in days."
              },
              "onlyIncludeUsersWithConversionEvent": {
                "type": "boolean",
                "description": "Flag to include only users with a conversion event in the metric."
              },
              "percentile": {
                "type": "number",
                "description": "Percentile value for statistical calculations."
              },
              "valueThreshold": {
                "type": "number",
                "description": "Threshold value for filtering metrics."
              },
              "cap": {
                "type": "number",
                "description": "Maximum cap for metric values."
              },
              "rollupTimeWindow": {
                "type": "string",
                "description": "General time window for rollup; can specify custom settings."
              },
              "customRollUpStart": {
                "type": "number",
                "description": "Custom start date for rollup in days since exposure."
              },
              "customRollUpEnd": {
                "type": "number",
                "description": "Custom end date for rollup in days since exposure."
              },
              "allowNullRatioDenominator": {
                "type": "boolean",
                "description": "Include units which do not have a denominator. Only applicable to ratios."
              }
            },
            "description": "Defines warehouse native metrics for advanced configurations."
          },
          "team": {
            "type": "string",
            "nullable": true,
            "description": "The team associated with the metric, applicable for enterprise environments."
          },
          "teamID": {
            "type": "string",
            "nullable": true,
            "description": "The team ID associated with the metric, applicable for enterprise environments."
          },
          "dryRun": {
            "type": "boolean",
            "description": "Skips persisting the metric (used to validate that inputs are correct)"
          }
        },
        "required": [
          "name",
          "type"
        ]
      }
      "MetricEventsCriteriaDto": {
        "type": "object",
        "properties": {
          "type": {
            "type": "string",
            "enum": [
              "value",
              "metadata",
              "user",
              "user_custom"
            ],
            "description": "Type of event criterion for filtering metrics. Options include `value`, `metadata`, `user`, and `user_custom`; in Warehouse Native, this should always be `metadata`."
          },
          "column": {
            "type": "string",
            "description": "Optional column specifying which data attribute to filter on."
          },
          "condition": {
            "type": "string",
            "enum": [
              "in",
              "not_in",
              "=",
              ">",
              "<",
              ">=",
              "<=",
              "is_null",
              "non_null",
              "contains",
              "not_contains",
              "sql_filter",
              "starts_with",
              "ends_with",
              "after_exposure",
              "is_true",
              "is_false"
            ],
            "description": "sql_filter, start_withs, ends_with, and after_exposure are only applicable in Warehouse Native"
          },
          "values": {
            "type": "array",
            "items": {
              "type": "string"
            },
            "description": "Optional array of values for the criterion to match against."
          },
          "null_vacuous_override": {
            "type": "boolean",
            "description": "If true, overrides null values in criterion evaluation."
          }
        },
        "required": [
          "type",
          "condition"
        ],
        "description": "Array of event criteria for defining filtering conditions in metrics analysis."
      },

Generator Config

metric:
    read:
      path: /console/v1/metrics/{id}
      method: GET
    create:
      path: /console/v1/metrics
      method: POST
    update:
      path: /console/v1/metrics/{id}
      method: POST
    delete:
      path: /console/v1/metrics/{id}
      method: DELETE
    schema:
      ignores:
        - message
        - data

Expected Behavior

The codegen should handle the referenced schema MetricEventsCriteriaDto in a way such that it is only defined once in the provider_code_spec.json or at least the generated resource metric_resource_gen.go

Actual Behavior

The Criteria struct/object is defined multiple times (once for each reference) https://gist.github.com/kenny-statsig/2a8d4d4c47857156429b864d54be634f.

Additional Information

No response

Code of Conduct

  • I agree to follow this project's Code of Conduct

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions