private String findSchemaType()

in common/common-protobuf/src/main/java/org/apache/servicecomb/codec/protobuf/schema/SchemaToProtoGenerator.java [132:176]


  private String findSchemaType(Schema<?> schema) {
    @SuppressWarnings("unchecked")
    String type = tryFindEnumType((List<String>) schema.getEnum());
    if (type != null) {
      return type;
    }

    type = findBaseType(schema.getType(), schema.getFormat());
    if (type != null) {
      return type;
    }

    Schema<?> itemProperty = schema.getItems();
    if (itemProperty != null) {
      String containerType = findArrayOrMapItemType(itemProperty);
      if (containerType != null) {
        return "repeated " + containerType;
      }
      return null;
    }

    itemProperty = (Schema<?>) schema.getAdditionalProperties();
    if (itemProperty != null) {
      String containerType = findArrayOrMapItemType(itemProperty);
      if (containerType != null) {
        return String.format("map<string, %s>", containerType);
      }
      return null;
    }

    type = schema.get$ref();
    if (type != null) {
      String typeName = type.substring(Components.COMPONENTS_SCHEMAS_REF.length());
      Schema<?> refSchema = openAPI.getComponents().getSchemas().get(typeName);
      if (refSchema == null) {
        throw new IllegalArgumentException("not found ref in components " + type);
      }
      if (StringUtils.isEmpty(refSchema.getName())) {
        refSchema.setName(typeName);
      }
      return findSchemaType(refSchema);
    }

    return findObjectType(schema);
  }