Skip to content

Commit fc68af8

Browse files
committed
vo-added-yaml-parser-using-swagger-parser
1 parent 9eecb44 commit fc68af8

File tree

1 file changed

+40
-0
lines changed

1 file changed

+40
-0
lines changed
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
package io.github.venkat1701.openapi.parser;
2+
3+
import io.swagger.v3.oas.models.OpenAPI;
4+
import io.swagger.v3.parser.OpenAPIV3Parser;
5+
import io.swagger.v3.parser.core.models.AuthorizationValue;
6+
import io.swagger.v3.parser.core.models.ParseOptions;
7+
import io.swagger.v3.parser.core.models.SwaggerParseResult;
8+
9+
import java.util.List;
10+
11+
public class YAMLParser {
12+
private String location;
13+
private OpenAPI openAPI;
14+
15+
public YAMLParser(String location) {
16+
if(location.isEmpty()) {
17+
throw new RuntimeException("YAML location is empty");
18+
} else if(location.isBlank()) {
19+
throw new RuntimeException("YAML location is blank");
20+
} else {
21+
this.location = location;
22+
openAPI = new OpenAPIV3Parser().read(this.location);
23+
}
24+
}
25+
26+
public SwaggerParseResult readLocationWithAuthValue(List<AuthorizationValue> authValue, ParseOptions parseOptions) {
27+
var result = new OpenAPIV3Parser().readLocation(this.location, authValue, parseOptions);
28+
this.openAPI = result.getOpenAPI();
29+
result.getMessages().forEach(System.out::println);
30+
return result;
31+
}
32+
33+
public OpenAPI getOpenAPI() {
34+
return this.openAPI;
35+
}
36+
37+
38+
39+
40+
}

0 commit comments

Comments
 (0)