Request body failure in Micronaut OpenAPI server generation

56 views Asked by At

If I uncomment the requestBody section of the following OpenAPI specification:

paths:
  /rentals:
    post:
      tags:
        - rentals
      operationId: create
#      requestBody:
#        content:
#          "application/json":
#            schema:
#              $ref: "#/components/schemas/RentalInfo"
      parameters:
        - name: name
          required: false
          in: query
          schema:
            type: string
            minLength: 3
      responses:
        "201":
          description: Created
          content:
            "application/json":
              schema:
                $ref: "#/components/schemas/RentalInfo"
        "400":
          description: Bad Request
components:
  schemas:
    RentalInfo:
      type: object
      properties:
        uuid: { type: string }
        name: { type: string }
      required: [ "uuid", "name" ]

Then I'm getting the following error:

Error finalizing type visitor [io.micronaut.openapi.visitor.OpenApiApplicationVisitor@2268ad32]: Cannot invoke "String.equals(Object)" because the return value of "io.swagger.v3.oas.models.parameters.Parameter.getIn()" is null

I tried to debug SchemaUtils and it seems like the response body method parameter gets picked up as a parameter but the in field is null because it is not a parameter.

The same thing happens if I rename method parameter names and they stop matching the OpenAPI contract values.

I am using Micronaut OpenAPI server code generation. If I try using the YAML included in this guide, the same thing happens.

My controller class looks like this:

@Controller
class RentalsController implements RentalsApi {

    @Override
    public HttpResponse<RentalInfo> create(final String name, final RentalInfo rentalInfo) {
        return null;
    }

    @Override
    public List<RentalInfo> search(final String name) {
        return List.of(
                new RentalInfo(UUID.randomUUID().toString(), "Rental 1"),
                new RentalInfo(UUID.randomUUID().toString(), "Rental 2")
        );
    }
}

Not having the class in place also stops the error from happening.

0

There are 0 answers