本文整理汇总了Java中io.swagger.models.Swagger类的典型用法代码示例。如果您正苦于以下问题:Java Swagger类的具体用法?Java Swagger怎么用?Java Swagger使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Swagger类属于io.swagger.models包,在下文中一共展示了Swagger类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: shouldCreatePropertyParametersFromPetstoreSwagger
import io.swagger.models.Swagger; //导入依赖的package包/类
@Test
public void shouldCreatePropertyParametersFromPetstoreSwagger() throws IOException {
final String specification = resource("/swagger/petstore.swagger.json");
final Swagger swagger = new SwaggerParser().parse(specification);
final Parameter petIdPathParameter = swagger.getPath("/pet/{petId}").getGet().getParameters().get(0);
final Optional<ConfigurationProperty> maybeConfigurationProperty = BaseSwaggerConnectorGenerator
.createPropertyFromParameter(petIdPathParameter);
final ConfigurationProperty expected = new ConfigurationProperty.Builder()//
.componentProperty(false)//
.deprecated(false)//
.description("ID of pet to return")//
.displayName("petId")//
.group("producer")//
.javaType(Long.class.getName())//
.kind("property")//
.required(true)//
.secret(false)//
.type("integer")//
.build();
assertThat(maybeConfigurationProperty).hasValue(expected);
}
示例2: getListing
import io.swagger.models.Swagger; //导入依赖的package包/类
@GET
@Produces(MediaType.APPLICATION_JSON)
@ApiOperation(value = "Generates the swagger.json file.", hidden = true)
public Response getListing(
@Context Application app,
@Context ServletContext context,
@Context ServletConfig config,
@Context HttpHeaders headers,
@Context UriInfo uriInfo
) {
// The generated and transformed Swagger model is cached in order to avoid running the transformations multiple times
// on the same model because Swagger caches the transformed model internally. The model won't change anyways.
Swagger swagger = cachedSwagger.updateAndGet(s -> {
if (s != null) return s;
return transformer.transform(process(app, context, config, headers, uriInfo));
});
return Response.ok().entity(swagger).build();
}
示例3: determineConnectorName
import io.swagger.models.Swagger; //导入依赖的package包/类
@Override
protected final String determineConnectorName(final ConnectorTemplate connectorTemplate, final ConnectorSettings connectorSettings) {
final Swagger swagger = parseSpecification(connectorSettings, false).getModel();
final Info info = swagger.getInfo();
if (info == null) {
return super.determineConnectorName(connectorTemplate, connectorSettings);
}
final String title = info.getTitle();
if (title == null) {
return super.determineConnectorName(connectorTemplate, connectorSettings);
}
return title;
}
示例4: swaggerDocProxy
import io.swagger.models.Swagger; //导入依赖的package包/类
@RequestMapping(value = "/swaggerDocProxy/{id}", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
public Swagger swaggerDocProxy(@PathVariable(value = "id") Integer id,
@RequestParam(value = "trimSystemController", defaultValue = "true") boolean trimSystemController,
HttpServletRequest request) {
Document document = documentService.findOne(id);
if (document != null) {
Swagger swagger = new SwaggerParser()
.parse(document.getContent());
if (trimSystemController) {
swagger = Generator.convertSwagger(swagger);
}
swagger.setHost(request.getServerName() + ":" + request.getServerPort() + prefix + "/" + id);
return swagger;
}
return null;
}
示例5: testTransform
import io.swagger.models.Swagger; //导入依赖的package包/类
@Test
public void testTransform() {
Operation operation = new Operation();
Swagger swagger = createSwagger(operation);
SwaggerModelTransformation transformation = mock(SwaggerModelTransformation.class);
SwaggerModelTransformer transformer = SwaggerModelTransformer.builder()
.addTransformation(transformation)
.build();
transformer.transform(swagger);
InOrder inOrder = inOrder(transformation);
inOrder.verify(transformation, times(1)).beforeHook(swagger);
inOrder.verify(transformation, times(3)).transformOperation(swagger, operation);
inOrder.verify(transformation, times(1)).afterHook(swagger);
}
示例6: testSwagger
import io.swagger.models.Swagger; //导入依赖的package包/类
public static SwaggerGenerator testSwagger(String resPath, SwaggerGeneratorContext context, Class<?> cls,
String... methods) {
SwaggerGeneratorForTest generator = new SwaggerGeneratorForTest(context, cls);
generator.setClassLoader(new ClassLoader() {
});
generator.replaceMethods(methods);
Swagger swagger = generator.generate();
String expectSchema = loadExpect(resPath);
Swagger expectSwagger = parse(expectSchema);
String schema = pretty(swagger);
swagger = parse(schema);
if (swagger != null && !swagger.equals(expectSwagger)) {
Assert.assertEquals(expectSchema, schema);
}
return generator;
}
示例7: map
import io.swagger.models.Swagger; //导入依赖的package包/类
void map(@NonNull HttpConfiguration httpConfiguration) throws IOException {
org.springframework.core.io.Resource[] resources;
try {
resources = ResourcePatternUtils.getResourcePatternResolver(resourceLoader).getResources(
applicationProperties.getResourcePath() + "/openapi/**.y*ml");
} catch (FileNotFoundException exp) {
LOG.warn("No Open API resources found in path:{}/openapi",
applicationProperties.getResourcePath());
return;
}
for (org.springframework.core.io.Resource resource : resources) {
InputStream inputStream =
new EnvironmentAwareResource(resource.getInputStream(), environment).getInputStream();
String result = CharStreams.toString(new InputStreamReader(inputStream, Charsets.UTF_8));
if (!StringUtils.isBlank(result)) {
Swagger swagger = openApiParser.parse(result);
mapOpenApiDefinition(swagger, httpConfiguration);
}
}
}
示例8: test
import io.swagger.models.Swagger; //导入依赖的package包/类
@Test
public void test() {
BeanUtils.setContext(Mockito.mock(ApplicationContext.class));
MicroserviceMeta mm = new MicroserviceMeta("app:ms");
List<SchemaMeta> smList = new ArrayList<>();
SwaggerGenerator generator = new SwaggerGenerator(context, TestRestEngineSchemaListenerSchemaImpl.class);
Swagger swagger = generator.generate();
swagger.setBasePath("");
SchemaMeta sm1 = new SchemaMeta(swagger, mm, "sid1");
smList.add(sm1);
RestEngineSchemaListener listener = new RestEngineSchemaListener();
SchemaMeta[] smArr = smList.toArray(new SchemaMeta[smList.size()]);
listener.onSchemaLoaded(smArr);
// 重复调用,不应该出异常
listener.onSchemaLoaded(smArr);
ServicePathManager spm = ServicePathManager.getServicePathManager(mm);
Assert.assertEquals(mm, spm.getMicroserviceMeta());
Assert.assertSame(sm1,
spm.consumerLocateOperation("/add/", "POST").getOperation().getOperationMeta().getSchemaMeta());
}
示例9: read
import io.swagger.models.Swagger; //导入依赖的package包/类
public static void read(Swagger swagger, Map<Class<?>, Object> interfaceMapRef,
String httpContext) {
final Reader reader = new Reader(swagger);
List<Entry<Class<?>, Object>> arrayList = new ArrayList<Entry<Class<?>, Object>>(interfaceMapRef.entrySet());
Collections.sort(arrayList, new Comparator<Entry<Class<?>, Object>>() {
@Override
public int compare(Entry<Class<?>, Object> o1, Entry<Class<?>, Object> o2) {
return o1.getKey().getSimpleName().compareTo(o2.getKey().getSimpleName());
}
});
for (Entry<Class<?>, Object> entry : arrayList) {
final ReaderContext context = new ReaderContext(swagger,
entry.getValue().getClass(), entry.getKey(), httpContext, null, false,
new ArrayList<String>(), new ArrayList<String>(), new ArrayList<String>(),
new ArrayList<Parameter>());
reader.read(context);
}
}
示例10: start
import io.swagger.models.Swagger; //导入依赖的package包/类
@Override
public void start(Future<Void> startFuture) throws Exception {
Json.mapper.registerModule(new JavaTimeModule());
FileSystem vertxFileSystem = vertx.fileSystem();
vertxFileSystem.readFile("swagger.json", readFile -> {
if (readFile.succeeded()) {
Swagger swagger = new SwaggerParser().parse(readFile.result().toString(Charset.forName("utf-8")));
Router swaggerRouter = SwaggerRouter.swaggerRouter(Router.router(vertx), swagger, vertx.eventBus(), new OperationIdServiceIdResolver());
deployVerticles(startFuture);
vertx.createHttpServer()
.requestHandler(swaggerRouter::accept)
.listen(8080);
startFuture.complete();
} else {
startFuture.fail(readFile.cause());
}
});
}
示例11: createBasePath
import io.swagger.models.Swagger; //导入依赖的package包/类
private String createBasePath(Swagger swagger) {
String basePath = "/";
if (swagger.getHost() == null) {
throw new ConfigurationException(
String.format("OpenAPI definition document '%s' must contain a 'host' attribute.",
swagger.getInfo().getDescription()));
}
basePath = basePath.concat(swagger.getHost());
if (swagger.getBasePath() != null) {
basePath = basePath.concat(swagger.getBasePath());
}
return basePath;
}
示例12: SchemaMeta
import io.swagger.models.Swagger; //导入依赖的package包/类
public SchemaMeta(Swagger swagger, MicroserviceMeta microserviceMeta, String schemaId) {
this.packageName = SchemaUtils.generatePackageName(microserviceMeta, schemaId);
this.swagger = swagger;
this.name = schemaId;
this.microserviceMeta = microserviceMeta;
this.microserviceQualifiedName = microserviceMeta.getName() + "." + schemaId;
// 确保swagger对应的接口是存在的
swaggerIntf = ClassUtils.getOrCreateInterface(swagger, microserviceMeta.getClassLoader(), packageName);
createOperationMgr("schemaMeta " + schemaId + " operation mgr");
operationMgr.setRegisterErrorFmt("Operation name repeat, schema=%s, operation=%s");
initOperations();
}
示例13: extractLdpathNamespaces
import io.swagger.models.Swagger; //导入依赖的package包/类
private ImmutableMap<String, String> extractLdpathNamespaces(Swagger swagger) {
Map<String, Object> extensions = swagger.getVendorExtensions();
ImmutableMap<String, Object> vendorExtensions =
extensions == null ? ImmutableMap.of() : ImmutableMap.copyOf(extensions);
if (vendorExtensions.containsKey(OpenApiSpecificationExtensions.LDPATH_NAMESPACES)) {
Object ldPathNamespaces =
vendorExtensions.get(OpenApiSpecificationExtensions.LDPATH_NAMESPACES);
try {
return ImmutableMap.copyOf((Map<String, String>) ldPathNamespaces);
} catch (ClassCastException cce) {
throw new LdPathExecutorRuntimeException(String.format(
"Vendor extension '%s' should contain a map of namespaces (eg. "
+ "{ \"rdfs\": \"http://www.w3.org/2000/01/rdf-schema#\", "
+ "\"rdf\": \"http://www.w3.org/1999/02/22-rdf-syntax-ns#\"})",
OpenApiSpecificationExtensions.LDPATH_NAMESPACES), cce);
}
}
return ImmutableMap.of();
}
示例14: getSwaggerJson
import io.swagger.models.Swagger; //导入依赖的package包/类
public JSONObject getSwaggerJson(String path) throws ServiceApiException {
Swagger swagger = getSwagger(path);
try {
// Re-parse as JsonObject to ensure ordering of definitions and paths.
// TODO: make this optional (see limberest.yaml comments in limberest-demo)
JsonObject swaggerJson = new JsonObject(Json.mapper().writeValueAsString(swagger));
if (swaggerJson.has("definitions"))
swaggerJson.put("definitions", new JsonObject(swaggerJson.getJSONObject("definitions").toString()));
if (swaggerJson.has("paths"))
swaggerJson.put("paths", new JsonObject(swaggerJson.getJSONObject("paths").toString()));
return swaggerJson;
}
catch (JsonProcessingException ex) {
throw new ServiceApiException(ex.getMessage(), ex);
}
}
示例15: getSwaggerString
import io.swagger.models.Swagger; //导入依赖的package包/类
public String getSwaggerString(String path, Format format, int prettyIndent)
throws ServiceApiException {
try {
Swagger swagger = getSwagger(path);
// TODO orderedKeys in limberest.yaml
boolean orderedKeys = true;
if (format == Format.json && orderedKeys) {
JSONObject swaggerJson = getSwaggerJson(path);
return swaggerJson.toString(prettyIndent);
}
else {
return getWriter(format, prettyIndent).writeValueAsString(swagger);
}
}
catch (JsonProcessingException ex) {
throw new ServiceApiException(ex.getMessage(), ex);
}
}