crnk-framework
crnk-framework copied to clipboard
crnk-gen-openapi: No Documentation how to use the OpenAPIGeneratorModule
I want to generate the openapi-specification out of my defined JsonApiResources but unfortunately I can't find a valid documentation. Also the "Meta"-Endpoints are also added if I generate the specification in the following way:
fun main() {
val config = OpenAPIGeneratorConfig()
config.buildDir = Files.createDirectories(Path.of("target", "openapi")).toFile()
config.outputFormat = OutputFormat.JSON
config.projectName = "Test API"
config.projectVersion = "1.0.0"
val generator = OpenAPIGeneratorModule()
generator.config = config
val metaConfig = MetaModuleConfig()
metaConfig.addMetaProvider(ResourceMetaProvider())
val metaModule = MetaModule.createServerModule(metaConfig)
val boot = CrnkBoot()
boot.serviceDiscovery = EmptyServiceDiscovery()
boot.addModule(TestApiModule())
boot.addModule(TestTestApiModule())
boot.addModule(metaModule)
boot.boot()
val generatorModule = OpenAPIGeneratorModule()
generatorModule.config = config
generatorModule.initDefaults(config.buildDir)
generatorModule.generate(metaModule.lookup)
}
How can I remove the Meta-Data, add dynamically example values and also remove not implemented Endpoints?
would be great to:
- add it to one of the generator test projects
- invoke it from a unit test to ensure it keeps working
- include it in the asciidoc to have an always working example
@remmeier, yes, but this isn't really working as expected. I don't want the /meta endpoints in the generated specification. Is there a Way to remove them?
for Typescript there is TSGeneratorConfig.excludes
which by default already ignores meta data. Something similar should be implemented for OpenAPI.
I think this is fixed in latest
but not in stable
There still is a lack of documentation om how to do this. I currently have the following Spring setup using maven:
<dependency>
<groupId>io.crnk</groupId>
<artifactId>crnk-gen-openapi</artifactId>
<version>3.4.20210509072026</version>
<scope>test</scope>
</dependency>
And the following test class:
package com.malkithegame.malki;
import java.io.File;
import java.io.IOException;
import java.nio.file.Paths;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.TestInstance;
import org.junit.jupiter.api.TestInstance.Lifecycle;
import org.springframework.boot.test.context.SpringBootTest;
import io.crnk.core.boot.CrnkBoot;
import io.crnk.gen.openapi.OpenAPIGeneratorConfig;
import io.crnk.gen.openapi.OpenAPIGeneratorModule;
import io.crnk.meta.MetaModule;
import io.crnk.meta.MetaModuleConfig;
import io.crnk.meta.provider.resource.ResourceMetaProvider;
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.DEFINED_PORT)
@DirtiesContext
@TestInstance(Lifecycle.PER_CLASS)
public class OpenApiGeneratorTest {
private MetaModule metaModule;
private OpenAPIGeneratorModule generatorModule;
@BeforeAll
void setup() {
setupServer();
}
@Test
public void generateOpenApi() throws IOException {
File openApiDir = Paths.get("openapi").toAbsolutePath().toFile();
generatorModule = new OpenAPIGeneratorModule();
OpenAPIGeneratorConfig config = new OpenAPIGeneratorConfig();
config.setBuildDir(openApiDir);
config.setGenDir(openApiDir);
config.setOutputSorted(true); // Ensures deterministic output
generatorModule.setConfig(config);
generatorModule.generate(metaModule.getLookup());
}
private CrnkBoot setupServer() {
MetaModuleConfig metaConfig = new MetaModuleConfig();
metaConfig.addMetaProvider(new ResourceMetaProvider());
metaModule = MetaModule.createServerModule(metaConfig);
CrnkBoot boot = new CrnkBoot();
boot.addModule(metaModule);
boot.boot();
return boot;
}
}
Unfortunately, I don't see any of my resources in the yaml file. I can't find anything in the repo or documentation how to go about this problem and to implement a basic setup.