OpenAPITools / openapi-generator

OpenAPI Generator allows generation of API client libraries (SDK generation), server stubs, documentation and configuration automatically given an OpenAPI Spec (v2, v3)
https://openapi-generator.tech
Apache License 2.0
22.06k stars 6.62k forks source link

[BUG][JAVA] Using incorrect @Multipart instead of @FormParam when generated Microprofile java client #10618

Open kariim77 opened 3 years ago

kariim77 commented 3 years ago

Bug Report Checklist

Description

When java client with microprofile is generated (in quarkus), for request with "application/x-www-form-urlencoded" consumes, incorrect annotations are present.

openapi-generator version

Open api version 5.2.1

This :

  public OAuth200 oAuthPasswordAuthenticate(@Multipart(value = "grant_type")  String grantType, @Multipart(value = "client_id")  String clientId, @Multipart(value = "client_secret")  String clientSecret, @Multipart(value = "username")  String username, @Multipart(value = "password")  String password) throws ApiException, ProcessingException;

Should be :

public OAuth200 getToken(@FormParam("grant_type") String grant_type, @FormParam("client_id") String clientId,
                             @FormParam("client_secret") String clientSecret, @FormParam("username") String username,
                             @FormParam("password") String password);

It cause an 400 Bad request error from server.

OpenAPI declaration file content or url
openapi: "3.0.2"
info:
servers: []
tags:
- name: "AuthPres"

  x-displayName: "Sécurité"
- name: "OAuthPassword"
  description: "Méthode d'authentification OAuth2 implémentant le **password Grant\
    \ Type**."
  x-displayName: "OAuth2 password"
paths:
  /auth/realms/HarvestAPI/protocol/openid-connect/token:
    post:
      tags:
      - "OAuthPassword"
      description: "Le jeton JWT à exploiter est retourné dans valeur de la proprié\
        té `access_token`.\n\nIl doit être précisé dans l**'entête HTTP** de toutes\
        \ les requêtes (sauf celles d'authentification)\ncomme ceci :\n\n`Authorization:\
        \ Bearer <access_token>`\n\nRappel : Les informations nécessaires à l'obtention\
        \ d'un jeton vous **sont fournies par Harvest**\nspécifiquement pour votre\
        \ application."
      operationId: "OAuthPasswordAuthenticate"
      requestBody:
        content:
          application/x-www-form-urlencoded:
            schema:
              $ref: "#/components/schemas/OAuthPassword"
            examples:
              OAuth2PasswordPayload:
                value:
                  grant_type: "password"
                  client_id: "clientId"
                  client_secret: "clientSecret"
                  username: "username"
                  password: "password"
        required: true
      responses:
        "200":
          description: "200 OK"
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/OAuth200"
        "400":
          description: "Erreur OAuth 400 (Bad Request)"
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/OAuthErr"
              example:
                error: "invalid_request"
                error_description: "Missing form parameter: grant_type"
        "401":
          description: "Erreur OAuth 401 (Unauthorized)"
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/OAuthErr"
              example:
                error: "invalid_grant"
                error_description: "Invalid user credentials"
melloware commented 2 years ago

+1 for this

bushi-go commented 2 years ago

+1 here