io.smallrye.openapi.api.OpenApiConfigImpl Java Examples

The following examples show how to use io.smallrye.openapi.api.OpenApiConfigImpl. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: SmallRyeOpenApiProcessor.java    From quarkus with Apache License 2.0 6 votes vote down vote up
private OpenAPI generateAnnotationModel(IndexView indexView, Capabilities capabilities) {
    Config config = ConfigProvider.getConfig();
    OpenApiConfig openApiConfig = new OpenApiConfigImpl(config);

    String defaultPath = config.getValue("quarkus.http.root-path", String.class);

    List<AnnotationScannerExtension> extensions = new ArrayList<>();
    // Add RestEasy if jaxrs
    if (capabilities.isCapabilityPresent(Capabilities.RESTEASY)) {
        extensions.add(new RESTEasyExtension(indexView));
    }
    // Add path if not null
    if (defaultPath != null) {
        extensions.add(new CustomPathExtension(defaultPath));
    }
    return new OpenApiAnnotationScanner(openApiConfig, indexView, extensions).scan();
}
 
Example #2
Source File: SmallRyeOpenApiProcessor.java    From quarkus with Apache License 2.0 6 votes vote down vote up
public OpenApiDocument loadDocument(OpenAPI staticModel, OpenAPI annotationModel) {
    Config config = ConfigProvider.getConfig();
    OpenApiConfig openApiConfig = new OpenApiConfigImpl(config);

    OpenAPI readerModel = OpenApiProcessor.modelFromReader(openApiConfig,
            Thread.currentThread().getContextClassLoader());

    OpenApiDocument document = createDocument(openApiConfig);
    if (annotationModel != null) {
        document.modelFromAnnotations(annotationModel);
    }
    document.modelFromReader(readerModel);
    document.modelFromStaticFile(staticModel);
    document.filter(filter(openApiConfig));
    document.initialize();
    return document;
}
 
Example #3
Source File: OpenApiDocumentProducer.java    From quarkus with Apache License 2.0 6 votes vote down vote up
/**
 * We load the document from the generated JSON file, which should have all the annotations
 *
 * Most apps will likely just want to serve the OpenAPI doc, rather than inject it, which is why we generated the
 * static file and parse it if required. The more Quarkus-like approach of serializing the doc to bytecode
 * can result in a lot of bytecode, which will likely just be turned straight into a static file anyway.
 */
@PostConstruct
void create() throws IOException {
    try (InputStream is = getClass().getClassLoader()
            .getResourceAsStream(OpenApiHandler.BASE_NAME + Format.JSON)) {
        if (is != null) {
            try (OpenApiStaticFile staticFile = new OpenApiStaticFile(is, Format.JSON)) {
                Config config = ConfigProvider.getConfig();
                OpenApiConfig openApiConfig = new OpenApiConfigImpl(config);

                OpenAPI readerModel = OpenApiProcessor.modelFromReader(openApiConfig,
                        Thread.currentThread().getContextClassLoader());
                document = OpenApiDocument.INSTANCE;
                document.reset();
                document.config(openApiConfig);

                document.modelFromReader(readerModel);
                document.modelFromStaticFile(io.smallrye.openapi.runtime.OpenApiProcessor.modelFromStaticFile(staticFile));
                document.filter(OpenApiProcessor.getFilter(openApiConfig, Thread.currentThread().getContextClassLoader()));
                document.initialize();
            }
        }
    }

}
 
Example #4
Source File: OpenApiDeploymentProcessorTest.java    From thorntail with Apache License 2.0 6 votes vote down vote up
/**
 * Common test method.
 * @throws Exception
 */
protected void doTest(
        Class modelReaderClass,
        String staticResource,
        boolean disableAnnotationScanning,
        Class filterClass,
        String expectedResource) throws Exception {

    System.setProperty(OASConfig.SCAN_DISABLE, "" + disableAnnotationScanning);
    System.setProperty(OASConfig.MODEL_READER, modelReaderClass != null ? modelReaderClass.getName() : "");
    System.setProperty(OASConfig.FILTER, filterClass != null ? filterClass.getName() : "");

    TestConfig cfg = new TestConfig();
    OpenApiConfig oaiConfig = new OpenApiConfigImpl(cfg);
    Archive archive = archive(staticResource);
    OpenApiDocument.INSTANCE.reset();
    OpenApiDeploymentProcessor processor = new OpenApiDeploymentProcessor(oaiConfig, archive);
    processor.process();
    new OpenApiServletContextListener(cfg).contextInitialized(null);

    String actual = OpenApiSerializer.serialize(OpenApiDocument.INSTANCE.get(), Format.JSON);
    String expected = loadResource(getClass().getResource(expectedResource));

    assertJsonEquals(expected, actual);
}
 
Example #5
Source File: ArchiveUtil.java    From smallrye-open-api with Apache License 2.0 5 votes vote down vote up
/**
 * Creates an {@link OpenApiConfig} instance from the given ShrinkWrap archive.
 * 
 * @param archive Shrinkwrap Archive instance
 * @return OpenApiConfig
 */
public static OpenApiConfig archiveToConfig(Archive<?> archive) {
    try (ShrinkWrapClassLoader cl = new ShrinkWrapClassLoader(archive)) {
        return new OpenApiConfigImpl(ConfigProvider.getConfig(cl));
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
}
 
Example #6
Source File: SmallRyeOpenApiProcessor.java    From quarkus with Apache License 2.0 5 votes vote down vote up
@BuildStep
OpenApiFilteredIndexViewBuildItem smallryeOpenApiIndex(CombinedIndexBuildItem combinedIndexBuildItem,
        BeanArchiveIndexBuildItem beanArchiveIndexBuildItem) {
    CompositeIndex compositeIndex = CompositeIndex.create(combinedIndexBuildItem.getIndex(),
            beanArchiveIndexBuildItem.getIndex());
    return new OpenApiFilteredIndexViewBuildItem(
            new FilteredIndexView(
                    compositeIndex,
                    new OpenApiConfigImpl(ConfigProvider.getConfig())));
}
 
Example #7
Source File: OpenApiServletContextListener.java    From thorntail with Apache License 2.0 4 votes vote down vote up
public OpenApiServletContextListener(Config config) {
    this.config = new OpenApiConfigImpl(config);
}