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

org.joinedworkz.common.OpenApiCartridge.xtend Maven / Gradle / Ivy

There is a newer version: 1.3.46
Show newest version
package org.joinedworkz.common

import java.util.Properties
import javax.inject.Inject
import javax.inject.Singleton
import org.joinedworkz.common.generator.CmnOpenApiGenerator
import org.joinedworkz.common.helper.CmnModelHelper
import org.joinedworkz.common.helper.OpenApiHelper
import org.joinedworkz.core.facility.AbstractCartridge
import org.joinedworkz.core.facility.Outlet
import org.joinedworkz.core.facility.Outlets
import org.joinedworkz.core.model.CmnComponent
import org.joinedworkz.core.model.CmnModel
import org.joinedworkz.core.model.CmnObject
import org.joinedworkz.core.model.CmnResource

@Singleton
class OpenApiCartridge extends AbstractCartridge {
	
	@Inject
	protected extension CmnModelHelper cmnModelHelper
	
	@Inject
	protected CmnOpenApiGenerator openApiGenerator
	
	@Inject
	protected OpenApiHelper openApiHelper
	
	override apply(CmnObject cmnObj, Outlets outlets) {
        apply(cmnObj, outlets, null)
    }
	
	override void apply(CmnObject obj, Outlets outlets, Properties properties) {
		val openApiOutlet = outlets.get("generatedOpenApi")
		val openApiHtmlOutlet = outlets.get("generatedOpenApiHtml")
		
		if (obj instanceof CmnModel) {
			obj.generateOpenApi(openApiOutlet, openApiHtmlOutlet, properties)
		}
	}

	def void generateOpenApi(CmnModel model, Outlet openApiOutlet, Outlet openApiHtmlOutlet, Properties properties) {
		
		val components = model.modelElements.filter(CmnComponent)
		val allComponents = newArrayList
		for (component : components) {
			allComponents.add(component)
			for (subComponent: component.subComponents) {
				allComponents.add(subComponent)
			}
		}
		
		for (component : allComponents) {
			val ctx = createGeneratorContext(model, openApiOutlet, openApiHtmlOutlet, properties)
			val resourcesForApi = openApiHelper.createProvidedResourceAdaptersForComponent(component)
			openApiGenerator.generateOpenApiYml(component, resourcesForApi, ctx)
			ctx.clearAdapters
		}
		
		val allResourcesOfModel = model.modelElements.filter(CmnResource).filter[!abstract]
		openApiGenerator.generateOpenApiYml(null, allResourcesOfModel, createGeneratorContext(model, openApiOutlet, openApiHtmlOutlet, properties))
	}
	
	def OpenApiGeneratorContext createGeneratorContext(CmnModel model, Outlet outlet, Outlet htmlOutlet, Properties properties) {
		return new OpenApiGeneratorContext(model, outlet, htmlOutlet, properties)
	}

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy