mirror of
https://github.com/OpenAPITools/openapi-generator.git
synced 2025-12-09 13:26:16 +00:00
add test case for nullable parent property (#16552)
* add nullable case to spring test spec * generate samples for changed spring input * add nullable case to general test spec * generate samples for changed general input * generate samples again * generates samples again * re-build from new sources, generates samples again
This commit is contained in:
@@ -34,6 +34,7 @@ src/main/java/org/openapitools/model/BigCat.java
|
||||
src/main/java/org/openapitools/model/Capitalization.java
|
||||
src/main/java/org/openapitools/model/Cat.java
|
||||
src/main/java/org/openapitools/model/Category.java
|
||||
src/main/java/org/openapitools/model/ChildWithNullable.java
|
||||
src/main/java/org/openapitools/model/ClassModel.java
|
||||
src/main/java/org/openapitools/model/Client.java
|
||||
src/main/java/org/openapitools/model/ContainerDefaultValue.java
|
||||
@@ -57,6 +58,7 @@ src/main/java/org/openapitools/model/NumberOnly.java
|
||||
src/main/java/org/openapitools/model/Order.java
|
||||
src/main/java/org/openapitools/model/OuterComposite.java
|
||||
src/main/java/org/openapitools/model/OuterEnum.java
|
||||
src/main/java/org/openapitools/model/ParentWithNullable.java
|
||||
src/main/java/org/openapitools/model/Pet.java
|
||||
src/main/java/org/openapitools/model/ReadOnlyFirst.java
|
||||
src/main/java/org/openapitools/model/ResponseObjectWithDifferentFieldNames.java
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
package org.openapitools.api;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import org.openapitools.model.ChildWithNullable;
|
||||
import org.openapitools.model.Client;
|
||||
import org.springframework.format.annotation.DateTimeFormat;
|
||||
import org.openapitools.model.FileSchemaTestClass;
|
||||
@@ -544,6 +545,35 @@ public interface FakeApi {
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* POST /fake/nullable : test nullable parent property
|
||||
*
|
||||
*
|
||||
* @param childWithNullable request body (required)
|
||||
* @return successful operation (status code 200)
|
||||
*/
|
||||
@ApiOperation(
|
||||
tags = { "fake" },
|
||||
value = "test nullable parent property",
|
||||
nickname = "testNullable",
|
||||
notes = ""
|
||||
)
|
||||
@ApiResponses({
|
||||
@ApiResponse(code = 200, message = "successful operation")
|
||||
})
|
||||
@RequestMapping(
|
||||
method = RequestMethod.POST,
|
||||
value = "/fake/nullable",
|
||||
consumes = { "application/json" }
|
||||
)
|
||||
default ResponseEntity<Void> testNullable(
|
||||
@ApiParam(value = "request body", required = true) @Valid @RequestBody ChildWithNullable childWithNullable
|
||||
) {
|
||||
return new ResponseEntity<>(HttpStatus.NOT_IMPLEMENTED);
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* PUT /fake/test-query-parameters
|
||||
* To test the collection format in query parameters
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package org.openapitools.api;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import org.openapitools.model.ChildWithNullable;
|
||||
import org.openapitools.model.Client;
|
||||
import org.springframework.format.annotation.DateTimeFormat;
|
||||
import org.openapitools.model.FileSchemaTestClass;
|
||||
|
||||
@@ -0,0 +1,101 @@
|
||||
package org.openapitools.model;
|
||||
|
||||
import java.net.URI;
|
||||
import java.util.Objects;
|
||||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import com.fasterxml.jackson.annotation.JsonCreator;
|
||||
import com.fasterxml.jackson.annotation.JsonSubTypes;
|
||||
import com.fasterxml.jackson.annotation.JsonTypeInfo;
|
||||
import com.fasterxml.jackson.annotation.JsonValue;
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import org.openapitools.model.ParentWithNullable;
|
||||
import java.time.OffsetDateTime;
|
||||
import javax.validation.Valid;
|
||||
import javax.validation.constraints.*;
|
||||
|
||||
|
||||
import java.util.*;
|
||||
import javax.annotation.Generated;
|
||||
|
||||
/**
|
||||
* ChildWithNullable
|
||||
*/
|
||||
|
||||
|
||||
@Generated(value = "org.openapitools.codegen.languages.SpringCodegen")
|
||||
public class ChildWithNullable extends ParentWithNullable {
|
||||
|
||||
private String otherProperty;
|
||||
|
||||
public ChildWithNullable otherProperty(String otherProperty) {
|
||||
this.otherProperty = otherProperty;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get otherProperty
|
||||
* @return otherProperty
|
||||
*/
|
||||
|
||||
@ApiModelProperty(value = "")
|
||||
@JsonProperty("otherProperty")
|
||||
public String getOtherProperty() {
|
||||
return otherProperty;
|
||||
}
|
||||
|
||||
public void setOtherProperty(String otherProperty) {
|
||||
this.otherProperty = otherProperty;
|
||||
}
|
||||
|
||||
|
||||
public ChildWithNullable type(TypeEnum type) {
|
||||
super.type(type);
|
||||
return this;
|
||||
}
|
||||
|
||||
public ChildWithNullable nullableProperty(String nullableProperty) {
|
||||
super.nullableProperty(nullableProperty);
|
||||
return this;
|
||||
}
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) {
|
||||
return true;
|
||||
}
|
||||
if (o == null || getClass() != o.getClass()) {
|
||||
return false;
|
||||
}
|
||||
ChildWithNullable childWithNullable = (ChildWithNullable) o;
|
||||
return Objects.equals(this.otherProperty, childWithNullable.otherProperty) &&
|
||||
super.equals(o);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(otherProperty, super.hashCode());
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append("class ChildWithNullable {\n");
|
||||
sb.append(" ").append(toIndentedString(super.toString())).append("\n");
|
||||
sb.append(" otherProperty: ").append(toIndentedString(otherProperty)).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 ");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,153 @@
|
||||
package org.openapitools.model;
|
||||
|
||||
import java.net.URI;
|
||||
import java.util.Objects;
|
||||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import com.fasterxml.jackson.annotation.JsonCreator;
|
||||
import com.fasterxml.jackson.annotation.JsonSubTypes;
|
||||
import com.fasterxml.jackson.annotation.JsonTypeInfo;
|
||||
import com.fasterxml.jackson.annotation.JsonValue;
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import java.time.OffsetDateTime;
|
||||
import javax.validation.Valid;
|
||||
import javax.validation.constraints.*;
|
||||
|
||||
|
||||
import java.util.*;
|
||||
import javax.annotation.Generated;
|
||||
|
||||
/**
|
||||
* ParentWithNullable
|
||||
*/
|
||||
|
||||
@JsonIgnoreProperties(
|
||||
value = "type", // ignore manually set type, it will be automatically generated by Jackson during serialization
|
||||
allowSetters = true // allows the type to be set during deserialization
|
||||
)
|
||||
@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "type", visible = true)
|
||||
@JsonSubTypes({
|
||||
@JsonSubTypes.Type(value = ChildWithNullable.class, name = "ChildWithNullable")
|
||||
})
|
||||
|
||||
@Generated(value = "org.openapitools.codegen.languages.SpringCodegen")
|
||||
public class ParentWithNullable {
|
||||
|
||||
/**
|
||||
* Gets or Sets type
|
||||
*/
|
||||
public enum TypeEnum {
|
||||
CHILDWITHNULLABLE("ChildWithNullable");
|
||||
|
||||
private String value;
|
||||
|
||||
TypeEnum(String value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
@JsonValue
|
||||
public String getValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return String.valueOf(value);
|
||||
}
|
||||
|
||||
@JsonCreator
|
||||
public static TypeEnum fromValue(String value) {
|
||||
for (TypeEnum b : TypeEnum.values()) {
|
||||
if (b.value.equals(value)) {
|
||||
return b;
|
||||
}
|
||||
}
|
||||
throw new IllegalArgumentException("Unexpected value '" + value + "'");
|
||||
}
|
||||
}
|
||||
|
||||
private TypeEnum type;
|
||||
|
||||
private String nullableProperty = null;
|
||||
|
||||
public ParentWithNullable type(TypeEnum type) {
|
||||
this.type = type;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get type
|
||||
* @return type
|
||||
*/
|
||||
|
||||
@ApiModelProperty(value = "")
|
||||
@JsonProperty("type")
|
||||
public TypeEnum getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
public void setType(TypeEnum type) {
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
public ParentWithNullable nullableProperty(String nullableProperty) {
|
||||
this.nullableProperty = nullableProperty;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get nullableProperty
|
||||
* @return nullableProperty
|
||||
*/
|
||||
|
||||
@ApiModelProperty(value = "")
|
||||
@JsonProperty("nullableProperty")
|
||||
public String getNullableProperty() {
|
||||
return nullableProperty;
|
||||
}
|
||||
|
||||
public void setNullableProperty(String nullableProperty) {
|
||||
this.nullableProperty = nullableProperty;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) {
|
||||
return true;
|
||||
}
|
||||
if (o == null || getClass() != o.getClass()) {
|
||||
return false;
|
||||
}
|
||||
ParentWithNullable parentWithNullable = (ParentWithNullable) o;
|
||||
return Objects.equals(this.type, parentWithNullable.type) &&
|
||||
Objects.equals(this.nullableProperty, parentWithNullable.nullableProperty);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(type, nullableProperty);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append("class ParentWithNullable {\n");
|
||||
sb.append(" type: ").append(toIndentedString(type)).append("\n");
|
||||
sb.append(" nullableProperty: ").append(toIndentedString(nullableProperty)).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 ");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -986,6 +986,27 @@ paths:
|
||||
x-accepts: application/json
|
||||
x-tags:
|
||||
- tag: fake
|
||||
/fake/nullable:
|
||||
post:
|
||||
description: ""
|
||||
operationId: testNullable
|
||||
requestBody:
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
$ref: '#/components/schemas/ChildWithNullable'
|
||||
description: request body
|
||||
required: true
|
||||
responses:
|
||||
"200":
|
||||
description: successful operation
|
||||
summary: test nullable parent property
|
||||
tags:
|
||||
- fake
|
||||
x-content-type: application/json
|
||||
x-accepts: application/json
|
||||
x-tags:
|
||||
- tag: fake
|
||||
/fake/body-with-query-params:
|
||||
put:
|
||||
operationId: testBodyWithQueryParams
|
||||
@@ -1862,6 +1883,25 @@ components:
|
||||
OuterBoolean:
|
||||
type: boolean
|
||||
x-codegen-body-parameter-name: boolean_post_body
|
||||
ParentWithNullable:
|
||||
discriminator:
|
||||
propertyName: type
|
||||
properties:
|
||||
type:
|
||||
enum:
|
||||
- ChildWithNullable
|
||||
type: string
|
||||
nullableProperty:
|
||||
nullable: true
|
||||
type: string
|
||||
type: object
|
||||
ChildWithNullable:
|
||||
allOf:
|
||||
- $ref: '#/components/schemas/ParentWithNullable'
|
||||
- properties:
|
||||
otherProperty:
|
||||
type: string
|
||||
type: object
|
||||
StringBooleanMap:
|
||||
additionalProperties:
|
||||
type: boolean
|
||||
|
||||
Reference in New Issue
Block a user