-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow schema exclusion to be package specific
- Loading branch information
Showing
7 changed files
with
85 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 28 additions & 0 deletions
28
...in/java/com/trickl/assertj/core/api/json/serialize/ExcludeInlineSchemaVisitorContext.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package com.trickl.assertj.core.api.json.serialize; | ||
|
||
import com.fasterxml.jackson.databind.JavaType; | ||
import com.fasterxml.jackson.module.jsonSchema.factories.VisitorContext; | ||
|
||
import java.util.List; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
|
||
@RequiredArgsConstructor | ||
public class ExcludeInlineSchemaVisitorContext extends VisitorContext { | ||
private final List<String> excludePackages; | ||
|
||
@Override | ||
public String getSeenSchemaUri(JavaType javaType) { | ||
if (javaType != null && !javaType.isPrimitive() && isInExcludedPackage(javaType)) { | ||
return javaTypeToUrn(javaType); | ||
} | ||
return null; | ||
} | ||
|
||
private boolean isInExcludedPackage(JavaType javaType) { | ||
String packageName = javaType.getRawClass().getPackage().getName(); | ||
return excludePackages.stream().anyMatch((exclude -> | ||
packageName.equals(exclude) || packageName.startsWith(exclude + ".") | ||
)); | ||
} | ||
} |
14 changes: 0 additions & 14 deletions
14
src/main/java/com/trickl/assertj/core/api/json/serialize/NoInlineSchemaVisitorContext.java
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 17 additions & 0 deletions
17
src/test/java/com/trickl/assertj/examples/NestedComplexExample.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package com.trickl.assertj.examples; | ||
|
||
import com.fasterxml.jackson.annotation.JsonProperty; | ||
|
||
import java.util.List; | ||
import java.util.Map; | ||
|
||
import lombok.Data; | ||
|
||
@Data | ||
public class NestedComplexExample { | ||
@JsonProperty("list-example") | ||
private List<Example> firstExample; | ||
|
||
@JsonProperty("map-example") | ||
private Map<String, Example> secondExample; | ||
} |
20 changes: 20 additions & 0 deletions
20
src/test/resources/com/trickl/assertj/examples/NestedComplexExample.schema.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
{ | ||
"id": "urn:jsonschema:com:trickl:assertj:examples:NestedComplexExample", | ||
"type": "object", | ||
"properties": { | ||
"list-example": { | ||
"type": "array", | ||
"items": { | ||
"type": "object", | ||
"$ref": "urn:jsonschema:com:trickl:assertj:examples:Example" | ||
} | ||
}, | ||
"map-example": { | ||
"additionalProperties": { | ||
"type": "object", | ||
"$ref": "urn:jsonschema:com:trickl:assertj:examples:Example" | ||
}, | ||
"type": "object" | ||
} | ||
} | ||
} |