Java Code Examples for io.swagger.v3.oas.models.OpenAPI#addServersItem()

The following examples show how to use io.swagger.v3.oas.models.OpenAPI#addServersItem() . 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 vote down vote up
@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: JavaJerseyServerCodegenTest.java    From openapi-generator with Apache License 2.0 6 votes vote down vote up
@Test
public void testInitialConfigValues() throws Exception {
    codegen.processOpts();

    OpenAPI openAPI = new OpenAPI();
    openAPI.addServersItem(new Server().url("https://api.abcde.xy:8082/v2"));
    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.additionalProperties().get(JavaJerseyServerCodegen.SERVER_PORT), "8082");
}
 
Example 3
Source File: JavaJerseyServerCodegenTest.java    From openapi-generator with Apache License 2.0 6 votes vote down vote up
@Test
public void testAdditionalPropertiesPutForConfigValues() throws Exception {
    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("serverPort", "8088");
    codegen.processOpts();

    OpenAPI openAPI = new OpenAPI();
    openAPI.addServersItem(new Server().url("https://api.abcde.xy:8082/v2"));
    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.additionalProperties().get(JavaJerseyServerCodegen.SERVER_PORT), "8088");
}
 
Example 4
Source File: AbstractJavaJAXRSServerCodegenTest.java    From openapi-generator with Apache License 2.0 6 votes vote down vote up
@Test
public void testInitialConfigValues() throws Exception {
    final AbstractJavaJAXRSServerCodegen codegen = new P_AbstractJavaJAXRSServerCodegen();
    codegen.processOpts();

    OpenAPI openAPI = new OpenAPI();
    openAPI.addServersItem(new Server().url("https://api.abcde.xy:8082/v2"));
    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.additionalProperties().get(AbstractJavaJAXRSServerCodegen.SERVER_PORT), "8082");
}
 
Example 5
Source File: AbstractJavaJAXRSServerCodegenTest.java    From openapi-generator with Apache License 2.0 6 votes vote down vote up
@Test
public void testAdditionalPropertiesPutForConfigValues() throws Exception {
    final AbstractJavaJAXRSServerCodegen codegen = new P_AbstractJavaJAXRSServerCodegen();
    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("serverPort", "8088");
    codegen.processOpts();

    OpenAPI openAPI = new OpenAPI();
    openAPI.addServersItem(new Server().url("https://api.abcde.xy:8082/v2"));
    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.additionalProperties().get(AbstractJavaJAXRSServerCodegen.SERVER_PORT), "8088");
}
 
Example 6
Source File: JavaJAXRSSpecServerCodegenTest.java    From openapi-generator with Apache License 2.0 6 votes vote down vote up
@Test
public void testInitialConfigValues() throws Exception {
    final JavaJAXRSSpecServerCodegen codegen = new JavaJAXRSSpecServerCodegen();
    codegen.processOpts();

    OpenAPI openAPI = new OpenAPI();
    openAPI.addServersItem(new Server().url("https://api.abcde.xy:8082/v2"));
    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.additionalProperties().get(JavaJAXRSSpecServerCodegen.SERVER_PORT), "8082");
    Assert.assertEquals(codegen.getOpenApiSpecFileLocation(), "src/main/openapi/openapi.yaml");
    Assert.assertEquals(codegen.additionalProperties().get(JavaJAXRSSpecServerCodegen.OPEN_API_SPEC_FILE_LOCATION), "src/main/openapi/openapi.yaml");
}
 
Example 7
Source File: URLPathUtilsTest.java    From openapi-generator with Apache License 2.0 6 votes vote down vote up
@Test
public void testSanitizeUrl() {
    String[][] testData = {
        { "https://abc1.xyz:9999/some/path", "https://abc1.xyz:9999/some/path" },
        { "HTTPS://abc2.xyz:9999/some/path", "https://abc2.xyz:9999/some/path" },
        { "http://abc3.xyz:9999/some/path", "http://abc3.xyz:9999/some/path" },
        { "HTTP://abc4.xyz:9999/some/path", "http://abc4.xyz:9999/some/path" },
        { "//abc5.xyz:9999/some/path", "http://abc5.xyz:9999/some/path" },
        { "abc6.xyz:9999/some/path", "http://abc6.xyz:9999/some/path" },
        { "localhost:9000/api", "http://localhost:9000/api" },
        { "/some/path", "http://localhost/some/path" } };

    for (String[] t:testData) {
        OpenAPI openAPI = new OpenAPI();
        openAPI.addServersItem(new Server().url(t[0]));

        Assert.assertEquals(URLPathUtils.getServerURL(openAPI, null).toString(), t[1]);
    }
}
 
Example 8
Source File: KotlinSpringServerCodegenTest.java    From openapi-generator with Apache License 2.0 6 votes vote down vote up
@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 9
Source File: SpringCodegenTest.java    From openapi-generator with Apache License 2.0 5 votes vote down vote up
@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 10
Source File: JavaJAXRSSpecServerCodegenTest.java    From openapi-generator with Apache License 2.0 5 votes vote down vote up
@Test
public void testAdditionalPropertiesPutForConfigValues() throws Exception {
    final JavaJAXRSSpecServerCodegen codegen = new JavaJAXRSSpecServerCodegen();
    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("serverPort", "8088");
    codegen.additionalProperties().put(JavaJAXRSSpecServerCodegen.OPEN_API_SPEC_FILE_LOCATION, "openapi.yml");
    codegen.processOpts();

    OpenAPI openAPI = new OpenAPI();
    openAPI.addServersItem(new Server().url("https://api.abcde.xy:8082/v2"));
    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.additionalProperties().get(AbstractJavaJAXRSServerCodegen.SERVER_PORT), "8088");
    Assert.assertEquals(codegen.getOpenApiSpecFileLocation(), "openapi.yml");
    Assert.assertEquals(codegen.additionalProperties().get(JavaJAXRSSpecServerCodegen.OPEN_API_SPEC_FILE_LOCATION), "openapi.yml");
}
 
Example 11
Source File: URLPathUtilsTest.java    From openapi-generator with Apache License 2.0 5 votes vote down vote up
@Test
public void testUrl() {
    OpenAPI openAPI = new OpenAPI();
    openAPI.addServersItem(new Server().url("https://abcdef.xyz:9999/some/path"));
    URL serverURL = URLPathUtils.getServerURL(openAPI, null);

    Assert.assertEquals(serverURL.getHost(), "abcdef.xyz");
    Assert.assertEquals(serverURL.getPort(), 9999);
    Assert.assertEquals(serverURL.getPath(), "/some/path");
    Assert.assertEquals(URLPathUtils.getScheme(serverURL, null), "https");
    Assert.assertEquals(URLPathUtils.getPort(serverURL, 8080), "9999");
    Assert.assertEquals(URLPathUtils.getPort(serverURL, "8081"), "9999");
    Assert.assertEquals(URLPathUtils.getPath(serverURL, "/abc"), "/some/path");
}
 
Example 12
Source File: ApiDocV3Service.java    From api-layer with Eclipse Public License 2.0 5 votes vote down vote up
private void updateServerUrl(OpenAPI openAPI, Server server, String basePath) {
    if (server != null) {
        server.setUrl(basePath);
        openAPI.setServers(Collections.singletonList(server));
    } else {
        openAPI.addServersItem(new Server().url(basePath));
    }
}
 
Example 13
Source File: MCRRestV2App.java    From mycore with GNU General Public License v3.0 5 votes vote down vote up
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 14
Source File: JaxRsActivatorNew.java    From pnc with Apache License 2.0 5 votes vote down vote up
private void configureSwagger() {
    OpenAPI oas = new OpenAPI();
    Info info = new Info().title("PNC")
            .description("PNC build system")
            .termsOfService("http://swagger.io/terms/")
            .license(new License().name("Apache 2.0").url("http://www.apache.org/licenses/LICENSE-2.0.html"));
    oas.info(info);
    oas.addServersItem(new Server().url("/pnc-rest-new"));

    final SecurityScheme authScheme = getAuthScheme();
    if (authScheme == null) {
        logger.warn("Not adding auth scheme to openapi definition as auth scheme could not been generated.");
    } else {
        oas.schemaRequirement(KEYCLOAK_AUTH, authScheme);
        oas.addSecurityItem(new SecurityRequirement().addList(KEYCLOAK_AUTH));
    }

    SwaggerConfiguration oasConfig = new SwaggerConfiguration().openAPI(oas);

    try {
        new JaxrsOpenApiContextBuilder().servletConfig(servletConfig)
                .application(this)
                .openApiConfiguration(oasConfig)
                .buildContext(true);
    } catch (OpenApiConfigurationException ex) {
        throw new IllegalArgumentException("Failed to setup OpenAPI configuration", ex);
    }
}
 
Example 15
Source File: JavaJAXRSCXFExtServerCodegenTest.java    From openapi-generator with Apache License 2.0 4 votes vote down vote up
@Test
public void testInitialConfigValues() throws Exception {
    codegen.processOpts();

    OpenAPI openAPI = new OpenAPI();
    openAPI.addServersItem(new Server().url("https://api.abcde.xy:8082/v2"));
    codegen.preprocessOpenAPI(openAPI);

    Map<String, Object> additionalProperties = codegen.additionalProperties();

    // Options processed by DefaultCodegen
    assertNull(additionalProperties.get(CodegenConstants.ALLOW_UNICODE_IDENTIFIERS));
    assertEquals(additionalProperties.get(CodegenConstants.API_PACKAGE), "org.openapitools.api");
    assertEquals(codegen.apiPackage(), "org.openapitools.api");
    assertNull(additionalProperties.get(CodegenConstants.DOCEXTENSION));
    assertNull(additionalProperties.get(CodegenConstants.ENSURE_UNIQUE_PARAMS));
    assertEquals(additionalProperties.get(CodegenConstants.HIDE_GENERATION_TIMESTAMP), Boolean.FALSE);
    assertEquals(codegen.isHideGenerationTimestamp(), false);
    assertEquals(additionalProperties.get(CodegenConstants.INVOKER_PACKAGE), "org.openapitools.api");
    assertEquals(codegen.getInvokerPackage(), "org.openapitools.api");
    assertNull(additionalProperties.get(CodegenConstants.MODEL_NAME_PREFIX));
    assertNull(additionalProperties.get(CodegenConstants.MODEL_NAME_SUFFIX));
    assertEquals(additionalProperties.get(CodegenConstants.MODEL_PACKAGE), "org.openapitools.model");
    assertEquals(codegen.modelPackage(), "org.openapitools.model");
    assertNull(additionalProperties.get(CodegenConstants.PREPEND_FORM_OR_BODY_PARAMETERS));
    assertNull(additionalProperties.get(CodegenConstants.REMOVE_OPERATION_ID_PREFIX));
    assertNull(additionalProperties.get(CodegenConstants.SORT_PARAMS_BY_REQUIRED_FLAG));
    assertNull(additionalProperties.get(CodegenConstants.TEMPLATE_DIR));
    // Options processed by AbstractJavaCodegen
    assertEquals(additionalProperties.get(CodegenConstants.ARTIFACT_DESCRIPTION), "OpenAPI Java");
    assertEquals(additionalProperties.get(CodegenConstants.ARTIFACT_ID), "openapi-cxf-server");
    assertEquals(additionalProperties.get(CodegenConstants.ARTIFACT_VERSION), "1.0.0");
    assertEquals(additionalProperties.get(CodegenConstants.ARTIFACT_URL),
            "https://github.com/openapitools/openapi-generator");
    assertEquals(additionalProperties.get(CodegenConstants.DEVELOPER_EMAIL), "[email protected]");
    assertEquals(additionalProperties.get(CodegenConstants.DEVELOPER_NAME), "OpenAPI-Generator Contributors");
    assertEquals(additionalProperties.get(CodegenConstants.DEVELOPER_ORGANIZATION), "OpenAPITools.org");
    assertEquals(additionalProperties.get(CodegenConstants.DEVELOPER_ORGANIZATION_URL), "http://openapitools.org");
    assertEquals(additionalProperties.get(CodegenConstants.GROUP_ID), "org.openapitools");
    assertEquals(additionalProperties.get(CodegenConstants.LICENSE_NAME), "Unlicense");
    assertEquals(additionalProperties.get(CodegenConstants.LICENSE_URL), "http://unlicense.org");
    assertEquals(additionalProperties.get(CodegenConstants.SCM_CONNECTION),
            "scm:git:[email protected]:openapitools/openapi-generator.git");
    assertEquals(additionalProperties.get(CodegenConstants.SCM_DEVELOPER_CONNECTION),
            "scm:git:[email protected]:openapitools/openapi-generator.git");
    assertEquals(additionalProperties.get(CodegenConstants.SCM_URL),
            "https://github.com/openapitools/openapi-generator");
    assertNull(additionalProperties.get(CodegenConstants.SERIALIZE_BIG_DECIMAL_AS_STRING));
    assertEquals(additionalProperties.get(CodegenConstants.SERIALIZABLE_MODEL), Boolean.FALSE);
    assertEquals(additionalProperties.get(CodegenConstants.SOURCE_FOLDER), "src/gen/java");
    assertEquals(additionalProperties.get(AbstractJavaCodegen.BOOLEAN_GETTER_PREFIX), "get");
    assertNull(additionalProperties.get(AbstractJavaCodegen.DATE_LIBRARY));
    assertEquals(additionalProperties.get(AbstractJavaCodegen.DISABLE_HTML_ESCAPING), Boolean.FALSE);
    assertEquals(additionalProperties.get(AbstractJavaCodegen.FULL_JAVA_UTIL), Boolean.FALSE);
    assertNull(additionalProperties.get(AbstractJavaCodegen.JAVA8_MODE));
    assertNull(additionalProperties.get(AbstractJavaCodegen.SUPPORT_ASYNC));
    assertEquals(additionalProperties.get(AbstractJavaCodegen.SUPPORT_JAVA6), Boolean.FALSE);
    assertEquals(additionalProperties.get(AbstractJavaCodegen.WITH_XML), false);
    // Options processed by AbstractJavaJAXRSServerCodegen
    assertNull(additionalProperties.get(CodegenConstants.IMPL_FOLDER));
    assertEquals(additionalProperties.get(BeanValidationFeatures.USE_BEANVALIDATION), Boolean.TRUE);
    assertEquals(additionalProperties.get(AbstractJavaJAXRSServerCodegen.SERVER_PORT), "8082");
    // Options processed by JavaCXFServerCodegen
    assertNull(additionalProperties.get(BeanValidationExtendedFeatures.USE_BEANVALIDATION_FEATURE));
    assertNull(additionalProperties.get(GzipFeatures.USE_GZIP_FEATURE));
    assertNull(additionalProperties.get(GzipTestFeatures.USE_GZIP_FEATURE_FOR_TESTS));
    assertNull(additionalProperties.get(JbossFeature.GENERATE_JBOSS_DEPLOYMENT_DESCRIPTOR));
    assertNull(additionalProperties.get(LoggingFeatures.USE_LOGGING_FEATURE));
    assertNull(additionalProperties.get(LoggingTestFeatures.USE_LOGGING_FEATURE_FOR_TESTS));
    assertNull(additionalProperties.get(SpringFeatures.GENERATE_SPRING_APPLICATION));
    assertNull(additionalProperties.get(SpringFeatures.GENERATE_SPRING_BOOT_APPLICATION));
    assertNull(additionalProperties.get(SpringFeatures.USE_SPRING_ANNOTATION_CONFIG));
    assertNull(additionalProperties.get(SwaggerFeatures.USE_SWAGGER_FEATURE));
    assertNull(additionalProperties.get(SwaggerUIFeatures.USE_SWAGGER_UI));
    assertNull(additionalProperties.get(UseGenericResponseFeatures.USE_GENERIC_RESPONSE));
    assertNull(additionalProperties.get(CXFServerFeatures.ADD_CONSUMES_PRODUCES_JSON));
    assertNull(additionalProperties.get(CXFServerFeatures.GENERATE_NON_SPRING_APPLICATION));
    assertNull(additionalProperties.get(CXFExtServerFeatures.GENERATE_OPERATION_BODY));
    assertNull(additionalProperties.get(CXFServerFeatures.LOAD_TEST_DATA_FROM_FILE));
    assertNull(additionalProperties.get(CXFExtServerFeatures.SUPPORT_MULTIPLE_SPRING_SERVICES));
    assertNull(additionalProperties.get(CXFExtServerFeatures.TEST_DATA_FILE));
    assertNull(additionalProperties.get(CXFExtServerFeatures.TEST_DATA_CONTROL_FILE));
    assertNull(additionalProperties.get(CXFServerFeatures.USE_ANNOTATED_BASE_PATH));
    assertNull(additionalProperties.get(CXFServerFeatures.USE_MULTIPART_FEATURE));
    assertNull(additionalProperties.get(CXFServerFeatures.USE_WADL_FEATURE));
}
 
Example 16
Source File: KotlinSpringServerCodegenTest.java    From openapi-generator with Apache License 2.0 4 votes vote down vote up
@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);
}