SwaggerHub introducing duplicate keys by lower casing when downloading SDK

22 Views Asked by At

I'm trying to use the BinanceSpotAPI on https://app.swaggerhub.com/apis/binance_api/BinanceSpotAPI/1.0 When I look at the raw code that is there, the /api/v3/aggTrades has a bunch of parameters, one of which is

m, "Was the buyer the maker?" and

M, "Was the trade the best price match?"

They are cased correctly. But when I download the sdk (from export -> client sdk -> python), going to that file shows that all of the instances of M have been replaced with m in almost all places. This means that there are duplicate keys. Also, the T is replaced with t. How is this possible? raw in swaggerhub:

aggTrade:
  type: object
  properties:
    a:
      type: integer
      format: int64
      description: Aggregate tradeId
      example: 26129
    p:
      ... [p ,q, f, l, removed for brevity] ...
    T:
      type: boolean
      description: Timestamp
      example: 1498793709153
    m:
      type: boolean
      description: Was the buyer the maker?
    M:
      type: boolean
      description: Was the trade the best price match?
  required:
    - a
    - p
    - q
    - f
    - l
    - T
    - m
    - M

but then this code is generated with the duplicate m:

swagger_types = {
        'a': 'int',
        'p': 'str',
        'q': 'str',
        'f': 'int',
        'l': 'int',
        't': 'bool',
        'm': 'bool',
        'm': 'bool'
    }

and

attribute_map = {
    'a': 'a',
    'p': 'p',
    'q': 'q',
    'f': 'f',
    'l': 'l',
    't': 'T',
    'm': 'm',
    'm': 'M'
}

I think the fact that theres a capital T and M in the value of the attribute_map is some kind of clue but no idea why this would be the case

to reproduce: go to the webpage download the python sdk look at /swagger_client/models/agg_trade.py, line 38

Looks like this happens in swaggerhub, but also when trying the same download in editor.swagger.io

Edit: another hint. When I try to use openapi-generator, it fails because one of the names is too long. But before it fails it does generate this file, and heres how it shows up.

class AggTrade(BaseModel):
"""
AggTrade
""" # noqa: E501
a: StrictInt = Field(description="Aggregate tradeId")
p: StrictStr = Field(description="Price")
q: StrictStr = Field(description="Quantity")
f: StrictInt = Field(description="First tradeId")
l: StrictInt = Field(description="Last tradeId")
t: StrictBool = Field(description="Timestamp", alias="T")
m: StrictBool = Field(description="Was the buyer the maker?")
m: StrictBool = Field(description="Was the trade the best price match?", alias="M")
__properties: ClassVar[List[str]] = ["a", "p", "q", "f", "l", "T", "m", "M"]


@classmethod
    def from_dict(cls, obj: Dict) -> Self:
        """Create an instance of AggTrade from a dict"""
        if obj is None:
            return None

        if not isinstance(obj, dict):
            return cls.model_validate(obj)

        _obj = cls.model_validate({
            "a": obj.get("a"),
            "p": obj.get("p"),
            "q": obj.get("q"),
            "f": obj.get("f"),
            "l": obj.get("l"),
            "T": obj.get("T"),
            "m": obj.get("m"),
            "M": obj.get("M")
        })
        return _obj
0

There are 0 best solutions below