Java Code Examples for io.swagger.v3.core.util.Json#prettyPrint()

The following examples show how to use io.swagger.v3.core.util.Json#prettyPrint() . 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: ExampleBuilderTest.java    From swagger-inflector with Apache License 2.0 6 votes vote down vote up
@Test
public void testIssue127() throws Exception {
    IntegerSchema integerProperty = new IntegerSchema();
    integerProperty.setFormat(null);
    integerProperty.setExample(new Long(4321));
    Schema model = new Schema();
    model.addProperties("unboundedInteger",integerProperty);


    Map<String, Schema> definitions = new HashMap<>();
    definitions.put("Address", model);

    Example rep = ExampleBuilder.fromSchema(new Schema().$ref("Address"), definitions);

    Json.prettyPrint(rep);
    assertEqualsIgnoreLineEnding(Json.pretty(rep),
            "{\n" +
            "  \"unboundedInteger\" : 4321\n" +
            "}");
}
 
Example 2
Source File: SwaggerConverterTest.java    From raptor with Apache License 2.0 5 votes vote down vote up
@Test
    public void testGenerateApis() throws JsonProcessingException {
        SwaggerConverter swaggerConverter = new SwaggerConverter(schema);
        List<OpenAPI> convert = swaggerConverter.convert();
//        for (OpenAPI openAPI : convert) {
//            Json.prettyPrint(openAPI);
//        }


        Json.prettyPrint(convert.get(0));
    }
 
Example 3
Source File: RaptorSwaggerConverterTest.java    From raptor with Apache License 2.0 5 votes vote down vote up
@Test
    public void testGenerateApis() throws JsonProcessingException {
        SwaggerConverter swaggerConverter = new RaptorSwaggerConverter(schema);
        List<OpenAPI> convert = swaggerConverter.convert();
//        for (OpenAPI openAPI : convert) {
//            Json.prettyPrint(openAPI);
//        }


        Json.prettyPrint(convert.get(0).getPaths().get("/test"));
    }
 
Example 4
Source File: ResponseContextSerializationTest.java    From swagger-inflector with Apache License 2.0 5 votes vote down vote up
@Test
public void testHeader() {
    ResponseContext ctx = new ResponseContext()
            .header("foo", "bar");

    Json.prettyPrint(ctx);

    for (String key : ctx.getHeaders().keySet()) {
        System.out.println(key);
        System.out.println(ctx.getHeaders().get(key));
    }
}
 
Example 5
Source File: DefaultGenerator.java    From openapi-generator with Apache License 2.0 4 votes vote down vote up
@SuppressWarnings("unchecked")
private Map<String, Object> buildSupportFileBundle(List<Object> allOperations, List<Object> allModels) {

    Map<String, Object> bundle = new HashMap<>(config.additionalProperties());
    bundle.put("apiPackage", config.apiPackage());

    Map<String, Object> apis = new HashMap<>();
    apis.put("apis", allOperations);

    URL url = URLPathUtils.getServerURL(openAPI, config.serverVariableOverrides());

    bundle.put("openAPI", openAPI);
    bundle.put("basePath", basePath);
    bundle.put("basePathWithoutHost", basePathWithoutHost);
    bundle.put("scheme", URLPathUtils.getScheme(url, config));
    bundle.put("host", url.getHost());
    bundle.put("contextPath", contextPath);
    bundle.put("apiInfo", apis);
    bundle.put("models", allModels);
    bundle.put("apiFolder", config.apiPackage().replace('.', File.separatorChar));
    bundle.put("modelPackage", config.modelPackage());

    Map<String, SecurityScheme> securitySchemeMap = openAPI.getComponents() != null ? openAPI.getComponents().getSecuritySchemes() : null;
    List<CodegenSecurity> authMethods = config.fromSecurity(securitySchemeMap);
    if (authMethods != null && !authMethods.isEmpty()) {
        bundle.put("authMethods", authMethods);
        bundle.put("hasAuthMethods", true);

        if (ProcessUtils.hasOAuthMethods(authMethods)) {
            bundle.put("hasOAuthMethods", true);
            bundle.put("oauthMethods", ProcessUtils.getOAuthMethods(authMethods));
        }
        if (ProcessUtils.hasHttpBearerMethods(authMethods)) {
            bundle.put("hasHttpBearerMethods", true);
        }
        if (ProcessUtils.hasHttpSignatureMethods(authMethods)) {
            bundle.put("hasHttpSignatureMethods", true);
        }
        if (ProcessUtils.hasHttpBasicMethods(authMethods)) {
            bundle.put("hasHttpBasicMethods", true);
        }
        if (ProcessUtils.hasApiKeyMethods(authMethods)) {
            bundle.put("hasApiKeyMethods", true);
        }
    }

    List<CodegenServer> servers = config.fromServers(openAPI.getServers());
    if (servers != null && !servers.isEmpty()) {
        bundle.put("servers", servers);
        bundle.put("hasServers", true);
    }

    if (openAPI.getExternalDocs() != null) {
        bundle.put("externalDocs", openAPI.getExternalDocs());
    }

    for (int i = 0; i < allModels.size() - 1; i++) {
        HashMap<String, CodegenModel> cm = (HashMap<String, CodegenModel>) allModels.get(i);
        CodegenModel m = cm.get("model");
        m.hasMoreModels = true;
    }

    config.postProcessSupportingFileData(bundle);

    if (GlobalSettings.getProperty("debugSupportingFiles") != null) {
        LOGGER.info("############ Supporting file info ############");
        Json.prettyPrint(bundle);
    }
    return bundle;
}
 
Example 6
Source File: OpenAPIV3ParserTest.java    From swagger-parser with Apache License 2.0 4 votes vote down vote up
private OpenAPI doRelativeFileTest(String location) {
    OpenAPIV3Parser parser = new OpenAPIV3Parser();
    ParseOptions options = new ParseOptions();
    options.setResolve(true);
    SwaggerParseResult readResult = parser.readLocation(location, null, options);

    if (readResult.getMessages().size() > 0) {
        Json.prettyPrint(readResult.getMessages());
    }
    final OpenAPI openAPI = readResult.getOpenAPI();
    final PathItem path = openAPI.getPaths().get("/health");
    assertEquals(path.getClass(), PathItem.class); //we successfully converted the RefPath to a Path

    final List<Parameter> parameters = path.getParameters();
    assertParamDetails(parameters, 0, QueryParameter.class, "param1", "query");
    assertParamDetails(parameters, 1, HeaderParameter.class, "param2", "header");

    final Operation operation = path.getGet();
    final List<Parameter> operationParams = operation.getParameters();
    assertParamDetails(operationParams, 0, PathParameter.class, "param3", "path");
    assertParamDetails(operationParams, 1, HeaderParameter.class, "param4", "header");

    final Map<String, ApiResponse> responsesMap = operation.getResponses();

    assertResponse(openAPI, responsesMap, "200","application/json", "Health information from the server", "#/components/schemas/health");
    assertResponse(openAPI, responsesMap, "400","*/*", "Your request was not valid", "#/components/schemas/error");
    assertResponse(openAPI, responsesMap, "500","*/*", "An unexpected error occur during processing", "#/components/schemas/error");

    final Map<String, Schema> definitions = openAPI.getComponents().getSchemas();
    final Schema refInDefinitions = definitions.get("refInDefinitions");
    assertEquals(refInDefinitions.getDescription(), "The example model");
    expectedPropertiesInModel(refInDefinitions, "foo", "bar");

    final ArraySchema arrayModel = (ArraySchema) definitions.get("arrayModel");
    final Schema arrayModelItems = arrayModel.getItems();
    assertEquals(arrayModelItems.get$ref(), "#/components/schemas/foo");

    final Schema fooModel = definitions.get("foo");
    assertEquals(fooModel.getDescription(), "Just another model");
    expectedPropertiesInModel(fooModel, "hello", "world");

    final ComposedSchema composedCat = (ComposedSchema) definitions.get("composedCat");
    final Schema child =  composedCat.getAllOf().get(2);
    expectedPropertiesInModel(child, "huntingSkill", "prop2", "reflexes", "reflexMap");
    final ArraySchema reflexes = (ArraySchema) child.getProperties().get("reflexes");
    final Schema reflexItems = reflexes.getItems();
    assertEquals(reflexItems.get$ref(), "#/components/schemas/reflex");
    assertTrue(definitions.containsKey(reflexItems.get$ref().substring(reflexItems.get$ref().lastIndexOf("/")+1)));

    final Schema reflexMap = (Schema) child.getProperties().get("reflexMap");
    final Schema reflexMapAdditionalProperties = (Schema) reflexMap.getAdditionalProperties();
    assertEquals(reflexMapAdditionalProperties.get$ref(), "#/components/schemas/reflex");

    assertEquals(composedCat.getAllOf().size(), 3);
    assertEquals(composedCat.getAllOf().get(0).get$ref(), "#/components/schemas/pet");
    assertEquals(composedCat.getAllOf().get(1).get$ref(), "#/components/schemas/foo_2");

    return openAPI;
}