openapi-generators / openapi-generators/openapi-python-client

Missing import when there is a const in the object

Ouverte
#1,074 3 commentaires 0 réactions 0 personnes assignées Voir sur GitHub

Personne n'a encore pris cette issue.

Langage dominant
Python
Étoiles
2k
Forks
293
Merge moyen
34 min
PR mergées (30 j)
1

Description

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

Guide de contribution

Ouvrir le guide de contribution

Par où commencer

  1. Lisez l'issue en entier, puis le guide de contribution du projet.
  2. Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
  3. Forkez le dépôt et travaillez sur une branche.
  4. Ouvrez une pull request qui référence le numéro de l'issue.

Piste de recherche

Commencez par la spécification OpenAPI fournie et examinez le fichier généré rivery_scim_client/models/book.py, en particulier la référence cast non définie signalée à la ligne 40. Comparez le comportement avec la pull request 1072 et vérifiez que la génération réussit sans l’erreur F821 et que le client généré passe Ruff.

Rédigé par le modèle d'indexation à partir du texte de l'issue.

Évaluation

Stack technique
python
Domaine
devtools
Type d'issue
Bug
Difficulté
3/5
Temps estimé
1-2 jours
Activité
À l'abandon
Clarté
Plutôt claire
Accessibilité débutants
30/100

Recevez les nouvelles issues par e-mail

Un résumé court des issues GitHub adaptées aux débutants.