Skip to content

Commit

Permalink
Add openapi resource annotation
Browse files Browse the repository at this point in the history
  • Loading branch information
lnash94 committed Jun 13, 2024
1 parent f7686b8 commit 4dc69c0
Show file tree
Hide file tree
Showing 9 changed files with 506 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -336,4 +336,12 @@ public String toString() {
public static final String JSON_EXTENSION = ".json";
public static final String YML_EXTENSION = ".yml";
public static final String UNDERSCORE = "_";

//openapi:ResourceInFo annotation
public static final String OPENAPI_RESOURCE_INFO = "openapi:ResourceInfo";
public static final String TAGS = "tags";
public static final String SUMMARY = "summary";
public static final String EXAMPLES = "examples";
public static final String OPERATION_ID = "operationId";
public static final String RESPONSE_ATTRIBUTE = "response";
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@
import io.ballerina.openapi.service.mapper.interceptor.model.RequestParameterInfo;
import io.ballerina.openapi.service.mapper.interceptor.model.ResponseInfo;
import io.ballerina.openapi.service.mapper.interceptor.pipeline.InterceptorPipeline;
import io.ballerina.openapi.service.mapper.metainfo.MetaInfoMapper;
import io.ballerina.openapi.service.mapper.metainfo.MetaInfoMapperImpl;
import io.ballerina.openapi.service.mapper.model.AdditionalData;
import io.ballerina.openapi.service.mapper.model.ModuleMemberVisitor;
import io.ballerina.openapi.service.mapper.model.OperationInventory;
Expand Down Expand Up @@ -81,6 +83,7 @@ public class ServiceMapperFactory {
private final ConstraintMapper constraintMapper;
private final HateoasMapper hateoasMapper;
private final InterceptorPipeline interceptorPipeline;
private final MetaInfoMapper metaInfoMapper;

public ServiceMapperFactory(OpenAPI openAPI, SemanticModel semanticModel, ModuleMemberVisitor moduleMemberVisitor,
List<OpenAPIMapperDiagnostic> diagnostics, ServiceDeclarationNode serviceDefinition) {
Expand All @@ -92,6 +95,7 @@ public ServiceMapperFactory(OpenAPI openAPI, SemanticModel semanticModel, Module
this.typeMapper = new TypeMapperImpl(getComponents(openAPI), additionalData);
this.constraintMapper = new ConstraintMapperImpl(openAPI, moduleMemberVisitor, diagnostics);
this.hateoasMapper = new HateoasMapperImpl();
this.metaInfoMapper = new MetaInfoMapperImpl();
}

public ServersMapper getServersMapper(Set<ListenerDeclarationNode> endpoints, ServiceDeclarationNode serviceNode) {
Expand Down Expand Up @@ -162,6 +166,11 @@ public HateoasMapper getHateoasMapper() {
return hateoasMapper;
}


public MetaInfoMapper getMetaInfoMapper() {
return metaInfoMapper;
}

private Components getComponents(OpenAPI openAPI) {
Components components = openAPI.getComponents();
if (Objects.isNull(components)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import io.ballerina.openapi.service.mapper.diagnostic.ExceptionDiagnostic;
import io.ballerina.openapi.service.mapper.diagnostic.OpenAPIMapperDiagnostic;
import io.ballerina.openapi.service.mapper.hateoas.HateoasMapper;
import io.ballerina.openapi.service.mapper.metainfo.MetaInfoMapper;
import io.ballerina.openapi.service.mapper.model.ModuleMemberVisitor;
import io.ballerina.openapi.service.mapper.model.OASGenerationMetaInfo;
import io.ballerina.openapi.service.mapper.model.OASResult;
Expand Down Expand Up @@ -206,6 +207,9 @@ public static OASResult generateOAS(OASGenerationMetaInfo oasGenerationMetaInfo)
HateoasMapper hateoasMapper = serviceMapperFactory.getHateoasMapper();
hateoasMapper.setOpenApiLinks(serviceDefinition, openapi);

MetaInfoMapper metaInfoMapper = serviceMapperFactory.getMetaInfoMapper();
metaInfoMapper.setResourceMetaData(openapi, serviceDefinition);

if (openapi.getComponents().getSchemas().isEmpty()) {
openapi.setComponents(null);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*
* Copyright (c) 2024, WSO2 LLC. (http://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.service.mapper.metainfo;

import io.ballerina.compiler.syntax.tree.ServiceDeclarationNode;
import io.swagger.v3.oas.models.OpenAPI;

/**
* Interface for Meta information mapper.
*
* @since 2.0.1
*/
public interface MetaInfoMapper {
void setResourceMetaData(OpenAPI openAPI, ServiceDeclarationNode serviceNode);
}
Loading

0 comments on commit 4dc69c0

Please sign in to comment.