public static Schema getSchema()

in oas-generator/oas-generator-core/src/main/java/org/apache/servicecomb/toolkit/generator/util/ModelConverter.java [77:159]


  public static Schema getSchema(Type cls, Components components, RequestResponse requestResponse) {

    for (ModelInterceptor interceptor : interceptorMgr) {
      Schema schema = interceptor.process(cls, components);
      if (schema != null) {
        return schema;
      }
    }

    if (cls instanceof Class && requestResponse != null) {

      List<Type> beanProperties = null;
      switch (requestResponse) {
        case REQUEST:
          beanProperties = getRequestBeanTypes((Class) cls);
          break;
        case RESPONSE:
          beanProperties = getResponseBeanTypes((Class) cls);
          break;
        default:
      }

      Optional.ofNullable(beanProperties)
          .ifPresent(properties -> properties.forEach(type ->
              {
                if (type instanceof ParameterizedType) {
                  Type[] actualTypeArguments = ((ParameterizedType) type).getActualTypeArguments();
                  Arrays.stream(actualTypeArguments).forEach(arg -> getSchema(arg, components, requestResponse));
                }

                if (type instanceof Class) {
                  getSchema(type, components, requestResponse);
                }
              })
          );
    }

    Schema schema = PrimitiveType.createProperty(cls);
    if (schema == null) {
      schema = context
          .resolve(new AnnotatedType(cls));
    }

    if (schema == null) {
      if (cls == List.class) {
        schema = new ArraySchema();
        ((ArraySchema) schema).setItems(new ObjectSchema());
      }
    }

    if (components == null) {
      return schema;
    }

    // correct reference
    Schema refSchema = schema;

    if (shouldExtractRef(schema)) {
      ensureSchemaNameExist(schema);
      schema.$ref(null);
      components.addSchemas(schema.getName(), schema);
      refSchema = new Schema();
      refSchema.set$ref(RefUtils.constructRef(schema.getName()));
    }

    if (schema instanceof ArraySchema) {
      ArraySchema arraySchema = (ArraySchema) schema;
      Schema itemSchema = arraySchema.getItems();
      if (shouldExtractRef(itemSchema)) {
        ensureSchemaNameExist(itemSchema);
        itemSchema.$ref(null);
        components.addSchemas(itemSchema.getName(), itemSchema);

        Schema itemRefSchema = new Schema();
        itemRefSchema.set$ref(RefUtils.constructRef(itemSchema.getName()));
        arraySchema.setItems(itemRefSchema);
      }

      refSchema = arraySchema;
    }

    return refSchema;
  }