OpenAPITools / OpenAPITools/openapi-generator

[BUG][JAVA] required on component only set on the getter of the model

Open
#13,196 1 comment 4 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Issue: Bug
Dominant language
Java
Stars
26.8k
Forks
7.7k
PR merge metrics
PR metrics pending

Description

We have a post method with a component as body.
This component has required field but sending a post with missing elements is allowed with the current generated code.
openapi yaml :
...
paths:
/events:
post:
tags:
- Event Data
operationId: createEvent
requestBody:
required: true
content:
application/json:
schema:
$ref: '#/components/schemas/event'
...
components:
schemas:
event:
title: event
description: event
type: object
required:
- eventName
properties:
eventName:
type: string

pom.xml
...

org.openapitools
openapi-generator-maven-plugin
6.0.1


spring-boot-api

generate


spring

true
true
true
false

spring-boot




...

event class generated :
...
@JsonProperty("eventName")
private String eventName;
...
@NotNull
@Schema(name = "eventName", required = true)
public String getEventName() {
return eventName;
}

public void setEventName(String eventName) {
this.eventName = eventName;
}

--

We expect the @NotNull on the setter to or even on the Property.
Now we can call the create without any content in the body except '{}'

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the generated Spring model from the OpenAPI YAML and Maven configuration in the issue, then inspect the generated event class and the generator path that places @NotNull on getEventName(). Add or adjust coverage for a missing eventName in {}, and consider the issue done when generated validation rejects the request while preserving the required annotation semantics.

Written by the indexing model from the issue text.

Assessment

Tech stack
java, openapi, spring
Domain
api, backend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.