本文整理了Java中io.swagger.models.Swagger
类的一些代码示例,展示了Swagger
类的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Swagger
类的具体详情如下:
包路径:io.swagger.models.Swagger
类名称:Swagger
暂无
代码示例来源:origin: blox/blox
@Override
public void apply(Swagger swagger) {
if (swagger.getDefinitions() != null) {
swagger.setDefinitions(new TreeMap<>(swagger.getDefinitions()));
}
if (swagger.getPaths() != null) {
swagger.setPaths(new TreeMap<>(swagger.getPaths()));
}
}
}
代码示例来源:origin: blox/blox
@TaskAction
public void generateSpec() throws IOException, GenerateException {
ClassLoader loader = projectClassLoader();
Set<Class<?>> classes = new HashSet<>();
for (String pkg : apiPackages) {
Reflections reflections =
new Reflections(
new ConfigurationBuilder()
.addClassLoaders(loader)
.addUrls(ClasspathHelper.forPackage(pkg, loader))
.setExpandSuperTypes(false)
.filterInputsBy(new FilterBuilder().includePackage(pkg)));
Set<Class<?>> springMVCClasses =
reflections.getTypesAnnotatedWith(
org.springframework.web.bind.annotation.RestController.class);
classes.addAll(springMVCClasses);
}
SpringMvcApiReader reader = new SpringMvcApiReader(new Swagger(), log);
Swagger swagger = reader.read(classes);
for (SwaggerFilter filter : filters) {
filter.apply(swagger);
}
Yaml.pretty().writeValue(swaggerFile, swagger);
}
代码示例来源:origin: Swagger2Markup/swagger2markup
@Override
public MarkupDocBuilder apply(MarkupDocBuilder markupDocBuilder, Parameters params) {
Swagger swagger = params.swagger;
if (isNotBlank(swagger.getHost()) || isNotBlank(swagger.getBasePath()) || isNotEmpty(swagger.getSchemes())) {
markupDocBuilder.sectionTitleLevel(params.titleLevel, labels.getLabel(Labels.URI_SCHEME));
MarkupDocBuilder paragraphBuilder = copyMarkupDocBuilder(markupDocBuilder);
if (isNotBlank(swagger.getHost())) {
paragraphBuilder.italicText(labels.getLabel(Labels.HOST))
.textLine(COLON + swagger.getHost());
}
if (isNotBlank(swagger.getBasePath())) {
paragraphBuilder.italicText(labels.getLabel(Labels.BASE_PATH))
.textLine(COLON + swagger.getBasePath());
}
if (isNotEmpty(swagger.getSchemes())) {
List<String> schemes = swagger.getSchemes().stream()
.map(Enum::toString)
.collect(Collectors.toList());
paragraphBuilder.italicText(labels.getLabel(Labels.SCHEMES))
.textLine(COLON + join(schemes, ", "));
}
markupDocBuilder.paragraph(paragraphBuilder.toString(), true);
}
return markupDocBuilder;
}
代码示例来源:origin: blox/blox
@Override
public void apply(Swagger swagger) {
ApiKeyAuthDefinition authorization = new ApiKeyAuthDefinition("Authorization", In.HEADER);
authorization.setVendorExtension("x-amazon-apigateway-authtype", authType);
swagger.securityDefinition(SECURITY_SCHEME_NAME, authorization);
for (Path path : swagger.getPaths().values()) {
for (Operation operation : path.getOperations()) {
operation.addSecurity(SECURITY_SCHEME_NAME, Collections.emptyList());
}
}
}
}
代码示例来源:origin: Swagger2Markup/swagger2markup
public void apply(Swagger swagger) {
swagger.setHost("newHostName"); //<1>
swagger.basePath("newBasePath");
Map<String, Path> paths = swagger.getPaths(); //<2>
paths.remove("/remove");
swagger.setPaths(paths);
}
}
代码示例来源:origin: io.syndesis/connector-generator
for (final Map.Entry<String, Path> pathEntry : notNull(swaggerModelInfo.getModel().getPaths()).entrySet()) {
for (final Map.Entry<HttpMethod, Operation> operationEntry : notNull(pathEntry.getValue().getOperationMap()).entrySet()) {
for (final Parameter parameter : notNull(operationEntry.getValue().getParameters())) {
if (!(parameter instanceof BodyParameter)) {
continue;
for (final Map.Entry<String, Response> responseEntry : notNull(operationEntry.getValue().getResponses()).entrySet()) {
if (!responseEntry.getKey().startsWith("2")) {
continue; // check only correct responses
if (responseEntry.getValue().getSchema() == null) {
final String message = "Operation " + operationEntry.getKey() + " " + pathEntry.getKey()
+ " does not provide a response schema for code " + responseEntry.getKey();
代码示例来源:origin: apache/cxf
MessageContext ctx = createMessageContext();
String currentBasePath = StringUtils.substringBeforeLast(ctx.getHttpServletRequest().getRequestURI(), "/");
data.setBasePath(currentBasePath);
if (data.getHost() == null) {
data.setHost(beanConfig.getHost());
if (data.getInfo() == null) {
data.setInfo(beanConfig.getInfo());
&& beanConfig.getSwagger().getSecurityDefinitions() != null
&& data.getSecurityDefinitions() == null) {
data.setSecurityDefinitions(beanConfig.getSwagger().getSecurityDefinitions());
if (replaceTags && data.getTags() != null) {
data.getTags().clear();
for (final Map.Entry<String, Path> entry : data.getPaths().entrySet()) {
Tag tag = null;
if (replaceTags && operations.containsKey(entry.getKey())) {
data.addTag(tag);
OperationResourceInfo ori = methods.get(key);
if (replaceTags && data.getTags() != null) {
Collections.sort(data.getTags(), new Comparator<Tag>() {
代码示例来源:origin: apache/servicecomb-java-chassis
protected void convertToInterface() {
if (interfaceCls != null) {
return;
}
ClassConfig classConfig = new ClassConfig();
classConfig.setClassName(interfaceName);
classConfig.setIntf(true);
if (swagger.getPaths() != null) {
for (Path path : swagger.getPaths().values()) {
for (Operation operation : path.getOperations()) {
Response result = operation.getResponses().get(SwaggerConst.SUCCESS_KEY);
JavaType resultJavaType = swaggerObjectMap.get(result.getSchema());
MethodConfig methodConfig = new MethodConfig();
methodConfig.setName(operation.getOperationId());
methodConfig.setResult(resultJavaType);
for (Parameter parameter : operation.getParameters()) {
String paramName = parameter.getName();
paramName = ClassUtils.correctMethodParameterName(paramName);
JavaType paramJavaType = ConverterMgr.findJavaType(this, parameter);
methodConfig.addParameter(paramName, paramJavaType);
}
classConfig.addMethod(methodConfig);
}
}
}
interfaceCls = JavassistUtils.createClass(classLoader, classConfig);
}
代码示例来源:origin: jooby-project/jooby
Optional.ofNullable(swagger.getTag(value))
.orElseGet(() -> {
Tag tag = new Tag().name(value);
swagger.addTag(tag);
return tag;
});
Optional.ofNullable(swagger.getPath(pattern))
.orElseGet(() -> {
Path path = new Path();
swagger.path(pattern, path);
return path;
});
swagger.addDefinition(entry.getKey(), doModel(type, entry.getValue()));
Operation op = new Operation();
tags.forEach(it -> op.addTag(it.getName()));
swagger.consumes(MediaType.json.name());
} else if (consumes.size() == 1) {
swagger.consumes(consumes);
swagger.produces(MediaType.json.name());
} else if (produces.size() == 1) {
swagger.produces(produces);
代码示例来源:origin: rakam-io/rakam
@Override
protected void configure() {
Info info = new Info()
.title("Rakam API Documentation")
.version(ServiceStarter.RAKAM_VERSION)
.description("An analytics platform API that lets you create your own analytics services.")
.contact(new Contact().email("contact@rakam.io"))
.url("http://www.apache.org/licenses/LICENSE-2.0.html"));
Swagger swagger = new Swagger().info(info)
.basePath("/")
.tags(ImmutableList.copyOf(tags))
.securityDefinition("write_key", new ApiKeyAuthDefinition().in(In.HEADER).name("write_key"))
.securityDefinition("read_key", new ApiKeyAuthDefinition().in(In.HEADER).name("read_key"))
.securityDefinition("master_key", new ApiKeyAuthDefinition().in(In.HEADER).name("master_key"));
String value = annotation.authorizations()[0].value();
if (value != null && !value.isEmpty()) {
operation.response(FORBIDDEN.code(), new Response()
.schema(new RefProperty("ErrorMessage"))
.description(value + " is invalid"));
代码示例来源:origin: io.syndesis.server/server-api-generator
@Test
public void shouldMakeNonUniqueOperationIdsUnique() {
final Swagger swagger = new Swagger().path("/path", new Path().get(new Operation().operationId("foo"))
.post(new Operation().operationId("foo")).put(new Operation().operationId("bar")));
final Connector generated = generator.configureConnector(SWAGGER_TEMPLATE, new Connector.Builder().id("connector1").build(),
createSettingsFrom(swagger));
final List<ConnectorAction> actions = generated.getActions();
assertThat(actions).hasSize(3);
assertThat(actions.get(0).getId()).hasValueSatisfying(id -> assertThat(id).endsWith("foo"));
assertThat(actions.get(1).getId()).hasValueSatisfying(id -> assertThat(id).endsWith("foo1"));
assertThat(actions.get(2).getId()).hasValueSatisfying(id -> assertThat(id).endsWith("bar"));
}
代码示例来源:origin: io.syndesis.server/server-api-generator
public SwaggerHelperOperationDescriptionGenerationTest(final String operationSummary, final String operationDescription,
final String expectedName, final String expectedDescription) {
operation = new Operation().description(operationDescription).summary(operationSummary);
swagger = new Swagger().path("/test", new Path().get(operation));
expected = new OperationDescription(expectedName, expectedDescription);
}
代码示例来源:origin: kongchen/swagger-maven-plugin
protected void updatePath(String operationPath, String httpMethod, Operation operation) {
if (httpMethod == null) {
return;
}
Path path = swagger.getPath(operationPath);
if (path == null) {
path = new Path();
swagger.path(operationPath, path);
}
path.set(httpMethod, operation);
}
代码示例来源:origin: yangfuhai/jboot
continue;
final Operation operation = new Operation();
if ("post".equalsIgnoreCase(httpMethod) && operation.getConsumes() == null) {
operation.addConsumes("application/x-www-form-urlencoded");
if (operation.getResponses() == null) {
operation.defaultResponse(new Response().description("successful operation"));
final String parsedPath = PathUtils.parsePath(operationPath, regexMap);
Path path = swagger.getPath(parsedPath);
if (path == null) {
path = new SwaggerPath();
swagger.path(parsedPath, path);
path.set(httpMethod.toLowerCase(), operation);
代码示例来源:origin: apache/servicecomb-java-chassis
private void correctInfo() {
Info info = swagger.getInfo();
if (info == null) {
info = new Info();
swagger.setInfo(info);
}
if (StringUtils.isEmpty(info.getTitle())) {
info.setTitle("swagger definition for " + cls.getName());
}
if (StringUtils.isEmpty(info.getVersion())) {
info.setVersion("1.0.0");
}
setJavaInterface(info, cls);
}
代码示例来源:origin: apache/servicecomb-java-chassis
protected void convertResponses() {
if (swagger.getPaths() == null) {
return;
}
for (Path path : swagger.getPaths().values()) {
for (Operation operation : path.getOperations()) {
for (Response response : operation.getResponses().values()) {
convert(response.getSchema());
Map<String, Property> headers = response.getHeaders();
if (headers == null) {
continue;
}
for (Property header : headers.values()) {
convert(header);
}
}
}
}
}
代码示例来源:origin: apache/servicecomb-java-chassis
private void convertInfo(io.swagger.annotations.Info infoAnnotation, Swagger swagger) {
if (infoAnnotation == null) {
return;
}
Info info = new Info();
info.setTitle(infoAnnotation.title());
info.setVersion(infoAnnotation.version());
info.setDescription(infoAnnotation.description());
info.setTermsOfService(infoAnnotation.termsOfService());
info.setContact(convertContact(infoAnnotation.contact()));
info.setLicense(convertLicense(infoAnnotation.license()));
info.getVendorExtensions().putAll(BaseReaderUtils.parseExtensions(infoAnnotation.extensions()));
swagger.setInfo(info);
}
代码示例来源:origin: apache/servicecomb-java-chassis
private void initOperations() {
if (swagger.getPaths() == null) {
LOGGER.warn(swagger.getInfo().getTitle() + " with path " + swagger.getBasePath()
+ " is an empty interface, please delete it or fill with one method!");
return;
for (Entry<String, Path> entry : swagger.getPaths().entrySet()) {
String strPath = entry.getKey();
Path path = entry.getValue();
for (Entry<HttpMethod, Operation> operationEntry : path.getOperationMap().entrySet()) {
Operation operation = operationEntry.getValue();
if (operation.getOperationId() == null) {
throw ExceptionUtils.operationIdInvalid(getSchemaId(), strPath);
Method method = ReflectUtils.findMethod(swaggerIntf, operation.getOperationId());
if (method == null) {
LOGGER.warn("method {} not found in swagger interface {}, schemaId={}",
operation.getOperationId(),
swaggerIntf.getName(),
getSchemaId());
代码示例来源:origin: io.syndesis.integration/integration-project-generator
@Test
public void shouldNormalizeSwaggerBasePaths() {
final Swagger swagger = new Swagger().path("/path", new Path().get(new Operation()));
assertThat(ProjectGeneratorHelper.normalizePaths(swagger).getPaths()).containsOnlyKeys("/path");
assertThat(ProjectGeneratorHelper.normalizePaths(swagger.basePath("/api")).getPaths()).containsOnlyKeys("/api/path");
}
}
代码示例来源:origin: apache/servicecomb-java-chassis
public List<Parameter> findSwaggerParameter(String methodName) {
for (Path path : swagger.getPaths().values()) {
for (Operation operation : path.getOperations()) {
if (methodName.equals(operation.getOperationId())) {
return operation.getParameters();
}
}
}
throw new Error("method not found, name=" + methodName);
}
内容来源于网络,如有侵权,请联系作者删除!