Skip to content

Commit

Permalink
Merge branch 'master' into bug/1375-empty-blank-parameter-example
Browse files Browse the repository at this point in the history
  • Loading branch information
gracekarina authored May 25, 2020
2 parents a4ba9fb + d0ad044 commit ebe8b2a
Show file tree
Hide file tree
Showing 7 changed files with 193 additions and 184 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package io.swagger.v3.parser.core.models;

import io.swagger.v3.oas.models.OpenAPI;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;

public class SwaggerParseResult {
Expand All @@ -27,4 +29,10 @@ public OpenAPI getOpenAPI() {
public void setOpenAPI(OpenAPI openAPI) {
this.openAPI = openAPI;
}

public static SwaggerParseResult ofError(String message){
final SwaggerParseResult result = new SwaggerParseResult();
result.setMessages(Collections.singletonList(message));
return result;
}
}

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package io.swagger.v3.parser.exception;

public class EncodingNotSupportedException extends RuntimeException {
private static final long serialVersionUID = 3686905713011188803L;

public EncodingNotSupportedException(String encoding) {
super(String.format("Encoding `%s` is not supported by JRE", encoding));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package io.swagger.v3.parser.exception;

/**
* Happens when it's unable to read content from file or other resource
*/
public class ReadContentException extends RuntimeException {
private static final long serialVersionUID = 4720926576862628428L;

public ReadContentException(String message, Throwable cause) {
super(message, cause);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,20 +26,25 @@

public class InlineModelResolver {
private OpenAPI openAPI;
private boolean skipMatches;
static Logger LOGGER = LoggerFactory.getLogger(InlineModelResolver.class);

Map<String, Schema> addedModels = new HashMap<>();
Map<String, String> generatedSignature = new HashMap<>();

private boolean flattenComposedSchemas;
private boolean camelCaseFlattenNaming;
private final boolean flattenComposedSchemas;
private final boolean camelCaseFlattenNaming;
private boolean skipMatches;

public InlineModelResolver(){this(false,false);}
public InlineModelResolver(){this(false, false, false);}

public InlineModelResolver(boolean flattenComposedSchemas, boolean camelCaseFlattenNaming) {
this(flattenComposedSchemas, camelCaseFlattenNaming, false);
}

public InlineModelResolver(boolean flattenComposedSchemas, boolean camelCaseFlattenNaming, boolean skipMatches) {
this.flattenComposedSchemas = flattenComposedSchemas;
this.camelCaseFlattenNaming = camelCaseFlattenNaming;
this.skipMatches = skipMatches;
}

public void flatten(OpenAPI openAPI) {
Expand Down Expand Up @@ -319,7 +324,7 @@ private String resolveModelName(String title, String key) {
}

public String matchGenerated(Schema model) {
if (this.skipMatches) {
if (skipMatches) {
return null;
}
String json = Json.pretty(model);
Expand Down Expand Up @@ -585,17 +590,17 @@ public void copyVendorExtensions(Schema source, Schema target) {
}
}

private boolean isObjectSchema(Schema schema) {
return schema instanceof ObjectSchema
|| "object".equalsIgnoreCase(schema.getType())
|| (schema.getType() == null && schema.getProperties() != null && !schema.getProperties().isEmpty());
}

public boolean isSkipMatches() {
return skipMatches;
}

public void setSkipMatches(boolean skipMatches) {
this.skipMatches = skipMatches;
}

private boolean isObjectSchema(Schema schema) {
return schema instanceof ObjectSchema
|| "object".equalsIgnoreCase(schema.getType())
|| (schema.getType() == null && schema.getProperties() != null && !schema.getProperties().isEmpty());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -1924,7 +1924,7 @@ public void readingSpecNodeShouldNotOverQuotingStringExample() throws Exception
String yaml = Files.readFile(new File("src/test/resources/over-quoted-example.yaml"));
JsonNode rootNode = Yaml.mapper().readValue(yaml, JsonNode.class);
OpenAPIV3Parser parser = new OpenAPIV3Parser();
OpenAPI openAPI = (parser.readWithInfo(null, rootNode)).getOpenAPI();
OpenAPI openAPI = (parser.parseJsonNode(null, rootNode)).getOpenAPI();

Map<String, Schema> definitions = openAPI.getComponents().getSchemas();
assertEquals("NoQuotePlease", definitions.get("CustomerType").getExample());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -432,7 +432,6 @@ public void testSkipInlineMatchesFalse() {
final OpenAPI openAPI = new OpenAPI();

final InlineModelResolver inlineModelResolver = new InlineModelResolver();
inlineModelResolver.setSkipMatches(false);

final Schema operationAlphaInAsset = new ObjectSchema();
operationAlphaInAsset.setTitle("operationAlphaInAsset");
Expand Down Expand Up @@ -484,8 +483,7 @@ public void testSkipInlineMatchesFalse() {
public void testSkipInlineMatchesTrue() {
final OpenAPI openAPI = new OpenAPI();

final InlineModelResolver inlineModelResolver = new InlineModelResolver();
inlineModelResolver.setSkipMatches(true);
final InlineModelResolver inlineModelResolver = new InlineModelResolver(false, false, true);

final Schema operationAlphaInAsset = new ObjectSchema();
operationAlphaInAsset.setTitle("operationAlphaInAsset");
Expand Down

0 comments on commit ebe8b2a

Please sign in to comment.