Skip to content

Commit

Permalink
rework on issue #305
Browse files Browse the repository at this point in the history
  • Loading branch information
gracekarina committed May 2, 2019
1 parent 5ff25f3 commit 5158df6
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 13 deletions.
41 changes: 31 additions & 10 deletions src/main/java/io/swagger/oas/inflector/OpenAPIInflector.java
Original file line number Diff line number Diff line change
Expand Up @@ -113,18 +113,14 @@ protected ObjectMapper getObjectMapper() {

protected void init(Configuration configuration) {
config = configuration;
//TODO check config option to determine which parser option to use
Configuration.ParserOption configOptions = config.getParserOptions();
ParseOptions options = new ParseOptions();
if (configOptions.getName().equals("resolve")){
options.setResolve(true);
}
if (configOptions.getName().equals("resolveFully")){
options.setResolveFully(true);
}
options.setResolve(true);
options.setResolveFully(true);
SwaggerParseResult swaggerParseResult = new OpenAPIV3Parser().readLocation(config.getSwaggerUrl(), null, options);
OpenAPI openAPI = swaggerParseResult.getOpenAPI();

OpenAPI exposedAPI = getExposedAPI(config);

if(!config.getValidatePayloads().isEmpty()) {
LOGGER.info("resolving openAPI");
new ExtensionsUtil().addExtensions(openAPI);
Expand Down Expand Up @@ -234,7 +230,7 @@ protected void init(Configuration configuration) {
ContextResolver.class);
}
enableProcessor(JacksonProcessor.class, MediaType.APPLICATION_JSON_TYPE);
enableSwaggerJSON(openAPI, configuration.getSwaggerProcessors());
enableSwaggerJSON(exposedAPI, configuration.getSwaggerProcessors());
} else if ("xml".equalsIgnoreCase(item)) {
// XML
if (!isRegistered(DefaultContentTypeProvider.class)) {
Expand All @@ -249,7 +245,7 @@ protected void init(Configuration configuration) {
Yaml.mapper().registerModule(simpleModule);
register(YamlExampleProvider.class);
enableProcessor(JacksonProcessor.class, JacksonProcessor.APPLICATION_YAML_TYPE);
enableSwaggerYAML(openAPI, configuration.getSwaggerProcessors());
enableSwaggerYAML(exposedAPI, configuration.getSwaggerProcessors());
}else if ("plain".equalsIgnoreCase(item)) {
// PLAIN
register(PlainExampleProvider.class);
Expand Down Expand Up @@ -372,6 +368,31 @@ else if (Configuration.Environment.PRODUCTION.equals(configuration.getEnvironmen
}
}

private OpenAPI getExposedAPI(Configuration config) {
Configuration.ParserOption configOptions = config.getParserOptions();
ParseOptions opts = new ParseOptions();

if (configOptions.getName().equals("original")){
opts.setResolve(false);
}
if (configOptions.getName().equals("resolve")){
opts.setResolve(true);
}
if (configOptions.getName().equals("resolveFully")){
opts.setResolveFully(true);
}
if (configOptions.getName().equals("flatten")){
opts.setFlatten(true);
}
if (configOptions.getName().equals("resolveCombinators")){
opts.setResolveCombinators(true);
}

SwaggerParseResult exposedSwaggerParseResult = new OpenAPIV3Parser().readLocation(config.getSwaggerUrl(), null, opts);
OpenAPI exposedAPI = exposedSwaggerParseResult.getOpenAPI();
return exposedAPI;
}

public static String basePath(String basePath, String path) {
if(StringUtils.isBlank(basePath)) {
basePath = "/";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ public void setParserOptions(ParserOption parserOptions) {
}

public static enum ParserOption {
RESOLVE_FULLY(1, "resolveFully"), RESOLVE(2, "resolve"), FLATTEN(3, "flatten"), RESOLVE_COMBINATOR(4, "resolveCombinators");
RESOLVE_FULLY(1, "resolveFully"), RESOLVE(2, "resolve"), FLATTEN(3, "flatten"), RESOLVE_COMBINATOR(4, "resolveCombinators"), ORIGINAL(5, "original");

private Integer id;
private String name;
Expand Down
4 changes: 2 additions & 2 deletions src/test/config/config1.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,15 @@ exampleProcessors:
- sequence

#Allows to configure parser options
parserOptions: resolveFully
parserOptions: original

# loads all by default, or pick and choose
inputValidators:
- requiredFieldValidator
- numericValidator
- stringValidator

# loads all by default, or pick and choose
# loads all by default, or pick and choose``l ,,,.
inputConverters:
- io.swagger.oas.sample.converters.SampleConverter
- defaultConverter
Expand Down

0 comments on commit 5158df6

Please sign in to comment.