/*
 *   Copyright 2016 Works Applications Co.,Ltd.
 *
 *    Licensed under the Apache License, Version 2.0 (the "License");
 *    you may not use this file except in compliance with the License.
 *    You may obtain a copy of the License at
 *
 *        http://www.apache.org/licenses/LICENSE-2.0
 *
 *    Unless required by applicable law or agreed to in writing, software
 *    distributed under the License is distributed on an "AS IS" BASIS,
 *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *    See the License for the specific language governing permissions and
 *    limitations under the License.
 */

package com.worksap.webapi.codingstarter.view.utils;

import io.swagger.models.Model;
import io.swagger.models.RefModel;
import io.swagger.models.properties.Property;

import java.util.Map;

/**
 * TODO: Write Javadoc
 */
public class SchemaUtils {

    public String resolveName(Property schema, Map<String, Model> definitions, String defaultName) {
        String title = schema.getTitle();
        if (title != null) {
            return title;
        }

        return defaultName;
    }

    public String resolveName(Model schema, Map<String, Model> definitions, String defaultName) {
        String title = schema.getTitle();
        if (title != null) {
            return title;
        }

        if (definitions != null && schema instanceof RefModel) {
            String simpleRef = ((RefModel) schema).getSimpleRef();
            Model resolveModel = definitions.get(simpleRef);

            String resolveTitle = resolveModel.getTitle();
            if (resolveTitle != null) {
                return resolveTitle;
            }

            return simpleRef;
        }

        return defaultName;
    }
}

@@ -800,16 +800,65 @@
 roperty;
+%0Aimport io.swagger.models.properties.RefProperty;
 %0A%0Aimport
@@ -1511,24 +1511,25 @@
 impleRef();%0A
+%0A
             
@@ -1577,17 +1577,16 @@
 leRef);%0A
-%0A
         
@@ -1802,11 +1802,160 @@
 e;%0A    %7D
+%0A%0A    public String resolveName(RefProperty schema, Map%3CString, Model%3E definitions, String defaultName) %7B%0A        return schema.getSimpleRef();%0A    %7D
 %0A%7D%0A

Fix RefProperty case