Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
import org.openapitools.codegen.api.TemplatingEngineAdapter;
import org.openapitools.codegen.config.GlobalSettings;
import org.openapitools.codegen.examples.ExampleGenerator;
import org.openapitools.codegen.languages.PythonClientCodegen;
import org.openapitools.codegen.languages.RustServerCodegen;
import org.openapitools.codegen.meta.FeatureSet;
import org.openapitools.codegen.meta.GeneratorMetadata;
Expand Down Expand Up @@ -3790,8 +3791,8 @@ public CodegenProperty fromProperty(String name, Schema p, boolean required, boo
}

Schema original = null;
// check if it's allOf (only 1 sub schema) with default/nullable/etc set in the top level
if (ModelUtils.isAllOf(p) && p.getAllOf().size() == 1 && ModelUtils.hasCommonAttributesDefined(p) ) {
// check if it's allOf (only 1 sub schema) with or without default/nullable/etc set in the top level
if (ModelUtils.isAllOf(p) && p.getAllOf().size() == 1 && !(this instanceof PythonClientCodegen)) {
if (p.getAllOf().get(0) instanceof Schema) {
original = p;
p = (Schema) p.getAllOf().get(0);
Expand Down Expand Up @@ -3997,7 +3998,7 @@ public CodegenProperty fromProperty(String name, Schema p, boolean required, boo
// restore original schema with default value, nullable, readonly etc
if (original != null) {
p = original;
// evaluate common attributes defined in the top level
// evaluate common attributes if defined in the top level
if (p.getNullable() != null) {
property.isNullable = p.getNullable();
} else if (p.getExtensions() != null && p.getExtensions().containsKey("x-nullable")) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -555,8 +555,8 @@ public void postProcessModelProperty(CodegenModel model, CodegenProperty propert
public CodegenProperty fromProperty(String name, Schema p, boolean required) {
final CodegenProperty property = super.fromProperty(name, p, required);

// Handle composed properties
if (ModelUtils.isComposedSchema(p)) {
// Handle composed properties and it's NOT allOf with a single ref only
if (ModelUtils.isComposedSchema(p) && !(ModelUtils.isAllOf(p) && p.getAllOf().size() == 1)) {
ComposedSchema composed = (ComposedSchema) p;

// Count the occurrences of allOf/anyOf/oneOf with exactly one child element
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4587,6 +4587,18 @@ public void testAllOfDefaultEnumType() {
Assert.assertFalse(defaultEnumSchemaProperty.isContainer);
Assert.assertFalse(defaultEnumSchemaProperty.isPrimitiveType);
Assert.assertEquals(defaultEnumSchemaProperty.defaultValue, "2");

// test allOf with a single sub-schema and no default value set in the top level
CodegenProperty allOfEnumSchemaProperty = modelWithReferencedSchema.vars.get(5);
Assert.assertEquals(allOfEnumSchemaProperty.getName(), "allofMinusnumberMinusenum");
Assert.assertFalse(allOfEnumSchemaProperty.isEnum);
Assert.assertTrue(allOfEnumSchemaProperty.getIsEnumOrRef());
Assert.assertTrue(allOfEnumSchemaProperty.isEnumRef);
Assert.assertFalse(allOfEnumSchemaProperty.isInnerEnum);
Assert.assertFalse(allOfEnumSchemaProperty.isString);
Assert.assertFalse(allOfEnumSchemaProperty.isContainer);
Assert.assertFalse(allOfEnumSchemaProperty.isPrimitiveType);
Assert.assertEquals(allOfEnumSchemaProperty.defaultValue, "null");
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -215,4 +215,7 @@ components:
default: 2
allOf:
- $ref: "#/components/schemas/NumberEnum"
allof-number-enum:
allOf:
- $ref: "#/components/schemas/NumberEnum"

Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,15 @@ defmodule OpenapiPetstore.Model.AllOfWithSingleRef do

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

defimpl Poison.Decoder, for: OpenapiPetstore.Model.AllOfWithSingleRef do
def decode(value, _options) do
import OpenapiPetstore.Deserializer
def decode(value, options) do
value
|> deserialize(:SingleRefType, :struct, OpenapiPetstore.Model.SingleRefType, options)
end
end

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**](SingleRefType.md) | | [optional] |
|**singleRefType** | **SingleRefType** | | [optional] |



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**](SingleRefType.md) | | [optional] |
|**singleRefType** | **SingleRefType** | | [optional] |



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**](SingleRefType.md) | | [optional] |
|**singleRefType** | **SingleRefType** | | [optional] |



Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,12 @@ public String toUrlQueryString(String prefix) {

// add `SingleRefType` to the URL query string
if (getSingleRefType() != null) {
joiner.add(getSingleRefType().toUrlQueryString(prefix + "SingleRefType" + suffix));
try {
joiner.add(String.format("%sSingleRefType%s=%s", prefix, suffix, URLEncoder.encode(String.valueOf(getSingleRefType()), "UTF-8").replaceAll("\\+", "%20")));
} catch (UnsupportedEncodingException e) {
// Should never happen, UTF-8 is always supported
throw new RuntimeException(e);
}
}

return joiner.toString();
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**](SingleRefType.md) | | [optional] |
|**singleRefType** | **SingleRefType** | | [optional] |



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**](SingleRefType.md) | | [optional] |
|**singleRefType** | **SingleRefType** | | [optional] |



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** | [**SingleRefType**](SingleRefType.md) | | [optional]
**single_ref_type** | [**\OpenAPI\Client\Model\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 @@ -58,7 +58,7 @@ class AllOfWithSingleRef implements ModelInterface, ArrayAccess, \JsonSerializab
*/
protected static $openAPITypes = [
'username' => 'string',
'single_ref_type' => 'SingleRefType'
'single_ref_type' => '\OpenAPI\Client\Model\SingleRefType'
];

/**
Expand Down Expand Up @@ -326,7 +326,7 @@ public function setUsername($username)
/**
* Gets single_ref_type
*
* @return SingleRefType|null
* @return \OpenAPI\Client\Model\SingleRefType|null
*/
public function getSingleRefType()
{
Expand All @@ -336,7 +336,7 @@ public function getSingleRefType()
/**
* Sets single_ref_type
*
* @param SingleRefType|null $single_ref_type single_ref_type
* @param \OpenAPI\Client\Model\SingleRefType|null $single_ref_type single_ref_type
*
* @return self
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,28 @@ class AllOfWithSingleRef

attr_accessor :single_ref_type

class EnumAttributeValidator
attr_reader :datatype
attr_reader :allowable_values

def initialize(datatype, allowable_values)
@allowable_values = allowable_values.map do |value|
case datatype.to_s
when /Integer/i
value.to_i
when /Float/i
value.to_f
else
value
end
end
end

def valid?(value)
!value || allowable_values.include?(value)
end
end

# Attribute mapping from ruby-style variable name to JSON key.
def self.attribute_map
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,28 @@ class AllOfWithSingleRef

attr_accessor :single_ref_type

class EnumAttributeValidator
attr_reader :datatype
attr_reader :allowable_values

def initialize(datatype, allowable_values)
@allowable_values = allowable_values.map do |value|
case datatype.to_s
when /Integer/i
value.to_i
when /Float/i
value.to_f
else
value
end
end
end

def valid?(value)
!value || allowable_values.include?(value)
end
end

# Attribute mapping from ruby-style variable name to JSON key.
def self.attribute_map
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,28 @@ class AllOfWithSingleRef

attr_accessor :single_ref_type

class EnumAttributeValidator
attr_reader :datatype
attr_reader :allowable_values

def initialize(datatype, allowable_values)
@allowable_values = allowable_values.map do |value|
case datatype.to_s
when /Integer/i
value.to_i
when /Float/i
value.to_f
else
value
end
end
end

def valid?(value)
!value || allowable_values.include?(value)
end
end

# Attribute mapping from ruby-style variable name to JSON key.
def self.attribute_map
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,5 +69,3 @@ class AllOfWithSingleRef {

}



Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ abstract class AllOfWithSingleRef implements Built<AllOfWithSingleRef, AllOfWith

@BuiltValueField(wireName: r'SingleRefType')
SingleRefType? get singleRefType;
// enum singleRefTypeEnum { admin, user, };

AllOfWithSingleRef._();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,12 @@ class AllOfWithSingleRef {
///
String? username;

///
/// Please note: This property should have been non-nullable! Since the specification file
/// does not include a default value (using the "default:" property), however, the generated
/// source code must fall back to having a nullable type.
/// Consider adding a "default:" property in the specification file to hide this note.
///
SingleRefType? singleRefType;

@override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,16 @@
import json


from typing import Any, Optional
from typing import Optional
from pydantic import BaseModel, Field, StrictStr
from petstore_api.models.single_ref_type import SingleRefType

class AllOfWithSingleRef(BaseModel):
"""
AllOfWithSingleRef
"""
username: Optional[StrictStr] = None
single_ref_type: Optional[Any] = Field(None, alias="SingleRefType")
single_ref_type: Optional[SingleRefType] = Field(None, alias="SingleRefType")
__properties = ["username", "SingleRefType"]

class Config:
Expand All @@ -53,9 +54,6 @@ def to_dict(self):
exclude={
},
exclude_none=True)
# override the default output from pydantic by calling `to_dict()` of single_ref_type
if self.single_ref_type:
_dict['SingleRefType'] = self.single_ref_type.to_dict()
return _dict

@classmethod
Expand All @@ -69,7 +67,7 @@ def from_dict(cls, obj: dict) -> AllOfWithSingleRef:

_obj = AllOfWithSingleRef.parse_obj({
"username": obj.get("username"),
"single_ref_type": SingleRefType.from_dict(obj.get("SingleRefType")) if obj.get("SingleRefType") is not None else None
"single_ref_type": obj.get("SingleRefType")
})
return _obj

Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,16 @@
import json


from typing import Any, Optional
from typing import Optional
from pydantic import BaseModel, Field, StrictStr
from petstore_api.models.single_ref_type import SingleRefType

class AllOfWithSingleRef(BaseModel):
"""
AllOfWithSingleRef
"""
username: Optional[StrictStr] = None
single_ref_type: Optional[Any] = Field(None, alias="SingleRefType")
single_ref_type: Optional[SingleRefType] = Field(None, alias="SingleRefType")
additional_properties: Dict[str, Any] = {}
__properties = ["username", "SingleRefType"]

Expand Down Expand Up @@ -55,9 +56,6 @@ def to_dict(self):
"additional_properties"
},
exclude_none=True)
# override the default output from pydantic by calling `to_dict()` of single_ref_type
if self.single_ref_type:
_dict['SingleRefType'] = self.single_ref_type.to_dict()
# puts key-value pairs in additional_properties in the top level
if self.additional_properties is not None:
for _key, _value in self.additional_properties.items():
Expand All @@ -76,7 +74,7 @@ def from_dict(cls, obj: dict) -> AllOfWithSingleRef:

_obj = AllOfWithSingleRef.parse_obj({
"username": obj.get("username"),
"single_ref_type": SingleRefType.from_dict(obj.get("SingleRefType")) if obj.get("SingleRefType") is not None else None
"single_ref_type": obj.get("SingleRefType")
})
# store additional fields in additional_properties
for _key in obj.keys():
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#include <sstream>
#include <stdexcept>
#include <regex>
#include <algorithm>
#include <boost/lexical_cast.hpp>
#include <boost/property_tree/ptree.hpp>
#include <boost/property_tree/json_parser.hpp>
Expand Down Expand Up @@ -63,17 +64,13 @@ ptree AllOfWithSingleRef::toPropertyTree() const
ptree pt;
ptree tmp_node;
pt.put("username", m_Username);
pt.add_child("SingleRefType", m_SingleRefType.toPropertyTree());
return pt;
}

void AllOfWithSingleRef::fromPropertyTree(ptree const &pt)
{
ptree tmp_node;
m_Username = pt.get("username", "");
if (pt.get_child_optional("SingleRefType")) {
m_SingleRefType = fromPt<SingleRefType>(pt.get_child("SingleRefType"));
}
}

std::string AllOfWithSingleRef::getUsername() const
Expand Down
Loading