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

com.reprezen.genflow.openapi3.doc.ExamplesHelper.xtend Maven / Gradle / Ivy

package com.reprezen.genflow.openapi3.doc

import com.fasterxml.jackson.databind.JsonNode
import com.fasterxml.jackson.databind.ObjectMapper
import com.fasterxml.jackson.dataformat.yaml.YAMLFactory
import com.reprezen.kaizen.oasparser.model3.Example
import java.util.Map

class ExamplesHelper implements Helper {

	extension HtmlHelper htmlHelper
	extension DocHelper docHelper

	val static ObjectMapper yamlMapper = new ObjectMapper(new YAMLFactory)

	override init() {
		htmlHelper = HelperHelper.htmlHelper
		docHelper = HelperHelper.docHelper
	}

	def  String renderExamples(Map examples) {
		examples?.keySet?.map[name|examples.get(name).render(name)]?.examplesSection
	}

	def String renderExample(Object example) {
		example?.exampleText?.exampleSection
	}

	def private String render(Example example,
		String name) {
		'''
			
«name»
«IF example.summary !== null»

«example.summary.htmlEscape»

«ENDIF» «IF example.description !== null»«example.description.docHtml»«ENDIF» «IF example.externalValue !== null»

External Value: «example.externalValue.htmlEscape»

«ENDIF» «example?.value?.exampleText»
''' } def private String exampleText(Object value) { val content = switch (value) { String: value default: yamlMapper.writerWithDefaultPrettyPrinter.writeValueAsString(yamlMapper.convertValue(value, JsonNode)) } '''
		«content.htmlEscape»
		
''' } def private String exampleSection(String html) { '''

Example

«html» ''' } def private String examplesSection(Iterable examples) { '''

Examples

«FOR example : examples» «example» «ENDFOR»
''' } }




© 2015 - 2025 Weber Informatics LLC | Privacy Policy