OpenAPI generator Java Client SE

977 views Asked by At

I've an OperAPI like this, with content "application/x-www-form-urlencoded" that i must use (the external API to implement support only that):

/token:
 post:
  operationId: retrieveToken
  requestBody:
    content:
      application/x-www-form-urlencoded:
        schema:
          title: GenerateTokenRequest
          type: object
          properties:
            grant_type:
              type: string
            client_id:
              type: string

The OpenAPI Generator Maven's plugin creates a request class "GenerateTokenRequest" for the schema object but in API implementation class it doesn't use. It generate a method with all requested fields as a list of parameter. The method is this:

 public GenerateTokenResponse retrieveToken(String grantType, String clientId, String clientSecret, String scope) throws ApiException {
    ApiResponse<GenerateTokenResponse> resp = retrieveTokenWithHttpInfo(grantType, clientId, clientSecret, scope);
    return resp.getData();
}

So, in this case the request class "GenerateTokenRequest" is generated but never used. Anyone can say me why? There is an alternative way for using my request class? Can I change something in OpenAPI file structure? Or there is a way to avoid the generation of the request class?


EDIT: Solved! The service i wanted to define was an OAuth2 authentication service so i've configured a securitySchemas of type "oauth2"

3

There are 3 answers

0
Cristian De Vecchi On BEST ANSWER

Solved! The service i wanted to define was an OAuth2 authentication service so i've configured a securitySchemas of type "oauth2"

1
FloFromYet On
paths:
  /token:
    post:
      operationId: retrieveToken
      requestBody:
        content:
          application/x-www-form-urlencoded:
            schema:
              type: object
              properties:
                grant_type:
                  type: string
                client_id:
                  type: string

If you use that structure, no request class "GenerateTokenRequest" will be generated, only the API

5
FloFromYet On

You have to replace

application/x-www-form-urlencoded

by

application/json or application/xml