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

[BallerinaToOpenAPI] Fix support @constraint annotation mapping for Ballerina to OpenAPI #1043

Closed
wants to merge 6 commits into from
Closed
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 @@ -61,8 +61,9 @@ public enum DiagnosticMessages {
DiagnosticSeverity.WARNING),
OAS_CONVERTOR_114("OAS_CONVERTOR_114", "Generated OpenAPI definition does not contain information " +
"for Ballerina type '%s'. ", DiagnosticSeverity.WARNING),

OAS_CONVERTOR_115("OAS_CONVERTOR_115", "Given Ballerina file does not contain any HTTP service.",
DiagnosticSeverity.ERROR),
OAS_CONVERTOR_116("OAS_CONVERTOR_116", "Failed to parser the Number value due to: %s ",
DiagnosticSeverity.ERROR);

private final String code;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
/*
* Copyright (c) 2022, WSO2 LLC. (https://www.wso2.com).
*
* WSO2 LLC. licenses this file to you 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.ballerina.openapi.converter.service;

import java.util.Optional;

/**
* This @link ConstraintAnnotation} class represents the constraint annotations.
*
* @since 1.9.0
*/
public class ConstraintAnnotation {
private final String minValue;
private final String maxValue;
private final String length;
private final String minLength;
private final String maxLength;
private final String minValueExclusive;
private final String maxValueExclusive;

public ConstraintAnnotation(ConstraintAnnotationBuilder builder) {
this.minValue = builder.minValue;
this.maxValue = builder.maxValue;
this.length = builder.length;
this.minLength = builder.minLength;
this.maxLength = builder.maxLength;
this.minValueExclusive = builder.minValueExclusive;
this.maxValueExclusive = builder.maxValueExclusive;
}

public Optional<String> getMinValue() {
return Optional.ofNullable(minValue);
}

public Optional<String> getMaxValue() {
return Optional.ofNullable(maxValue);
}

public Optional<String> getLength() {
return Optional.ofNullable(length);
}

public Optional<String> getMinLength() {
return Optional.ofNullable(minLength);
}

public Optional<String> getMaxLength() {
return Optional.ofNullable(maxLength);
}

public Optional<String> getMinValueExclusive() {
return Optional.ofNullable(minValueExclusive);
}

public Optional<String> getMaxValueExclusive() {
return Optional.ofNullable(maxValueExclusive);
}

/**
* This is the builder class for the {@link ConstraintAnnotation}.
*/
public static class ConstraintAnnotationBuilder {
private String minValue;
private String maxValue;
private String length;
private String minLength;
private String maxLength;
private String minValueExclusive;
private String maxValueExclusive;

public ConstraintAnnotationBuilder withMinValue(String minValue) {
this.minValue = minValue;
return this;
}

public ConstraintAnnotationBuilder withLength(String length) {
this.length = length;
return this;
}

public ConstraintAnnotationBuilder withMaxValue(String maxValue) {
this.maxValue = maxValue;
return this;
}

public ConstraintAnnotationBuilder withMinLength(String minLength) {
this.minLength = minLength;
return this;
}

public ConstraintAnnotationBuilder withMaxLength(String maxLength) {
this.maxLength = maxLength;
return this;
}

public ConstraintAnnotationBuilder withMinValueExclusive(String minValueExclusive) {
this.minValueExclusive = minValueExclusive;
return this;
}

public ConstraintAnnotationBuilder withMaxValueExclusive(String maxValueExclusive) {
this.maxValueExclusive = maxValueExclusive;
return this;
}

public ConstraintAnnotation build() {
ConstraintAnnotation constraintAnnotation = new ConstraintAnnotation(this);
return constraintAnnotation;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@
import io.ballerina.compiler.syntax.tree.NodeVisitor;
import io.ballerina.compiler.syntax.tree.TypeDefinitionNode;

import java.util.LinkedList;
import java.util.List;
import java.util.LinkedHashSet;

/**
* Visitor to get the TypeDefinitionNode and ListenerDeclarationNodes.
Expand All @@ -32,8 +31,8 @@
*/
public class ModuleMemberVisitor extends NodeVisitor {

LinkedList<TypeDefinitionNode> typeDefinitionNodes = new LinkedList<>();
LinkedList<ListenerDeclarationNode> listenerDeclarationNodes = new LinkedList<>();
LinkedHashSet<TypeDefinitionNode> typeDefinitionNodes = new LinkedHashSet<>();
LinkedHashSet<ListenerDeclarationNode> listenerDeclarationNodes = new LinkedHashSet<>();

@Override
public void visit(TypeDefinitionNode typeDefinitionNode) {
Expand All @@ -45,11 +44,11 @@ public void visit(ListenerDeclarationNode listenerDeclarationNode) {
listenerDeclarationNodes.add(listenerDeclarationNode);
}

public List<TypeDefinitionNode> getTypeDefinitionNodes() {
public LinkedHashSet<TypeDefinitionNode> getTypeDefinitionNodes() {
return typeDefinitionNodes;
}

public List<ListenerDeclarationNode> getListenerDeclarationNodes() {
public LinkedHashSet<ListenerDeclarationNode> getListenerDeclarationNodes() {
return listenerDeclarationNodes;
}
}
Loading