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

com.reprezen.genflow.swagger.doc.AttrDetails.xtend Maven / Gradle / Ivy

The newest version!
package com.reprezen.genflow.swagger.doc

class AttrDetails {

	extension AttributeHelper = HelperHelper.attributeHelper
	extension HtmlHelper = HelperHelper.htmlHelper

	var Object obj
	val String id

	new(Object obj) {
		this.obj = obj
		this.id = this.htmlId
	}

	def setObject(Object obj) {
		this.obj = obj
	}

	def details(boolean topLevel) {
		val details = detailRows
		if (!details.empty) {
			val detailsTable = details.detailsTable
			if (topLevel) {
				// wrapping in an outer table to make it look the same as in the case where there really is 
				// an outer table that contains this. Otherwise bootstrap css gives it an odd look
				'''
«detailsTable»
''' } else { detailsTable } } } def private detailsTable(String rows) { '''
«rows»
''' } def getInfoButton() { if(!detailRows.empty) getInfoButton(id) } def private getInfoButton(String id) { ''' ''' } def private String getDetailRows() { ''' «detailRow("Format")» «detailRow("Default")» «detailRow("Bounds")» «detailRow("Multiple Of")» «detailRow("Length")» «detailRow("Pattern")» «detailRow("Allowed Values")» «detailRow("Unique Values")» «detailRow("Example")» ''' } def private detailRow(String detailName) { val String value = switch detailName { case "Format": obj.format case "Default": obj.defaultValue?.toString case "Bounds": bounds case "Multiple Of": obj.multipleOf?.toString case "Length": lengthBounds case "Pattern": obj.pattern?.htmlEscape case "Allowed Values": enumList case "Unique Values": obj.uniqueItems?.toString case "Example": obj.example?.toString default: throw new IllegalArgumentException("Internal error - unexpected detail label: " + detailName) } if (value !== null) { '''«detailName»«value»''' } } def private getBounds() { val minEq = if(!obj.exclusiveMinimum) "=" val maxEq = if(!obj.exclusiveMaximum) "=" val bounds = if (obj.minimum !== null) { if (obj.maximum !== null) { '''«obj.minimum» <«minEq» «obj.name» <«maxEq» «obj.maximum»''' } } else if (obj.minimum !== null) { '''«obj.name» >«minEq» «obj.minimum»''' } else if (obj.maximum !== null) { '''«obj.name» <«maxEq» «obj.maximum»''' } bounds?.htmlEscape } def private String getLengthBounds() { if (obj.minLength > 0 && obj.maxLength < Integer::MAX_VALUE) { '''«obj.minLength» <= length <= «obj.maxLength»''' } else if (obj.minLength > 0) { '''length >= «obj.minLength»''' } else if (obj.maxLength < Integer::MAX_VALUE) { '''length <= «obj.maxLength»''' } } def private getEnumList() { obj.enums?.map[it?.toString?.htmlEscape]?.join("
") } }




© 2015 - 2025 Weber Informatics LLC | Privacy Policy