I have a Spring Boot (2.4.0) REST service, using Java 11. The endpoints and objects are generated from an OpenAPI 3.0.3 file using openapi-generator-maven-plugin v5.0.1
In the API there is a GET request that takes two query params. At least one of them must be present. This example mentions to use minProperties. Although I've specified minProperties in the OpenAPI file, the autogenerated object doesn't validate this. Is there a way to get this working?
OpenAPI 3.3 Snippet:
parameters:
- in: query
name: id
required: true
style: form
explode: true
schema:
title: EntityId
type: object
properties:
businessId:
type: string
nonBusinessId:
type: string
minProperties: 1
additionalProperties: false
openapi-generator-maven-plugin conf:
<plugin>
<groupId>org.openapitools</groupId>
<artifactId>openapi-generator-maven-plugin</artifactId>
<version>5.0.1</version>
<executions>
<execution>
<id>generate-api</id>
<goals>
<goal>generate</goal>
</goals>
<configuration>
<inputSpec>${project.build.directory}/swagger/apis/api.yaml</inputSpec>
<generatorName>spring</generatorName>
<apiPackage>com.acme.api</apiPackage>
<modelPackage>com.acme.api.dto</modelPackage>
<configOptions>
<dateLibrary>java8</dateLibrary>
<interfaceOnly>true</interfaceOnly>
<java8>true</java8>
<useBeanValidation>true</useBeanValidation>
<performBeanValidation>true</performBeanValidation>
<delegatePattern>true</delegatePattern>
</configOptions>
</configuration>
</execution>
</executions>
</plugin>
Generated Class:
public class EntityId {
@JsonProperty("businessId")
private String businessId;
@JsonProperty("nonBusinessId")
private String nonBusinessId;
public EntityId businessId(String businessId) {
this.businessId = businessId;
return this;
}
/**
* Get businessId
* @return businessId
*/
@ApiModelProperty(value = "")
public String getBusinessId() {
return businessId;
}
public void setBusinessId(String businessId) {
this.businessId = businessId;
}
public EntityId nonBusinessId(String nonBusinessId) {
this.nonBusinessId = nonBusinessId;
return this;
}
/**
* Get nonBusinessId
* @return nonBusinessId
*/
@ApiModelProperty(value = "")
public String getNonBusinessId() {
return nonBusinessId;
}
public void setNonBusinessId(String nonBusinessId) {
this.nonBusinessId = nonBusinessId;
}
@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
EntityId entityId = (EntityId) o;
return Objects.equals(this.businessId, entityId.businessId) &&
Objects.equals(this.nonBusinessId, entityId.nonBusinessId);
}
@Override
public int hashCode() {
return Objects.hash(businessId, nonBusinessId);
}
@Override
public String toString() {
StringBuilder sb = new StringBuilder();
sb.append("class EntityId {\n");
sb.append(" businessId: ").append(toIndentedString(businessId)).append("\n");
sb.append(" nonBusinessId: ").append(toIndentedString(nonBusinessId)).append("\n");
sb.append("}");
return sb.toString();
}
/**
* Convert the given object to string with each line indented by 4 spaces
* (except the first line).
*/
private String toIndentedString(Object o) {
if (o == null) {
return "null";
}
return o.toString().replace("\n", "\n ");
}
}