Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix spring child constructor missing parent params #16976

Closed
Show file tree
Hide file tree
Changes from 15 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 @@ -3724,6 +3724,10 @@ protected void addProperties(Map<String, Schema> properties, List<String> requir
return;
}
if (ModelUtils.isComposedSchema(schema)) {
// fix issue #16797 and #15796, constructor fail by missing parent required params
if (schema.getProperties() != null && !schema.getProperties().isEmpty()) {
properties.putAll(schema.getProperties());
}

if (schema.getAllOf() != null) {
for (Object component : schema.getAllOf()) {
Expand All @@ -3747,6 +3751,11 @@ protected void addProperties(Map<String, Schema> properties, List<String> requir
}
}

for (String r : required) {
if (!properties.containsKey(r)) {
LOGGER.error("Required var %s not in properties", r);
}
}
return;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4388,4 +4388,34 @@ public void givenMultipartForm_whenGenerateBlockedServer_thenParameterAreCreated
assertFileContains(Paths.get(outputPath + "/src/main/java/org/openapitools/api/PetApi.java"),
"@Valid @RequestParam(value = \"additionalMetadata\", required = false) String additionalMetadata");
}

@Test
public void testMultiInheritanceParentRequiredParams_issue16797() throws IOException {
final Map<String, File> output = generateFromContract("src/test/resources/3_0/spring/issue_16797.yaml", SPRING_BOOT);
// constructor should as
// public Object4(Type1 pageInfo, String responseType, String requestId, Boolean success) {
// super(responseType, requestId, success, pageInfo);
// }
JavaFileAssert.assertThat(output.get("Object4.java"))
.assertConstructor("Type1", "String", "String", "Boolean")
.hasParameter("responseType").toConstructor()
.hasParameter("requestId").toConstructor()
.hasParameter("success").toConstructor()
.hasParameter("pageInfo").toConstructor()
;
}

@Test
public void testMultiInheritanceParentRequiredParams_issue15796() throws IOException {
final Map<String, File> output = generateFromContract("src/test/resources/3_0/spring/issue_15796.yaml", SPRING_BOOT);
// constructor should as this
//public Poodle(String race, String type) {
// super(race, type);
//}
JavaFileAssert.assertThat(output.get("Poodle.java"))
.assertConstructor("String", "String")
.hasParameter("type").toConstructor()
.hasParameter("race").toConstructor()
;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
openapi: 3.0.0
info:
title: My service
description: My service
version: 1.0.0
servers:
- url: 'https://localhost'
paths:
/generator/test:
get:
summary: Get test generator models
responses:
200:
description: Everything is fine
components:
schemas:
Pet:
type: object
required:
- type
properties:
name:
type: string
type:
type: string
discriminator:
propertyName: type
mapping:
CAT: '#/components/schemas/Cat'
DOG: '#/components/schemas/Dog'
Cat:
type: object
allOf:
- $ref: '#/components/schemas/Pet'
required:
- race
properties:
paws:
type: integer
race:
type: string
discriminator:
propertyName: race
mapping:
PERSIAN: '#/components/schemas/Persian'
MAINE_COON: '#/components/schemas/MaineCoon'
Dog:
type: object
allOf:
- $ref: '#/components/schemas/Pet'
required:
- race
properties:
tails:
type: integer
race:
type: string
discriminator:
propertyName: race
mapping:
POODLE: '#/components/schemas/Poodle'
LABRADOR: '#/components/schemas/Labrador'
Poodle:
type: object
allOf:
- $ref: '#/components/schemas/Dog'
properties:
hairType:
type: string
required:
- race
Labrador:
type: object
allOf:
- $ref: '#/components/schemas/Dog'
properties:
hairColor:
type: string
required:
- race
Persian:
type: object
allOf:
- $ref: '#/components/schemas/Cat'
properties:
hairType:
type: string
required:
- race
MaineCoon:
type: object
allOf:
- $ref: '#/components/schemas/Cat'
properties:
hairColor:
type: string
required:
- race
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
openapi: 3.0.1
info:
title: OpenAPI definition
version: v0
servers:
- url: /
- url: '{protocolAndBaseURL}'
variables:
protocolAndBaseURL:
default: 'https://localhost'
paths:
/user:
get:
tags:
- user
summary: Get User By Id
operationId: getUserById
parameters:
- in: query
name: id
description: Unique Id of an User
schema:
type: integer
default: 10
responses:
default:
description: successful operation
content:
application/json:
schema:
$ref: "#/components/schemas/Object4"

components:
schemas:

Object1:
type: object
properties:
responseType:
type: string
requestId:
type: string
success:
type: boolean
default: true
required:
- responseType
- requestId
- success
discriminator:
propertyName: responseType

Object2:
allOf:
- $ref: '#/components/schemas/Object1'
- type: object

Type1:
type: object
properties:
pageSize:
minimum: 1
type: integer
format: int32
rowCount:
minimum: 0
type: integer
format: int32
required:
- pageSize
- rowCount

Object3:
allOf:
- $ref: '#/components/schemas/Object2'
properties:
pageInfo:
$ref: '#/components/schemas/Type1'
required:
- pageInfo

Object4:
allOf:
- $ref: '#/components/schemas/Object3'
- type: object
properties:
data:
type: string
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import 'package:openapi/api.dart';
## Properties
Name | Type | Description | Notes
------------ | ------------- | ------------- | -------------
**name** | **String** | Name of the related entity. | [optional]
**atReferredType** | **String** | The actual type of the target instance when needed for disambiguation. | [optional]
**href** | **String** | Hyperlink reference | [optional]
**id** | **String** | unique identifier | [optional]
**atSchemaLocation** | **String** | A URI to a JSON-Schema file that defines additional attributes and relationships | [optional]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,16 @@ import 'package:openapi/api.dart';
## Properties
Name | Type | Description | Notes
------------ | ------------- | ------------- | -------------
**href** | **String** | Hyperlink reference | [optional]
**id** | **String** | unique identifier |
**barPropA** | **String** | | [optional]
**fooPropB** | **String** | | [optional]
**foo** | [**FooRefOrValue**](FooRefOrValue.md) | | [optional]
**href** | **String** | Hyperlink reference | [optional]
**atSchemaLocation** | **String** | A URI to a JSON-Schema file that defines additional attributes and relationships | [optional]
**atBaseType** | **String** | When sub-classing, this defines the super-class | [optional]
**atType** | **String** | When sub-classing, this defines the sub-class Extensible name |
**name** | **String** | Name of the related entity. | [optional]
**atReferredType** | **String** | The actual type of the target instance when needed for disambiguation. | [optional]

[[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import 'package:openapi/api.dart';
Name | Type | Description | Notes
------------ | ------------- | ------------- | -------------
**foorefPropA** | **String** | | [optional]
**name** | **String** | Name of the related entity. | [optional]
**atReferredType** | **String** | The actual type of the target instance when needed for disambiguation. | [optional]
**href** | **String** | Hyperlink reference | [optional]
**id** | **String** | unique identifier | [optional]
**atSchemaLocation** | **String** | A URI to a JSON-Schema file that defines additional attributes and relationships | [optional]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,16 @@ import 'package:openapi/api.dart';
## Properties
Name | Type | Description | Notes
------------ | ------------- | ------------- | -------------
**fooPropA** | **String** | | [optional]
**fooPropB** | **String** | | [optional]
**href** | **String** | Hyperlink reference | [optional]
**id** | **String** | unique identifier | [optional]
**atSchemaLocation** | **String** | A URI to a JSON-Schema file that defines additional attributes and relationships | [optional]
**atBaseType** | **String** | When sub-classing, this defines the super-class | [optional]
**atType** | **String** | When sub-classing, this defines the sub-class Extensible name |
**foorefPropA** | **String** | | [optional]
**name** | **String** | Name of the related entity. | [optional]
**atReferredType** | **String** | The actual type of the target instance when needed for disambiguation. | [optional]

[[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import 'package:openapi/api.dart';
Name | Type | Description | Notes
------------ | ------------- | ------------- | -------------
**toppings** | **String** | | [optional]
**pizzaSize** | **num** | | [optional]
**href** | **String** | Hyperlink reference | [optional]
**id** | **String** | unique identifier | [optional]
**atSchemaLocation** | **String** | A URI to a JSON-Schema file that defines additional attributes and relationships | [optional]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ part 'bar_ref.g.dart';
/// BarRef
///
/// Properties:
/// * [name] - Name of the related entity.
/// * [atReferredType] - The actual type of the target instance when needed for disambiguation.
/// * [href] - Hyperlink reference
/// * [id] - unique identifier
/// * [atSchemaLocation] - A URI to a JSON-Schema file that defines additional attributes and relationships
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
//

// ignore_for_file: unused_element
import 'package:openapi/src/model/foo_ref_or_value.dart';
import 'package:openapi/src/model/bar_ref.dart';
import 'package:openapi/src/model/bar.dart';
import 'package:built_value/built_value.dart';
Expand All @@ -14,11 +15,16 @@ part 'bar_ref_or_value.g.dart';
/// BarRefOrValue
///
/// Properties:
/// * [href] - Hyperlink reference
/// * [id] - unique identifier
/// * [barPropA]
/// * [fooPropB]
/// * [foo]
/// * [href] - Hyperlink reference
/// * [atSchemaLocation] - A URI to a JSON-Schema file that defines additional attributes and relationships
/// * [atBaseType] - When sub-classing, this defines the super-class
/// * [atType] - When sub-classing, this defines the sub-class Extensible name
/// * [name] - Name of the related entity.
/// * [atReferredType] - The actual type of the target instance when needed for disambiguation.
@BuiltValue()
abstract class BarRefOrValue implements Built<BarRefOrValue, BarRefOrValueBuilder> {
/// One Of [Bar], [BarRef]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ part 'foo_ref.g.dart';
///
/// Properties:
/// * [foorefPropA]
/// * [name] - Name of the related entity.
/// * [atReferredType] - The actual type of the target instance when needed for disambiguation.
/// * [href] - Hyperlink reference
/// * [id] - unique identifier
/// * [atSchemaLocation] - A URI to a JSON-Schema file that defines additional attributes and relationships
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,16 @@ part 'foo_ref_or_value.g.dart';
/// FooRefOrValue
///
/// Properties:
/// * [fooPropA]
/// * [fooPropB]
/// * [href] - Hyperlink reference
/// * [id] - unique identifier
/// * [atSchemaLocation] - A URI to a JSON-Schema file that defines additional attributes and relationships
/// * [atBaseType] - When sub-classing, this defines the super-class
/// * [atType] - When sub-classing, this defines the sub-class Extensible name
/// * [foorefPropA]
/// * [name] - Name of the related entity.
/// * [atReferredType] - The actual type of the target instance when needed for disambiguation.
@BuiltValue()
abstract class FooRefOrValue implements Built<FooRefOrValue, FooRefOrValueBuilder> {
/// One Of [Foo], [FooRef]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ part 'pizza_speziale.g.dart';
///
/// Properties:
/// * [toppings]
/// * [pizzaSize]
/// * [href] - Hyperlink reference
/// * [id] - unique identifier
/// * [atSchemaLocation] - A URI to a JSON-Schema file that defines additional attributes and relationships
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import com.fasterxml.jackson.annotation.JsonTypeInfo;
import org.openapitools.model.Bar;
import org.openapitools.model.BarRef;
import org.openapitools.model.FooRefOrValue;
import org.openapitools.jackson.nullable.JsonNullable;
import java.time.OffsetDateTime;
import javax.validation.Valid;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonSubTypes;
import com.fasterxml.jackson.annotation.JsonTypeInfo;
import org.openapitools.model.Pizza;
import java.math.BigDecimal;
import org.openapitools.model.Pizza;
import org.openapitools.jackson.nullable.JsonNullable;
import java.time.OffsetDateTime;
import javax.validation.Valid;
Expand Down
Loading