本文整理汇总了Java中io.swagger.parser.SwaggerParser类的典型用法代码示例。如果您正苦于以下问题:Java SwaggerParser类的具体用法?Java SwaggerParser怎么用?Java SwaggerParser使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
SwaggerParser类属于io.swagger.parser包,在下文中一共展示了SwaggerParser类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: shouldCreatePropertyParametersFromPetstoreSwagger
import io.swagger.parser.SwaggerParser; //导入依赖的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: swaggerDocProxy
import io.swagger.parser.SwaggerParser; //导入依赖的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;
}
示例3: start
import io.swagger.parser.SwaggerParser; //导入依赖的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());
}
});
}
示例4: testSwaggerJSON
import io.swagger.parser.SwaggerParser; //导入依赖的package包/类
@Test
public void testSwaggerJSON() {
SutInfoDto dto = remoteController.getSutInfo();
String swaggerJson = given().accept(Formats.JSON_V1)
.get(dto.swaggerJsonUrl)
.then()
.statusCode(200)
.extract().asString();
Swagger swagger = new SwaggerParser().parse(swaggerJson);
assertEquals("/", swagger.getBasePath());
assertEquals(3, swagger.getPaths().size());
}
示例5: testSwaggerJSON
import io.swagger.parser.SwaggerParser; //导入依赖的package包/类
@Test
public void testSwaggerJSON() {
SutInfoDto dto = remoteController.getSutInfo();
String swaggerJson = given().accept(Formats.JSON_V1)
.get(dto.swaggerJsonUrl)
.then()
.statusCode(200)
.extract().asString();
Swagger swagger = new SwaggerParser().parse(swaggerJson);
assertEquals("/", swagger.getBasePath());
assertEquals(2, swagger.getPaths().size());
}
示例6: start
import io.swagger.parser.SwaggerParser; //导入依赖的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")));
SwaggerManager.getInstance().setSwagger(swagger);
Router swaggerRouter = SwaggerRouter.swaggerRouter(Router.router(vertx), swagger, vertx.eventBus(), new OperationIdServiceIdResolver());
deployVerticles(startFuture);
vertx.createHttpServer()
.requestHandler(swaggerRouter::accept)
.listen(config().getInteger("http.port", 8080));
startFuture.complete();
} else {
startFuture.fail(readFile.cause());
}
});
}
示例7: testSwaggerJSON
import io.swagger.parser.SwaggerParser; //导入依赖的package包/类
@Test
public void testSwaggerJSON() {
SutInfoDto dto = remoteController.getSutInfo();
String swaggerJson = given().accept(Formats.JSON_V1)
.get(dto.swaggerJsonUrl)
.then()
.statusCode(200)
.extract().asString();
Swagger swagger = new SwaggerParser().parse(swaggerJson);
assertEquals("/api", swagger.getBasePath());
assertEquals(2, swagger.getPaths().size());
}
示例8: SwaggerDiff
import io.swagger.parser.SwaggerParser; //导入依赖的package包/类
/**
* @param oldSpec
* @param newSpec
* @param auths
* @param version
*/
private SwaggerDiff(String oldSpec, String newSpec, List<AuthorizationValue> auths,
String version) {
if (SWAGGER_VERSION_V2.equals(version)) {
SwaggerParser swaggerParser = new SwaggerParser();
oldSpecSwagger = swaggerParser.read(oldSpec, auths, true);
newSpecSwagger = swaggerParser.read(newSpec, auths, true);
} else {
SwaggerCompatConverter swaggerCompatConverter = new SwaggerCompatConverter();
try {
oldSpecSwagger = swaggerCompatConverter.read(oldSpec, auths);
newSpecSwagger = swaggerCompatConverter.read(newSpec, auths);
} catch (IOException e) {
logger.error("cannot read api-doc from spec[version_v1.x]", e);
return;
}
}
if (null == oldSpecSwagger || null == newSpecSwagger) { throw new RuntimeException(
"cannot read api-doc from spec."); }
}
示例9: process
import io.swagger.parser.SwaggerParser; //导入依赖的package包/类
public Swagger process(String resource) {
if (resource == null) {
throw new IllegalArgumentException("No file or URL specified");
}
File file = new File(resource);
if (!file.exists()) {
try {
new URL(resource);
} catch (MalformedURLException e) {
throw new IllegalArgumentException("File doesn't exist or invalid URL!");
}
}
return new SwaggerParser().read(resource);
}
示例10: createSwagger
import io.swagger.parser.SwaggerParser; //导入依赖的package包/类
private void createSwagger(String pathToJsonFile) throws FileNotFoundException {
swagger = new SwaggerParser().read(pathToJsonFile);
if (swagger != null) {
// if no scheme is defined, use http by default
host = (swagger.getSchemes().size() >= 1 ? swagger.getSchemes().get(0).name().toLowerCase() : "http")
+ "://" + swagger.getHost() + swagger.getBasePath();
log.debug("Host : " + host);
getEntryPoints();
} else {
throw new FileNotFoundException("Error, unable to read the Json file at : " + pathToJsonFile);
}
}
示例11: tryGetOpenApi
import io.swagger.parser.SwaggerParser; //导入依赖的package包/类
private static Swagger tryGetOpenApi(File file, String userDefinedFilename)
throws OpenApiConversionException {
try {
Swagger swagger = new SwaggerParser().read(file.getAbsolutePath());
if (swagger == null) {
throw new OpenApiConversionException(
String.format(
"OpenAPI spec in file {%s} is ill formed and cannot be parsed",
userDefinedFilename));
} else {
return swagger;
}
} catch (RuntimeException ex) {
throw new OpenApiConversionException(
String.format(
"OpenAPI spec in file {%s} is ill formed and cannot be parsed: %s",
userDefinedFilename, ex.getMessage()));
}
}
示例12: shouldCreatePropertyParametersFromPetstoreSwagger
import io.swagger.parser.SwaggerParser; //导入依赖的package包/类
@Test
public void shouldCreatePropertyParametersFromPetstoreSwagger() throws IOException {
final String specification = resource("/petstore.json");
final Swagger swagger = new SwaggerParser().parse(specification);
final Parameter petIdPathParameter = swagger.getPath("/pet/{petId}").getGet().getParameters().get(0);
final Optional<ConfigurationProperty> maybeConfigurationProperty = SwaggerConnectorGenerator
.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);
}
示例13: main
import io.swagger.parser.SwaggerParser; //导入依赖的package包/类
public static void main(String[] args) throws IOException {
SpringApplication.run(DocuDemoApplication.class, args);
String swaggerFile = args[0];
boolean example = FileUtil.toBoolean(args[1]);
File file = new File(swaggerFile);
ApiData apiData = new ApiData();
IndexData indexData = new IndexData();
ResponseModelData responseModelData = new ResponseModelData();
if (file.exists()) {
Swagger swagger = new SwaggerParser().read(swaggerFile);
indexData.buildIndexPage(swagger);
apiData.buildAPIPages(swagger, example);
responseModelData.buildResponseModelPage(swagger);
// JS and CSS files for creating tree structure for json object
FileUtil fileUtil = new FileUtil();
fileUtil.createLib();
logger.info("The documentation portal is generated at this location: /docuDemo/Portal");
System.exit(0);
} else {
logger.error("======================Error===============================");
logger.error("Please input a valid file location");
System.exit(1);
}
}
示例14: writeDynamicResource
import io.swagger.parser.SwaggerParser; //导入依赖的package包/类
private byte[] writeDynamicResource(InputStream is) throws IOException {
String str = CharStreams.toString(new InputStreamReader(is, Charsets.UTF_8));
Swagger swagger = new SwaggerParser().parse(str);
// set the resource listing tag
Tag dynamic = new Tag();
dynamic.setName("dynamic");
dynamic.setDescription("Dynamic Cypher resources");
swagger.addTag(dynamic);
// add resources to the path
Map<String,Path> paths = swagger.getPaths();
paths.putAll(configuration.getCypherResources());
Map<String,Path> sorted = new LinkedHashMap<>();
List<String> keys = new ArrayList<>();
keys.addAll(paths.keySet());
Collections.sort(keys);
for (String key : keys) {
sorted.put(key, paths.get(key));
}
swagger.setPaths(sorted);
// return updated swagger JSON
return Json.pretty(swagger).getBytes();
}
示例15: OpenApiRequestMapper
import io.swagger.parser.SwaggerParser; //导入依赖的package包/类
@Autowired
public OpenApiRequestMapper(@NonNull InformationProductResourceProvider informationProductLoader,
@NonNull SwaggerParser openApiParser, @NonNull ApplicationProperties applicationProperties,
@NonNull GetRequestHandlerFactory getRequestHandlerFactory) {
this.informationProductResourceProvider = informationProductLoader;
this.openApiParser = openApiParser;
this.applicationProperties = applicationProperties;
this.getRequestHandlerFactory = getRequestHandlerFactory;
}