OpenApi Generator to generate parameter with @RequestBody as String

Viewed 999

I have the following OpenApi specs:

paths:
  /student:
    post:
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: "#/components/schemas/Student"
      responses:
        204:


components:
  schemas:
    Student:
      type: object
      properties:
        name:
          type: string
        school:
          type: string

With org.openapitools.generator, it generates a controller with function like below

void addStudent(@RequestBody Student student) {
}

Is there any way to configure the generator to generate @RequestBody as String?

void addStudent(@RequestBody String student) {
}
1 Answers

I think you need to set your response as text/plain with schema: type: string in your OpenAPI.

Apart from that, you can keep the Student schema in your OpenAPI and the generator should generate it as a java class.

    paths:
      /ping:
        get:
          responses:
            '200':
              description: OK
              content:
                text/plain:
                  schema:
                    type: string
                    example: pong

Read the official docs here.

Related