ThriftDocStringExtractor extends DocStringExtractor { @Override protected Map<String, String> getDocStringsFromFiles(Map<String, byte[]> files) { final ImmutableMap.Builder<String, String> docStrings = ImmutableMap.builder(); for (byte[] file : files.values()) { try { final Map<String, Object> json = new ObjectMapper().readValue(file, JSON_VALUE_TYPE); @SuppressWarnings("unchecked") final Map<String, Object> namespaces = (Map<String, Object>) json.getOrDefault("namespaces", ImmutableMap.of()); final String packageName = (String) namespaces.get("java"); json.forEach((key, children) -> { if (children instanceof Collection) { @SuppressWarnings("unchecked") final Collection<Object> castChildren = (Collection<Object>) children; castChildren.forEach( grandChild -> traverseChildren(docStrings, packageName, FQCN_DELIM, grandChild)); } }); } catch (IOException e) { throw new IllegalStateException(e); } } return docStrings.build(); } ThriftDocStringExtractor();   }
@Test void testThriftTestJson() throws Exception { final Map<String, String> docStrings = extractor.getDocStringsFromFiles( ImmutableMap.of( "META-INF/armeria/thrift/ThriftTest.json", Resources.toByteArray(Resources.getResource( "META-INF/armeria/thrift/ThriftTest.json")))); assertThat(docStrings.get("thrift.test.Numberz")).isEqualTo("Docstring!"); assertThat(docStrings.get("thrift.test.ThriftTest/testVoid")).isEqualTo( "Prints \"testVoid()\" and returns nothing."); }
@Test void testCassandraJson() throws Exception { final Map<String, String> docStrings = extractor.getDocStringsFromFiles( ImmutableMap.of( "META-INF/armeria/thrift/ThriftTest.json", Resources.toByteArray(Resources.getResource( "META-INF/armeria/thrift/cassandra.json")))); assertThat(docStrings.get("com.linecorp.armeria.service.test.thrift.cassandra.Compression")) .isEqualTo("CQL query compression"); assertThat( docStrings.get("com.linecorp.armeria.service.test.thrift.cassandra.CqlResultType")).isNull(); }