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

body type mismatch

Ouverte
#963 0 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
In the _get_kwargs generated method, the body is determined as File type (because the format in my swagger definition is binary), but it tries to access its .to_dict attribute (because body_type is considered as data due to the content type application/x-www-form-urlencoded), which does not exist because it is a file

OpenAPI Spec File

"content": {
    "application/x-www-form-urlencoded": {
        "schema": {
            "description": "do stuff",
            "type": "string",
            "format": "binary"
        }
    }
}

Desktop (please complete the following information):

  • OS: macOS 13.3.1
  • Python Version: 3.9.8
  • openapi-python-client version: 0.17.2

Additional context
In the macro, the arguments macro determine the argument type of body based on endpoint.bodies[0].prop.get_type_string(), whereas in the body_to_kwarg macro it determines it based on body.body_type, which is determined by the following:

        if simplified_content_type == "application/x-www-form-urlencoded":
            body_type = BodyType.DATA
        elif simplified_content_type == "multipart/form-data":
            body_type = BodyType.FILES
        elif simplified_content_type == "application/octet-stream":
            body_type = BodyType.CONTENT
        elif simplified_content_type == "application/json" or simplified_content_type.endswith("+json"):
            body_type = BodyType.JSON

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

Start with the generated _get_kwargs method and trace the arguments and body_to_kwarg macros, especially how endpoint.bodies[0].prop.get_type_string() differs from body.body_type. Review the application/x-www-form-urlencoded BodyType mapping and verify that a binary body no longer attempts to access .to_dict.

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

Évaluation

Stack technique
python
Domaine
api, tooling
Type d'issue
Bug
Difficulté
4/5
Temps estimé
3-5 jours
Activité
À l'abandon
Clarté
Plutôt claire
Accessibilité débutants
38/100

Recevez les nouvelles issues par e-mail

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