-
-
Notifications
You must be signed in to change notification settings - Fork 7.4k
Open
Labels
Description
Bug Report Checklist
- Have you provided a full/minimal spec to reproduce the issue?
- Have you validated the input using an OpenAPI validator?
- 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
When running the generator with a setup like
components:
schemas:
Mailbox:
type: object
allOf:
- $ref: '#/components/schemas/MailboxProperties'
- required:
- name
- userIdentifier
MailboxProperties:
type: object
properties:
name:
type: string
minLength: 1
maxLength: 255
nullable: false
userIdentifier:
type: string
minLength: 1
maxLength: 255
nullable: falsethe output in 7.13.0 and earlier looked like the following for the model of Mailbox for the name getter
@NotNull @Size(min = 1, max = 255)
@Schema(name = "name", requiredMode = Schema.RequiredMode.REQUIRED)
@JsonProperty("name")
public String getName() {
return name;
}with the upgrade to 7.14.0, this has lost the @NotNull annotation and has the incorrect value for the requiredMode
@Size(min = 1, max = 255)
@Schema(name = "name", requiredMode = Schema.RequiredMode.NOT_REQUIRED)
@JsonProperty("name")
public @Nullable String getName() {
return name;
}This is breaking alot of our services which rely on these to perform validation
openapi-generator version
I'm upgrading from 7.10.0 to 7.14.0 but verified the regression occurs in 7.14.0 as it doesnt occur with 7.13.0
OpenAPI declaration file content or url
openapi: 3.0.0
info:
title: mailbox
version: 1.0.0
paths:
/mailboxes:
post:
requestBody:
required: true
content:
application/json:
schema:
$ref: '#/components/schemas/Mailbox'
responses:
'201':
description: created.
components:
schemas:
Mailbox:
type: object
allOf:
- $ref: '#/components/schemas/MailboxProperties'
- required:
- name
- userIdentifier
MailboxProperties:
type: object
properties:
name:
type: string
minLength: 1
maxLength: 255
nullable: false
emailAddress:
type: string
format: email
minLength: 1
maxLength: 255
nullable: false
userIdentifier:
type: string
minLength: 1
maxLength: 255
nullable: false
Generation Details
Run via the gradle kotlin build.gradle.kts file the task openApiGenerate
plugins {
id("java")
id("org.openapi.generator") version "7.14.0"
}
group = "com.test"
version = "1.0-SNAPSHOT"
repositories {
mavenCentral()
}
openApiGenerate {
generatorName.set("spring")
inputSpec.set("${projectDir}/openapi.yaml")
outputDir.set("${buildDir}/generated/openapi")
apiPackage.set("com.test.bob.api")
modelPackage.set("com.test.bob.model")
invokerPackage.set("com.test.bob.invoker")
configOptions.set(
mapOf(
"configPackage" to "com.test.bob.configuration",
"useSpringBoot3" to "true",
"delegatePattern" to "true",
"generatedConstructorWithRequiredArgs" to "false"
)
)
}
sourceSets["main"].java.srcDir("${buildDir}/generated/openapi/src/main/java")Steps to reproduce
Generate the java code from the spec, inspect the model class for Mailbox, note the getter for name has been generated as
@Size(min = 1, max = 255)
@Schema(name = "name", requiredMode = Schema.RequiredMode.NOT_REQUIRED)
@JsonProperty("name")
public @Nullable String getName() {
return name;
}when this should be
@NotNull @Size(min = 1, max = 255)
@Schema(name = "name", requiredMode = Schema.RequiredMode.REQUIRED)
@JsonProperty("name")
public String getName() {
return name;
}Related issues/PRs
I think it maybe related to the fix for #21342 in 7.1.4.0 version @wing328
Reactions are currently unavailable