openapi-generators / openapi-python-client

Generate modern Python clients from OpenAPI
MIT License
1.27k stars 196 forks source link

Missing import when there is a const in the object #1074

Open dorcohe opened 2 months ago

dorcohe commented 2 months ago

Describe the bug Version: 0.21.1 When I try to generate a client it fails with the following error: Error(s) encountered while generating, client was not created

ruff failed

rivery_scim_client/models/book.py:40:21: F821 Undefined name cast Found 209 errors (208 fixed, 1 remaining).

As you can see there is an import missing. I publish a PR that should solve it. https://github.com/openapi-generators/openapi-python-client/pull/1072

OpenAPI Spec File I created a dummy openapi specification.

{
    "openapi": "3.1.0",
    "info": {
        "title": "FastAPI",
        "version": "0.1.0"
    },
    "paths": {
        "/books": {
            "post": {
                "summary": "Create User",
                "operationId": "create_user_books_post",
                "requestBody": {
                    "content": {
                        "application/json": {
                            "schema": {
                                "$ref": "#/components/schemas/Book"
                            }
                        }
                    },
                    "required": true
                },
                "responses": {
                    "200": {
                        "description": "Successful Response",
                        "content": {
                            "application/json": {
                                "schema": {}
                            }
                        }
                    },
                    "422": {
                        "description": "Validation Error",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/HTTPValidationError"
                                }
                            }
                        }
                    }
                }
            }
        }
    },
    "components": {
        "schemas": {
            "Book": {
                "properties": {
                    "item_type": {
                        "const": "book",
                        "title": "Item Type",
                        "default": "book"
                    }
                },
                "type": "object",
                "title": "Book"
            },
            "ErrorResponse": {
                "properties": {
                    "schemas": {
                        "items": {
                            "type": "string"
                        },
                        "type": "array",
                        "title": "Schemas",
                        "default": [
                            "urn:ietf:params:scim:api:messages:2.0:Error"
                        ]
                    },
                    "status": {
                        "type": "integer",
                        "title": "Status"
                    },
                    "details": {
                        "type": "string",
                        "title": "Details"
                    }
                },
                "type": "object",
                "required": [
                    "status",
                    "details"
                ],
                "title": "ErrorResponse"
            },
            "HTTPValidationError": {
                "properties": {
                    "detail": {
                        "items": {
                            "$ref": "#/components/schemas/ValidationError"
                        },
                        "type": "array",
                        "title": "Detail"
                    }
                },
                "type": "object",
                "title": "HTTPValidationError"
            },
            "ValidationError": {
                "properties": {
                    "loc": {
                        "items": {
                            "anyOf": [
                                {
                                    "type": "string"
                                },
                                {
                                    "type": "integer"
                                }
                            ]
                        },
                        "type": "array",
                        "title": "Location"
                    },
                    "msg": {
                        "type": "string",
                        "title": "Message"
                    },
                    "type": {
                        "type": "string",
                        "title": "Error Type"
                    }
                },
                "type": "object",
                "required": [
                    "loc",
                    "msg",
                    "type"
                ],
                "title": "ValidationError"
            }
        },
        "securitySchemes": {
            "HTTPBearer": {
                "type": "http",
                "scheme": "bearer"
            }
        }
    }
}

Additional context Add any other context about the problem here. N/A

dorcohe commented 1 month ago

ping

ykim commented 4 weeks ago

I'm also encountering this issue. Any chances the related PR will be merged in as part of a release?