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?
CodePudding user response:
You have to replace
application/x-www-form-urlencoded
by
application/json or application/xml
CodePudding user response:
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