@Test void testDiscoverType_Avro() { ContentHandle content = resourceToContentHandle("avro.json"); ArtifactType type = ArtifactTypeUtil.discoverType(content, null); Assertions.assertEquals(ArtifactType.AVRO, type); }
public static ArtifactType discoverType(ContentHandle content, String contentType) throws InvalidArtifactTypeException { boolean triedProto = false; if (contentType == null || contentType.toLowerCase().contains("proto")) { triedProto = true; ArtifactType type = tryProto(content); if (type != null) { return type; } } try { JsonNode tree = mapper.readTree(content.content()); if (tree.has("openapi") || tree.has("swagger")) { return ArtifactType.OPENAPI; } if (tree.has("asyncapi")) { return ArtifactType.ASYNCAPI; } if (tree.has("$schema") && tree.get("$schema").asText().contains("json-schema.org")) { return ArtifactType.JSON; } if (tree.has("type")) { return ArtifactType.AVRO; } throw new InvalidArtifactTypeException("Failed to discover artifact type from JSON content."); } catch (Exception e) { } if (!triedProto) { ArtifactType type = tryProto(content); if (type != null) { return type; } } if (tryGraphQL(content)) { return ArtifactType.GRAPHQL; } try (InputStream stream = content.stream()) { Document xmlDocument = DocumentBuilderAccessor.getDocumentBuilder().parse(stream); Element root = xmlDocument.getDocumentElement(); String ns = root.getNamespaceURI(); if (ns != null && ns.equals("http: return ArtifactType.XSD; } else if (ns != null && (ns.equals("http: || ns.equals("http: return ArtifactType.WSDL; } else { return ArtifactType.XML; } } catch (Exception e) { } throw new InvalidArtifactTypeException("Failed to discover artifact type from content."); }
ArtifactTypeUtil { public static ArtifactType discoverType(ContentHandle content, String contentType) throws InvalidArtifactTypeException { boolean triedProto = false; if (contentType == null || contentType.toLowerCase().contains("proto")) { triedProto = true; ArtifactType type = tryProto(content); if (type != null) { return type; } } try { JsonNode tree = mapper.readTree(content.content()); if (tree.has("openapi") || tree.has("swagger")) { return ArtifactType.OPENAPI; } if (tree.has("asyncapi")) { return ArtifactType.ASYNCAPI; } if (tree.has("$schema") && tree.get("$schema").asText().contains("json-schema.org")) { return ArtifactType.JSON; } if (tree.has("type")) { return ArtifactType.AVRO; } throw new InvalidArtifactTypeException("Failed to discover artifact type from JSON content."); } catch (Exception e) { } if (!triedProto) { ArtifactType type = tryProto(content); if (type != null) { return type; } } if (tryGraphQL(content)) { return ArtifactType.GRAPHQL; } try (InputStream stream = content.stream()) { Document xmlDocument = DocumentBuilderAccessor.getDocumentBuilder().parse(stream); Element root = xmlDocument.getDocumentElement(); String ns = root.getNamespaceURI(); if (ns != null && ns.equals("http: return ArtifactType.XSD; } else if (ns != null && (ns.equals("http: || ns.equals("http: return ArtifactType.WSDL; } else { return ArtifactType.XML; } } catch (Exception e) { } throw new InvalidArtifactTypeException("Failed to discover artifact type from content."); } }
ArtifactTypeUtil { public static ArtifactType discoverType(ContentHandle content, String contentType) throws InvalidArtifactTypeException { boolean triedProto = false; if (contentType == null || contentType.toLowerCase().contains("proto")) { triedProto = true; ArtifactType type = tryProto(content); if (type != null) { return type; } } try { JsonNode tree = mapper.readTree(content.content()); if (tree.has("openapi") || tree.has("swagger")) { return ArtifactType.OPENAPI; } if (tree.has("asyncapi")) { return ArtifactType.ASYNCAPI; } if (tree.has("$schema") && tree.get("$schema").asText().contains("json-schema.org")) { return ArtifactType.JSON; } if (tree.has("type")) { return ArtifactType.AVRO; } throw new InvalidArtifactTypeException("Failed to discover artifact type from JSON content."); } catch (Exception e) { } if (!triedProto) { ArtifactType type = tryProto(content); if (type != null) { return type; } } if (tryGraphQL(content)) { return ArtifactType.GRAPHQL; } try (InputStream stream = content.stream()) { Document xmlDocument = DocumentBuilderAccessor.getDocumentBuilder().parse(stream); Element root = xmlDocument.getDocumentElement(); String ns = root.getNamespaceURI(); if (ns != null && ns.equals("http: return ArtifactType.XSD; } else if (ns != null && (ns.equals("http: || ns.equals("http: return ArtifactType.WSDL; } else { return ArtifactType.XML; } } catch (Exception e) { } throw new InvalidArtifactTypeException("Failed to discover artifact type from content."); } private  ArtifactTypeUtil(); }
ArtifactTypeUtil { public static ArtifactType discoverType(ContentHandle content, String contentType) throws InvalidArtifactTypeException { boolean triedProto = false; if (contentType == null || contentType.toLowerCase().contains("proto")) { triedProto = true; ArtifactType type = tryProto(content); if (type != null) { return type; } } try { JsonNode tree = mapper.readTree(content.content()); if (tree.has("openapi") || tree.has("swagger")) { return ArtifactType.OPENAPI; } if (tree.has("asyncapi")) { return ArtifactType.ASYNCAPI; } if (tree.has("$schema") && tree.get("$schema").asText().contains("json-schema.org")) { return ArtifactType.JSON; } if (tree.has("type")) { return ArtifactType.AVRO; } throw new InvalidArtifactTypeException("Failed to discover artifact type from JSON content."); } catch (Exception e) { } if (!triedProto) { ArtifactType type = tryProto(content); if (type != null) { return type; } } if (tryGraphQL(content)) { return ArtifactType.GRAPHQL; } try (InputStream stream = content.stream()) { Document xmlDocument = DocumentBuilderAccessor.getDocumentBuilder().parse(stream); Element root = xmlDocument.getDocumentElement(); String ns = root.getNamespaceURI(); if (ns != null && ns.equals("http: return ArtifactType.XSD; } else if (ns != null && (ns.equals("http: || ns.equals("http: return ArtifactType.WSDL; } else { return ArtifactType.XML; } } catch (Exception e) { } throw new InvalidArtifactTypeException("Failed to discover artifact type from content."); } private  ArtifactTypeUtil(); static ArtifactType discoverType(ContentHandle content, String contentType); }
ArtifactTypeUtil { public static ArtifactType discoverType(ContentHandle content, String contentType) throws InvalidArtifactTypeException { boolean triedProto = false; if (contentType == null || contentType.toLowerCase().contains("proto")) { triedProto = true; ArtifactType type = tryProto(content); if (type != null) { return type; } } try { JsonNode tree = mapper.readTree(content.content()); if (tree.has("openapi") || tree.has("swagger")) { return ArtifactType.OPENAPI; } if (tree.has("asyncapi")) { return ArtifactType.ASYNCAPI; } if (tree.has("$schema") && tree.get("$schema").asText().contains("json-schema.org")) { return ArtifactType.JSON; } if (tree.has("type")) { return ArtifactType.AVRO; } throw new InvalidArtifactTypeException("Failed to discover artifact type from JSON content."); } catch (Exception e) { } if (!triedProto) { ArtifactType type = tryProto(content); if (type != null) { return type; } } if (tryGraphQL(content)) { return ArtifactType.GRAPHQL; } try (InputStream stream = content.stream()) { Document xmlDocument = DocumentBuilderAccessor.getDocumentBuilder().parse(stream); Element root = xmlDocument.getDocumentElement(); String ns = root.getNamespaceURI(); if (ns != null && ns.equals("http: return ArtifactType.XSD; } else if (ns != null && (ns.equals("http: || ns.equals("http: return ArtifactType.WSDL; } else { return ArtifactType.XML; } } catch (Exception e) { } throw new InvalidArtifactTypeException("Failed to discover artifact type from content."); } private  ArtifactTypeUtil(); static ArtifactType discoverType(ContentHandle content, String contentType);  }