Java Code Examples for io.swagger.v3.oas.models.OpenAPI#setInfo()
The following examples show how to use
io.swagger.v3.oas.models.OpenAPI#setInfo() .
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: SpringCodegenTest.java From openapi-generator with Apache License 2.0 | 6 votes |
@Test public void testInitialConfigValues() throws Exception { final SpringCodegen codegen = new SpringCodegen(); codegen.processOpts(); OpenAPI openAPI = new OpenAPI(); openAPI.addServersItem(new Server().url("https://api.abcde.xy:8082/v2")); openAPI.setInfo(new Info()); codegen.preprocessOpenAPI(openAPI); Assert.assertEquals(codegen.additionalProperties().get(CodegenConstants.HIDE_GENERATION_TIMESTAMP), Boolean.FALSE); Assert.assertEquals(codegen.isHideGenerationTimestamp(), false); Assert.assertEquals(codegen.modelPackage(), "org.openapitools.model"); Assert.assertEquals(codegen.additionalProperties().get(CodegenConstants.MODEL_PACKAGE), "org.openapitools.model"); Assert.assertEquals(codegen.apiPackage(), "org.openapitools.api"); Assert.assertEquals(codegen.additionalProperties().get(CodegenConstants.API_PACKAGE), "org.openapitools.api"); Assert.assertEquals(codegen.getInvokerPackage(), "org.openapitools.api"); Assert.assertEquals(codegen.additionalProperties().get(CodegenConstants.INVOKER_PACKAGE), "org.openapitools.api"); Assert.assertEquals(codegen.getBasePackage(), "org.openapitools"); Assert.assertEquals(codegen.additionalProperties().get(SpringCodegen.BASE_PACKAGE), "org.openapitools"); Assert.assertEquals(codegen.getConfigPackage(), "org.openapitools.configuration"); Assert.assertEquals(codegen.additionalProperties().get(SpringCodegen.CONFIG_PACKAGE), "org.openapitools.configuration"); Assert.assertEquals(codegen.additionalProperties().get(SpringCodegen.SERVER_PORT), "8082"); Assert.assertEquals(codegen.additionalProperties().get(SpringCodegen.UNHANDLED_EXCEPTION_HANDLING), false); }
Example 2
Source File: TestUtils.java From openapi-generator with Apache License 2.0 | 6 votes |
public static OpenAPI createOpenAPI() { OpenAPI openAPI = new OpenAPI(); openAPI.setComponents(new Components()); openAPI.setPaths(new Paths()); final Info info = new Info(); info.setDescription("API under test"); info.setVersion("1.0.7"); info.setTitle("My title"); openAPI.setInfo(info); final Server server = new Server(); server.setUrl("https://localhost:9999/root"); openAPI.setServers(Collections.singletonList(server)); return openAPI; }
Example 3
Source File: KotlinSpringServerCodegenTest.java From openapi-generator with Apache License 2.0 | 6 votes |
@Test public void testInitialConfigValues() throws Exception { final KotlinSpringServerCodegen codegen = new KotlinSpringServerCodegen(); codegen.processOpts(); final OpenAPI openAPI = new OpenAPI(); openAPI.addServersItem(new Server().url("https://api.abcde.xy:8082/v2")); openAPI.setInfo(new Info()); codegen.preprocessOpenAPI(openAPI); Assert.assertEquals(codegen.getLibrary(), KotlinSpringServerCodegen.SPRING_BOOT); Assert.assertTrue(codegen.supportedLibraries().containsKey(KotlinSpringServerCodegen.SPRING_BOOT)); Assert.assertEquals(codegen.modelPackage(), "org.openapitools.model"); Assert.assertEquals(codegen.additionalProperties().get(CodegenConstants.MODEL_PACKAGE), "org.openapitools.model"); Assert.assertEquals(codegen.apiPackage(), "org.openapitools.api"); Assert.assertEquals(codegen.additionalProperties().get(CodegenConstants.API_PACKAGE), "org.openapitools.api"); Assert.assertEquals(codegen.getBasePackage(), "org.openapitools"); Assert.assertEquals(codegen.additionalProperties().get(KotlinSpringServerCodegen.BASE_PACKAGE), "org.openapitools"); Assert.assertEquals(codegen.getInvokerPackage(), "org.openapitools"); Assert.assertEquals(codegen.getServerPort(), "8080"); Assert.assertEquals(codegen.additionalProperties().get(KotlinSpringServerCodegen.SERVER_PORT), "8080"); }
Example 4
Source File: ApiDocControllerTest.java From api-layer with Eclipse Public License 2.0 | 6 votes |
private OpenAPI getDummyOpenApiObject() { List<Server> servers = new ArrayList<>(); servers.add(0, new Server().url("/api/v1/apicatalog")); OpenAPI openAPI = new OpenAPI(); openAPI.setPaths(new Paths()); openAPI.setTags(new ArrayList<>()); openAPI.setOpenapi("3.0.0"); openAPI.setServers(servers); Info info = new Info(); info.setTitle("Service title"); info.setDescription("Service description"); info.setVersion("1.0.0"); openAPI.setInfo(info); return openAPI; }
Example 5
Source File: AbstractApiDocServiceTest.java From api-layer with Eclipse Public License 2.0 | 6 votes |
private OpenAPI getDummyOpenApiObject(List<Server> servers) { OpenAPI openAPI = new OpenAPI(); openAPI.setPaths(new Paths()); openAPI.setTags(new ArrayList<>()); openAPI.setOpenapi("3.0.0"); openAPI.setServers(servers); Info info = new Info(); info.setTitle("API Catalog"); info.setDescription("REST API for the API Catalog service which is a component of the API Mediation Layer. Use this API to retrieve information regarding catalog dashboard tiles, tile contents and its status, API documentation and status for the registered services."); info.setVersion("1.0.0"); openAPI.setInfo(info); Tag tag = new Tag(); tag.setName("API Catalog"); tag.setDescription("Current state information"); openAPI.getTags().add(tag); openAPI.getPaths().put("/api1", new PathItem()); openAPI.getPaths().put("/api2", new PathItem()); return openAPI; }
Example 6
Source File: SwaggerConfig.java From swagger-maven-plugin with MIT License | 6 votes |
public OpenAPI createSwaggerModel() { OpenAPI spec = new OpenAPI(); servers.forEach(s -> spec.addServersItem(s.createServerModel())); if (info != null) { spec.setInfo(info.createInfoModel()); } if (descriptionFile != null) { if (spec.getInfo() == null) { spec.setInfo(new Info()); } try { spec.getInfo().setDescription(Files.readAllLines(descriptionFile.toPath()).stream().collect(Collectors.joining("\n"))); } catch (IOException e) { throw new RuntimeException("Unable to read descriptor file " + descriptionFile, e); } } return spec; }
Example 7
Source File: OpenApiObjectGenerator.java From flow with Apache License 2.0 | 6 votes |
private OpenAPI createBasicModel() { OpenAPI openAPI = new OpenAPI(); Info info = new Info(); info.setTitle(configuration.getApplicationTitle()); info.setVersion(configuration.getApplicationApiVersion()); openAPI.setInfo(info); Paths paths = new Paths(); openAPI.setPaths(paths); Server server = new Server(); server.setUrl(configuration.getServerUrl()); server.setDescription(configuration.getServerDescription()); openAPI.setServers(Collections.singletonList(server)); Components components = new Components(); SecurityScheme vaadinConnectOAuth2Scheme = new SecurityScheme() .type(SecurityScheme.Type.OAUTH2) .flows(new OAuthFlows().password(new OAuthFlow() .tokenUrl(VAADIN_CONNECT_OAUTH2_TOKEN_URL) .scopes(new Scopes()))); components.addSecuritySchemes(VAADIN_CONNECT_OAUTH2_SECURITY_SCHEME, vaadinConnectOAuth2Scheme); openAPI.components(components); return openAPI; }
Example 8
Source File: OpenAPIGenerator.java From spring-openapi with MIT License | 5 votes |
public OpenAPI generate(OpenApiGeneratorConfig openApiGeneratorConfig) { logger.info("Starting OpenAPI generation"); environment = openApiGeneratorConfig.getEnvironment(); initializeExampleInterceptor(openApiGeneratorConfig); OpenAPI openAPI = new OpenAPI(); openAPI.setComponents(createComponentsWrapper()); openAPI.setPaths(createPathsWrapper()); openAPI.setInfo(info); logger.info("OpenAPI generation done!"); return openAPI; }
Example 9
Source File: Swagger3RestDocGenerator.java From RestDoc with Apache License 2.0 | 5 votes |
private void convertInfo(RootModel rootModel, OpenAPI openApi) { var info = new Info(); info.setDescription(_config.getDescription()); info.setVersion(_config.getVersion()); info.setTitle(_config.getTitle()); openApi.setInfo(info); }
Example 10
Source File: SpringCodegenTest.java From openapi-generator with Apache License 2.0 | 5 votes |
@Test public void testAdditionalPropertiesPutForConfigValues() throws Exception { final SpringCodegen codegen = new SpringCodegen(); codegen.additionalProperties().put(CodegenConstants.HIDE_GENERATION_TIMESTAMP, "true"); codegen.additionalProperties().put(CodegenConstants.MODEL_PACKAGE, "xyz.yyyyy.mmmmm.model"); codegen.additionalProperties().put(CodegenConstants.API_PACKAGE, "xyz.yyyyy.aaaaa.api"); codegen.additionalProperties().put(CodegenConstants.INVOKER_PACKAGE, "xyz.yyyyy.iiii.invoker"); codegen.additionalProperties().put(SpringCodegen.BASE_PACKAGE, "xyz.yyyyy.bbbb.base"); codegen.additionalProperties().put(SpringCodegen.CONFIG_PACKAGE, "xyz.yyyyy.cccc.config"); codegen.additionalProperties().put(SpringCodegen.SERVER_PORT, "8088"); codegen.processOpts(); OpenAPI openAPI = new OpenAPI(); openAPI.addServersItem(new Server().url("https://api.abcde.xy:8082/v2")); openAPI.setInfo(new Info()); openAPI.getInfo().setTitle("Some test API"); codegen.preprocessOpenAPI(openAPI); Assert.assertEquals(codegen.additionalProperties().get(CodegenConstants.HIDE_GENERATION_TIMESTAMP), Boolean.TRUE); Assert.assertEquals(codegen.isHideGenerationTimestamp(), true); Assert.assertEquals(codegen.modelPackage(), "xyz.yyyyy.mmmmm.model"); Assert.assertEquals(codegen.additionalProperties().get(CodegenConstants.MODEL_PACKAGE), "xyz.yyyyy.mmmmm.model"); Assert.assertEquals(codegen.apiPackage(), "xyz.yyyyy.aaaaa.api"); Assert.assertEquals(codegen.additionalProperties().get(CodegenConstants.API_PACKAGE), "xyz.yyyyy.aaaaa.api"); Assert.assertEquals(codegen.getInvokerPackage(), "xyz.yyyyy.iiii.invoker"); Assert.assertEquals(codegen.additionalProperties().get(CodegenConstants.INVOKER_PACKAGE), "xyz.yyyyy.iiii.invoker"); Assert.assertEquals(codegen.getBasePackage(), "xyz.yyyyy.bbbb.base"); Assert.assertEquals(codegen.additionalProperties().get(SpringCodegen.BASE_PACKAGE), "xyz.yyyyy.bbbb.base"); Assert.assertEquals(codegen.getConfigPackage(), "xyz.yyyyy.cccc.config"); Assert.assertEquals(codegen.additionalProperties().get(SpringCodegen.CONFIG_PACKAGE), "xyz.yyyyy.cccc.config"); Assert.assertEquals(codegen.additionalProperties().get(SpringCodegen.TITLE), "someTest"); Assert.assertEquals(codegen.additionalProperties().get(SpringCodegen.SERVER_PORT), "8088"); }
Example 11
Source File: MCRRestV2App.java From mycore with GNU General Public License v3.0 | 5 votes |
private void setupOAS() { OpenAPI oas = new OpenAPI(); Info oasInfo = new Info(); oas.setInfo(oasInfo); oasInfo.setVersion(MCRCoreVersion.getVersion()); oasInfo.setTitle(getApplicationName()); License oasLicense = new License(); oasLicense.setName("GNU General Public License, version 3"); oasLicense.setUrl("http://www.gnu.org/licenses/gpl-3.0.txt"); oasInfo.setLicense(oasLicense); URI baseURI = URI.create(MCRFrontendUtil.getBaseURL()); Server oasServer = new Server(); oasServer.setUrl(baseURI.resolve("api").toString()); oas.addServersItem(oasServer); SwaggerConfiguration oasConfig = new SwaggerConfiguration() .openAPI(oas) .resourcePackages(Stream.of(getRestPackages()).collect(Collectors.toSet())) .ignoredRoutes( MCRConfiguration2.getString("MCR.RestAPI.V2.OpenAPI.IgnoredRoutes") .map(MCRConfiguration2::splitValue) .orElseGet(Stream::empty) .collect(Collectors.toSet())) .prettyPrint(true); try { new JaxrsOpenApiContextBuilder() .application(getApplication()) .openApiConfiguration(oasConfig) .buildContext(true); } catch (OpenApiConfigurationException e) { throw new InternalServerErrorException(e); } }
Example 12
Source File: KotlinSpringServerCodegenTest.java From openapi-generator with Apache License 2.0 | 4 votes |
@Test public void testAdditionalPropertiesPutForConfigValues() throws Exception { final KotlinSpringServerCodegen codegen = new KotlinSpringServerCodegen(); codegen.additionalProperties().put(CodegenConstants.MODEL_PACKAGE, "xyz.yyyyy.mmmmm.model"); codegen.additionalProperties().put(CodegenConstants.API_PACKAGE, "xyz.yyyyy.aaaaa.api"); codegen.additionalProperties().put(KotlinSpringServerCodegen.BASE_PACKAGE, "xyz.yyyyy.bbbb.base"); codegen.additionalProperties().put(KotlinSpringServerCodegen.SERVER_PORT, "8088"); codegen.additionalProperties().put(KotlinSpringServerCodegen.EXCEPTION_HANDLER, false); codegen.additionalProperties().put(KotlinSpringServerCodegen.GRADLE_BUILD_FILE, false); codegen.additionalProperties().put(KotlinSpringServerCodegen.SWAGGER_ANNOTATIONS, true); codegen.additionalProperties().put(KotlinSpringServerCodegen.SERVICE_INTERFACE, true); codegen.additionalProperties().put(KotlinSpringServerCodegen.SERVICE_IMPLEMENTATION, true); codegen.additionalProperties().put(KotlinSpringServerCodegen.USE_BEANVALIDATION, false); codegen.additionalProperties().put(KotlinSpringServerCodegen.REACTIVE, false); codegen.processOpts(); final OpenAPI openAPI = new OpenAPI(); openAPI.addServersItem(new Server().url("https://api.abcde.xy:8082/v2")); openAPI.setInfo(new Info()); openAPI.getInfo().setTitle("Some test API"); codegen.preprocessOpenAPI(openAPI); Assert.assertEquals(codegen.modelPackage(), "xyz.yyyyy.mmmmm.model"); Assert.assertEquals(codegen.additionalProperties().get(CodegenConstants.MODEL_PACKAGE), "xyz.yyyyy.mmmmm.model"); Assert.assertEquals(codegen.apiPackage(), "xyz.yyyyy.aaaaa.api"); Assert.assertEquals(codegen.additionalProperties().get(CodegenConstants.API_PACKAGE), "xyz.yyyyy.aaaaa.api"); Assert.assertEquals(codegen.getBasePackage(), "xyz.yyyyy.bbbb.base"); Assert.assertEquals(codegen.additionalProperties().get(KotlinSpringServerCodegen.BASE_PACKAGE), "xyz.yyyyy.bbbb.base"); Assert.assertEquals(codegen.additionalProperties().get(KotlinSpringServerCodegen.TITLE), "someTest"); Assert.assertEquals(codegen.additionalProperties().get(KotlinSpringServerCodegen.SERVER_PORT), "8088"); Assert.assertFalse(codegen.getExceptionHandler()); Assert.assertEquals(codegen.additionalProperties().get(KotlinSpringServerCodegen.EXCEPTION_HANDLER), false); Assert.assertFalse(codegen.getGradleBuildFile()); Assert.assertEquals(codegen.additionalProperties().get(KotlinSpringServerCodegen.GRADLE_BUILD_FILE), false); Assert.assertTrue(codegen.getSwaggerAnnotations()); Assert.assertEquals(codegen.additionalProperties().get(KotlinSpringServerCodegen.SWAGGER_ANNOTATIONS), true); Assert.assertTrue(codegen.getServiceInterface()); Assert.assertEquals(codegen.additionalProperties().get(KotlinSpringServerCodegen.SERVICE_INTERFACE), true); Assert.assertTrue(codegen.getServiceImplementation()); Assert.assertEquals(codegen.additionalProperties().get(KotlinSpringServerCodegen.SERVICE_IMPLEMENTATION), true); Assert.assertFalse(codegen.getUseBeanValidation()); Assert.assertEquals(codegen.additionalProperties().get(KotlinSpringServerCodegen.USE_BEANVALIDATION), false); Assert.assertFalse(codegen.isReactive()); Assert.assertEquals(codegen.additionalProperties().get(KotlinSpringServerCodegen.REACTIVE), false); }
Example 13
Source File: ManipulatorListener.java From swagger-maven-plugin with MIT License | 4 votes |
@Override public void beforeScan(Reader reader, OpenAPI swagger) { Info info = new Info(); info.setTitle("Manipulator Title"); swagger.setInfo(info); }
Example 14
Source File: OpenAPIDeserializer.java From swagger-parser with Apache License 2.0 | 4 votes |
public OpenAPI parseRoot(JsonNode node, ParseResult result, String path) { String location = ""; OpenAPI openAPI = new OpenAPI(); if (node.getNodeType().equals(JsonNodeType.OBJECT)) { ObjectNode rootNode = (ObjectNode) node; // required String value = getString("openapi", rootNode, true, location, result); // we don't even try if the version isn't there if(value == null || !value.startsWith("3.0")) { return null; } openAPI.setOpenapi(value); ObjectNode obj = getObject("info", rootNode, true, location, result); if (obj != null) { Info info = getInfo(obj, "info", result); openAPI.setInfo(info); } obj = getObject("components", rootNode, false, location, result); if (obj != null) { Components components = getComponents(obj, "components", result); openAPI.setComponents(components); this.components=components; } obj = getObject("paths", rootNode, true, location, result); if (obj != null) { Paths paths = getPaths(obj, "paths", result); openAPI.setPaths(paths); } ArrayNode array = getArray("servers", rootNode, false, location, result); if (array != null && array.size() > 0) { openAPI.setServers(getServersList(array, String.format("%s.%s", location, "servers"), result, path)); }else { Server defaultServer = new Server(); defaultServer.setUrl("/"); List<Server> servers = new ArrayList<>(); servers.add(defaultServer); openAPI.setServers(servers); } obj = getObject("externalDocs", rootNode, false, location, result); if (obj != null) { ExternalDocumentation externalDocs = getExternalDocs(obj, "externalDocs", result); openAPI.setExternalDocs(externalDocs); } array = getArray("tags", rootNode, false, location, result); if (array != null && array.size() > 0) { openAPI.setTags(getTagList(array, "tags", result)); } array = getArray("security", rootNode, false, location, result); if (array != null && array.size() > 0) { List<SecurityRequirement> securityRequirements = getSecurityRequirementsList(array, "security", result); if (securityRequirements != null && securityRequirements. size() > 0) { openAPI.setSecurity(securityRequirements); } } Map <String,Object> extensions = getExtensions(rootNode); if(extensions != null && extensions.size() > 0) { openAPI.setExtensions(extensions); } Set<String> keys = getKeys(rootNode); for(String key : keys) { if(!ROOT_KEYS.contains(key) && !key.startsWith("x-")) { result.extra(location, key, node.get(key)); } } } else { result.invalidType(location, "openapi", "object", node); result.invalid(); return null; } return openAPI; }
Example 15
Source File: OAS3Parser.java From carbon-apimgt with Apache License 2.0 | 4 votes |
/** * This method generates API definition to the given api * * @param swaggerData api * @return API definition in string format * @throws APIManagementException */ @Override public String generateAPIDefinition(SwaggerData swaggerData) throws APIManagementException { OpenAPI openAPI = new OpenAPI(); // create path if null if (openAPI.getPaths() == null) { openAPI.setPaths(new Paths()); } //Create info object Info info = new Info(); info.setTitle(swaggerData.getTitle()); if (swaggerData.getDescription() != null) { info.setDescription(swaggerData.getDescription()); } Contact contact = new Contact(); //Create contact object and map business owner info if (swaggerData.getContactName() != null) { contact.setName(swaggerData.getContactName()); } if (swaggerData.getContactEmail() != null) { contact.setEmail(swaggerData.getContactEmail()); } if (swaggerData.getContactName() != null || swaggerData.getContactEmail() != null) { //put contact object to info object info.setContact(contact); } info.setVersion(swaggerData.getVersion()); openAPI.setInfo(info); updateSwaggerSecurityDefinition(openAPI, swaggerData, "https://test.com"); updateLegacyScopesFromSwagger(openAPI, swaggerData); if (APIConstants.GRAPHQL_API.equals(swaggerData.getTransportType())) { modifyGraphQLSwagger(openAPI); } else { for (SwaggerData.Resource resource : swaggerData.getResources()) { addOrUpdatePathToSwagger(openAPI, resource); } } return Json.pretty(openAPI); }
Example 16
Source File: OpenAPIService.java From proteus with Apache License 2.0 | 2 votes |
@SuppressWarnings("rawtypes") protected void generateSpec() throws Exception { Set<Class<?>> classes = this.registeredControllers; OpenAPIExtensions.setExtensions(Collections.singletonList(new ServerParameterExtension())); OpenAPI openApi = new OpenAPI(); Info info = mapper.convertValue(openAPIConfig.getValue("info").unwrapped(), Info.class); openApi.setInfo(info); Map<String, SecurityScheme> securitySchemes = mapper.convertValue( openAPIConfig.getValue("securitySchemes").unwrapped(),new TypeReference<Map<String, SecurityScheme>>(){}); if (openApi.getComponents() == null) { openApi.setComponents(new Components()); } openApi.getComponents().setSecuritySchemes(securitySchemes); List<Server> servers = mapper.convertValue(openAPIConfig.getValue("servers").unwrapped(), new TypeReference<List<Server>>(){}); openApi.setServers(servers); SwaggerConfiguration config = new SwaggerConfiguration().resourceClasses(classes.stream().map(Class::getName).collect(Collectors.toSet())).openAPI(openApi); if(jsonViewQueryParameterName != null) { if(config.getUserDefinedOptions() == null) { config.setUserDefinedOptions(new HashMap<>()); } config.getUserDefinedOptions().put("jsonViewQueryParameterName", jsonViewQueryParameterName); } Set<String> modelConverterClasses = new HashSet<>(); modelConverterClasses.add(ServerModelResolver.class.getName()); List<String> additionalConverterClasses = openAPIConfig.getStringList("converterClasses"); modelConverterClasses.addAll(additionalConverterClasses); config.setModelConverterClassess(modelConverterClasses); OpenApiContext ctx = new GenericOpenApiContext().openApiConfiguration(config) .openApiReader(new Reader(config)) .openApiScanner(new JaxrsApplicationAndAnnotationScanner().openApiConfiguration(config)) .init(); openApi = ctx.read(); this.openApi = openApi; this.spec = writer.writeValueAsString(openApi); }