Skip to content

Commit

Permalink
Merge pull request #1562 from lnash94/contraint_support_test_fix
Browse files Browse the repository at this point in the history
Sync master with constraint support
  • Loading branch information
lnash94 authored Oct 24, 2023
2 parents 48e6cde + 4ecc318 commit 321ac86
Show file tree
Hide file tree
Showing 60 changed files with 3,112 additions and 164 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,8 @@ public class Constants {
public static final String WILD_CARD_SUMMARY = "Any type of entity body";
public static final String MEDIA_TYPE = "mediaType";
public static final String TUPLE = "tuple";
public static final String REGEX_INTERPOLATION_PATTERN = "^(?!.*\\$\\{).+$";
public static final String DATE_CONSTRAINT_ANNOTATION = "constraint:Date";

/**
* Enum to select the Ballerina Type.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,12 +61,19 @@ 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", "Generated OpenAPI definition does not contain `%s` request" +
OAS_CONVERTOR_116("OAS_CONVERTOR_116", "Failed to parse the Number value due to: %s ",
DiagnosticSeverity.ERROR),
OAS_CONVERTOR_117("OAS_CONVERTOR_117", "Generated OpenAPI definition does not contain `%s` request" +
" body information, as it's not supported by the OpenAPI tool.",
DiagnosticSeverity.WARNING);
DiagnosticSeverity.WARNING),
OAS_CONVERTOR_118("OAS_CONVERTOR_118", "Generated OpenAPI definition does not contain variable " +
"assignment '%s' in constraint validation.", DiagnosticSeverity.WARNING),
OAS_CONVERTOR_119("OAS_CONVERTOR_119", "Given REGEX pattern '%s' is not supported by the OpenAPI " +
"tool, it may also not support interpolation within the REGEX pattern.", DiagnosticSeverity.WARNING),
OAS_CONVERTOR_120("OAS_CONVERTER_120", "Ballerina Date constraints might not be reflected in the " +
"OpenAPI definition", DiagnosticSeverity.WARNING);

private final String code;
private final String description;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
/*
* Copyright (c) 2023, 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;
private final String pattern;

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;
this.pattern = builder.pattern;
}

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);
}

public Optional<String> getPattern() {
return Optional.ofNullable(pattern);
}

/**
* 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;
private String pattern;

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 ConstraintAnnotationBuilder withPattern(String pattern) {
this.pattern = pattern;
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,8 @@
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;
import java.util.Set;

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

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

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

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

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

0 comments on commit 321ac86

Please sign in to comment.