Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] [Python] Model generated without any properties #16857

Closed
Mapiarz opened this issue Oct 18, 2023 · 4 comments · Fixed by #16943
Closed

[BUG] [Python] Model generated without any properties #16857

Mapiarz opened this issue Oct 18, 2023 · 4 comments · Fixed by #16943

Comments

@Mapiarz
Copy link

Mapiarz commented Oct 18, 2023

Description

The generator seems to generate a pydantic model without any properties, thus is useless. See below for full example.

openapi-generator version

7.0.1

OpenAPI declaration file content or url

This is minimal schema that reproduces the issue. This schema comes from third party and is outside of my control, I cannot change it.

openapi: 3.0.0

info:
  title: Foo
  version: 1.0.0

paths:
  /foo:
    get:
      responses:
        '200':
          description: example
          content:
            application/json:
              schema:
                type: array
                items:
                 $ref: '#/components/schemas/Payment'


components:
  schemas:
    DateTime:
      type: string
      format: date-time
      example: "2019-01-01T00:00:00"
    Datetime:
      allOf:
        - $ref: '#/components/schemas/DateTime'
      example: "2019-01-01 00:00:00" 
    Payment:
      type: object
      properties:
        date:
          $ref: '#/components/schemas/Datetime'
        amount:
          type: number
          format: float
          example: 625.0
Generation Details

Generating the sdk like this:
pnpm dlx @openapitools/openapi-generator-cli generate -i spec.yaml -g python -o /package --package-name my_package

It generates a Datetime pydantic model without any properties:

# coding: utf-8

"""
    Foo

    No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)

    The version of the OpenAPI document: 1.0.0
    Generated by OpenAPI Generator (https://openapi-generator.tech)

    Do not edit the class manually.
"""  # noqa: E501


from __future__ import annotations
import pprint
import re  # noqa: F401
import json



from pydantic import BaseModel

class Datetime(BaseModel):
    """
    Datetime
    """
    __properties = []

    class Config:
        """Pydantic configuration"""
        allow_population_by_field_name = True
        validate_assignment = True

    def to_str(self) -> str:
        """Returns the string representation of the model using alias"""
        return pprint.pformat(self.dict(by_alias=True))

    def to_json(self) -> str:
        """Returns the JSON representation of the model using alias"""
        return json.dumps(self.to_dict())

    @classmethod
    def from_json(cls, json_str: str) -> Datetime:
        """Create an instance of Datetime from a JSON string"""
        return cls.from_dict(json.loads(json_str))

    def to_dict(self):
        """Returns the dictionary representation of the model using alias"""
        _dict = self.dict(by_alias=True,
                          exclude={
                          },
                          exclude_none=True)
        return _dict

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

        if not isinstance(obj, dict):
            return Datetime.parse_obj(obj)

        _obj = Datetime.parse_obj({
        })
        return _obj
@fa0311
Copy link
Contributor

fa0311 commented Oct 20, 2023

Duplicate Datetime key.
Please use the correct yaml format.

@Mapiarz
Copy link
Author

Mapiarz commented Oct 20, 2023

It's DateTime and Datetime. Are you saying it's case insensitive?

@fa0311
Copy link
Contributor

fa0311 commented Oct 20, 2023

I was mistaken. It is case sensitive.
More research is needed.

@wing328 wing328 mentioned this issue Oct 31, 2023
5 tasks
@wing328
Copy link
Member

wing328 commented Oct 31, 2023

update: I've filed #16943 to fix it

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants