com.fasterxml.jackson.module.jsonSchema.JsonSchemaGenerator Java Examples
The following examples show how to use
com.fasterxml.jackson.module.jsonSchema.JsonSchemaGenerator.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: JSONSchema.java From pulsar with Apache License 2.0 | 6 votes |
/** * Implemented for backwards compatibility reasons * since the original schema generated by JSONSchema was based off the json schema standard * since then we have standardized on Avro * * @return */ public SchemaInfo getBackwardsCompatibleJsonSchemaInfo() { SchemaInfo backwardsCompatibleSchemaInfo; try { ObjectMapper objectMapper = new ObjectMapper(); JsonSchemaGenerator schemaGen = new JsonSchemaGenerator(objectMapper); JsonSchema jsonBackwardsCompatibleSchema = schemaGen.generateSchema(pojo); backwardsCompatibleSchemaInfo = new SchemaInfo(); backwardsCompatibleSchemaInfo.setName(""); backwardsCompatibleSchemaInfo.setProperties(schemaInfo.getProperties()); backwardsCompatibleSchemaInfo.setType(SchemaType.JSON); backwardsCompatibleSchemaInfo.setSchema(objectMapper.writeValueAsBytes(jsonBackwardsCompatibleSchema)); } catch (JsonProcessingException ex) { throw new RuntimeException(ex); } return backwardsCompatibleSchemaInfo; }
Example #2
Source File: JsonSchemaTests.java From spring-cloud-contract with Apache License 2.0 | 5 votes |
@Test void should_produce_a_json_schema_of_a_yaml_model() throws IOException { ObjectMapper mapper = new ObjectMapper(); mapper.enable(SerializationFeature.INDENT_OUTPUT); JsonSchemaGenerator schemaGen = new JsonSchemaGenerator(mapper); JsonSchema schema = schemaGen.generateSchema(YamlContract.class); String schemaString = mapper.writeValueAsString(schema); File schemaFile = new File("target/contract_schema.json"); Files.write(schemaFile.toPath(), schemaString.getBytes()); }
Example #3
Source File: MetadataResource.java From alchemy with MIT License | 5 votes |
@Inject public MetadataResource(Environment environment, IdentitiesMetadata metadata, Mappers mapper) { this.metadata = metadata; this.identityTypesByName = Maps.transformValues(metadata, DTO_TYPES_MAPPER); this.schemaGenerator = new JsonSchemaGenerator(environment.getObjectMapper()); this.mapper = mapper; }
Example #4
Source File: MonetaryAmountSchemaSerializerTest.java From jackson-datatype-money with MIT License | 5 votes |
@Test void shouldSerializeJsonSchemaWithQuotedDecimalNumbers() throws Exception { final ObjectMapper unit = unit(module().withQuotedDecimalNumbers()); final JsonSchemaGenerator generator = new JsonSchemaGenerator(unit); final JsonSchema jsonSchema = generator.generateSchema(MonetaryAmount.class); final String actual = unit.writeValueAsString(jsonSchema); final String expected = "{\"type\":\"object\",\"id\":\"urn:jsonschema:javax:money:MonetaryAmount\",\"properties\":" + "{\"amount\":{\"type\":\"string\",\"required\":true}," + "\"currency\":{\"type\":\"string\",\"required\":true}," + "\"formatted\":{\"type\":\"string\"}}}"; assertThat(actual, is(expected)); }
Example #5
Source File: MonetaryAmountSchemaSerializerTest.java From jackson-datatype-money with MIT License | 5 votes |
@Test void shouldSerializeJsonSchemaWithCustomFieldNames() throws Exception { final ObjectMapper unit = unit(module().withAmountFieldName("value") .withCurrencyFieldName("unit") .withFormattedFieldName("pretty")); final JsonSchemaGenerator generator = new JsonSchemaGenerator(unit); final JsonSchema jsonSchema = generator.generateSchema(MonetaryAmount.class); final String actual = unit.writeValueAsString(jsonSchema); final String expected = "{\"type\":\"object\",\"id\":\"urn:jsonschema:javax:money:MonetaryAmount\",\"properties\":" + "{\"value\":{\"type\":\"number\",\"required\":true}," + "\"unit\":{\"type\":\"string\",\"required\":true}," + "\"pretty\":{\"type\":\"string\"}}}"; assertThat(actual, is(expected)); }
Example #6
Source File: MonetaryAmountSchemaSerializerTest.java From jackson-datatype-money with MIT License | 5 votes |
@Test void shouldSerializeJsonSchema() throws Exception { final ObjectMapper unit = unit(module()); final JsonSchemaGenerator generator = new JsonSchemaGenerator(unit); final JsonSchema jsonSchema = generator.generateSchema(MonetaryAmount.class); final String actual = unit.writeValueAsString(jsonSchema); final String expected = "{\"type\":\"object\",\"id\":\"urn:jsonschema:javax:money:MonetaryAmount\",\"properties\":" + "{\"amount\":{\"type\":\"number\",\"required\":true}," + "\"currency\":{\"type\":\"string\",\"required\":true}," + "\"formatted\":{\"type\":\"string\"}}}"; assertThat(actual, is(expected)); }
Example #7
Source File: CurrencyUnitSchemaSerializerTest.java From jackson-datatype-money with MIT License | 5 votes |
@Test void shouldSerializeJsonSchema() throws Exception { JsonSchemaGenerator generator = new JsonSchemaGenerator(unit); JsonSchema jsonSchema = generator.generateSchema(CurrencyUnit.class); final String actual = unit.writeValueAsString(jsonSchema); final String expected = "{\"type\":\"string\"}"; assertThat(actual, is(expected)); }
Example #8
Source File: JsonSchemaCompatibilityCheckTest.java From pulsar with Apache License 2.0 | 5 votes |
public static <T> OldJSONSchema<T> of(Class<T> pojo, Map<String, String> properties) throws JsonProcessingException { ObjectMapper mapper = new ObjectMapper(); JsonSchemaGenerator schemaGen = new JsonSchemaGenerator(mapper); JsonSchema schema = schemaGen.generateSchema(pojo); SchemaInfo info = new SchemaInfo(); info.setName(""); info.setProperties(properties); info.setType(SchemaType.JSON); info.setSchema(mapper.writeValueAsBytes(schema)); return new OldJSONSchema<>(info, pojo, mapper); }
Example #9
Source File: SchemaDataValidatorTest.java From pulsar with Apache License 2.0 | 5 votes |
@Test public void testJsonSchemaTypeWithJsonSchemaData() throws Exception { ObjectMapper mapper = ObjectMapperFactory.getThreadLocal(); SchemaData data = SchemaData.builder() .type(SchemaType.JSON) .data( mapper.writeValueAsBytes( new JsonSchemaGenerator(mapper) .generateSchema(Foo.class))) .build(); SchemaDataValidator.validateSchemaData(data); }
Example #10
Source File: CommandController.java From ESarch with Apache License 2.0 | 5 votes |
public CommandController(CommandGateway commandGateway, ObjectMapper objectMapper, JsonSchemaGenerator jsonSchemaGenerator) { this.commandGateway = commandGateway; this.objectMapper = objectMapper; this.jsonSchemaGenerator = jsonSchemaGenerator; }
Example #11
Source File: ExtensionSchemaValidationTest.java From syndesis with Apache License 2.0 | 5 votes |
@Test @Ignore("Used to generate the initial extension definition") public void generateBaseExtensionDefinition() throws Exception { JsonSchemaGenerator schemaGen = new JsonSchemaGenerator(OBJECT_MAPPER); com.fasterxml.jackson.module.jsonSchema.JsonSchema schema = schemaGen.generateSchema(Extension.class); LOG.info(OBJECT_MAPPER.writeValueAsString(schema)); }
Example #12
Source File: CommandContractTest.java From ESarch with Apache License 2.0 | 5 votes |
@Before public void setup() { final CommandGateway commandGateway = mock(CommandGateway.class); when(commandGateway.send(any())).thenReturn(completedFuture(null)); when(commandGateway.send(any(CreateCompanyCommand.class))) .thenReturn(completedFuture(COMPANY_ID)); when(commandGateway.send(any(CreateOrderBookCommand.class))) .thenReturn(completedFuture(ORDER_BOOK_ID)); when(commandGateway.send(any(CreatePortfolioCommand.class))) .thenReturn(completedFuture(PORTFOLIO_ID)); when(commandGateway.send(any(CreateUserCommand.class))) .thenReturn(completedFuture(USER_ID)); when(commandGateway.send(any(StartBuyTransactionCommand.class))) .thenReturn(completedFuture(BUY_TRANSACTION_ID)); when(commandGateway.send(any(StartSellTransactionCommand.class))) .thenReturn(completedFuture(SELL_TRANSACTION_ID)); final ObjectMapper objectMapper = new ObjectMapper(); objectMapper.registerModule(new KotlinModule()); final JsonSchemaGenerator jsonSchemaGenerator = new JsonSchemaGenerator(objectMapper); final CommandController commandController = new CommandController(commandGateway, objectMapper, jsonSchemaGenerator); commandController.setBeanClassLoader(this.getClass().getClassLoader()); RestAssuredMockMvc.standaloneSetup(commandController); }
Example #13
Source File: UiFormSchemaGenerator.java From sf-java-ui with MIT License | 4 votes |
private JsonSchemaGenerator initSchemaGen(ObjectMapper mapper) { return new JsonSchemaGenerator(mapper, new CustomSchemaFactoryWrapper()); }
Example #14
Source File: UiFormSchemaGenerator.java From sf-java-ui with MIT License | 4 votes |
private JsonSchema generateSchema(Class<? extends Serializable> formDto, JsonSchemaGenerator schemaGen) throws JsonMappingException { return schemaGen.generateSchema(formDto); }
Example #15
Source File: UiFormSchemaGenerator.java From sf-java-ui with MIT License | 4 votes |
public UiForm generate(Class<? extends Serializable> formDto) throws JsonMappingException { Set<Field> declaredFields = ReflectionUtils.getAllFields(formDto, field -> !Modifier.isStatic(field.getModifiers())); ObjectMapper mapper = new ObjectMapper(); JsonSchemaGenerator schemaGen = initSchemaGen(mapper); JsonSchema schema = generateSchema(formDto, schemaGen); Map<Field, JsonNode> nodes = initFieldsFormDefinition(mapper, declaredFields); Map<Field, JsonNode> sortedNodes = reorderFieldsBasedOnIndex(nodes); handlerGroupedFields(mapper, declaredFields, sortedNodes); Optional<ObjectNode> tabbedFields = Optional .ofNullable(handleTabbedFields(mapper, declaredFields, sortedNodes)); ArrayNode formDefinition = mapper.createArrayNode(); tabbedFields.ifPresent(formDefinition::add); sortedNodes.entrySet().stream().forEach(nodesElement -> formDefinition.add(nodesElement.getValue())); handleActionsAnnotation(mapper, formDto, formDefinition); return new UiForm(schema, formDefinition); }
Example #16
Source File: CreateCompanyApiIntegrationTest.java From ESarch with Apache License 2.0 | 4 votes |
@Bean public JsonSchemaGenerator jsonSchemaGenerator(ObjectMapper objectMapper) { return new JsonSchemaGenerator(objectMapper); }
Example #17
Source File: AppConfig.java From ESarch with Apache License 2.0 | 4 votes |
@Bean public JsonSchemaGenerator jsonSchemaGenerator(ObjectMapper objectMapper) { return new JsonSchemaGenerator(objectMapper); }