org.joinedworkz.common.OpenApiCartridge.xtend Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of common-base Show documentation
Show all versions of common-base Show documentation
DSL based modeling framework - facilities common base
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