Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings
Discussion options

Hey!

I'm new to openapi-python-client. I recently generated the ConfigCat Public Management API via uvx openapi-python-client generate using this json file provided by ConfigCat.

The Problem

Looking through the generated code, found some issues like the python snippet below from file update_setting_value_v2.py:

  1. The arg body is a union of two exact same types
  2. The line if isinstance(body, list["JsonPatchOperation"]) isn't correct python (see relevant PEP here), it should be something like if isinstance(body, list) and all(isinstance(item, JsonPatchOperation) for item in body)

What might be causing this? Any pointers would be greatly appreciated, thank you 🙏

def _get_kwargs(
    environment_id: UUID,
    setting_id: int,
    *,
    body: Union[
        list["JsonPatchOperation"],
        list["JsonPatchOperation"],
    ],
    reason: Union[Unset, str] = UNSET,
) -> dict[str, Any]:
    headers: dict[str, Any] = {}

    params: dict[str, Any] = {}

    params["reason"] = reason

    params = {k: v for k, v in params.items() if v is not UNSET and v is not None}

    _kwargs: dict[str, Any] = {
        "method": "patch",
        "url": f"/v1/environments/{environment_id}/settings/{setting_id}/value",
        "params": params,
    }

    if isinstance(body, list["JsonPatchOperation"]):
        _json_body = []
        for body_item_data in body:
            body_item = body_item_data.to_dict()
            _json_body.append(body_item)

        _kwargs["json"] = _json_body
        headers["Content-Type"] = "application/json"
    if isinstance(body, list["JsonPatchOperation"]):
        _json_body = []
        for body_item_data in body:
            body_item = body_item_data.to_dict()
            _json_body.append(body_item)

        _kwargs["json"] = _json_body
        headers["Content-Type"] = "application/*+json"

    _kwargs["headers"] = headers
    return _kwargs

Extra Info

uv version: 0.4.6

The section in ConfigCat json linked above that's relevant to the code snippet
"patch": {
        "tags": [
          "Feature Flag & Setting values V2"
        ],
        "summary": "Update value",
        "description": "This endpoint updates the value of a Feature Flag or Setting\nwith a collection of [JSON Patch](https://jsonpatch.com) operations in a specified Environment.\n\nOnly the `defaultValue`, `targetingRules`, and `percentageEvaluationAttribute` fields are modifiable by this endpoint.\n\nThe advantage of using JSON Patch is that you can describe individual update operations on a resource\nwithout touching attributes that you don't want to change. It supports collection reordering, so it also\ncan be used for reordering the targeting rules of a Feature Flag or Setting.\n\nFor example: We have the following resource of a Feature Flag.\n```json\n{\n  \"defaultValue\": {\n    \"boolValue\": false\n  },\n  \"targetingRules\": [\n    {\n      \"conditions\": [\n        {\n          \"userCondition\": {\n            \"comparisonAttribute\": \"Email\",\n            \"comparator\": \"sensitiveTextEquals\",\n            \"comparisonValue\": {\n              \"stringValue\": \"test@example.com\"\n            }\n          }\n        }\n      ],\n      \"percentageOptions\": [],\n      \"value\": {\n        \"boolValue\": true\n      }\n    }\n  ]\n}\n```\nIf we send an update request body as below:\n```json\n[\n  {\n    \"op\": \"replace\",\n    \"path\": \"/targetingRules/0/value/boolValue\",\n    \"value\": true\n  }\n]\n```\nOnly the first Targeting Rule's `value` is going to be set to `false` and all the other fields are remaining unchanged.\n\nSo we get a response like this:\n```json\n{\n  \"defaultValue\": {\n    \"boolValue\": false\n  },\n  \"targetingRules\": [\n    {\n      \"conditions\": [\n        {\n          \"userCondition\": {\n            \"comparisonAttribute\": \"Email\",\n            \"comparator\": \"sensitiveTextEquals\",\n            \"comparisonValue\": {\n              \"stringValue\": \"test@example.com\"\n            }\n          }\n        }\n      ],\n      \"percentageOptions\": [],\n      \"value\": {\n        \"boolValue\": false\n      }\n    }\n  ]\n}\n```",
        "operationId": "update-setting-value-v2",
        "parameters": [
          {
            "name": "environmentId",
            "in": "path",
            "description": "The identifier of the Environment.",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          },
          {
            "name": "settingId",
            "in": "path",
            "description": "The id of the Setting.",
            "required": true,
            "schema": {
              "type": "integer",
              "format": "int32"
            }
          },
          {
            "name": "reason",
            "in": "query",
            "description": "The reason note for the Audit Log if the Product's \"Config changes require a reason\" preference is turned on.",
            "schema": {
              "type": "string"
            }
          }
        ],
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "type": "array",
                "items": {
                  "$ref": "#/components/schemas/JsonPatchOperation"
                }
              },
              "examples": {
                "turn on a feature flag": {
                  "description": "This example turns on a feature flag.",
                  "value": [
                    {
                      "op": "replace",
                      "path": "/defaultValue/boolValue",
                      "value": true
                    }
                  ]
                },
                "add targeting rules": {
                  "description": "This example adds an evaluation rule with two conditions to the Flag's targeting rules.",
                  "value": [
                    {
                      "op": "add",
                      "path": "/targetingRules/-",
                      "value": {
                        "conditions": [
                          {
                            "userCondition": {
                              "comparator": "sensitiveTextEquals",
                              "comparisonAttribute": "Email",
                              "comparisonValue": {
                                "stringValue": "example@test.com"
                              }
                            }
                          },
                          {
                            "userCondition": {
                              "comparator": "sensitiveTextEquals",
                              "comparisonAttribute": "Role",
                              "comparisonValue": {
                                "stringValue": "Developer"
                              }
                            }
                          }
                        ],
                        "value": {
                          "boolValue": false
                        }
                      }
                    }
                  ]
                },
                "modify targeting rule": {
                  "description": "This example modifies a targeting rule's value.",
                  "value": [
                    {
                      "op": "replace",
                      "path": "/targetingRules/0/value/boolValue",
                      "value": "true"
                    }
                  ]
                },
                "modify targeting rule's condition": {
                  "description": "This example modifies a condition's comparison attribute within a targeting rule.",
                  "value": [
                    {
                      "op": "replace",
                      "path": "/targetingRules/0/conditions/0/userCondition/comparisonAttribute",
                      "value": "Role"
                    }
                  ]
                },
                "add segment condition": {
                  "description": "This example adds a segment condition to a targeting rule.",
                  "value": [
                    {
                      "op": "add",
                      "path": "/targetingRules/0/conditions/-",
                      "value": {
                        "segmentCondition": {
                          "segmentComparator": "isIn",
                          "segmentId": "008a1fd6-8245-4ea8-90dc-a1dc36c1b4ff"
                        }
                      }
                    }
                  ]
                },
                "add prerequisite flag condition": {
                  "description": "This example adds a prerequisite flag condition to a targeting rule.",
                  "value": [
                    {
                      "op": "add",
                      "path": "/targetingRules/0/conditions/-",
                      "value": {
                        "prerequisiteFlagCondition": {
                          "prerequisiteSettingId": "isIn",
                          "comparator": "008a1fd6-8245-4ea8-90dc-a1dc36c1b4ff",
                          "prerequisiteComparisonValue": {
                            "boolValue": true
                          }
                        }
                      }
                    }
                  ]
                },
                "reorder targeting rules": {
                  "description": "This example swaps the first and the second targeting rule.",
                  "value": [
                    {
                      "op": "move",
                      "path": "/targetingRules/1",
                      "from": "/targetingRules/0"
                    }
                  ]
                },
                "reorder targeting rule conditions": {
                  "description": "This example swaps the first and the second condition of a targeting rule.",
                  "value": [
                    {
                      "op": "move",
                      "path": "/targetingRules/0/conditions/1",
                      "from": "/targetingRules/0/conditions/0"
                    }
                  ]
                }
              }
            },
            "text/json": {
              "schema": {
                "type": "array",
                "items": {
                  "$ref": "#/components/schemas/JsonPatchOperation"
                }
              },
              "examples": {
                "turn on a feature flag": {
                  "description": "This example turns on a feature flag.",
                  "value": [
                    {
                      "op": "replace",
                      "path": "/defaultValue/boolValue",
                      "value": true
                    }
                  ]
                },
                "add targeting rules": {
                  "description": "This example adds an evaluation rule with two conditions to the Flag's targeting rules.",
                  "value": [
                    {
                      "op": "add",
                      "path": "/targetingRules/-",
                      "value": {
                        "conditions": [
                          {
                            "userCondition": {
                              "comparator": "sensitiveTextEquals",
                              "comparisonAttribute": "Email",
                              "comparisonValue": {
                                "stringValue": "example@test.com"
                              }
                            }
                          },
                          {
                            "userCondition": {
                              "comparator": "sensitiveTextEquals",
                              "comparisonAttribute": "Role",
                              "comparisonValue": {
                                "stringValue": "Developer"
                              }
                            }
                          }
                        ],
                        "value": {
                          "boolValue": false
                        }
                      }
                    }
                  ]
                },
                "modify targeting rule": {
                  "description": "This example modifies a targeting rule's value.",
                  "value": [
                    {
                      "op": "replace",
                      "path": "/targetingRules/0/value/boolValue",
                      "value": "true"
                    }
                  ]
                },
                "modify targeting rule's condition": {
                  "description": "This example modifies a condition's comparison attribute within a targeting rule.",
                  "value": [
                    {
                      "op": "replace",
                      "path": "/targetingRules/0/conditions/0/userCondition/comparisonAttribute",
                      "value": "Role"
                    }
                  ]
                },
                "add segment condition": {
                  "description": "This example adds a segment condition to a targeting rule.",
                  "value": [
                    {
                      "op": "add",
                      "path": "/targetingRules/0/conditions/-",
                      "value": {
                        "segmentCondition": {
                          "segmentComparator": "isIn",
                          "segmentId": "008a1fd6-8245-4ea8-90dc-a1dc36c1b4ff"
                        }
                      }
                    }
                  ]
                },
                "add prerequisite flag condition": {
                  "description": "This example adds a prerequisite flag condition to a targeting rule.",
                  "value": [
                    {
                      "op": "add",
                      "path": "/targetingRules/0/conditions/-",
                      "value": {
                        "prerequisiteFlagCondition": {
                          "prerequisiteSettingId": "isIn",
                          "comparator": "008a1fd6-8245-4ea8-90dc-a1dc36c1b4ff",
                          "prerequisiteComparisonValue": {
                            "boolValue": true
                          }
                        }
                      }
                    }
                  ]
                },
                "reorder targeting rules": {
                  "description": "This example swaps the first and the second targeting rule.",
                  "value": [
                    {
                      "op": "move",
                      "path": "/targetingRules/1",
                      "from": "/targetingRules/0"
                    }
                  ]
                },
                "reorder targeting rule conditions": {
                  "description": "This example swaps the first and the second condition of a targeting rule.",
                  "value": [
                    {
                      "op": "move",
                      "path": "/targetingRules/0/conditions/1",
                      "from": "/targetingRules/0/conditions/0"
                    }
                  ]
                }
              }
            },
            "application/*+json": {
              "schema": {
                "type": "array",
                "items": {
                  "$ref": "#/components/schemas/JsonPatchOperation"
                }
              },
              "examples": {
                "turn on a feature flag": {
                  "description": "This example turns on a feature flag.",
                  "value": [
                    {
                      "op": "replace",
                      "path": "/defaultValue/boolValue",
                      "value": true
                    }
                  ]
                },
                "add targeting rules": {
                  "description": "This example adds an evaluation rule with two conditions to the Flag's targeting rules.",
                  "value": [
                    {
                      "op": "add",
                      "path": "/targetingRules/-",
                      "value": {
                        "conditions": [
                          {
                            "userCondition": {
                              "comparator": "sensitiveTextEquals",
                              "comparisonAttribute": "Email",
                              "comparisonValue": {
                                "stringValue": "example@test.com"
                              }
                            }
                          },
                          {
                            "userCondition": {
                              "comparator": "sensitiveTextEquals",
                              "comparisonAttribute": "Role",
                              "comparisonValue": {
                                "stringValue": "Developer"
                              }
                            }
                          }
                        ],
                        "value": {
                          "boolValue": false
                        }
                      }
                    }
                  ]
                },
                "modify targeting rule": {
                  "description": "This example modifies a targeting rule's value.",
                  "value": [
                    {
                      "op": "replace",
                      "path": "/targetingRules/0/value/boolValue",
                      "value": "true"
                    }
                  ]
                },
                "modify targeting rule's condition": {
                  "description": "This example modifies a condition's comparison attribute within a targeting rule.",
                  "value": [
                    {
                      "op": "replace",
                      "path": "/targetingRules/0/conditions/0/userCondition/comparisonAttribute",
                      "value": "Role"
                    }
                  ]
                },
                "add segment condition": {
                  "description": "This example adds a segment condition to a targeting rule.",
                  "value": [
                    {
                      "op": "add",
                      "path": "/targetingRules/0/conditions/-",
                      "value": {
                        "segmentCondition": {
                          "segmentComparator": "isIn",
                          "segmentId": "008a1fd6-8245-4ea8-90dc-a1dc36c1b4ff"
                        }
                      }
                    }
                  ]
                },
                "add prerequisite flag condition": {
                  "description": "This example adds a prerequisite flag condition to a targeting rule.",
                  "value": [
                    {
                      "op": "add",
                      "path": "/targetingRules/0/conditions/-",
                      "value": {
                        "prerequisiteFlagCondition": {
                          "prerequisiteSettingId": "isIn",
                          "comparator": "008a1fd6-8245-4ea8-90dc-a1dc36c1b4ff",
                          "prerequisiteComparisonValue": {
                            "boolValue": true
                          }
                        }
                      }
                    }
                  ]
                },
                "reorder targeting rules": {
                  "description": "This example swaps the first and the second targeting rule.",
                  "value": [
                    {
                      "op": "move",
                      "path": "/targetingRules/1",
                      "from": "/targetingRules/0"
                    }
                  ]
                },
                "reorder targeting rule conditions": {
                  "description": "This example swaps the first and the second condition of a targeting rule.",
                  "value": [
                    {
                      "op": "move",
                      "path": "/targetingRules/0/conditions/1",
                      "from": "/targetingRules/0/conditions/0"
                    }
                  ]
                }
              }
            }
          },
          "required": true
        },
        "responses": {
          "200": {
            "description": "When the patch was successful.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/SettingFormulaModel"
                }
              }
            }
          },
          "204": {
            "description": "When no change applied on the resource."
          },
          "400": {
            "description": "Bad request."
          },
          "404": {
            "description": "Not found."
          },
          "429": {
            "description": "Too many requests. In case of the request rate exceeds the rate limits."
          }
        }
      }
    },
You must be logged in to vote

Replies: 0 comments

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
🙏
Q&A
Labels
None yet
1 participant
Morty Proxy This is a proxified and sanitized view of the page, visit original site.