io.swagger.codegen.languages.AbstractJavaCodegen Java Examples

The following examples show how to use io.swagger.codegen.languages.AbstractJavaCodegen. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: SundrioGenerator.java    From sundrio with Apache License 2.0 5 votes vote down vote up
public TypeDef createModel(String name, Model model, AbstractJavaCodegen config, Map<String, Model> allDefinitions) {

        String prefix = name.contains(DOT)
                ? name.substring(0, name.lastIndexOf(DOT))
                : EMPTY;

        String packageName = prefix.isEmpty() ? config.modelPackage() : config.modelPackage() + DOT + prefix;
        String className = prefix.isEmpty() ? name : name.substring(name.lastIndexOf(DOT) + 1);

        ClassRef superClass = null;
        List<ClassRef> interfaces = new ArrayList<>();
        List<Property> fields = new ArrayList<>();
        List<Method> methods = new ArrayList<>();

        if (model instanceof ComposedModel) {
            ComposedModel composed = (ComposedModel) model;

            // interfaces (intermediate models)
            if (composed.getInterfaces() != null) {
                for (RefModel _interface : composed.getInterfaces()) {
                    Model interfaceModel = null;
                    if (allDefinitions != null) {
                        interfaceModel = allDefinitions.get(_interface.getSimpleRef());
                    }

                }

                return new TypeDefBuilder()
                        .withKind(Kind.CLASS)
                        .withPackageName(packageName)
                        .withName(className)
                        .withImplementsList(interfaces)
                        .withExtendsList(superClass)
                        .withProperties(fields)
                        .withMethods(methods)
                        .build();
            }
        }
        return null;
    }