-
Notifications
You must be signed in to change notification settings - Fork 136
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
10692e8
commit d924e7f
Showing
7 changed files
with
126 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
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
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
100 changes: 100 additions & 0 deletions
100
src/test/java/com/fasterxml/jackson/module/jsonSchema/TestVisitorContext.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,100 @@ | ||
package com.fasterxml.jackson.module.jsonSchema; | ||
|
||
import com.fasterxml.jackson.databind.*; | ||
import com.fasterxml.jackson.module.jsonSchema.factories.SchemaFactoryWrapper; | ||
|
||
public class TestVisitorContext extends SchemaTestBase | ||
{ | ||
static class Foo { | ||
private String fooProp1; | ||
private int fooProp2; | ||
private Bar fooProp3; | ||
|
||
public String getFooProp1() { | ||
return fooProp1; | ||
} | ||
|
||
public void setFooProp1(String fooProp1) { | ||
this.fooProp1 = fooProp1; | ||
} | ||
|
||
public int getFooProp2() { | ||
return fooProp2; | ||
} | ||
|
||
public void setFooProp2(int fooProp2) { | ||
this.fooProp2 = fooProp2; | ||
} | ||
|
||
public Bar getFooProp3() { | ||
return fooProp3; | ||
} | ||
|
||
public void setFooProp3(Bar fooProp3) { | ||
this.fooProp3 = fooProp3; | ||
} | ||
} | ||
|
||
static class Bar { | ||
private String barProp1; | ||
private int barProp2; | ||
|
||
public String getBarProp1() { | ||
return barProp1; | ||
} | ||
|
||
public void setBarProp1(String barProp1) { | ||
this.barProp1 = barProp1; | ||
} | ||
|
||
public int getBarProp2() { | ||
return barProp2; | ||
} | ||
|
||
public void setBarProp2(int barProp2) { | ||
this.barProp2 = barProp2; | ||
} | ||
} | ||
|
||
static class Qwer { | ||
private String qwerProp1; | ||
private Bar qwerProp2; | ||
|
||
public String getQwerProp1() { | ||
return qwerProp1; | ||
} | ||
|
||
public void setQwerProp1(String qwerProp1) { | ||
this.qwerProp1 = qwerProp1; | ||
} | ||
|
||
public Bar getQwerProp2() { | ||
return qwerProp2; | ||
} | ||
|
||
public void setQwerProp2(Bar qwerProp2) { | ||
this.qwerProp2 = qwerProp2; | ||
} | ||
} | ||
|
||
// for [jsonSchema#47] | ||
public void testSchemaGeneration() throws Exception { | ||
String schemaStr = generateSchema(Foo.class); | ||
schemaStr = generateSchema(Qwer.class); | ||
// ok, not very robust but has to do: | ||
if (schemaStr.indexOf("$ref") >= 0) { | ||
fail("Should not have $ref for type Bar (as per issue #47): "+schemaStr); | ||
} | ||
} | ||
|
||
private final static ObjectMapper MAPPER = new ObjectMapper(); | ||
|
||
private String generateSchema(Class<?> clazz) throws Exception | ||
{ | ||
MAPPER.configure(SerializationFeature.INDENT_OUTPUT, true); | ||
SchemaFactoryWrapper visitor = new SchemaFactoryWrapper(); | ||
MAPPER.acceptJsonFormatVisitor(MAPPER.constructType(clazz), visitor); | ||
return MAPPER.writeValueAsString(visitor.finalSchema()); | ||
} | ||
|
||
} |