Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
2420819
better support of inline schema in array item
wing328 Apr 10, 2022
699a858
update tests
wing328 Apr 10, 2022
86e4cf2
update samples
wing328 Apr 10, 2022
e0c409e
Merge remote-tracking branch 'origin/master' into inline-model-resolver1
wing328 Apr 10, 2022
287b589
regenerate samples
wing328 Apr 11, 2022
24335b4
fix allof naming, remove files
wing328 Apr 11, 2022
40846c6
add files
wing328 Apr 11, 2022
a278634
update samples
wing328 Apr 11, 2022
019e7c9
update readme
wing328 Apr 11, 2022
63b7d02
fix tests
wing328 Apr 17, 2022
43afbb3
Merge remote-tracking branch 'origin/master' into inline-model-resolver1
wing328 Apr 17, 2022
13deddc
update samples
wing328 Apr 17, 2022
33dc94b
update samples
wing328 Apr 17, 2022
89f4fda
add new files
wing328 Apr 17, 2022
0157114
update test spec
wing328 Apr 18, 2022
d87f512
add back tests
wing328 Apr 18, 2022
f52e1f4
remove unused files
wing328 Apr 18, 2022
53cf35c
comment out python test
wing328 Apr 18, 2022
63a04f2
update js test using own spec
wing328 Apr 18, 2022
e94decd
remove files
wing328 Apr 18, 2022
0c66fb5
Merge remote-tracking branch 'origin/master' into inline-model-resolver1
wing328 Apr 18, 2022
354eafe
remove unused files
wing328 Apr 18, 2022
1e58cbd
remove files
wing328 Apr 18, 2022
7cd1854
remove unused files
wing328 Apr 18, 2022
0ef336a
better handling of allOf with a single type
wing328 Apr 18, 2022
ce929ef
comment out go test
wing328 Apr 18, 2022
a6135cf
remove test_all_of_with_single_ref_single_ref_type.py
wing328 Apr 19, 2022
9190fbb
fix inline resolver, uncomment go test
wing328 Apr 19, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
fix inline resolver, uncomment go test
  • Loading branch information
wing328 committed Apr 19, 2022
commit 9190fbb0f836d85aa4ed6623c485d09c8ec2e8f6
Original file line number Diff line number Diff line change
Expand Up @@ -183,10 +183,14 @@ private void gatherInlineModels(Schema schema, String modelPrefix) {
//Schema refSchema = this.makeSchemaResolve(modelPrefix, StringUtils.camelize(propName), prop);
Schema refSchema = this.makeSchemaResolve(modelPrefix, "_" + propName, prop);
props.put(propName, refSchema);
} else if (prop instanceof ComposedSchema && ((ComposedSchema)prop).getAllOf().size() == 1) {
// allOf with only 1 type
LOGGER.info("allOf schema used by the property `{}` replaced by its only item (a type).", propName);
props.put(propName, ((ComposedSchema)prop).getAllOf().get(0));
} else if (prop instanceof ComposedSchema) {
ComposedSchema m = (ComposedSchema) prop;
if (m.getAllOf() != null && m.getAllOf().size() == 1 &&
!(m.getAllOf().get(0).getType() == null || "object".equals(m.getAllOf().get(0).getType()))) {
// allOf with only 1 type (non-model)
LOGGER.info("allOf schema used by the property `{}` replaced by its only item (a type)", propName);
props.put(propName, m.getAllOf().get(0));
}
}
}
}
Expand Down Expand Up @@ -893,7 +897,8 @@ private Schema modelFromProperty(OpenAPI openAPI, Schema object, String path) {
model.setExtensions(object.getExtensions());
model.setExclusiveMinimum(object.getExclusiveMinimum());
model.setExclusiveMaximum(object.getExclusiveMaximum());
model.setExample(object.getExample());
// no need to set it again as it's set earlier
//model.setExample(object.getExample());
model.setDeprecated(object.getDeprecated());

if (properties != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,6 @@ public void testPrimitiveTypeInOneOf() throws IOException {
}

@Test
@Ignore
public void testNullableComposition() throws IOException {
File output = Files.createTempDirectory("test").toFile();
output.deleteOnExit();
Expand All @@ -159,7 +158,7 @@ public void testNullableComposition() throws IOException {
List<File> files = generator.opts(configurator.toClientOptInput()).generate();
files.forEach(File::deleteOnExit);

TestUtils.assertFileContains(Paths.get(output + "/model_example.go"), "Child NullableExampleChild");
TestUtils.assertFileContains(Paths.get(output + "/model_example.go"), "Child NullableChild");
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public partial class AllOfWithSingleRef : IEquatable<AllOfWithSingleRef>, IVali
/// <summary>
/// Gets or Sets SingleRefType
/// </summary>
[DataMember(Name="SingleRefType", EmitDefaultValue=false)]
[DataMember(Name="SingleRefType", EmitDefaultValue=true)]
public SingleRefType? SingleRefType { get; set; }
/// <summary>
/// Initializes a new instance of the <see cref="AllOfWithSingleRef" /> class.
Expand All @@ -42,6 +42,7 @@ public partial class AllOfWithSingleRef : IEquatable<AllOfWithSingleRef>, IVali
/// <param name="singleRefType">singleRefType.</param>
public AllOfWithSingleRef(string username = default(string), SingleRefType? singleRefType = default(SingleRefType?))
{
this.SingleRefType = singleRefType;
this.Username = username;
this.SingleRefType = singleRefType;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ defmodule OpenapiPetstore.Model.AllOfWithSingleRef do

@type t :: %__MODULE__{
:"username" => String.t | nil,
:"SingleRefType" => OpenapiPetstore.Model.SingleRefType.t | nil
:"SingleRefType" => SingleRefType | nil
}
end

Expand Down
3 changes: 2 additions & 1 deletion samples/client/petstore/java/feign/api/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2119,7 +2119,8 @@ components:
username:
type: string
SingleRefType:
$ref: '#/components/schemas/SingleRefType'
allOf:
- $ref: '#/components/schemas/SingleRefType'
type: object
SingleRefType:
enum:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import org.openapitools.client.model.SingleRefType;
import org.openapitools.jackson.nullable.JsonNullable;
import com.fasterxml.jackson.annotation.JsonIgnore;
import org.openapitools.jackson.nullable.JsonNullable;
import java.util.NoSuchElementException;
import com.fasterxml.jackson.annotation.JsonPropertyOrder;
import com.fasterxml.jackson.annotation.JsonTypeName;

Expand All @@ -39,7 +43,7 @@ public class AllOfWithSingleRef {
private String username;

public static final String JSON_PROPERTY_SINGLE_REF_TYPE = "SingleRefType";
private SingleRefType singleRefType;
private JsonNullable<SingleRefType> singleRefType = JsonNullable.<SingleRefType>undefined();

public AllOfWithSingleRef() {
}
Expand Down Expand Up @@ -72,8 +76,8 @@ public void setUsername(String username) {


public AllOfWithSingleRef singleRefType(SingleRefType singleRefType) {
this.singleRefType = JsonNullable.<SingleRefType>of(singleRefType);

this.singleRefType = singleRefType;
return this;
}

Expand All @@ -83,20 +87,28 @@ public AllOfWithSingleRef singleRefType(SingleRefType singleRefType) {
**/
@javax.annotation.Nullable
@ApiModelProperty(value = "")
@JsonProperty(JSON_PROPERTY_SINGLE_REF_TYPE)
@JsonInclude(value = JsonInclude.Include.USE_DEFAULTS)
@JsonIgnore

public SingleRefType getSingleRefType() {
return singleRefType;
return singleRefType.orElse(null);
}


@JsonProperty(JSON_PROPERTY_SINGLE_REF_TYPE)
@JsonInclude(value = JsonInclude.Include.USE_DEFAULTS)
public void setSingleRefType(SingleRefType singleRefType) {

public JsonNullable<SingleRefType> getSingleRefType_JsonNullable() {
return singleRefType;
}

@JsonProperty(JSON_PROPERTY_SINGLE_REF_TYPE)
public void setSingleRefType_JsonNullable(JsonNullable<SingleRefType> singleRefType) {
this.singleRefType = singleRefType;
}

public void setSingleRefType(SingleRefType singleRefType) {
this.singleRefType = JsonNullable.<SingleRefType>of(singleRefType);
}


@Override
public boolean equals(Object o) {
Expand All @@ -108,12 +120,23 @@ public boolean equals(Object o) {
}
AllOfWithSingleRef allOfWithSingleRef = (AllOfWithSingleRef) o;
return Objects.equals(this.username, allOfWithSingleRef.username) &&
Objects.equals(this.singleRefType, allOfWithSingleRef.singleRefType);
equalsNullable(this.singleRefType, allOfWithSingleRef.singleRefType);
}

private static <T> boolean equalsNullable(JsonNullable<T> a, JsonNullable<T> b) {
return a == b || (a != null && b != null && a.isPresent() && b.isPresent() && Objects.deepEquals(a.get(), b.get()));
}

@Override
public int hashCode() {
return Objects.hash(username, singleRefType);
return Objects.hash(username, hashCodeNullable(singleRefType));
}

private static <T> int hashCodeNullable(JsonNullable<T> a) {
if (a == null) {
return 1;
}
return a.isPresent() ? Arrays.deepHashCode(new Object[]{a.get()}) : 31;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,11 @@
import com.fasterxml.jackson.annotation.JsonValue;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import org.openapitools.client.model.AllOfWithSingleRefSingleRefType;
import org.openapitools.client.model.SingleRefType;
import org.openapitools.jackson.nullable.JsonNullable;
import com.fasterxml.jackson.annotation.JsonIgnore;
import org.openapitools.jackson.nullable.JsonNullable;
import java.util.NoSuchElementException;
import org.junit.jupiter.api.Test;


Expand Down
3 changes: 2 additions & 1 deletion samples/client/petstore/java/webclient/api/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2119,7 +2119,8 @@ components:
username:
type: string
SingleRefType:
$ref: '#/components/schemas/SingleRefType'
allOf:
- $ref: '#/components/schemas/SingleRefType'
type: object
SingleRefType:
enum:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
| Name | Type | Description | Notes |
|------------ | ------------- | ------------- | -------------|
|**username** | **String** | | [optional] |
|**singleRefType** | **SingleRefType** | | [optional] |
|**singleRefType** | [**SingleRefType**](SingleRefType.md) | | [optional] |



Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import org.openapitools.client.model.SingleRefType;
import org.openapitools.jackson.nullable.JsonNullable;
import com.fasterxml.jackson.annotation.JsonIgnore;
import org.openapitools.jackson.nullable.JsonNullable;
import java.util.NoSuchElementException;
import com.fasterxml.jackson.annotation.JsonPropertyOrder;
import com.fasterxml.jackson.annotation.JsonTypeName;

Expand All @@ -39,7 +43,7 @@ public class AllOfWithSingleRef {
private String username;

public static final String JSON_PROPERTY_SINGLE_REF_TYPE = "SingleRefType";
private SingleRefType singleRefType;
private JsonNullable<SingleRefType> singleRefType = JsonNullable.<SingleRefType>undefined();

public AllOfWithSingleRef() {
}
Expand Down Expand Up @@ -72,8 +76,8 @@ public void setUsername(String username) {


public AllOfWithSingleRef singleRefType(SingleRefType singleRefType) {
this.singleRefType = JsonNullable.<SingleRefType>of(singleRefType);

this.singleRefType = singleRefType;
return this;
}

Expand All @@ -83,20 +87,28 @@ public AllOfWithSingleRef singleRefType(SingleRefType singleRefType) {
**/
@javax.annotation.Nullable
@ApiModelProperty(value = "")
@JsonProperty(JSON_PROPERTY_SINGLE_REF_TYPE)
@JsonInclude(value = JsonInclude.Include.USE_DEFAULTS)
@JsonIgnore

public SingleRefType getSingleRefType() {
return singleRefType;
return singleRefType.orElse(null);
}


@JsonProperty(JSON_PROPERTY_SINGLE_REF_TYPE)
@JsonInclude(value = JsonInclude.Include.USE_DEFAULTS)
public void setSingleRefType(SingleRefType singleRefType) {

public JsonNullable<SingleRefType> getSingleRefType_JsonNullable() {
return singleRefType;
}

@JsonProperty(JSON_PROPERTY_SINGLE_REF_TYPE)
public void setSingleRefType_JsonNullable(JsonNullable<SingleRefType> singleRefType) {
this.singleRefType = singleRefType;
}

public void setSingleRefType(SingleRefType singleRefType) {
this.singleRefType = JsonNullable.<SingleRefType>of(singleRefType);
}


@Override
public boolean equals(Object o) {
Expand All @@ -108,12 +120,23 @@ public boolean equals(Object o) {
}
AllOfWithSingleRef allOfWithSingleRef = (AllOfWithSingleRef) o;
return Objects.equals(this.username, allOfWithSingleRef.username) &&
Objects.equals(this.singleRefType, allOfWithSingleRef.singleRefType);
equalsNullable(this.singleRefType, allOfWithSingleRef.singleRefType);
}

private static <T> boolean equalsNullable(JsonNullable<T> a, JsonNullable<T> b) {
return a == b || (a != null && b != null && a.isPresent() && b.isPresent() && Objects.deepEquals(a.get(), b.get()));
}

@Override
public int hashCode() {
return Objects.hash(username, singleRefType);
return Objects.hash(username, hashCodeNullable(singleRefType));
}

private static <T> int hashCodeNullable(JsonNullable<T> a) {
if (a == null) {
return 1;
}
return a.isPresent() ? Arrays.deepHashCode(new Object[]{a.get()}) : 31;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,11 @@
import com.fasterxml.jackson.annotation.JsonValue;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import org.openapitools.client.model.AllOfWithSingleRefSingleRefType;
import org.openapitools.client.model.SingleRefType;
import org.openapitools.jackson.nullable.JsonNullable;
import com.fasterxml.jackson.annotation.JsonIgnore;
import org.openapitools.jackson.nullable.JsonNullable;
import java.util.NoSuchElementException;
import org.junit.Assert;
import org.junit.Ignore;
import org.junit.Test;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@
Name | Type | Description | Notes
------------ | ------------- | ------------- | -------------
**username** | **string** | | [optional]
**single_ref_type** | [**\OpenAPI\Client\Model\SingleRefType**](SingleRefType.md) | | [optional]
**single_ref_type** | [**SingleRefType**](SingleRefType.md) | | [optional]

[[Back to Model list]](../../README.md#models) [[Back to API list]](../../README.md#endpoints) [[Back to README]](../../README.md)
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ class AllOfWithSingleRef implements ModelInterface, ArrayAccess, \JsonSerializab
*/
protected static $openAPITypes = [
'username' => 'string',
'single_ref_type' => '\OpenAPI\Client\Model\SingleRefType'
'single_ref_type' => 'SingleRefType'
];

/**
Expand Down Expand Up @@ -238,7 +238,7 @@ public function setUsername($username)
/**
* Gets single_ref_type
*
* @return \OpenAPI\Client\Model\SingleRefType|null
* @return SingleRefType|null
*/
public function getSingleRefType()
{
Expand All @@ -248,7 +248,7 @@ public function getSingleRefType()
/**
* Sets single_ref_type
*
* @param \OpenAPI\Client\Model\SingleRefType|null $single_ref_type single_ref_type
* @param SingleRefType|null $single_ref_type single_ref_type
*
* @return self
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ def self.openapi_types
# List of attributes with nullable: true
def self.openapi_nullable
Set.new([
:'single_ref_type'
])
end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ def self.openapi_types
# List of attributes with nullable: true
def self.openapi_nullable
Set.new([
:'single_ref_type'
])
end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export interface AllOfWithSingleRef {
* @type {SingleRefType}
* @memberof AllOfWithSingleRef
*/
singleRefType?: SingleRefType;
singleRefType?: SingleRefType | null;
}

export function AllOfWithSingleRefFromJSON(json: any): AllOfWithSingleRef {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export interface EnumPatternObject {
* @type {StringEnum}
* @memberof EnumPatternObject
*/
nullableStringEnum?: StringEnum;
nullableStringEnum?: StringEnum | null;
/**
*
* @type {NumberEnum}
Expand All @@ -55,7 +55,7 @@ export interface EnumPatternObject {
* @type {NumberEnum}
* @memberof EnumPatternObject
*/
nullableNumberEnum?: NumberEnum;
nullableNumberEnum?: NumberEnum | null;
}

export function EnumPatternObjectFromJSON(json: any): EnumPatternObject {
Expand Down
Loading