Skip to content

Commit

Permalink
Removing empty classes
Browse files Browse the repository at this point in the history
Some generated classes are empty and not really used

Signed-off-by: Francisco Javier Tirado Sarti <[email protected]>
  • Loading branch information
fjtirado committed Aug 2, 2024
1 parent 646d9ff commit 7dec2a6
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 3 deletions.
9 changes: 6 additions & 3 deletions api/src/main/resources/schema/workflow.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -664,7 +664,8 @@ $defs:
basic:
type: object
oneOf:
- properties:
- title: BasicAuthInfo
properties:
username:
type: string
description: The username to use.
Expand All @@ -680,7 +681,8 @@ $defs:
bearer:
type: object
oneOf:
- properties:
- title: BearerAuthInfo
properties:
token:
type: string
description: The bearer token to use.
Expand All @@ -693,7 +695,8 @@ $defs:
oauth2:
type: object
oneOf:
- properties:
- title: OAuth2Info
properties:
authority:
type: string
format: uri
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/*
* Copyright 2020-Present The Serverless Workflow Specification Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.serverlessworkflow.generator;

import com.fasterxml.jackson.databind.JsonNode;
import com.sun.codemodel.JClassContainer;
import com.sun.codemodel.JType;
import org.jsonschema2pojo.Schema;
import org.jsonschema2pojo.rules.RuleFactory;
import org.jsonschema2pojo.rules.TypeRule;

public class EmptyObjectTypeRule extends TypeRule {

protected EmptyObjectTypeRule(RuleFactory ruleFactory) {
super(ruleFactory);
}

@Override
public JType apply(
String nodeName,
JsonNode node,
JsonNode parent,
JClassContainer generatableType,
Schema currentSchema) {
return isEmptyObject(node)
? generatableType.owner().ref(Object.class)
: super.apply(nodeName, node, parent, generatableType, currentSchema);
}

private boolean isEmptyObject(JsonNode node) {
return node.size() == 1 && node.has("type") && node.get("type").asText().equals("object");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@ public Rule<JClassContainer, JType> getSchemaRule() {
return new AllAnyOneOfSchemaRule(this);
}

@Override
public Rule<JClassContainer, JType> getTypeRule() {
return new EmptyObjectTypeRule(this);
}

@Override
public Rule<JDefinedClass, JDefinedClass> getAdditionalPropertiesRule() {
return new UnevaluatedPropertiesRule(this);
Expand Down

0 comments on commit 7dec2a6

Please sign in to comment.