org.eclipse.microprofile.openapi.models.OpenAPI Java Examples
The following examples show how to use
org.eclipse.microprofile.openapi.models.OpenAPI.
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: RolesAllowedScopeScanTests.java From smallrye-open-api with Apache License 2.0 | 6 votes |
@Test public void testDeclaredRolesMethodRolesAllowedGeneratedScheme() throws IOException { Index index = indexOf(RolesAllowedApp.class, RolesDeclaredResource.class); OpenApiConfig config = emptyConfig(); IndexView filtered = new FilteredIndexView(index, config); OpenApiAnnotationScanner scanner = new OpenApiAnnotationScanner(config, filtered); OpenAPI result = scanner.scan(); printToConsole(result); SecurityRequirement requirement = result.getPaths().getPathItem("/v1/secured").getGET().getSecurity().get(0); assertNotNull(requirement); assertEquals(1, requirement.getScheme("rolesScheme").size()); assertEquals("admin", requirement.getScheme("rolesScheme").get(0)); assertArrayEquals(new String[] { "admin", "users" }, result.getComponents() .getSecuritySchemes() .get("rolesScheme") .getFlows() .getClientCredentials() .getScopes() .keySet() .toArray()); }
Example #2
Source File: SpringAnnotationScanner.java From smallrye-open-api with Apache License 2.0 | 6 votes |
/** * Find and process all Spring Controllers * TODO: Also support org.springframework.stereotype.Controller annotations ? * * @param context the scanning context * @param openApi the openAPI model */ private void processControllerClasses(final AnnotationScannerContext context, OpenAPI openApi) { // Get all Spring controllers and convert them to OpenAPI models (and merge them into a single one) Collection<AnnotationInstance> controllerAnnotations = context.getIndex() .getAnnotations(SpringConstants.REST_CONTROLLER); List<ClassInfo> applications = new ArrayList<>(); for (AnnotationInstance annotationInstance : controllerAnnotations) { if (annotationInstance.target().kind().equals(AnnotationTarget.Kind.CLASS)) { ClassInfo classInfo = annotationInstance.target().asClass(); applications.add(classInfo); } else { SpringLogging.log.ignoringAnnotation(SpringConstants.REST_CONTROLLER.withoutPackagePrefix()); } } // this can be a useful extension point to set/override the application path processScannerExtensions(context, applications); for (ClassInfo controller : applications) { OpenAPI applicationOpenApi = processControllerClass(context, controller); openApi = MergeUtil.merge(openApi, applicationOpenApi); } }
Example #3
Source File: DefinitionReader.java From smallrye-open-api with Apache License 2.0 | 6 votes |
/** * Reads a OpenAPIDefinition annotation. * * @param context the scanning context * @param openApi OpenAPIImpl * @param annotationInstance {@literal @}OpenAPIDefinition annotation */ public static void processDefinition(final AnnotationScannerContext context, final OpenAPI openApi, final AnnotationInstance annotationInstance) { IoLogging.log.annotation("@OpenAPIDefinition"); openApi.setInfo(InfoReader.readInfo(annotationInstance.value(DefinitionConstant.PROP_INFO))); openApi.setTags(TagReader.readTags(annotationInstance.value(DefinitionConstant.PROP_TAGS)).orElse(null)); openApi.setServers( ServerReader.readServers(annotationInstance.value(DefinitionConstant.PROP_SERVERS)).orElse(null)); openApi.setSecurity(SecurityRequirementReader .readSecurityRequirements(annotationInstance.value(DefinitionConstant.PROP_SECURITY)).orElse(null)); openApi.setExternalDocs( ExternalDocsReader .readExternalDocs(annotationInstance.value(ExternalDocsConstant.PROP_EXTERNAL_DOCS))); openApi.setComponents(ComponentsReader.readComponents(context, annotationInstance.value(DefinitionConstant.PROP_COMPONENTS))); }
Example #4
Source File: OpenApiAnnotationScanner.java From smallrye-open-api with Apache License 2.0 | 6 votes |
/** * Scans all <code>@OpenAPIDefinition</code> annotations present on <code>package-info</code> * classes known to the scanner's index. * * @param oai the current OpenAPI result * @return the created OpenAPI */ private OpenAPI processPackageOpenAPIDefinitions(final AnnotationScannerContext context, OpenAPI oai) { List<AnnotationInstance> packageDefs = context.getIndex() .getAnnotations(DefinitionConstant.DOTNAME_OPEN_API_DEFINITION) .stream() .filter(annotation -> annotation.target().kind() == AnnotationTarget.Kind.CLASS) .filter(annotation -> annotation.target().asClass().name().withoutPackagePrefix().equals("package-info")) .collect(Collectors.toList()); for (AnnotationInstance packageDef : packageDefs) { OpenAPI packageOai = new OpenAPIImpl(); DefinitionReader.processDefinition(context, packageOai, packageDef); oai = MergeUtil.merge(oai, packageOai); } return oai; }
Example #5
Source File: OpenApiDocumentProducer.java From quarkus with Apache License 2.0 | 6 votes |
/** * 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 #6
Source File: OpenApiParser.java From smallrye-open-api with Apache License 2.0 | 6 votes |
/** * Parses the resource found at the given URL. This method accepts resources * either in JSON or YAML format. It will parse the input and, assuming it is * valid, return an instance of {@link OpenAPI}. * * @param url URL to OpenAPI document * @return OpenAPIImpl parsed from URL * @throws IOException URL parameter is not found */ public static final OpenAPI parse(URL url) throws IOException { try { String fname = url.getFile(); if (fname == null) { throw IoMessages.msg.noFileName(url.toURI().toString()); } int lidx = fname.lastIndexOf('.'); if (lidx == -1 || lidx >= fname.length()) { throw IoMessages.msg.invalidFileName(url.toURI().toString()); } String ext = fname.substring(lidx + 1); boolean isJson = ext.equalsIgnoreCase("json"); boolean isYaml = ext.equalsIgnoreCase("yaml") || ext.equalsIgnoreCase("yml"); if (!isJson && !isYaml) { throw IoMessages.msg.invalidFileExtension(url.toURI().toString()); } try (InputStream stream = url.openStream()) { return parse(stream, isJson ? Format.JSON : Format.YAML); } } catch (URISyntaxException e) { throw new IOException(e); } }
Example #7
Source File: SmallRyeOpenApiProcessor.java From quarkus with Apache License 2.0 | 6 votes |
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 #8
Source File: ResourceParameterTests.java From smallrye-open-api with Apache License 2.0 | 6 votes |
/*************************************************************************/ /* * Test cases derived from original example in SmallRye OpenAPI issue #260. * * https://github.com/smallrye/smallrye-open-api/issues/260 * */ @Test public void testGenericSetResponseWithSetIndexed() throws IOException, JSONException { Index i = indexOf(FruitResource.class, Fruit.class, Seed.class, Set.class); OpenApiAnnotationScanner scanner = new OpenApiAnnotationScanner(emptyConfig(), i); OpenAPI result = scanner.scan(); printToConsole(result); assertJsonEquals("responses.generic-collection.set-indexed.json", result); }
Example #9
Source File: SmallRyeOpenApiProcessor.java From quarkus with Apache License 2.0 | 6 votes |
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 #10
Source File: ResourceParameterTests.java From smallrye-open-api with Apache License 2.0 | 6 votes |
/*************************************************************************/ /* * Test case derived from original example in SmallRye OpenAPI issue #239. * * https://github.com/smallrye/smallrye-open-api/issues/239 * */ @Test public void testBeanParamMultipartFormInheritance() throws IOException, JSONException { Index i = indexOf(BeanParamMultipartFormInheritanceResource.class, MultipartFormVerify.class, MultipartFormUploadIconForm.class, BeanParamBase.class, BeanParamImpl.class, BeanParamAddon.class); OpenApiAnnotationScanner scanner = new OpenApiAnnotationScanner(emptyConfig(), i); OpenAPI result = scanner.scan(); printToConsole(result); assertJsonEquals("params.beanparam-multipartform-inherited.json", result); }
Example #11
Source File: RolesAllowedScopeScanTests.java From smallrye-open-api with Apache License 2.0 | 6 votes |
@Test public void testSchemesWithoutRoles() throws IOException { Index index = indexOf(UndeclaredFlowsNoRolesAllowedApp.class, NoRolesResource.class); OpenApiConfig config = emptyConfig(); IndexView filtered = new FilteredIndexView(index, config); OpenApiAnnotationScanner scanner = new OpenApiAnnotationScanner(config, filtered); OpenAPI result = scanner.scan(); printToConsole(result); SecurityRequirement requirement = result.getPaths().getPathItem("/v1/secured").getGET().getSecurity().get(0); assertNotNull(requirement); assertEquals(1, requirement.getScheme("oidc").size()); assertEquals("admin", requirement.getScheme("oidc").get(0)); assertNull(result.getComponents() .getSecuritySchemes() .get("oidc") .getFlows()); }
Example #12
Source File: CustomExtensionParsingTests.java From smallrye-open-api with Apache License 2.0 | 6 votes |
@Test public void testCustomAnnotationScannerExtension() { Index index = IndexScannerTestBase.indexOf(ExtensionParsingTestResource.class); OpenApiAnnotationScanner scanner = new OpenApiAnnotationScanner(IndexScannerTestBase.emptyConfig(), index, Arrays.asList(new AnnotationScannerExtension() { @Override public Object parseExtension(String name, String value) { /* * "parsing" consists of creating a singleton map with the * extension name as the key and the unparsed value as the value */ return Collections.singletonMap(name, value); } })); OpenAPI result = scanner.scan(); org.eclipse.microprofile.openapi.models.callbacks.Callback cb; cb = result.getPaths().getPathItem("/ext-custom").getPOST().getCallbacks().get("extendedCallback"); Map<String, Object> ext = cb.getPathItem("http://localhost:8080/resources/ext-callback").getGET().getExtensions(); assertEquals(4, ext.size()); assertEquals(Collections.singletonMap("x-object", "{ \"key\":\"value\" }"), ext.get("x-object")); assertEquals("{ \"key\":\"value\" }", ext.get("x-object-unparsed")); assertEquals(Collections.singletonMap("x-array", "[ \"val1\",\"val2\" ]"), ext.get("x-array")); assertEquals("true", ext.get("x-booltrue")); }
Example #13
Source File: RolesAllowedScopeScanTests.java From smallrye-open-api with Apache License 2.0 | 6 votes |
@Test public void testMethodRolesAllowedGeneratedScheme() throws IOException { Index index = indexOf(RolesAllowedApp.class, RolesAllowedResource2.class); OpenApiConfig config = emptyConfig(); IndexView filtered = new FilteredIndexView(index, config); OpenApiAnnotationScanner scanner = new OpenApiAnnotationScanner(config, filtered); OpenAPI result = scanner.scan(); printToConsole(result); SecurityRequirement requirement = result.getPaths().getPathItem("/v2/secured").getGET().getSecurity().get(0); assertNotNull(requirement); assertEquals(2, requirement.getScheme("rolesScheme").size()); assertEquals("admin", requirement.getScheme("rolesScheme").get(0)); assertEquals("users", requirement.getScheme("rolesScheme").get(1)); assertArrayEquals(new String[] { "admin", "users" }, result.getComponents() .getSecuritySchemes() .get("rolesScheme") .getFlows() .getClientCredentials() .getScopes() .keySet() .toArray()); }
Example #14
Source File: MergeUtilTest.java From smallrye-open-api with Apache License 2.0 | 6 votes |
/** * Performs a single full merge test. Two documents are loaded (as resources) and then * merged. The expected merge result is then loaded and compared with the actual result. * * @param resource1 * @param resource2 * @param expected * @throws IOException * @throws ParseException * @throws JSONException */ private static void doTest(String resource1, String resource2, String expected) throws IOException, ParseException, JSONException { URL resource1Url = MergeUtilTest.class.getResource(resource1); URL resource2Url = MergeUtilTest.class.getResource(resource2); URL expectedUrl = MergeUtilTest.class.getResource(expected); String expectedContent = loadResource(expectedUrl); OpenAPI resource1Model = OpenApiParser.parse(resource1Url); OpenAPI resource2Model = OpenApiParser.parse(resource2Url); OpenAPI actualModel = MergeUtil.merge(resource1Model, resource2Model); String actual = OpenApiSerializer.serialize(actualModel, Format.JSON); assertJsonEquals(expectedContent, actual); }
Example #15
Source File: DefinitionReader.java From smallrye-open-api with Apache License 2.0 | 6 votes |
/** * Reads a OpenAPIDefinition Json node. * * @param openApi the OpenAPI model * @param node the Json node */ public static void processDefinition(final OpenAPI openApi, final JsonNode node) { IoLogging.log.jsonNode("OpenAPIDefinition"); openApi.setOpenapi(JsonUtil.stringProperty(node, DefinitionConstant.PROP_OPENAPI)); openApi.setInfo(InfoReader.readInfo(node.get(DefinitionConstant.PROP_INFO))); openApi.setTags(TagReader.readTags(node.get(DefinitionConstant.PROP_TAGS)).orElse(null)); openApi.setServers(ServerReader.readServers(node.get(DefinitionConstant.PROP_SERVERS)).orElse(null)); openApi.setSecurity(SecurityRequirementReader .readSecurityRequirements(node.get(DefinitionConstant.PROP_SECURITY)).orElse(null)); openApi.setExternalDocs( ExternalDocsReader.readExternalDocs(node.get(ExternalDocsConstant.PROP_EXTERNAL_DOCS))); openApi.setComponents( ComponentsReader.readComponents(node.get(DefinitionConstant.PROP_COMPONENTS))); openApi.setPaths(PathsReader.readPaths(node.get(DefinitionConstant.PROP_PATHS))); ExtensionReader.readExtensions(node, openApi); }
Example #16
Source File: OpenApiAnnotationScanner.java From smallrye-open-api with Apache License 2.0 | 6 votes |
private OpenAPI scanMicroProfileOpenApiAnnotations() { // Initialize a new OAI document. Even if nothing is found, this will be returned. OpenAPI openApi = new OpenAPIImpl(); openApi.setOpenapi(OpenApiConstants.OPEN_API_VERSION); // Creating a new instance of a registry which will be set on the thread context. SchemaRegistry schemaRegistry = SchemaRegistry.newInstance(annotationScannerContext.getConfig(), openApi, annotationScannerContext.getIndex()); // Register custom schemas if available getCustomSchemaRegistry(annotationScannerContext.getConfig()).registerCustomSchemas(schemaRegistry); // Find all OpenAPIDefinition annotations at the package level ScannerLogging.log.scanning("OpenAPI"); processPackageOpenAPIDefinitions(annotationScannerContext, openApi); return openApi; }
Example #17
Source File: FilterUtilTest.java From smallrye-open-api with Apache License 2.0 | 6 votes |
/** * Creates and returns the filter to use for the test. */ private OASFilter filter() { return new OASFilter() { /** * @see org.eclipse.microprofile.openapi.OASFilter#filterOpenAPI(org.eclipse.microprofile.openapi.models.OpenAPI) */ @Override public void filterOpenAPI(OpenAPI openAPI) { openAPI.getInfo().setLicense(null); openAPI.getInfo().setTitle("Updated API Title"); } /** * @see org.eclipse.microprofile.openapi.OASFilter#filterPathItem(org.eclipse.microprofile.openapi.models.PathItem) */ @Override public PathItem filterPathItem(PathItem pathItem) { if (pathItem.getRef() != null) { return null; } else { return pathItem; } } }; }
Example #18
Source File: ModelUtil.java From smallrye-open-api with Apache License 2.0 | 6 votes |
/** * Adds a {@link Tag} to the {@link OpenAPI} model. If a tag having the same * name already exists in the model, the tags' attributes are merged, with the * new tag's attributes overriding the value of any attributes specified on * both. * * @param openApi the OpenAPI model * @param tag a new {@link Tag} to add */ public static void addTag(OpenAPI openApi, Tag tag) { List<Tag> tags = openApi.getTags(); if (tags == null || tags.isEmpty()) { openApi.addTag(tag); return; } Tag current = tags.stream().filter(t -> t.getName().equals(tag.getName())).findFirst().orElse(null); int currentIndex = tags.indexOf(current); if (current != null) { Tag replacement = MergeUtil.mergeObjects(current, tag); tags = new ArrayList<>(tags); tags.set(currentIndex, replacement); openApi.setTags(tags); } else { openApi.addTag(tag); } }
Example #19
Source File: JaxRsAnnotationScanner.java From smallrye-open-api with Apache License 2.0 | 6 votes |
/** * Processing a single JAX-RS resource class (annotated with @Path). * * @param openApi * @param resourceClass * @param locatorPathParameters */ private void processResourceClass(final AnnotationScannerContext context, OpenAPI openApi, ClassInfo resourceClass, List<Parameter> locatorPathParameters) { JaxRsLogging.log.processingClass(resourceClass.simpleName()); // Process @SecurityScheme annotations. processSecuritySchemeAnnotation(resourceClass, openApi); // Process Java security processJavaSecurity(resourceClass, openApi); // Now find and process the operation methods processResourceMethods(context, resourceClass, openApi, locatorPathParameters); }
Example #20
Source File: JaxRsAnnotationScannerTest.java From smallrye-open-api with Apache License 2.0 | 6 votes |
@Test public void testTagScanning_OrderGivenStaticFile() throws IOException, JSONException { Index i = indexOf(TagTestResource1.class, TagTestResource2.class); OpenApiAnnotationScanner scanner = new OpenApiAnnotationScanner(nestingSupportConfig(), i); OpenAPI scanResult = scanner.scan(); OpenAPI staticResult = OpenApiParser.parse(new ByteArrayInputStream( "{\"info\" : {\"title\" : \"Tag order in static file\",\"version\" : \"1.0.0-static\"},\"tags\": [{\"name\":\"tag3\"},{\"name\":\"tag1\"}]}" .getBytes()), Format.JSON); OpenApiDocument doc = OpenApiDocument.INSTANCE; doc.config(nestingSupportConfig()); doc.modelFromStaticFile(staticResult); doc.modelFromAnnotations(scanResult); doc.initialize(); OpenAPI result = doc.get(); printToConsole(result); assertJsonEquals("resource.tags.ordergiven.staticfile.json", result); }
Example #21
Source File: TomEEOpenAPIExtension.java From tomee with Apache License 2.0 | 6 votes |
public OpenAPI getOrCreateOpenAPI(final Application application) { if (classes != null) { final ClassLoader loader = Thread.currentThread().getContextClassLoader(); return openapis.computeIfAbsent(application, app -> createOpenApi(application.getClass(), classes.stream().map(c -> { try { return loader.loadClass(c); } catch (final ClassNotFoundException e) { throw new IllegalArgumentException(e); } }))); } if (packages == null && (!application.getSingletons().isEmpty() || !application.getClasses().isEmpty())) { return openapis.computeIfAbsent(application, app -> createOpenApi(application.getClass(), Stream.concat(endpoints.stream().map(Bean::getBeanClass), Stream.concat(app.getClasses().stream(), app.getSingletons().stream().map(Object::getClass))))); } return openapis.computeIfAbsent(application, app -> createOpenApi(application.getClass(), endpoints.stream().map(Bean::getBeanClass))); }
Example #22
Source File: ModelUtil.java From smallrye-open-api with Apache License 2.0 | 5 votes |
/** * Gets the {@link Paths} from the OAI model. If it doesn't exist, creates it. * * @param openApi OpenAPI * @return Paths */ public static Paths paths(OpenAPI openApi) { if (openApi.getPaths() == null) { openApi.setPaths(new PathsImpl()); } return openApi.getPaths(); }
Example #23
Source File: SmallRyeOpenApiProcessor.java From quarkus with Apache License 2.0 | 5 votes |
private OpenAPI generateStaticModel(ApplicationArchivesBuildItem archivesBuildItem) throws IOException { Result result = findStaticModel(archivesBuildItem); if (result != null) { try (InputStream is = Files.newInputStream(result.path); OpenApiStaticFile staticFile = new OpenApiStaticFile(is, result.format)) { return io.smallrye.openapi.runtime.OpenApiProcessor.modelFromStaticFile(staticFile); } } return null; }
Example #24
Source File: ModelUtil.java From smallrye-open-api with Apache License 2.0 | 5 votes |
/** * Gets the {@link Components} from the OAI model. If it doesn't exist, creates it. * * @param openApi OpenAPI * @return Components */ public static Components components(OpenAPI openApi) { if (openApi.getComponents() == null) { openApi.setComponents(new ComponentsImpl()); } return openApi.getComponents(); }
Example #25
Source File: SpringAnnotationScanner.java From smallrye-open-api with Apache License 2.0 | 5 votes |
/** * Processes a Spring Controller and creates an {@link OpenAPI} model. Performs * annotation scanning and other processing. Returns a model unique to that single Spring * controller. * * @param context the scanning context * @param controllerClass the Spring REST controller */ private OpenAPI processControllerClass(final AnnotationScannerContext context, ClassInfo controllerClass) { SpringLogging.log.processingController(controllerClass.simpleName()); OpenAPI openApi = new OpenAPIImpl(); openApi.setOpenapi(OpenApiConstants.OPEN_API_VERSION); // Get the @RequestMapping info and save it for later AnnotationInstance requestMappingAnnotation = JandexUtil.getClassAnnotation(controllerClass, SpringConstants.REQUEST_MAPPING); if (requestMappingAnnotation != null) { this.currentAppPath = ParameterProcessor.requestMappingValuesToPath(requestMappingAnnotation); } else { this.currentAppPath = "/"; } // Process @OpenAPIDefinition annotation processDefinitionAnnotation(context, controllerClass, openApi); // Process @SecurityScheme annotations processSecuritySchemeAnnotation(controllerClass, openApi); // Process @Server annotations processServerAnnotation(controllerClass, openApi); // Process Java security processJavaSecurity(controllerClass, openApi); // Now find and process the operation methods processControllerMethods(context, controllerClass, openApi, null); return openApi; }
Example #26
Source File: JaxRsAnnotationScannerTest.java From smallrye-open-api with Apache License 2.0 | 5 votes |
@Test public void testTagScanning_OrderGivenAnnotations() throws IOException, JSONException { Index i = indexOf(TagTestApp.class, TagTestResource1.class, TagTestResource2.class); OpenApiAnnotationScanner scanner = new OpenApiAnnotationScanner(nestingSupportConfig(), i); OpenAPI result = scanner.scan(); printToConsole(result); assertJsonEquals("resource.tags.ordergiven.annotation.json", result); }
Example #27
Source File: SpringAnnotationScanner.java From smallrye-open-api with Apache License 2.0 | 5 votes |
@Override public OpenAPI scan(final AnnotationScannerContext context, OpenAPI openApi) { // Get all Spring controllers and convert them to OpenAPI models (and merge them into a single one) processControllerClasses(context, openApi); boolean tagsDefined = openApi.getTags() != null && !openApi.getTags().isEmpty(); // Sort the tags unless the application has defined the order in OpenAPIDefinition annotation(s) sortTags(openApi, tagsDefined); // Now that all paths have been created, sort them (we don't have a better way to organize them). sortPaths(openApi); return openApi; }
Example #28
Source File: OpenApiSpecStyleValidatorTest.java From openapi-style-validator with Apache License 2.0 | 5 votes |
@Test void validatePingOpenAPI_WithoutSchema_and_components() { OpenAPI openAPI = createSimplePingOpenAPI(); OpenApiSpecStyleValidator validator = new OpenApiSpecStyleValidator(openAPI); ValidatorParameters parameters = new ValidatorParameters(); List<StyleError> errors = validator.validate(parameters); assertTrue(errors.size() == 0); }
Example #29
Source File: ResourceInheritanceTests.java From smallrye-open-api with Apache License 2.0 | 5 votes |
@Test public void testInheritedResourceMethod() throws IOException, JSONException { Index i = indexOf(GenericResource.class, ExampleResource1.class, ExampleResource2.class, Greetable.class, Greetable.GreetingBean.class); OpenApiConfig config = emptyConfig(); IndexView filtered = new FilteredIndexView(i, config); OpenApiAnnotationScanner scanner = new OpenApiAnnotationScanner(config, filtered); OpenAPI result = scanner.scan(); printToConsole(result); assertJsonEquals("resource.inheritance.params.json", result); }
Example #30
Source File: JaxRsAnnotationScannerTest.java From smallrye-open-api with Apache License 2.0 | 5 votes |
@Test public void testPackageInfoDefinitionScanning() throws IOException, JSONException { Indexer indexer = new Indexer(); index(indexer, "test/io/smallrye/openapi/runtime/scanner/package-info.class"); index(indexer, "test/io/smallrye/openapi/runtime/scanner/resources/PackageInfoTestApplication.class"); index(indexer, "test/io/smallrye/openapi/runtime/scanner/resources/PackageInfoTestApplication$PackageInfoTestResource.class"); OpenApiAnnotationScanner scanner = new OpenApiAnnotationScanner(emptyConfig(), indexer.complete()); OpenAPI result = scanner.scan(); printToConsole(result); assertJsonEquals("resource.testPackageInfoDefinitionScanning.json", result); }