forked from loafle/openapi-generator-original
[ruby] fix oneOf handling (#5706)
* [ruby] fix oneOf handling * use previous ruby configs due to issue #4690 * check for oneOf model in base_object * validate the attributes in partial_oneof_module
This commit is contained in:
@@ -2,15 +2,14 @@
|
||||
|
||||
## Properties
|
||||
|
||||
Name | Type | Description | Notes
|
||||
------------ | ------------- | ------------- | -------------
|
||||
| Name | Type | Description | Notes |
|
||||
| ---- | ---- | ----------- | ----- |
|
||||
|
||||
## Code Sample
|
||||
|
||||
```ruby
|
||||
require 'Petstore'
|
||||
require 'petstore'
|
||||
|
||||
instance = Petstore::ArrayAlias.new()
|
||||
```
|
||||
|
||||
|
||||
|
||||
@@ -2,15 +2,14 @@
|
||||
|
||||
## Properties
|
||||
|
||||
Name | Type | Description | Notes
|
||||
------------ | ------------- | ------------- | -------------
|
||||
| Name | Type | Description | Notes |
|
||||
| ---- | ---- | ----------- | ----- |
|
||||
|
||||
## Code Sample
|
||||
|
||||
```ruby
|
||||
require 'Petstore'
|
||||
require 'petstore'
|
||||
|
||||
instance = Petstore::MapAlias.new()
|
||||
```
|
||||
|
||||
|
||||
|
||||
@@ -2,11 +2,10 @@
|
||||
|
||||
All URIs are relative to *http://petstore.swagger.io/v2*
|
||||
|
||||
Method | HTTP request | Description
|
||||
------------- | ------------- | -------------
|
||||
[**array**](UsageApi.md#array) | **GET** /array | Use alias to array
|
||||
[**map**](UsageApi.md#map) | **GET** /map | Use alias to map
|
||||
|
||||
| Method | HTTP request | Description |
|
||||
| ------ | ------------ | ----------- |
|
||||
| [**array**](UsageApi.md#array) | **GET** /array | Use alias to array |
|
||||
| [**map**](UsageApi.md#map) | **GET** /map | Use alias to map |
|
||||
|
||||
|
||||
## array
|
||||
@@ -39,10 +38,9 @@ end
|
||||
|
||||
### Parameters
|
||||
|
||||
|
||||
Name | Type | Description | Notes
|
||||
------------- | ------------- | ------------- | -------------
|
||||
**array_alias** | [**ArrayAlias**](ArrayAlias.md)| | [optional]
|
||||
| Name | Type | Description | Notes |
|
||||
| ---- | ---- | ----------- | ----- |
|
||||
| **array_alias** | [**ArrayAlias**](ArrayAlias.md) | | [optional] |
|
||||
|
||||
### Return type
|
||||
|
||||
@@ -88,10 +86,9 @@ end
|
||||
|
||||
### Parameters
|
||||
|
||||
|
||||
Name | Type | Description | Notes
|
||||
------------- | ------------- | ------------- | -------------
|
||||
**map_alias** | [**MapAlias**](MapAlias.md)| | [optional]
|
||||
| Name | Type | Description | Notes |
|
||||
| ---- | ---- | ----------- | ----- |
|
||||
| **map_alias** | [**MapAlias**](MapAlias.md) | | [optional] |
|
||||
|
||||
### Return type
|
||||
|
||||
|
||||
@@ -274,8 +274,9 @@ module Petstore
|
||||
data.each { |k, v| hash[k] = convert_to_type(v, sub_type) }
|
||||
end
|
||||
else
|
||||
# models, e.g. Pet
|
||||
Petstore.const_get(return_type).build_from_hash(data)
|
||||
# models (e.g. Pet) or oneOf
|
||||
klass = Petstore.const_get(return_type)
|
||||
klass.respond_to?(:openapi_one_of) ? klass.build(data) : klass.build_from_hash(data)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -21,6 +21,11 @@ module Petstore
|
||||
}
|
||||
end
|
||||
|
||||
# Returns all the JSON keys this model knows about, including the ones defined in its parent(s)
|
||||
def self.acceptable_attributes
|
||||
attribute_map.values.concat(superclass.acceptable_attributes)
|
||||
end
|
||||
|
||||
# Attribute type mapping.
|
||||
def self.openapi_types
|
||||
{
|
||||
@@ -151,7 +156,9 @@ module Petstore
|
||||
end
|
||||
end
|
||||
else # model
|
||||
Petstore.const_get(type).build_from_hash(value)
|
||||
# models (e.g. Pet) or oneOf
|
||||
klass = Petstore.const_get(type)
|
||||
klass.respond_to?(:openapi_one_of) ? klass.build(value) : klass.build_from_hash(value)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -177,7 +184,7 @@ module Petstore
|
||||
is_nullable = self.class.openapi_nullable.include?(attr)
|
||||
next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}"))
|
||||
end
|
||||
|
||||
|
||||
hash[param] = _to_hash(value)
|
||||
end
|
||||
hash
|
||||
@@ -202,4 +209,5 @@ module Petstore
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
@@ -21,6 +21,11 @@ module Petstore
|
||||
}
|
||||
end
|
||||
|
||||
# Returns all the JSON keys this model knows about
|
||||
def self.acceptable_attributes
|
||||
attribute_map.values
|
||||
end
|
||||
|
||||
# Attribute type mapping.
|
||||
def self.openapi_types
|
||||
{
|
||||
@@ -147,7 +152,9 @@ module Petstore
|
||||
end
|
||||
end
|
||||
else # model
|
||||
Petstore.const_get(type).build_from_hash(value)
|
||||
# models (e.g. Pet) or oneOf
|
||||
klass = Petstore.const_get(type)
|
||||
klass.respond_to?(:openapi_one_of) ? klass.build(value) : klass.build_from_hash(value)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -173,7 +180,7 @@ module Petstore
|
||||
is_nullable = self.class.openapi_nullable.include?(attr)
|
||||
next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}"))
|
||||
end
|
||||
|
||||
|
||||
hash[param] = _to_hash(value)
|
||||
end
|
||||
hash
|
||||
@@ -198,4 +205,5 @@ module Petstore
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user