Skip to content

[BUG] [SPRING] [JAVA] required ignored in requestBody #16561

@rawfg

Description

@rawfg

Bug Report Checklist

  • Have you provided a full/minimal spec to reproduce the issue?
  • Have you validated the input using an OpenAPI validator (example)?
  • Have you tested with the latest master to confirm the issue still exists?
  • Have you searched for related issues/PRs?
  • What's the actual output vs expected output?
  • [Optional] Sponsorship to speed up the bug fix or feature request (example)
Description

Using the required property in the requestBody has no effect when using the Spring Java generator.

openapi-generator version

6.6.0, 7.0.0, also detected on 7.0.1-SNAPSHOT.

OpenAPI declaration file content or url
openapi: 3.0.3

info:
  title: "Sample API"
  version: 1.0.0
  contact:
    name: App
    url: https://localhost
  description: Sample OAS for bug.

paths:
  /upload/{id}/file:
    put:
      operationId: "putFile"
      parameters:
        - name: "id"
          in: "path"
          description: ID
          required: true
          schema:
            pattern: \\d{4}
            type: string
          example: "1234"
      requestBody:
        required: true
        description: File image
        content:
          multipart/form-data:
            schema:
              properties:
                file:
                  type: string
                  format: binary
            encoding:
              file:
                contentType: image/png, image/jpeg
      responses:
        204:
          description: Uploaded
        404:
          description: Not Found
Generation Details

There is a sample repository to reproduce.

Steps to reproduce
  1. Clone the sample repository
  2. run the mvn generate-sources command
  3. examine generated sources
Related issues/PRs
Suggest a fix

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions