pub.codex.apix.scan.ApiDescriptionReader Maven / Gradle / Ivy
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;
}
}