All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.rocketbase.commons.openapi.OpenApiConverter Maven / Gradle / Ivy

There is a newer version: 3.3.2
Show newest version
package io.rocketbase.commons.openapi;

import io.rocketbase.commons.util.Nulls;
import io.swagger.v3.oas.models.media.Schema;

import java.util.List;
import java.util.Set;

public interface OpenApiConverter {

    /**
     * @param genericReturnType full classpath of java return class
     * @return should return a typescript value datatype
     */
    String getReturnType(String genericReturnType);

    /**
     * @param schema extra type infos
     * @return typescript valid type name
     */
    String convertType(Schema schema);

    /**
     * @param allTypes returnTypes, parameters etc.
     * @return unqiue set of typescriptTypes that should get imported
     */
    Set getImportTypes(Set allTypes);

    /**
     * used to remove package string from full classpath of class
     */
    default String removePackage(String value) {
        return Nulls.notNull(value).substring(Nulls.notNull(value).lastIndexOf(".") + 1);
    }

    default String removeRefPath(String value) {
        return value.substring(value.lastIndexOf("/") + 1);
    }

    default Set getListTypes() {
        return Set.of("java.util.List", "java.util.Collection", "java.util.Set");
    }

    default Set getNativeTypes() {
        return Set.of("string", "boolean", "long", "void", "any", "unknown", "integer", "number", "object", "file", "blob");
    }

    default Set getJavaToUnknowns() {
        return Set.of("InputStreamResource", "InputStream", "Resource", "byte", "byte[]", "OutputStream", "Object");
    }

    default boolean hasPageableParameter(List parameterTypes) {
        return Nulls.notNull(parameterTypes)
                .contains("org.springframework.data.domain.Pageable");
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy