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

Add OAS mapping for HTTP status code errors #1604

Merged
merged 13 commits into from
Feb 14, 2024
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,51 @@ public String toString() {
// TODO: remove this after fixing https://github.com/ballerina-platform/ballerina-standard-library/issues/4245
HTTP_CODES = Collections.unmodifiableMap(httpCodeMap);
}
public static final Map<String, String> HTTP_STATUS_CODE_ERRORS;
static {
Map<String, String> httpErrorCodeMap = new HashMap<>();
httpErrorCodeMap.put("DefaultStatusCodeError", "default");
httpErrorCodeMap.put("BadRequestError", "400");
httpErrorCodeMap.put("UnauthorizedError", "401");
httpErrorCodeMap.put("PaymentRequiredError", "402");
httpErrorCodeMap.put("ForbiddenError", "403");
httpErrorCodeMap.put("NotFoundError", "404");
httpErrorCodeMap.put("MethodNotAllowedError", "405");
httpErrorCodeMap.put("NotAcceptableError", "406");
httpErrorCodeMap.put("ProxyAuthenticationRequiredError", "407");
httpErrorCodeMap.put("RequestTimeOutError", "408");
httpErrorCodeMap.put("ConflictError", "409");
httpErrorCodeMap.put("GoneError", "410");
httpErrorCodeMap.put("LengthRequiredError", "411");
httpErrorCodeMap.put("PreconditionFailedError", "412");
httpErrorCodeMap.put("PayloadTooLargeError", "413");
httpErrorCodeMap.put("UriTooLongError", "414");
httpErrorCodeMap.put("UnsupportedMediaTypeError", "415");
httpErrorCodeMap.put("RangeNotSatisfiableError", "416");
httpErrorCodeMap.put("ExpectationFailedError", "417");
httpErrorCodeMap.put("MisdirectedRequestError", "421");
httpErrorCodeMap.put("UnprocessableEntityError", "422");
httpErrorCodeMap.put("LockedError", "423");
httpErrorCodeMap.put("FailedDependencyError", "424");
httpErrorCodeMap.put("TooEarlyError", "425");
httpErrorCodeMap.put("UpgradeRequiredError", "426");
httpErrorCodeMap.put("PreconditionRequiredError", "428");
httpErrorCodeMap.put("TooManyRequestsError", "429");
httpErrorCodeMap.put("RequestHeaderFieldsTooLargeError", "431");
httpErrorCodeMap.put("UnavailableDueToLegalReasonsError", "451");
httpErrorCodeMap.put("InternalServerErrorError", "500");
httpErrorCodeMap.put("NotImplementedError", "501");
httpErrorCodeMap.put("BadGatewayError", "502");
httpErrorCodeMap.put("ServiceUnavailableError", "503");
httpErrorCodeMap.put("GatewayTimeoutError", "504");
httpErrorCodeMap.put("HttpVersionNotSupportedError", "505");
httpErrorCodeMap.put("VariantAlsoNegotiatesError", "506");
httpErrorCodeMap.put("InsufficientStorageError", "507");
httpErrorCodeMap.put("LoopDetectedError", "508");
httpErrorCodeMap.put("NotExtendedError", "510");
httpErrorCodeMap.put("NetworkAuthenticationRequiredError", "511");
HTTP_STATUS_CODE_ERRORS = Collections.unmodifiableMap(httpErrorCodeMap);
}
public static final Map<String, String> HTTP_CODE_DESCRIPTIONS;
static {
Map<String, String> httpCodeDescriptionMap = new HashMap<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,10 +96,12 @@ public void setConstraints() {
}
Map<String, Schema> schemas = components.getSchemas();
for (Map.Entry<String, Schema> schemaEntry : schemas.entrySet()) {
TypeDefinitionNode typeDefinitionNode = moduleMemberVisitor.getTypeDefinitionNode(schemaEntry.getKey());
if (Objects.isNull(typeDefinitionNode)) {
Optional<TypeDefinitionNode> typeDefNodeOpt = moduleMemberVisitor.getTypeDefinitionNode(
schemaEntry.getKey());
if (typeDefNodeOpt.isEmpty()) {
continue;
}
TypeDefinitionNode typeDefinitionNode = typeDefNodeOpt.get();
if (typeDefinitionNode.metadata().isPresent()) {
ConstraintAnnotation.ConstraintAnnotationBuilder constraintBuilder =
new ConstraintAnnotation.ConstraintAnnotationBuilder();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import io.ballerina.openapi.service.mapper.utils.MapperCommonUtils;

import java.util.LinkedHashSet;
import java.util.Optional;
import java.util.Set;

/**
Expand All @@ -49,12 +50,12 @@ public Set<ListenerDeclarationNode> getListenerDeclarationNodes() {
return listenerDeclarationNodes;
}

public TypeDefinitionNode getTypeDefinitionNode(String typeName) {
public Optional<TypeDefinitionNode> getTypeDefinitionNode(String typeName) {
for (TypeDefinitionNode typeDefinitionNode : typeDefinitionNodes) {
if (MapperCommonUtils.unescapeIdentifier(typeDefinitionNode.typeName().text()).equals(typeName)) {
return typeDefinitionNode;
return Optional.of(typeDefinitionNode);
}
}
return null;
return Optional.empty();
}
}
Loading
Loading