/*
 * Copyright 2000-2017 Holon TDCN.
 * 
 * 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.holonplatform.jaxrs.swagger.internal;

import com.holonplatform.core.i18n.LocalizationContext;
import com.holonplatform.core.internal.utils.ObjectUtils;
import com.holonplatform.core.property.Property;
import com.holonplatform.core.property.PropertyValueConverter.PropertyConversionException;

import io.swagger.converter.ModelConverters;

/**
 * Default {@link SwaggerPropertyFactory} implementation.
 *
 * @since 5.0.0
 */
public enum DefaultSwaggerPropertyFactory implements SwaggerPropertyFactory {

	INSTANCE;

	/* (non-Javadoc)
	 * @see com.holonplatform.jaxrs.swagger.internal.SwaggerPropertyFactory#create(com.holonplatform.core.property.Property)
	 */
	@Override
	public io.swagger.models.properties.Property create(Property<?> property) throws PropertyConversionException {
		ObjectUtils.argumentNotNull(property, "Property must be not null");
		
		// TODO validators
		
		io.swagger.models.properties.Property p = ModelConverters.getInstance().readAsProperty(property.getType());
		configureProperty(p, property);
		return p;
	}

	private static void configureProperty(io.swagger.models.properties.Property property, Property<?> source) {
		// read-only
		if (source.isReadOnly()) {
			property.setReadOnly(Boolean.TRUE);
		}
		// i18n
		String message = LocalizationContext.translate(source, true);
		if (message != null) {
			property.setTitle(message);
		}
	}

}

@@ -656,24 +656,122 @@
 nternal;%0D%0A%0D%0A
+import java.time.LocalDate;%0D%0Aimport java.time.LocalDateTime;%0D%0Aimport java.time.OffsetDateTime;%0D%0A%0D%0A
 import com.h
@@ -874,16 +874,73 @@
 Utils;%0D%0A
+import com.holonplatform.core.internal.utils.TypeUtils;%0D%0A
 import c
@@ -1077,53 +1077,213 @@
 n;%0D%0A
-%0D%0Aimport io.swagger.converter.ModelConverters
+import com.holonplatform.core.temporal.TemporalType;%0D%0A%0D%0Aimport io.swagger.converter.ModelConverters;%0D%0Aimport io.swagger.models.properties.DateProperty;%0D%0Aimport io.swagger.models.properties.DateTimeProperty
 ;%0D%0A%0D
@@ -1471,16 +1471,21 @@
 ;%0D%0A%0D%0A%09/*
+%0D%0A%09 *
  (non-Ja
@@ -1500,16 +1500,21 @@
 %09 * @see
+%0D%0A%09 *
  com.hol
@@ -1822,18 +1822,16 @@
 ull%22);%0D%0A
-%09%09
 %0D%0A%09%09// T
@@ -1846,18 +1846,954 @@
 dators%0D%0A
-%09%09
+%0D%0A%09%09// temporals%0D%0A%09%09if (TypeUtils.isDate(property.getType()) %7C%7C TypeUtils.isCalendar(property.getType())) %7B%0D%0A%09%09%09TemporalType type = property.getConfiguration().getTemporalType().orElse(TemporalType.DATE);%0D%0A%09%09%09io.swagger.models.properties.Property p;%0D%0A%09%09%09if (type == TemporalType.DATE) %7B%0D%0A%09%09%09%09p = new DateProperty();%0D%0A%09%09%09%7D else %7B%0D%0A%09%09%09%09p = new DateTimeProperty();%0D%0A%09%09%09%7D%0D%0A%09%09%09configureProperty(p, property);%0D%0A%09%09%09return p;%0D%0A%09%09%7D%0D%0A%0D%0A%09%09if (LocalDate.class.isAssignableFrom(property.getType())) %7B%0D%0A%09%09%09DateProperty p = new DateProperty();%0D%0A%09%09%09configureProperty(p, property);%0D%0A%09%09%09return p;%0D%0A%09%09%7D%0D%0A%09%09if (LocalDateTime.class.isAssignableFrom(property.getType())) %7B%0D%0A%09%09%09DateTimeProperty p = new DateTimeProperty();%0D%0A%09%09%09configureProperty(p, property);%0D%0A%09%09%09return p;%0D%0A%09%09%7D%0D%0A%09%09if (OffsetDateTime.class.isAssignableFrom(property.getType())) %7B%0D%0A%09%09%09DateTimeProperty p = new DateTimeProperty();%0D%0A%09%09%09configureProperty(p, property);%0D%0A%09%09%09return p;%0D%0A%09%09%7D%0D%0A%0D%0A%09%09// dft
 %0D%0A%09%09io.s

Add TemporalType property check and Temporals handling