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 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 void apply(CmnObject obj, Outlets osa) {
		val openApiOutlet = osa.get("generatedOpenApi")
		val openApiHtmlOutlet = osa.get("generatedOpenApiHtml")
		
		if (obj instanceof CmnModel) {
			obj.generateOpenApi(openApiOutlet, openApiHtmlOutlet)
		}
	}

	def void generateOpenApi(CmnModel model, Outlet openApiOutlet, Outlet openApiHtmlOutlet) {
		
		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)
			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))
	}
	
	def OpenApiGeneratorContext createGeneratorContext(CmnModel model, Outlet outlet, Outlet htmlOutlet) {
		return new OpenApiGeneratorContext(model, outlet, htmlOutlet)
	}

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy