Forum Discussion

rhanda's avatar
rhanda
New Contributor
8 months ago

Not able to generate Swagger/OpenAPI for a request having RequestBody as protobuf.Message

Hello Community,

 

I'm working on a project which uses Kotlin and Springboot and we want to document our API using Swagger/OpenAPI.

One of the endpoint is used as both GRPC and HTTPS. The requestBody in it of type com.google.protobuf.Message. 
We have added custom decoders to parse the JSON to Message object using com.google.protobuf.util.JsonFormat.

 

We are using springdoc-openapi-webflux-ui for Swagger/OpenAPI ui and the problem that it is not able to generate example request body for the above API and it gets stuck.

What would be the best approach to solve it?

How to add custom decoders?

Can we use the custom decoder to define the schema used in Swagger? I'm referring to the schema present in /v3/api-docs, like 

"requestBody": {
 "content": {
    "application/json": {
        "schema": {
            "$ref": "#/components/schemas/ValidateRequest"
         }
    }
},
}

 

 

Example api:

@PostMapping(
value = ["/validate"],
produces = [MediaType.APPLICATION_JSON_VALUE],
consumes = [MediaType.APPLICATION_JSON_VALUE],
)
suspend fun sendOTPObject(
@RequestBody requestBody: ValidateRequest,
ğŸ˜ž ResponseEntity<ValidateRequest> {

    return ResponseEntity.ok(requestBody)
}