public static JCodeModel buildBodyJCodeModel ( String basePackage , String schemaLocation , String name , String schema , Annotator annotator ) { JCodeModel codeModel = new JCodeModel ( ) ; SchemaStore schemaStore = new SchemaStore ( ) ; GenerationConfig config = Config . getPojoConfig ( ) ; if ( config == null ) { config = getDefaultGenerationConfig ( ) ; } if ( annotator == null ) { annotator = new Jackson2Annotator ( config ) ; } RuleFactory ruleFactory = new RuleFactory ( config , annotator , schemaStore ) ; SchemaMapper mapper = new SchemaMapper ( ruleFactory , new SchemaGenerator ( ) ) ; boolean useParent = StringUtils . hasText ( schemaLocation ) ; try { if ( useParent ) { mapper . generate ( codeModel , name , basePackage , schema , new URI ( schemaLocation ) ) ; } else { mapper . generate ( codeModel , name , basePackage , schema ) ; } } catch ( Exception e ) { // TODO make this smarter by checking refs if ( useParent && e . getMessage ( ) . contains ( "classpath" ) ) { logger . debug ( "Referenced Schema contains self $refs or not found in classpath. Regenerating model withouth classpath: for " + name ) ; codeModel = new JCodeModel ( ) ; try { mapper . generate ( codeModel , name , basePackage , schema ) ; return codeModel ; } catch ( IOException e1 ) { // do nothing } } logger . error ( "Error generating pojo from schema" + name , e ) ; return null ; } return codeModel ; }
Builds a JCodeModel for classes that will be used as Request or Response bodies