All Downloads are FREE. Search and download functionalities are using the official Maven repository.

pub.codex.apix.scan.ApiDescriptionReader Maven / Gradle / Ivy

There is a newer version: 5.0.2
Show newest version
package pub.codex.apix.scan;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.web.servlet.mvc.condition.PatternsRequestCondition;
import pub.codex.apix.context.RequestMappingContext;
import pub.codex.apix.schema.ApiDescription;
import pub.codex.apix.schema.Operation;

import java.util.List;

import static com.google.common.collect.Lists.newArrayList;

@Component
public class ApiDescriptionReader {


    private ApiOperationReader apiOperationReader;

    @Autowired
    public ApiDescriptionReader(ApiOperationReader apiOperationReader) {
        this.apiOperationReader = apiOperationReader;
    }

    /**
     * 读取API描述信息
     *
     * @param context
     */
    public List read(RequestMappingContext context) {


        PatternsRequestCondition patternsCondition = context.getPatternsCondition();

        List apiDescriptionList = newArrayList();

        for (String path : patternsCondition.getPatterns()) {

            List operations = apiOperationReader.read(context);

            context.getApiDescriptionBuilder()
                    .setPath(path)
                    .setMethodName(context.getName())
                    .setOperations(operations);

            ApiDescription apiDescription = context.apiDescriptionBuilder().build();

            apiDescriptionList.add(apiDescription);
        }

        return apiDescriptionList;
    }


}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy