Skip to content

Commit 409c6b7

Browse files
Merge pull request #395 from fjtirado/Removing_empty_classes
Removing empty classes
2 parents 646d9ff + 60618ad commit 409c6b7

File tree

3 files changed

+57
-3
lines changed

3 files changed

+57
-3
lines changed

api/src/main/resources/schema/workflow.yaml

+6-3
Original file line numberDiff line numberDiff line change
@@ -664,7 +664,8 @@ $defs:
664664
basic:
665665
type: object
666666
oneOf:
667-
- properties:
667+
- title: BasicAuthenticationData
668+
properties:
668669
username:
669670
type: string
670671
description: The username to use.
@@ -680,7 +681,8 @@ $defs:
680681
bearer:
681682
type: object
682683
oneOf:
683-
- properties:
684+
- title: BearerAuthenticationData
685+
properties:
684686
token:
685687
type: string
686688
description: The bearer token to use.
@@ -693,7 +695,8 @@ $defs:
693695
oauth2:
694696
type: object
695697
oneOf:
696-
- properties:
698+
- title: OAuth2AutenthicationData
699+
properties:
697700
authority:
698701
type: string
699702
format: uri
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
/*
2+
* Copyright 2020-Present The Serverless Workflow Specification Authors
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package io.serverlessworkflow.generator;
17+
18+
import com.fasterxml.jackson.databind.JsonNode;
19+
import com.sun.codemodel.JClassContainer;
20+
import com.sun.codemodel.JType;
21+
import org.jsonschema2pojo.Schema;
22+
import org.jsonschema2pojo.rules.RuleFactory;
23+
import org.jsonschema2pojo.rules.TypeRule;
24+
25+
public class EmptyObjectTypeRule extends TypeRule {
26+
27+
protected EmptyObjectTypeRule(RuleFactory ruleFactory) {
28+
super(ruleFactory);
29+
}
30+
31+
@Override
32+
public JType apply(
33+
String nodeName,
34+
JsonNode node,
35+
JsonNode parent,
36+
JClassContainer generatableType,
37+
Schema currentSchema) {
38+
return isEmptyObject(node)
39+
? generatableType.owner().ref(Object.class)
40+
: super.apply(nodeName, node, parent, generatableType, currentSchema);
41+
}
42+
43+
private boolean isEmptyObject(JsonNode node) {
44+
return node.size() == 1 && node.has("type") && node.get("type").asText().equals("object");
45+
}
46+
}

custom-generator/src/main/java/io/serverlessworkflow/generator/UnreferencedFactory.java

+5
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,11 @@ public Rule<JClassContainer, JType> getSchemaRule() {
2727
return new AllAnyOneOfSchemaRule(this);
2828
}
2929

30+
@Override
31+
public Rule<JClassContainer, JType> getTypeRule() {
32+
return new EmptyObjectTypeRule(this);
33+
}
34+
3035
@Override
3136
public Rule<JDefinedClass, JDefinedClass> getAdditionalPropertiesRule() {
3237
return new UnevaluatedPropertiesRule(this);

0 commit comments

Comments
 (0)