/**
 *  Copyright 2013 SmartBear Software, Inc.
 *
 *  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.smartbear.swagger4j.impl;

import com.smartbear.swagger4j.SwaggerFormat;
import com.smartbear.swagger4j.SwaggerStore;

import java.io.IOException;
import java.io.OutputStreamWriter;
import java.io.StringWriter;
import java.io.Writer;
import java.util.HashMap;
import java.util.Map;

/**
 * General utilities methods, classes and constants
 */

public class Utils {

    /**
     * Method for creating a filename from a path - replaces format references and adds the extension.
     *
     * @param path the path to fix
     * @param format the format to use
     * @return the created fileName
     */

    public static String createFileNameFromPath(String path, SwaggerFormat format) {
        assert path != null && format != null : "Path and format must not be null";

        String name = path.replaceAll("\\{format\\}", format.getExtension());

        if (name.indexOf('.') == -1)
            name += "." + format.getExtension();
        return name;
    }

    /**
     * SwaggerStore implementation that writes Swagger definitions to a map of fileName to StringWriter
     *
     * @see SwaggerStore
     */

    public static class MapSwaggerStore implements SwaggerStore
    {
        final Map<String,StringWriter> files = new HashMap<String, StringWriter>();

        @Override
        public Writer createResource(String path) throws IOException {
            StringWriter writer = new StringWriter();
            files.put(path, writer);
            return writer;
        }

        public Map<String,StringWriter> getFileMap() {
            return files;
        }
    }

    /**
     * SwaggerStore implementation that writes Swagger definitions to the Console; for debugging
     *
     * @see SwaggerStore
     */

    public static class ConsoleSwaggerStore implements SwaggerStore
    {
        @Override
        public Writer createResource(String path) {
            System.out.println( "\nCreating file [" + path + "]");
            return new OutputStreamWriter(System.out);
        }
    }

}

@@ -2643,11 +2643,1273 @@
 %7D%0A    %7D%0A
+    %0A    /**%0A     * Utility class to get finer data type parsing.%0A     */%0A    public static class SwaggerDataParser %7B%0A%0A        private final SwaggerParser parser;%0A%0A        public SwaggerDataParser(SwaggerParser parser) %7B%0A            this.parser = parser;%0A        %7D%0A%0A        public SwaggerParser getParser() %7B%0A            return parser;%0A        %7D%0A%0A        public Boolean getBoolean(String name) %7B%0A            return parser.getBoolean(name);%0A        %7D%0A        %0A        public String getString(String name) %7B%0A            return parser.getString(name);%0A        %7D%0A        %0A        public Integer getInteger(String name) %7B%0A            Number number = parser.getNumber(name);%0A            return number != null ? number.intValue() : null;%0A        %7D%0A%0A        public Long getLong(String name) %7B%0A            Number number = parser.getNumber(name);%0A            return number != null ? number.longValue() : null;%0A        %7D%0A%0A        public Double getDouble(String name) %7B%0A            Number number = parser.getNumber(name);%0A            return number != null ? number.doubleValue() : null;%0A        %7D%0A%0A        public Float getFloat(String name) %7B%0A            Number number = parser.getNumber(name);%0A            return number != null ? number.floatValue() : null;%0A        %7D%0A    %7D
 %0A%7D%0A

add Swagger data parser for fine primitive parsing