use of io.swagger.models.Swagger in project java-chassis by ServiceComb.
the class TestDefinition method testMicroserviceMetaManager.
@Test
public void testMicroserviceMetaManager() throws Exception {
MicroserviceMetaManager microserviceMetaManager = new MicroserviceMetaManager();
microserviceMetaManager.getOrCreateMicroserviceMeta("testname");
Assert.assertEquals("microservice meta manager", microserviceMetaManager.getName());
Assert.assertEquals("Not allow regsiter repeat data, name=%s, key=%s", microserviceMetaManager.getRegisterErrorFmt());
Assert.assertEquals(0, microserviceMetaManager.getAllSchemaMeta("testname").size());
Swagger oSwagger = new Swagger();
Info oInfo = new Info();
oInfo.setVendorExtension("x-java-interface", "java.lang.String");
oSwagger.setInfo(oInfo);
Assert.assertEquals("java.lang.String", (ClassUtils.getJavaInterface(oSwagger)).getName());
oInfo.setVendorExtension("x-java-class", "java.lang.String");
}
use of io.swagger.models.Swagger in project java-chassis by ServiceComb.
the class RestOperationMeta method init.
public void init(OperationMeta operationMeta) {
this.operationMeta = operationMeta;
Swagger swagger = operationMeta.getSchemaMeta().getSwagger();
Operation operation = operationMeta.getSwaggerOperation();
this.produces = operation.getProduces();
if (produces == null) {
this.produces = swagger.getProduces();
}
setAbsolutePath(concatPath(swagger.getBasePath(), operationMeta.getOperationPath()));
this.createProduceProcessors();
Method method = operationMeta.getMethod();
Type[] genericParamTypes = method.getGenericParameterTypes();
if (genericParamTypes.length != operation.getParameters().size()) {
throw new Error("Param count is not equal between swagger and method, path=" + absolutePath);
}
// 初始化所有rest param
for (int idx = 0; idx < genericParamTypes.length; idx++) {
Parameter parameter = operation.getParameters().get(idx);
Type genericParamType = genericParamTypes[idx];
RestParam param = new RestParam(idx, parameter, genericParamType);
addParam(param);
}
this.pathBuilder = new URLPathBuilder(absolutePath, paramMap);
}
use of io.swagger.models.Swagger in project ORCID-Source by ORCID.
the class PublicSwaggerResource method scan.
/**
* Scan the classes and add in the OAuth information
*
*/
@Override
protected synchronized Swagger scan(Application app) {
// tell swagger to pick up our jaxb annotations
Json.mapper().registerModule(new JaxbAnnotationModule());
Swagger s = super.scan(app);
OAuth2Definition oauthTwoLegs = new OAuth2Definition();
oauthTwoLegs.application(this.tokenEndPoint);
oauthTwoLegs.scope(ScopePathType.READ_PUBLIC.value(), "Read Public record");
s.securityDefinition("orcid_two_legs", oauthTwoLegs);
return s;
}
use of io.swagger.models.Swagger in project cxf by apache.
the class Swagger2Feature method addSwaggerResource.
@Override
protected void addSwaggerResource(Server server, Bus bus) {
JAXRSServiceFactoryBean sfb = (JAXRSServiceFactoryBean) server.getEndpoint().get(JAXRSServiceFactoryBean.class.getName());
ServerProviderFactory factory = (ServerProviderFactory) server.getEndpoint().get(ServerProviderFactory.class.getName());
ApplicationInfo appInfo = null;
if (!isScan()) {
appInfo = factory.getApplicationProvider();
if (appInfo == null) {
Set<Class<?>> serviceClasses = new HashSet<>();
for (ClassResourceInfo cri : sfb.getClassResourceInfo()) {
serviceClasses.add(cri.getServiceClass());
}
appInfo = new ApplicationInfo(new DefaultApplication(serviceClasses), bus);
server.getEndpoint().put(Application.class.getName(), appInfo);
}
}
List<Object> swaggerResources = new LinkedList<>();
if (customizer == null) {
customizer = new Swagger2Customizer();
}
ApiListingResource apiListingResource = new Swagger2ApiListingResource(customizer);
swaggerResources.add(apiListingResource);
List<Object> providers = new ArrayList<>();
if (isRunAsFilter()) {
providers.add(new SwaggerContainerRequestFilter(appInfo == null ? null : appInfo.getProvider(), customizer));
}
final Properties swaggerProps = getSwaggerProperties(bus);
final Registration swaggerUiRegistration = getSwaggerUi(bus, swaggerProps, isRunAsFilter());
if (!isRunAsFilter()) {
swaggerResources.addAll(swaggerUiRegistration.getResources());
}
providers.addAll(swaggerUiRegistration.getProviders());
sfb.setResourceClassesFromBeans(swaggerResources);
List<ClassResourceInfo> cris = sfb.getClassResourceInfo();
if (!isRunAsFilter()) {
for (ClassResourceInfo cri : cris) {
if (ApiListingResource.class.isAssignableFrom(cri.getResourceClass())) {
InjectionUtils.injectContextProxies(cri, apiListingResource);
}
}
}
customizer.setClassResourceInfos(cris);
customizer.setDynamicBasePath(dynamicBasePath);
BeanConfig beanConfig = appInfo == null ? new BeanConfig() : new ApplicationBeanConfig(appInfo.getProvider());
initBeanConfig(beanConfig, swaggerProps);
Swagger swagger = beanConfig.getSwagger();
if (swagger != null && securityDefinitions != null) {
swagger.setSecurityDefinitions(securityDefinitions);
}
customizer.setBeanConfig(beanConfig);
providers.add(new ReaderConfigFilter());
if (beanConfig.isUsePathBasedConfig()) {
providers.add(new ServletConfigProvider());
}
factory.setUserProviders(providers);
}
use of io.swagger.models.Swagger in project carbon-apimgt by wso2.
the class APIDefinitionFromSwagger20 method removeScopeFromSwaggerDefinition.
@Override
public String removeScopeFromSwaggerDefinition(String resourceConfigJSON, String name) {
SwaggerParser swaggerParser = new SwaggerParser();
Swagger swagger = swaggerParser.parse(resourceConfigJSON);
Map<String, SecuritySchemeDefinition> securitySchemeDefinitionMap = swagger.getSecurityDefinitions();
if (securitySchemeDefinitionMap != null && !securitySchemeDefinitionMap.isEmpty()) {
OAuth2Definition oAuth2Definition = (OAuth2Definition) securitySchemeDefinitionMap.get(APIMgtConstants.OAUTH2SECURITY);
if (oAuth2Definition != null) {
// Removing Scope from Swagger SecurityDefinition
oAuth2Definition.getScopes().remove(name);
// Finding Security requirements at root level
List<SecurityRequirement> securityRequirements = swagger.getSecurity();
if (securityRequirements != null && !securityRequirements.isEmpty()) {
// Get List of Security Requirements
Iterator<SecurityRequirement> securityRequirementIterator = securityRequirements.iterator();
while (securityRequirementIterator.hasNext()) {
SecurityRequirement securityRequirement = securityRequirementIterator.next();
Map<String, List<String>> secListMap = securityRequirement.getRequirements();
// get Oauth2Security scopes
List<String> scopesList = secListMap.get(APIMgtConstants.OAUTH2SECURITY);
if (scopesList != null) {
// Remove Scope from root level
scopesList.remove(name);
}
// Check root level security Requirements is empty
if (securityRequirement.getRequirements().isEmpty()) {
// Check root level security Requirements
securityRequirementIterator.remove();
}
}
if (securityRequirements.isEmpty()) {
// Remove root level security
swagger.setSecurity(null);
}
}
Map<String, Path> pathMap = swagger.getPaths();
if (pathMap != null && !pathMap.isEmpty()) {
for (Map.Entry<String, Path> pathEntry : pathMap.entrySet()) {
Path path = pathEntry.getValue();
List<Operation> operationList = path.getOperations();
for (Operation operation : operationList) {
List<Map<String, List<String>>> operationSecurityList = operation.getSecurity();
if (operationSecurityList != null && !operationSecurityList.isEmpty()) {
Iterator<Map<String, List<String>>> securityMapIterator = operationSecurityList.iterator();
while (securityMapIterator.hasNext()) {
Map<String, List<String>> securityMap = securityMapIterator.next();
List<String> scopesList = securityMap.get(APIMgtConstants.OAUTH2SECURITY);
scopesList.remove(name);
if (scopesList.isEmpty()) {
securityMapIterator.remove();
}
}
if (operationSecurityList.isEmpty()) {
operation.setSecurity(null);
}
}
}
}
}
}
}
return Json.pretty(swagger);
}
Aggregations