Java Code Examples for io.swagger.models.Swagger#getInfo()

The following examples show how to use io.swagger.models.Swagger#getInfo() . 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: ApexClientCodegen.java    From TypeScript-Microservices with MIT License 6 votes vote down vote up
@Override
public void preprocessSwagger(Swagger swagger) {
    Info info = swagger.getInfo();
    String calloutLabel = info.getTitle();
    additionalProperties.put("calloutLabel", calloutLabel);
    String sanitized = sanitizeName(calloutLabel);
    additionalProperties.put("calloutName", sanitized);
    supportingFiles.add(new SupportingFile("namedCredential.mustache", srcPath + "/namedCredentials",
        sanitized + ".namedCredential"
    ));

    if (additionalProperties.get(BUILD_METHOD).equals("sfdx")) {
        generateSfdxSupportingFiles();
    } else if (additionalProperties.get(BUILD_METHOD).equals("ant")) {
        generateAntSupportingFiles();
    }

}
 
Example 2
Source File: StaticHtml2Generator.java    From TypeScript-Microservices with MIT License 6 votes vote down vote up
@Override
public void preprocessSwagger(Swagger swagger) {
    super.preprocessSwagger(swagger);

    if (swagger.getInfo() != null) {
        Info info = swagger.getInfo();
        if (StringUtils.isBlank(jsProjectName) && info.getTitle() != null) {
            // when jsProjectName is not specified, generate it from info.title
            jsProjectName = sanitizeName(dashize(info.getTitle()));
        }
    }

    // default values
    if (StringUtils.isBlank(jsProjectName)) {
        jsProjectName = "swagger-js-client";
    }
    if (StringUtils.isBlank(jsModuleName)) {
        jsModuleName = camelize(underscore(jsProjectName));
    }

    additionalProperties.put("jsProjectName", jsProjectName);
    additionalProperties.put("jsModuleName", jsModuleName);

    preparHtmlForGlobalDescription(swagger);
}
 
Example 3
Source File: SwaggerDefinitionProcessorTest.java    From servicecomb-java-chassis with Apache License 2.0 6 votes vote down vote up
@Test
public void testProcess() {
  Swagger swagger = SwaggerGenerator.generate(SwaggerTestTarget.class);

  assertEquals(1, swagger.getTags().size());
  io.swagger.models.Tag tag = swagger.getTags().get(0);
  assertEquals("testTag", tag.getName());
  assertEquals("desc", tag.getDescription());
  assertEquals("testValue", tag.getExternalDocs().getDescription());
  assertEquals("testUrl", tag.getExternalDocs().getUrl());
  assertEquals("127.0.0.1", swagger.getHost());
  assertThat(swagger.getSchemes(), contains(io.swagger.models.Scheme.HTTP, io.swagger.models.Scheme.HTTPS));
  io.swagger.models.Info info = swagger.getInfo();
  assertEquals("title", info.getTitle());
  assertEquals("version", info.getVersion());
  assertEquals("desc", info.getDescription());
  assertEquals("contactName", info.getContact().getName());
  assertEquals("licenseName", info.getLicense().getName());
  assertThat(swagger.getConsumes(), Matchers.contains(MediaType.APPLICATION_JSON, MediaType.TEXT_PLAIN));
  assertThat(swagger.getProduces(), Matchers.contains(MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML));
}
 
Example 4
Source File: ServiceCombDocumentationSwaggerMapper.java    From spring-cloud-huawei with Apache License 2.0 5 votes vote down vote up
private void changeSwaggerInfo(String originalSchemaId, Swagger swagger) {
  String fullClassName = DefinitionCache.getFullClassNameBySchema(originalSchemaId);
  String xInterfaceName = genXInterfaceName(appName, serviceName, mapSchemaId(originalSchemaId));

  Info info = swagger.getInfo();
  info.setTitle(TITLE_PREFIX + fullClassName);
  info.setVendorExtension(X_JAVA_INTERFACE, xInterfaceName);
}
 
Example 5
Source File: JavaVertXServerCodegen.java    From TypeScript-Microservices with MIT License 5 votes vote down vote up
@Override
public void preprocessSwagger(Swagger swagger) {
    super.preprocessSwagger(swagger);

    // add full swagger definition in a mustache parameter
    String swaggerDef = Json.pretty(swagger);
    this.additionalProperties.put("fullSwagger", swaggerDef);

    // add server port from the swagger file, 8080 by default
    String host = swagger.getHost();
    String port = extractPortFromHost(host);
    this.additionalProperties.put("serverPort", port);

    // retrieve api version from swagger file, 1.0.0-SNAPSHOT by default
    if (swagger.getInfo() != null && swagger.getInfo().getVersion() != null) {
        artifactVersion = apiVersion = swagger.getInfo().getVersion();
    } else {
        artifactVersion = apiVersion;
    }

    /*
     * manage operation & custom serviceId because operationId field is not
     * required and may be empty
     */
    Map<String, Path> paths = swagger.getPaths();
    if (paths != null) {
        for (Entry<String, Path> entry : paths.entrySet()) {
            manageOperationNames(entry.getValue(), entry.getKey());
        }
    }
    this.additionalProperties.remove("gson");
}
 
Example 6
Source File: StaticHtmlGenerator.java    From TypeScript-Microservices with MIT License 5 votes vote down vote up
public void preprocessSwagger(Swagger swagger) {
    Info info = swagger.getInfo();
    info.setDescription(toHtml(info.getDescription()));
    info.setTitle(toHtml(info.getTitle()));
    Map<String, Model> models = swagger.getDefinitions();
    for (Model model : models.values()) {
        model.setDescription(toHtml(model.getDescription()));
        model.setTitle(toHtml(model.getTitle()));
    }
}
 
Example 7
Source File: ElixirClientCodegen.java    From TypeScript-Microservices with MIT License 5 votes vote down vote up
@Override
public void preprocessSwagger(Swagger swagger) {
     Info info = swagger.getInfo();
     if (moduleName == null) {
         if (info.getTitle() != null) {
             // default to the appName (from title field)
             setModuleName(modulized(escapeText(info.getTitle())));
         } else {
             setModuleName(defaultModuleName);
         }
    }
    additionalProperties.put("moduleName", moduleName);

    if (!additionalProperties.containsKey(CodegenConstants.PACKAGE_NAME)) {
        additionalProperties.put(CodegenConstants.PACKAGE_NAME, underscored(moduleName));
    }

    supportingFiles.add(new SupportingFile("connection.ex.mustache",
        sourceFolder(),
        "connection.ex"));

    supportingFiles.add(new SupportingFile("request_builder.ex.mustache",
        sourceFolder(),
        "request_builder.ex"));


    supportingFiles.add(new SupportingFile("deserializer.ex.mustache",
        sourceFolder(),
        "deserializer.ex"));
}
 
Example 8
Source File: BashClientCodegen.java    From TypeScript-Microservices with MIT License 5 votes vote down vote up
/**
 * Preprocess original properties from the Swagger definition where necessary.
 *
 * @param swagger [description]
 */
@Override
public void preprocessSwagger(Swagger swagger) {
    super.preprocessSwagger(swagger);

    if ("/".equals(swagger.getBasePath())) {
        swagger.setBasePath("");
    }

    if(swagger.getInfo() != null
       && swagger.getInfo().getVendorExtensions()!=null) {
      String bash_codegen_app_description
        = (String)swagger.getInfo().getVendorExtensions()
                                          .get("x-bash-codegen-description");

      if(bash_codegen_app_description != null) {

        bash_codegen_app_description
          = escapeText(bash_codegen_app_description);

        additionalProperties.put("x-bash-codegen-app-description",
          bash_codegen_app_description);

      }
    }

}
 
Example 9
Source File: SwaggerUtils.java    From servicecomb-java-chassis with Apache License 2.0 5 votes vote down vote up
public static Class<?> getInterface(Swagger swagger) {
  Info info = swagger.getInfo();
  if (info == null) {
    return null;
  }

  String name = getInterfaceName(info.getVendorExtensions());
  if (StringUtils.isEmpty(name)) {
    return null;
  }

  return ReflectUtils.getClassByName(name);
}
 
Example 10
Source File: Swagger2Customizer.java    From cxf with Apache License 2.0 5 votes vote down vote up
protected void applyDefaultVersion(Swagger data) {
    if (applyDefaultVersion && data.getInfo() != null && data.getInfo().getVersion() == null
            && beanConfig != null && beanConfig.getResourcePackage() != null) {
        Package resourcePackage = Package.getPackage(beanConfig.getResourcePackage());
        if (resourcePackage != null) {
            data.getInfo().setVersion(resourcePackage.getImplementationVersion());
        }
    }
}
 
Example 11
Source File: SwaggerInfoBuilder.java    From swagger-coverage with Apache License 2.0 4 votes vote down vote up
@Override
public SwaggerInfoBuilder configure(Swagger swagger, List<ConditionRule> rules) {
    info = swagger.getInfo();
    return this;
}
 
Example 12
Source File: ClojureClientCodegen.java    From TypeScript-Microservices with MIT License 4 votes vote down vote up
@Override
public void preprocessSwagger(Swagger swagger) {
    super.preprocessSwagger(swagger);

    if (additionalProperties.containsKey(PROJECT_NAME)) {
        projectName = ((String) additionalProperties.get(PROJECT_NAME));
    }
    if (additionalProperties.containsKey(PROJECT_DESCRIPTION)) {
        projectDescription = ((String) additionalProperties.get(PROJECT_DESCRIPTION));
    }
    if (additionalProperties.containsKey(PROJECT_VERSION)) {
        projectVersion = ((String) additionalProperties.get(PROJECT_VERSION));
    }
    if (additionalProperties.containsKey(BASE_NAMESPACE)) {
        baseNamespace = ((String) additionalProperties.get(BASE_NAMESPACE));
    }

    if (swagger.getInfo() != null) {
        Info info = swagger.getInfo();
        if (projectName == null &&  info.getTitle() != null) {
            // when projectName is not specified, generate it from info.title
            projectName = dashize(info.getTitle());
        }
        if (projectVersion == null) {
            // when projectVersion is not specified, use info.version
            projectVersion = info.getVersion();
        }
        if (projectDescription == null) {
            // when projectDescription is not specified, use info.description
            projectDescription = info.getDescription();
        }

        if (info.getContact() != null) {
            Contact contact = info.getContact();
            if (additionalProperties.get(PROJECT_URL) == null) {
                additionalProperties.put(PROJECT_URL, contact.getUrl());
            }
        }
        if (info.getLicense() != null) {
            License license = info.getLicense();
            if (additionalProperties.get(PROJECT_LICENSE_NAME) == null) {
                additionalProperties.put(PROJECT_LICENSE_NAME, license.getName());
            }
            if (additionalProperties.get(PROJECT_LICENSE_URL) == null) {
                additionalProperties.put(PROJECT_LICENSE_URL, license.getUrl());
            }
        }
    }

    // default values
    if (projectName == null) {
        projectName = "swagger-clj-client";
    }
    if (projectVersion == null) {
        projectVersion = "1.0.0";
    }
    if (projectDescription == null) {
        projectDescription = "Client library of " + projectName;
    }
    if (baseNamespace == null) {
        baseNamespace = dashize(projectName);
    }
    apiPackage = baseNamespace + ".api";

    additionalProperties.put(PROJECT_NAME, projectName);
    additionalProperties.put(PROJECT_DESCRIPTION, escapeText(projectDescription));
    additionalProperties.put(PROJECT_VERSION, projectVersion);
    additionalProperties.put(BASE_NAMESPACE, baseNamespace);
    additionalProperties.put(CodegenConstants.API_PACKAGE, apiPackage);

    final String baseNamespaceFolder = sourceFolder + File.separator + namespaceToFolder(baseNamespace);
    supportingFiles.add(new SupportingFile("project.mustache", "", "project.clj"));
    supportingFiles.add(new SupportingFile("core.mustache", baseNamespaceFolder, "core.clj"));
    supportingFiles.add(new SupportingFile("git_push.sh.mustache", "", "git_push.sh"));
    supportingFiles.add(new SupportingFile("gitignore.mustache", "", ".gitignore"));
}
 
Example 13
Source File: JavascriptClientCodegen.java    From TypeScript-Microservices with MIT License 4 votes vote down vote up
@Override
public void preprocessSwagger(Swagger swagger) {
    super.preprocessSwagger(swagger);

    if (swagger.getInfo() != null) {
        Info info = swagger.getInfo();
        if (StringUtils.isBlank(projectName) && info.getTitle() != null) {
            // when projectName is not specified, generate it from info.title
            projectName = sanitizeName(dashize(info.getTitle()));
        }
        if (StringUtils.isBlank(projectVersion)) {
            // when projectVersion is not specified, use info.version
            projectVersion = escapeUnsafeCharacters(escapeQuotationMark(info.getVersion()));
        }
        if (projectDescription == null) {
            // when projectDescription is not specified, use info.description
            projectDescription = sanitizeName(info.getDescription());
        }

        // when licenceName is not specified, use info.license
        if (additionalProperties.get(CodegenConstants.LICENSE_NAME) == null && info.getLicense() != null) {
            License license = info.getLicense();
            licenseName = license.getName();
        }
    }

    // default values
    if (StringUtils.isBlank(projectName)) {
        projectName = "swagger-js-client";
    }
    if (StringUtils.isBlank(moduleName)) {
        moduleName = camelize(underscore(projectName));
    }
    if (StringUtils.isBlank(projectVersion)) {
        projectVersion = "1.0.0";
    }
    if (projectDescription == null) {
        projectDescription = "Client library of " + projectName;
    }
    if (StringUtils.isBlank(licenseName)) {
        licenseName = "Unlicense";
    }

    additionalProperties.put(PROJECT_NAME, projectName);
    additionalProperties.put(MODULE_NAME, moduleName);
    additionalProperties.put(PROJECT_DESCRIPTION, escapeText(projectDescription));
    additionalProperties.put(PROJECT_VERSION, projectVersion);
    additionalProperties.put(CodegenConstants.LICENSE_NAME, licenseName);
    additionalProperties.put(CodegenConstants.API_PACKAGE, apiPackage);
    additionalProperties.put(CodegenConstants.INVOKER_PACKAGE, invokerPackage);
    additionalProperties.put(CodegenConstants.LOCAL_VARIABLE_PREFIX, localVariablePrefix);
    additionalProperties.put(CodegenConstants.MODEL_PACKAGE, modelPackage);
    additionalProperties.put(CodegenConstants.SOURCE_FOLDER, sourceFolder);
    additionalProperties.put(USE_PROMISES, usePromises);
    additionalProperties.put(USE_INHERITANCE, supportsInheritance);
    additionalProperties.put(EMIT_MODEL_METHODS, emitModelMethods);
    additionalProperties.put(EMIT_JS_DOC, emitJSDoc);
    additionalProperties.put(USE_ES6, useES6);

    // make api and model doc path available in mustache template
    additionalProperties.put("apiDocPath", apiDocPath);
    additionalProperties.put("modelDocPath", modelDocPath);

    String[][] supportingTemplateFiles = JAVASCRIPT_SUPPORTING_FILES;
    if (useES6) {
        supportingTemplateFiles = JAVASCRIPT_ES6_SUPPORTING_FILES;
    }

    for (String[] supportingTemplateFile :supportingTemplateFiles) {
        supportingFiles.add(new SupportingFile(supportingTemplateFile[0], "", supportingTemplateFile[1]));
    }
}
 
Example 14
Source File: TestSwaggerDefinition.java    From servicecomb-java-chassis with Apache License 2.0 4 votes vote down vote up
@SuppressWarnings("unchecked")
@Test
public void testSwaggerDefinition() {
  Swagger swagger = SwaggerGenerator.generate(SwaggerAnnotation.class);

  Assert.assertEquals(SwaggerAnnotation.class.getName(),
      swagger.getInfo().getVendorExtensions().get(SwaggerConst.EXT_JAVA_INTF));
  Assert.assertEquals("2.0", swagger.getSwagger());
  Assert.assertEquals("/base", swagger.getBasePath());
  Assert.assertEquals("host", swagger.getHost());
  Assert.assertEquals(Arrays.asList("json", "xml"), swagger.getConsumes());
  Assert.assertEquals(Arrays.asList("abc", "123"), swagger.getProduces());

  Assert.assertEquals(1, swagger.getTags().size());
  io.swagger.models.Tag tagA = swagger.getTags().get(0);
  Assert.assertEquals("tagA", tagA.getName());
  Assert.assertEquals("desc of tagA", tagA.getDescription());
  Assert.assertEquals("tagA ext docs", tagA.getExternalDocs().getDescription());
  Assert.assertEquals("url of tagA ext docs", tagA.getExternalDocs().getUrl());
  Assert.assertEquals(1, tagA.getVendorExtensions().size());

  Map<String, Object> tagValue = (Map<String, Object>) tagA.getVendorExtensions().get("x-tagA");
  Assert.assertEquals("value of tagAExt", tagValue.get("x-tagAExt"));

  io.swagger.models.Info info = swagger.getInfo();
  Assert.assertEquals("title of SwaggerAnnotation", info.getTitle());
  Assert.assertEquals("0.1", info.getVersion());
  Assert.assertEquals("termsOfService", info.getTermsOfService());
  Assert.assertEquals("description of info for SwaggerAnnotation", info.getDescription());

  Assert.assertEquals("contact", info.getContact().getName());
  Assert.assertEquals("[email protected]", info.getContact().getEmail());
  Assert.assertEquals("http://contact", info.getContact().getUrl());

  Assert.assertEquals("license ", info.getLicense().getName());
  Assert.assertEquals("http://license", info.getLicense().getUrl());

  Assert.assertEquals(2, info.getVendorExtensions().size());

  Map<String, Object> infoValue = (Map<String, Object>) info.getVendorExtensions().get("x-info");
  Assert.assertEquals("value of infoExt", infoValue.get("x-infoExt"));

  Assert.assertEquals("SwaggerAnnotation ext docs", swagger.getExternalDocs().getDescription());
  Assert.assertEquals("url of SwaggerAnnotation ext docs", swagger.getExternalDocs().getUrl());
}
 
Example 15
Source File: OAS2Parser.java    From carbon-apimgt with Apache License 2.0 4 votes vote down vote up
/**
 * This method validates the given OpenAPI definition by content
 *
 * @param apiDefinition     OpenAPI Definition content
 * @param returnJsonContent whether to return the converted json form of the OpenAPI definition
 * @return APIDefinitionValidationResponse object with validation information
 */
@Override
public APIDefinitionValidationResponse validateAPIDefinition(String apiDefinition, boolean returnJsonContent)
        throws APIManagementException {
    APIDefinitionValidationResponse validationResponse = new APIDefinitionValidationResponse();
    SwaggerParser parser = new SwaggerParser();
    SwaggerDeserializationResult parseAttemptForV2 = parser.readWithInfo(apiDefinition);
    boolean swaggerErrorFound = false;
    for (String message : parseAttemptForV2.getMessages()) {
        OASParserUtil.addErrorToValidationResponse(validationResponse, message);
        if (message.contains(APIConstants.SWAGGER_IS_MISSING_MSG)) {
            ErrorItem errorItem = new ErrorItem();
            errorItem.setErrorCode(ExceptionCodes.INVALID_OAS2_FOUND.getErrorCode());
            errorItem.setMessage(ExceptionCodes.INVALID_OAS2_FOUND.getErrorMessage());
            errorItem.setDescription(ExceptionCodes.INVALID_OAS2_FOUND.getErrorMessage());
            validationResponse.getErrorItems().add(errorItem);
            swaggerErrorFound = true;
        }
    }
    if (parseAttemptForV2.getSwagger() == null || swaggerErrorFound) {
        validationResponse.setValid(false);
    } else {
        Swagger swagger = parseAttemptForV2.getSwagger();
        Info info = swagger.getInfo();
        OASParserUtil.updateValidationResponseAsSuccess(
                validationResponse, apiDefinition, swagger.getSwagger(),
                info.getTitle(), info.getVersion(), swagger.getBasePath(), info.getDescription(),
                (swagger.getHost() == null || swagger.getHost().isEmpty()) ? null :
                        new ArrayList<String>(Arrays.asList(swagger.getHost()))
        );
        validationResponse.setParser(this);
        if (returnJsonContent) {
            if (!apiDefinition.trim().startsWith("{")) { // not a json (it is yaml)
                try {
                    JsonNode jsonNode = DeserializationUtils.readYamlTree(apiDefinition);
                    validationResponse.setJsonContent(jsonNode.toString());
                } catch (IOException e) {
                    throw new APIManagementException("Error while reading API definition yaml", e);
                }
            } else {
                validationResponse.setJsonContent(apiDefinition);
            }
        }
    }
    return validationResponse;
}
 
Example 16
Source File: ImportController.java    From restfiddle with Apache License 2.0 4 votes vote down vote up
private void swaggerToRFConverter(String projectId, String name, MultipartFile file) throws IOException {
// MultipartFile file
File tempFile = File.createTempFile("RF_SWAGGER_IMPORT", "JSON");
file.transferTo(tempFile);
Swagger swagger = new SwaggerParser().read(tempFile.getAbsolutePath());

String host = swagger.getHost();
String basePath = swagger.getBasePath();

Info info = swagger.getInfo();
String title = info.getTitle();
String description = info.getDescription();

NodeDTO folderNode = createFolder(projectId, title);
folderNode.setDescription(description);

ConversationDTO conversationDTO;

Map<String, Path> paths = swagger.getPaths();
Set<String> keySet = paths.keySet();
for (Iterator<String> iterator = keySet.iterator(); iterator.hasNext();) {
    String pathKey = iterator.next();
    Path path = paths.get(pathKey);

    Map<HttpMethod, Operation> operationMap = path.getOperationMap();
    Set<HttpMethod> operationsKeySet = operationMap.keySet();
    for (Iterator<HttpMethod> operIterator = operationsKeySet.iterator(); operIterator.hasNext();) {
	HttpMethod httpMethod = operIterator.next();
	Operation operation = operationMap.get(httpMethod);

	conversationDTO = new ConversationDTO();
	RfRequestDTO rfRequestDTO = new RfRequestDTO();
	rfRequestDTO.setApiUrl("http://" + host + basePath + pathKey);
	rfRequestDTO.setMethodType(httpMethod.name());
	operation.getParameters();
	conversationDTO.setRfRequestDTO(rfRequestDTO);
	ConversationDTO createdConversation = conversationController.create(conversationDTO);
	conversationDTO.setId(createdConversation.getId());

	String operationId = operation.getOperationId();
	String summary = operation.getSummary();
	// Request Node
	NodeDTO childNode = new NodeDTO();
	childNode.setName(operationId);
	childNode.setDescription(summary);
	childNode.setProjectId(projectId);
	childNode.setConversationDTO(conversationDTO);
	NodeDTO createdChildNode = nodeController.create(folderNode.getId(), childNode);
	System.out.println("created node : " + createdChildNode.getName());
    }
}
   }