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 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)
}
}