forked from loafle/openapi-generator-original
[ci] Update gitattributes and allow skipping docs generation for Windows CI workflows (#7273)
This commit is contained in:
parent
da84d8e3bf
commit
0e9c6dd9a8
29
.gitattributes
vendored
29
.gitattributes
vendored
@ -1 +1,28 @@
|
|||||||
**/*.mustache linguist-vendored=true
|
* text=auto
|
||||||
|
|
||||||
|
## Windows Specific stuff
|
||||||
|
*.vcproj text eol=crlf
|
||||||
|
*.bat text eol=crlf
|
||||||
|
*.cmd text eol=crlf
|
||||||
|
|
||||||
|
*.txt text eol=lf
|
||||||
|
*.yaml text eol=lf
|
||||||
|
*.yml text eol=lf
|
||||||
|
*.json text eol=lf
|
||||||
|
*.md text eol=lf
|
||||||
|
*.xml text eol=lf
|
||||||
|
gradlew text eol=lf
|
||||||
|
*.sh text eol=lf
|
||||||
|
*.properties text eol=lf
|
||||||
|
*.java text eol=lf
|
||||||
|
.gitignore text eol=lf
|
||||||
|
.gradle text eol=lf
|
||||||
|
.sbt text eol=lf
|
||||||
|
.scala text eol=lf
|
||||||
|
.ts text eol=lf
|
||||||
|
.adoc text eol=lf
|
||||||
|
.svg text eol=lf
|
||||||
|
|
||||||
|
*.mustache text eol=lf linguist-vendored=true
|
||||||
|
*.hbs text eol=lf linguist-vendored=true
|
||||||
|
*.handlebars text eol=lf linguist-vendored=true
|
||||||
|
@ -65,7 +65,10 @@ jobs:
|
|||||||
runs-on: ${{ matrix.os }}
|
runs-on: ${{ matrix.os }}
|
||||||
strategy:
|
strategy:
|
||||||
matrix:
|
matrix:
|
||||||
os: [ubuntu-latest, windows-latest]
|
os: [ubuntu-latest]
|
||||||
|
include:
|
||||||
|
- os: windows-latest
|
||||||
|
flags: --skip-docs
|
||||||
steps:
|
steps:
|
||||||
- name: Check out code
|
- name: Check out code
|
||||||
uses: actions/checkout@v2
|
uses: actions/checkout@v2
|
||||||
@ -79,4 +82,4 @@ jobs:
|
|||||||
git config core.fileMode false
|
git config core.fileMode false
|
||||||
mkdir -p modules/openapi-generator-cli/target/
|
mkdir -p modules/openapi-generator-cli/target/
|
||||||
mv artifact/openapi-generator-cli.jar modules/openapi-generator-cli/target/
|
mv artifact/openapi-generator-cli.jar modules/openapi-generator-cli/target/
|
||||||
./bin/utils/ensure-up-to-date
|
./bin/utils/ensure-up-to-date ${{ matrix.flags }}
|
||||||
|
@ -19,6 +19,13 @@ if [ $status -ne 0 ]; then
|
|||||||
exit $status
|
exit $status
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
if [[ "--skip-docs" == "${1}" ]]; then
|
||||||
|
# We export here rather than modify our iterable so that:
|
||||||
|
# - the scripts can show they ran and echo meaningfully
|
||||||
|
# - the scripts can do cleanup (if necessary) when skipped
|
||||||
|
export SKIP_EXPORT_DOCS=true
|
||||||
|
fi
|
||||||
|
|
||||||
# Some special case generators may expect to be run as a stanalone process (e.g. modifying classpath)
|
# Some special case generators may expect to be run as a stanalone process (e.g. modifying classpath)
|
||||||
# Docs should always be run, regardless of batch or operation.
|
# Docs should always be run, regardless of batch or operation.
|
||||||
declare -a always_iterate=(
|
declare -a always_iterate=(
|
||||||
|
@ -5,6 +5,11 @@ echo "# START SCRIPT: ${SCRIPT}"
|
|||||||
|
|
||||||
executable="./modules/openapi-generator-cli/target/openapi-generator-cli.jar"
|
executable="./modules/openapi-generator-cli/target/openapi-generator-cli.jar"
|
||||||
|
|
||||||
|
if [[ "true" == "${SKIP_EXPORT_DOCS}" ]]; then
|
||||||
|
echo "Skipping doc exports. Note that docs generated by Windows may break paths as they have not yet been normalized to OS-specific paths."
|
||||||
|
exit 0
|
||||||
|
fi
|
||||||
|
|
||||||
for GENERATOR in $(java -jar ${executable} list --short --include all | sed -e 's/,/\'$'\n''/g')
|
for GENERATOR in $(java -jar ${executable} list --short --include all | sed -e 's/,/\'$'\n''/g')
|
||||||
do
|
do
|
||||||
./bin/utils/export_generator.sh ${GENERATOR}
|
./bin/utils/export_generator.sh ${GENERATOR}
|
||||||
|
@ -110,9 +110,6 @@ hs_err_pid*
|
|||||||
.AppleDouble
|
.AppleDouble
|
||||||
.LSOverride
|
.LSOverride
|
||||||
|
|
||||||
# Icon must end with two \r
|
|
||||||
Icon
|
|
||||||
|
|
||||||
# Thumbnails
|
# Thumbnails
|
||||||
._*
|
._*
|
||||||
|
|
||||||
|
168
modules/openapi-generator-gradle-plugin/gradlew.bat
vendored
168
modules/openapi-generator-gradle-plugin/gradlew.bat
vendored
@ -1,84 +1,84 @@
|
|||||||
@if "%DEBUG%" == "" @echo off
|
@if "%DEBUG%" == "" @echo off
|
||||||
@rem ##########################################################################
|
@rem ##########################################################################
|
||||||
@rem
|
@rem
|
||||||
@rem Gradle startup script for Windows
|
@rem Gradle startup script for Windows
|
||||||
@rem
|
@rem
|
||||||
@rem ##########################################################################
|
@rem ##########################################################################
|
||||||
|
|
||||||
@rem Set local scope for the variables with windows NT shell
|
@rem Set local scope for the variables with windows NT shell
|
||||||
if "%OS%"=="Windows_NT" setlocal
|
if "%OS%"=="Windows_NT" setlocal
|
||||||
|
|
||||||
set DIRNAME=%~dp0
|
set DIRNAME=%~dp0
|
||||||
if "%DIRNAME%" == "" set DIRNAME=.
|
if "%DIRNAME%" == "" set DIRNAME=.
|
||||||
set APP_BASE_NAME=%~n0
|
set APP_BASE_NAME=%~n0
|
||||||
set APP_HOME=%DIRNAME%
|
set APP_HOME=%DIRNAME%
|
||||||
|
|
||||||
@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
|
@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
|
||||||
set DEFAULT_JVM_OPTS=
|
set DEFAULT_JVM_OPTS=
|
||||||
|
|
||||||
@rem Find java.exe
|
@rem Find java.exe
|
||||||
if defined JAVA_HOME goto findJavaFromJavaHome
|
if defined JAVA_HOME goto findJavaFromJavaHome
|
||||||
|
|
||||||
set JAVA_EXE=java.exe
|
set JAVA_EXE=java.exe
|
||||||
%JAVA_EXE% -version >NUL 2>&1
|
%JAVA_EXE% -version >NUL 2>&1
|
||||||
if "%ERRORLEVEL%" == "0" goto init
|
if "%ERRORLEVEL%" == "0" goto init
|
||||||
|
|
||||||
echo.
|
echo.
|
||||||
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
|
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
|
||||||
echo.
|
echo.
|
||||||
echo Please set the JAVA_HOME variable in your environment to match the
|
echo Please set the JAVA_HOME variable in your environment to match the
|
||||||
echo location of your Java installation.
|
echo location of your Java installation.
|
||||||
|
|
||||||
goto fail
|
goto fail
|
||||||
|
|
||||||
:findJavaFromJavaHome
|
:findJavaFromJavaHome
|
||||||
set JAVA_HOME=%JAVA_HOME:"=%
|
set JAVA_HOME=%JAVA_HOME:"=%
|
||||||
set JAVA_EXE=%JAVA_HOME%/bin/java.exe
|
set JAVA_EXE=%JAVA_HOME%/bin/java.exe
|
||||||
|
|
||||||
if exist "%JAVA_EXE%" goto init
|
if exist "%JAVA_EXE%" goto init
|
||||||
|
|
||||||
echo.
|
echo.
|
||||||
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
|
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
|
||||||
echo.
|
echo.
|
||||||
echo Please set the JAVA_HOME variable in your environment to match the
|
echo Please set the JAVA_HOME variable in your environment to match the
|
||||||
echo location of your Java installation.
|
echo location of your Java installation.
|
||||||
|
|
||||||
goto fail
|
goto fail
|
||||||
|
|
||||||
:init
|
:init
|
||||||
@rem Get command-line arguments, handling Windows variants
|
@rem Get command-line arguments, handling Windows variants
|
||||||
|
|
||||||
if not "%OS%" == "Windows_NT" goto win9xME_args
|
if not "%OS%" == "Windows_NT" goto win9xME_args
|
||||||
|
|
||||||
:win9xME_args
|
:win9xME_args
|
||||||
@rem Slurp the command line arguments.
|
@rem Slurp the command line arguments.
|
||||||
set CMD_LINE_ARGS=
|
set CMD_LINE_ARGS=
|
||||||
set _SKIP=2
|
set _SKIP=2
|
||||||
|
|
||||||
:win9xME_args_slurp
|
:win9xME_args_slurp
|
||||||
if "x%~1" == "x" goto execute
|
if "x%~1" == "x" goto execute
|
||||||
|
|
||||||
set CMD_LINE_ARGS=%*
|
set CMD_LINE_ARGS=%*
|
||||||
|
|
||||||
:execute
|
:execute
|
||||||
@rem Setup the command line
|
@rem Setup the command line
|
||||||
|
|
||||||
set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
|
set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
|
||||||
|
|
||||||
@rem Execute Gradle
|
@rem Execute Gradle
|
||||||
"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
|
"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
|
||||||
|
|
||||||
:end
|
:end
|
||||||
@rem End local scope for the variables with windows NT shell
|
@rem End local scope for the variables with windows NT shell
|
||||||
if "%ERRORLEVEL%"=="0" goto mainEnd
|
if "%ERRORLEVEL%"=="0" goto mainEnd
|
||||||
|
|
||||||
:fail
|
:fail
|
||||||
rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
|
rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
|
||||||
rem the _cmd.exe /c_ return code!
|
rem the _cmd.exe /c_ return code!
|
||||||
if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
|
if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
|
||||||
exit /b 1
|
exit /b 1
|
||||||
|
|
||||||
:mainEnd
|
:mainEnd
|
||||||
if "%OS%"=="Windows_NT" endlocal
|
if "%OS%"=="Windows_NT" endlocal
|
||||||
|
|
||||||
:omega
|
:omega
|
||||||
|
@ -1,100 +1,100 @@
|
|||||||
@rem
|
@rem
|
||||||
@rem Copyright 2015 the original author or authors.
|
@rem Copyright 2015 the original author or authors.
|
||||||
@rem
|
@rem
|
||||||
@rem Licensed under the Apache License, Version 2.0 (the "License");
|
@rem Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
@rem you may not use this file except in compliance with the License.
|
@rem you may not use this file except in compliance with the License.
|
||||||
@rem You may obtain a copy of the License at
|
@rem You may obtain a copy of the License at
|
||||||
@rem
|
@rem
|
||||||
@rem https://www.apache.org/licenses/LICENSE-2.0
|
@rem https://www.apache.org/licenses/LICENSE-2.0
|
||||||
@rem
|
@rem
|
||||||
@rem Unless required by applicable law or agreed to in writing, software
|
@rem Unless required by applicable law or agreed to in writing, software
|
||||||
@rem distributed under the License is distributed on an "AS IS" BASIS,
|
@rem distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
@rem See the License for the specific language governing permissions and
|
@rem See the License for the specific language governing permissions and
|
||||||
@rem limitations under the License.
|
@rem limitations under the License.
|
||||||
@rem
|
@rem
|
||||||
|
|
||||||
@if "%DEBUG%" == "" @echo off
|
@if "%DEBUG%" == "" @echo off
|
||||||
@rem ##########################################################################
|
@rem ##########################################################################
|
||||||
@rem
|
@rem
|
||||||
@rem Gradle startup script for Windows
|
@rem Gradle startup script for Windows
|
||||||
@rem
|
@rem
|
||||||
@rem ##########################################################################
|
@rem ##########################################################################
|
||||||
|
|
||||||
@rem Set local scope for the variables with windows NT shell
|
@rem Set local scope for the variables with windows NT shell
|
||||||
if "%OS%"=="Windows_NT" setlocal
|
if "%OS%"=="Windows_NT" setlocal
|
||||||
|
|
||||||
set DIRNAME=%~dp0
|
set DIRNAME=%~dp0
|
||||||
if "%DIRNAME%" == "" set DIRNAME=.
|
if "%DIRNAME%" == "" set DIRNAME=.
|
||||||
set APP_BASE_NAME=%~n0
|
set APP_BASE_NAME=%~n0
|
||||||
set APP_HOME=%DIRNAME%
|
set APP_HOME=%DIRNAME%
|
||||||
|
|
||||||
@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
|
@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
|
||||||
set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m"
|
set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m"
|
||||||
|
|
||||||
@rem Find java.exe
|
@rem Find java.exe
|
||||||
if defined JAVA_HOME goto findJavaFromJavaHome
|
if defined JAVA_HOME goto findJavaFromJavaHome
|
||||||
|
|
||||||
set JAVA_EXE=java.exe
|
set JAVA_EXE=java.exe
|
||||||
%JAVA_EXE% -version >NUL 2>&1
|
%JAVA_EXE% -version >NUL 2>&1
|
||||||
if "%ERRORLEVEL%" == "0" goto init
|
if "%ERRORLEVEL%" == "0" goto init
|
||||||
|
|
||||||
echo.
|
echo.
|
||||||
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
|
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
|
||||||
echo.
|
echo.
|
||||||
echo Please set the JAVA_HOME variable in your environment to match the
|
echo Please set the JAVA_HOME variable in your environment to match the
|
||||||
echo location of your Java installation.
|
echo location of your Java installation.
|
||||||
|
|
||||||
goto fail
|
goto fail
|
||||||
|
|
||||||
:findJavaFromJavaHome
|
:findJavaFromJavaHome
|
||||||
set JAVA_HOME=%JAVA_HOME:"=%
|
set JAVA_HOME=%JAVA_HOME:"=%
|
||||||
set JAVA_EXE=%JAVA_HOME%/bin/java.exe
|
set JAVA_EXE=%JAVA_HOME%/bin/java.exe
|
||||||
|
|
||||||
if exist "%JAVA_EXE%" goto init
|
if exist "%JAVA_EXE%" goto init
|
||||||
|
|
||||||
echo.
|
echo.
|
||||||
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
|
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
|
||||||
echo.
|
echo.
|
||||||
echo Please set the JAVA_HOME variable in your environment to match the
|
echo Please set the JAVA_HOME variable in your environment to match the
|
||||||
echo location of your Java installation.
|
echo location of your Java installation.
|
||||||
|
|
||||||
goto fail
|
goto fail
|
||||||
|
|
||||||
:init
|
:init
|
||||||
@rem Get command-line arguments, handling Windows variants
|
@rem Get command-line arguments, handling Windows variants
|
||||||
|
|
||||||
if not "%OS%" == "Windows_NT" goto win9xME_args
|
if not "%OS%" == "Windows_NT" goto win9xME_args
|
||||||
|
|
||||||
:win9xME_args
|
:win9xME_args
|
||||||
@rem Slurp the command line arguments.
|
@rem Slurp the command line arguments.
|
||||||
set CMD_LINE_ARGS=
|
set CMD_LINE_ARGS=
|
||||||
set _SKIP=2
|
set _SKIP=2
|
||||||
|
|
||||||
:win9xME_args_slurp
|
:win9xME_args_slurp
|
||||||
if "x%~1" == "x" goto execute
|
if "x%~1" == "x" goto execute
|
||||||
|
|
||||||
set CMD_LINE_ARGS=%*
|
set CMD_LINE_ARGS=%*
|
||||||
|
|
||||||
:execute
|
:execute
|
||||||
@rem Setup the command line
|
@rem Setup the command line
|
||||||
|
|
||||||
set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
|
set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
|
||||||
|
|
||||||
@rem Execute Gradle
|
@rem Execute Gradle
|
||||||
"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
|
"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
|
||||||
|
|
||||||
:end
|
:end
|
||||||
@rem End local scope for the variables with windows NT shell
|
@rem End local scope for the variables with windows NT shell
|
||||||
if "%ERRORLEVEL%"=="0" goto mainEnd
|
if "%ERRORLEVEL%"=="0" goto mainEnd
|
||||||
|
|
||||||
:fail
|
:fail
|
||||||
rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
|
rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
|
||||||
rem the _cmd.exe /c_ return code!
|
rem the _cmd.exe /c_ return code!
|
||||||
if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
|
if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
|
||||||
exit /b 1
|
exit /b 1
|
||||||
|
|
||||||
:mainEnd
|
:mainEnd
|
||||||
if "%OS%"=="Windows_NT" endlocal
|
if "%OS%"=="Windows_NT" endlocal
|
||||||
|
|
||||||
:omega
|
:omega
|
||||||
|
@ -1352,7 +1352,9 @@ public class DefaultGenerator implements Generator {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
String relativeMeta = METADATA_DIR + File.separator + "VERSION";
|
// NOTE: Don't use File.separator here as we write linux-style paths to FILES, and File.separator will
|
||||||
|
// result in incorrect match on Windows machines.
|
||||||
|
String relativeMeta = METADATA_DIR + "/VERSION";
|
||||||
filesToSort.sort(PathFileComparator.PATH_COMPARATOR);
|
filesToSort.sort(PathFileComparator.PATH_COMPARATOR);
|
||||||
filesToSort.forEach(f -> {
|
filesToSort.forEach(f -> {
|
||||||
String tmp = outDir.toPath().relativize(f.toPath()).normalize().toString();
|
String tmp = outDir.toPath().relativize(f.toPath()).normalize().toString();
|
||||||
|
@ -1,152 +1,152 @@
|
|||||||
package org.openapitools.codegen.asciidoc;
|
package org.openapitools.codegen.asciidoc;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.nio.charset.StandardCharsets;
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.nio.file.Files;
|
import java.nio.file.Files;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.TreeMap;
|
import java.util.TreeMap;
|
||||||
|
|
||||||
import org.apache.commons.io.FileUtils;
|
import org.apache.commons.io.FileUtils;
|
||||||
import org.openapitools.codegen.ClientOptInput;
|
import org.openapitools.codegen.ClientOptInput;
|
||||||
import org.openapitools.codegen.CodegenConfig;
|
import org.openapitools.codegen.CodegenConfig;
|
||||||
import org.openapitools.codegen.DefaultGenerator;
|
import org.openapitools.codegen.DefaultGenerator;
|
||||||
import org.openapitools.codegen.MockDefaultGenerator;
|
import org.openapitools.codegen.MockDefaultGenerator;
|
||||||
import org.openapitools.codegen.TestUtils;
|
import org.openapitools.codegen.TestUtils;
|
||||||
import org.openapitools.codegen.config.CodegenConfigurator;
|
import org.openapitools.codegen.config.CodegenConfigurator;
|
||||||
import org.openapitools.codegen.languages.AsciidocDocumentationCodegen;
|
import org.openapitools.codegen.languages.AsciidocDocumentationCodegen;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
import org.testng.Assert;
|
import org.testng.Assert;
|
||||||
import org.testng.annotations.Test;
|
import org.testng.annotations.Test;
|
||||||
|
|
||||||
import io.swagger.v3.oas.models.OpenAPI;
|
import io.swagger.v3.oas.models.OpenAPI;
|
||||||
|
|
||||||
/** unit test asciidoc markup generation against ping.yaml openapi spec. */
|
/** unit test asciidoc markup generation against ping.yaml openapi spec. */
|
||||||
public class AsciidocGeneratorTest {
|
public class AsciidocGeneratorTest {
|
||||||
|
|
||||||
private static final Logger LOGGER = LoggerFactory.getLogger(AsciidocGeneratorTest.class);
|
private static final Logger LOGGER = LoggerFactory.getLogger(AsciidocGeneratorTest.class);
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testPingSpecTitle() throws Exception {
|
public void testPingSpecTitle() throws Exception {
|
||||||
final OpenAPI openAPI = TestUtils.parseFlattenSpec("src/test/resources/3_0/ping.yaml");
|
final OpenAPI openAPI = TestUtils.parseFlattenSpec("src/test/resources/3_0/ping.yaml");
|
||||||
|
|
||||||
AsciidocDocumentationCodegen codeGen = new AsciidocDocumentationCodegen();
|
AsciidocDocumentationCodegen codeGen = new AsciidocDocumentationCodegen();
|
||||||
codeGen.preprocessOpenAPI(openAPI);
|
codeGen.preprocessOpenAPI(openAPI);
|
||||||
|
|
||||||
Assert.assertEquals(openAPI.getInfo().getTitle(), "ping test");
|
Assert.assertEquals(openAPI.getInfo().getTitle(), "ping test");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testGenerateIndexAsciidocMarkupFileWithAsciidocGenerator() throws Exception {
|
public void testGenerateIndexAsciidocMarkupFileWithAsciidocGenerator() throws Exception {
|
||||||
|
|
||||||
File output = Files.createTempDirectory("test").toFile();
|
File output = Files.createTempDirectory("test").toFile();
|
||||||
|
|
||||||
final CodegenConfigurator configurator = new CodegenConfigurator().setGeneratorName("asciidoc")
|
final CodegenConfigurator configurator = new CodegenConfigurator().setGeneratorName("asciidoc")
|
||||||
.setInputSpec("src/test/resources/3_0/ping.yaml").setOutputDir(output.getAbsolutePath())
|
.setInputSpec("src/test/resources/3_0/ping.yaml").setOutputDir(output.getAbsolutePath())
|
||||||
.addAdditionalProperty(AsciidocDocumentationCodegen.SNIPPET_DIR, "MY-SNIPPET-DIR")
|
.addAdditionalProperty(AsciidocDocumentationCodegen.SNIPPET_DIR, "MY-SNIPPET-DIR")
|
||||||
.addAdditionalProperty(AsciidocDocumentationCodegen.SPEC_DIR, "MY-SPEC-DIR");
|
.addAdditionalProperty(AsciidocDocumentationCodegen.SPEC_DIR, "MY-SPEC-DIR");
|
||||||
|
|
||||||
final ClientOptInput clientOptInput = configurator.toClientOptInput();
|
final ClientOptInput clientOptInput = configurator.toClientOptInput();
|
||||||
DefaultGenerator generator = new DefaultGenerator();
|
DefaultGenerator generator = new DefaultGenerator();
|
||||||
generator.setGenerateMetadata(false);
|
generator.setGenerateMetadata(false);
|
||||||
List<File> generatedFiles = generator.opts(clientOptInput).generate();
|
List<File> generatedFiles = generator.opts(clientOptInput).generate();
|
||||||
TestUtils.ensureContainsFile(generatedFiles, output, "index.adoc");
|
TestUtils.ensureContainsFile(generatedFiles, output, "index.adoc");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testGenerateIndexAsciidocMarkupContent() throws Exception {
|
public void testGenerateIndexAsciidocMarkupContent() throws Exception {
|
||||||
final File output = Files.createTempDirectory("test").toFile();
|
final File output = Files.createTempDirectory("test").toFile();
|
||||||
output.mkdirs();
|
output.mkdirs();
|
||||||
output.deleteOnExit();
|
output.deleteOnExit();
|
||||||
|
|
||||||
final OpenAPI openAPI = TestUtils.parseFlattenSpec("src/test/resources/3_0/ping.yaml");
|
final OpenAPI openAPI = TestUtils.parseFlattenSpec("src/test/resources/3_0/ping.yaml");
|
||||||
CodegenConfig codegenConfig = new AsciidocDocumentationCodegen();
|
CodegenConfig codegenConfig = new AsciidocDocumentationCodegen();
|
||||||
codegenConfig.setOutputDir(output.getAbsolutePath());
|
codegenConfig.setOutputDir(output.getAbsolutePath());
|
||||||
ClientOptInput clientOptInput = new ClientOptInput().openAPI(openAPI).config(codegenConfig);
|
ClientOptInput clientOptInput = new ClientOptInput().openAPI(openAPI).config(codegenConfig);
|
||||||
|
|
||||||
DefaultGenerator generator = new DefaultGenerator();
|
DefaultGenerator generator = new DefaultGenerator();
|
||||||
List<File> files = generator.opts(clientOptInput).generate();
|
List<File> files = generator.opts(clientOptInput).generate();
|
||||||
boolean markupFileGenerated = false;
|
boolean markupFileGenerated = false;
|
||||||
for (File file : files) {
|
for (File file : files) {
|
||||||
if (file.getName().equals("index.adoc")) {
|
if (file.getName().equals("index.adoc")) {
|
||||||
markupFileGenerated = true;
|
markupFileGenerated = true;
|
||||||
String markupContent = FileUtils.readFileToString(file, StandardCharsets.UTF_8);
|
String markupContent = FileUtils.readFileToString(file, StandardCharsets.UTF_8);
|
||||||
// check on some basic asciidoc markup content
|
// check on some basic asciidoc markup content
|
||||||
Assert.assertTrue(markupContent.contains("= ping test"),
|
Assert.assertTrue(markupContent.contains("= ping test"),
|
||||||
"expected = header in: " + markupContent.substring(0, 50));
|
"expected = header in: " + markupContent.substring(0, 50));
|
||||||
Assert.assertTrue(markupContent.contains(":toc: "),
|
Assert.assertTrue(markupContent.contains(":toc: "),
|
||||||
"expected = :toc: " + markupContent.substring(0, 50));
|
"expected = :toc: " + markupContent.substring(0, 50));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Assert.assertTrue(markupFileGenerated, "Default api file is not generated!");
|
Assert.assertTrue(markupFileGenerated, "Default api file is not generated!");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testAdditionalDirectoriesGeneratedIntoHeaderAttributes() throws Exception {
|
public void testAdditionalDirectoriesGeneratedIntoHeaderAttributes() throws Exception {
|
||||||
File output = Files.createTempDirectory("test").toFile();
|
File output = Files.createTempDirectory("test").toFile();
|
||||||
|
|
||||||
LOGGER.info("test: generating sample markup " + output.getAbsolutePath());
|
LOGGER.info("test: generating sample markup " + output.getAbsolutePath());
|
||||||
|
|
||||||
Map<String, Object> props = new TreeMap<String, Object>();
|
Map<String, Object> props = new TreeMap<String, Object>();
|
||||||
props.put("specDir", "spec");
|
props.put("specDir", "spec");
|
||||||
|
|
||||||
final CodegenConfigurator configurator = new CodegenConfigurator().setGeneratorName("asciidoc")
|
final CodegenConfigurator configurator = new CodegenConfigurator().setGeneratorName("asciidoc")
|
||||||
.setInputSpec("src/test/resources/3_0/ping.yaml").setOutputDir(output.getAbsolutePath())
|
.setInputSpec("src/test/resources/3_0/ping.yaml").setOutputDir(output.getAbsolutePath())
|
||||||
.addAdditionalProperty(AsciidocDocumentationCodegen.SPEC_DIR, "SPEC-DIR")
|
.addAdditionalProperty(AsciidocDocumentationCodegen.SPEC_DIR, "SPEC-DIR")
|
||||||
.addAdditionalProperty(AsciidocDocumentationCodegen.SNIPPET_DIR, "MY/SNIPPET/DIR");
|
.addAdditionalProperty(AsciidocDocumentationCodegen.SNIPPET_DIR, "MY/SNIPPET/DIR");
|
||||||
|
|
||||||
DefaultGenerator generator = new DefaultGenerator();
|
DefaultGenerator generator = new DefaultGenerator();
|
||||||
List<File> files = generator.opts(configurator.toClientOptInput()).generate();
|
List<File> files = generator.opts(configurator.toClientOptInput()).generate();
|
||||||
boolean markupFileGenerated = false;
|
boolean markupFileGenerated = false;
|
||||||
for (File file : files) {
|
for (File file : files) {
|
||||||
if (file.getName().equals("index.adoc")) {
|
if (file.getName().equals("index.adoc")) {
|
||||||
markupFileGenerated = true;
|
markupFileGenerated = true;
|
||||||
String markupContent = FileUtils.readFileToString(file, StandardCharsets.UTF_8);
|
String markupContent = FileUtils.readFileToString(file, StandardCharsets.UTF_8);
|
||||||
Assert.assertTrue(markupContent.contains(":specDir: SPEC-DIR"),
|
Assert.assertTrue(markupContent.contains(":specDir: SPEC-DIR"),
|
||||||
"expected :specDir: in: " + markupContent.substring(0, 250));
|
"expected :specDir: in: " + markupContent.substring(0, 250));
|
||||||
Assert.assertTrue(markupContent.contains(":snippetDir: MY/SNIPPET/DIR"),
|
Assert.assertTrue(markupContent.contains(":snippetDir: MY/SNIPPET/DIR"),
|
||||||
"expected :snippetDir: in: " + markupContent.substring(0, 250));
|
"expected :snippetDir: in: " + markupContent.substring(0, 250));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Assert.assertTrue(markupFileGenerated, "index.adoc is not generated!");
|
Assert.assertTrue(markupFileGenerated, "index.adoc is not generated!");
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testHeaderAttributesFlagRemovesAttributesFromMarkupHeaderSection() throws Exception {
|
public void testHeaderAttributesFlagRemovesAttributesFromMarkupHeaderSection() throws Exception {
|
||||||
File output = Files.createTempDirectory("test").toFile();
|
File output = Files.createTempDirectory("test").toFile();
|
||||||
|
|
||||||
LOGGER.info("test: generating sample markup " + output.getAbsolutePath());
|
LOGGER.info("test: generating sample markup " + output.getAbsolutePath());
|
||||||
|
|
||||||
Map<String, Object> props = new TreeMap<String, Object>();
|
Map<String, Object> props = new TreeMap<String, Object>();
|
||||||
props.put("specDir", "spec");
|
props.put("specDir", "spec");
|
||||||
|
|
||||||
final CodegenConfigurator configurator = new CodegenConfigurator()
|
final CodegenConfigurator configurator = new CodegenConfigurator()
|
||||||
.setGeneratorName("asciidoc")
|
.setGeneratorName("asciidoc")
|
||||||
.setInputSpec("src/test/resources/3_0/ping.yaml")
|
.setInputSpec("src/test/resources/3_0/ping.yaml")
|
||||||
.setOutputDir(output.getAbsolutePath())
|
.setOutputDir(output.getAbsolutePath())
|
||||||
.addAdditionalProperty(AsciidocDocumentationCodegen.HEADER_ATTRIBUTES_FLAG, "false") // option avoids generation of attributes
|
.addAdditionalProperty(AsciidocDocumentationCodegen.HEADER_ATTRIBUTES_FLAG, "false") // option avoids generation of attributes
|
||||||
.addAdditionalProperty(AsciidocDocumentationCodegen.SPEC_DIR, "SPEC-DIR")
|
.addAdditionalProperty(AsciidocDocumentationCodegen.SPEC_DIR, "SPEC-DIR")
|
||||||
.addAdditionalProperty(AsciidocDocumentationCodegen.SNIPPET_DIR, "MY/SNIPPET/DIR");
|
.addAdditionalProperty(AsciidocDocumentationCodegen.SNIPPET_DIR, "MY/SNIPPET/DIR");
|
||||||
|
|
||||||
DefaultGenerator generator = new DefaultGenerator();
|
DefaultGenerator generator = new DefaultGenerator();
|
||||||
boolean markupFileGenerated = false;
|
boolean markupFileGenerated = false;
|
||||||
List<File> files = generator.opts(configurator.toClientOptInput()).generate();
|
List<File> files = generator.opts(configurator.toClientOptInput()).generate();
|
||||||
for (File file : files) {
|
for (File file : files) {
|
||||||
if (file.getName().equals("index.adoc")) {
|
if (file.getName().equals("index.adoc")) {
|
||||||
markupFileGenerated = true;
|
markupFileGenerated = true;
|
||||||
String markupContent = FileUtils.readFileToString(file, StandardCharsets.UTF_8);
|
String markupContent = FileUtils.readFileToString(file, StandardCharsets.UTF_8);
|
||||||
Assert.assertFalse(markupContent.contains(":specDir: SPEC-DIR"),
|
Assert.assertFalse(markupContent.contains(":specDir: SPEC-DIR"),
|
||||||
"not expected :specDir: in: " + markupContent.substring(0, 250));
|
"not expected :specDir: in: " + markupContent.substring(0, 250));
|
||||||
Assert.assertFalse(markupContent.contains(":snippetDir: MY/SNIPPET/DIR"),
|
Assert.assertFalse(markupContent.contains(":snippetDir: MY/SNIPPET/DIR"),
|
||||||
"not expected :snippetDir: in: " + markupContent.substring(0, 250));
|
"not expected :snippetDir: in: " + markupContent.substring(0, 250));
|
||||||
Assert.assertFalse(markupContent.contains(":toc:"),
|
Assert.assertFalse(markupContent.contains(":toc:"),
|
||||||
"not expected :toc: in: " + markupContent.substring(0, 250)); // typical attributes not found in markup.
|
"not expected :toc: in: " + markupContent.substring(0, 250)); // typical attributes not found in markup.
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Assert.assertTrue(markupFileGenerated, "index.adoc is not generated!");
|
Assert.assertTrue(markupFileGenerated, "index.adoc is not generated!");
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1,47 +1,47 @@
|
|||||||
package org.openapitools.codegen.asciidoc;
|
package org.openapitools.codegen.asciidoc;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import org.mockito.MockitoAnnotations;
|
import org.mockito.MockitoAnnotations;
|
||||||
import org.openapitools.codegen.languages.AsciidocDocumentationCodegen;
|
import org.openapitools.codegen.languages.AsciidocDocumentationCodegen;
|
||||||
import org.openapitools.codegen.templating.mustache.LambdaTest;
|
import org.openapitools.codegen.templating.mustache.LambdaTest;
|
||||||
import org.testng.annotations.BeforeMethod;
|
import org.testng.annotations.BeforeMethod;
|
||||||
import org.testng.annotations.Test;
|
import org.testng.annotations.Test;
|
||||||
|
|
||||||
import org.testng.Assert;
|
import org.testng.Assert;
|
||||||
|
|
||||||
public class LinkMarkupFilterTest extends LambdaTest {
|
public class LinkMarkupFilterTest extends LambdaTest {
|
||||||
|
|
||||||
@BeforeMethod
|
@BeforeMethod
|
||||||
public void setup() {
|
public void setup() {
|
||||||
MockitoAnnotations.initMocks(this);
|
MockitoAnnotations.initMocks(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testLinkMarkupFilterDoesNotLinkMissingFile() {
|
public void testLinkMarkupFilterDoesNotLinkMissingFile() {
|
||||||
|
|
||||||
final AsciidocDocumentationCodegen generator = new AsciidocDocumentationCodegen();
|
final AsciidocDocumentationCodegen generator = new AsciidocDocumentationCodegen();
|
||||||
final Map<String, Object> ctx = context("link", generator.new LinkMarkupLambda("DOES_NOT_EXIST"));
|
final Map<String, Object> ctx = context("link", generator.new LinkMarkupLambda("DOES_NOT_EXIST"));
|
||||||
|
|
||||||
final String result = execute("{{#link}}not.an.existing.file.adoc{{/link}}", ctx);
|
final String result = execute("{{#link}}not.an.existing.file.adoc{{/link}}", ctx);
|
||||||
Assert.assertTrue(result.contains("// file not found, no"), "unexpected filtered: " + result);
|
Assert.assertTrue(result.contains("// file not found, no"), "unexpected filtered: " + result);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testLinkMarkupFilterLinksFoundFileOk() throws IOException {
|
public void testLinkMarkupFilterLinksFoundFileOk() throws IOException {
|
||||||
|
|
||||||
File tempFile = File.createTempFile("LinkMarkupFilterTestDummyfile", ".adoc");
|
File tempFile = File.createTempFile("LinkMarkupFilterTestDummyfile", ".adoc");
|
||||||
tempFile.deleteOnExit();
|
tempFile.deleteOnExit();
|
||||||
|
|
||||||
final AsciidocDocumentationCodegen generator = new AsciidocDocumentationCodegen();
|
final AsciidocDocumentationCodegen generator = new AsciidocDocumentationCodegen();
|
||||||
final Map<String, Object> ctx = context("linkIntoMarkup", generator.new LinkMarkupLambda(tempFile.getParent()));
|
final Map<String, Object> ctx = context("linkIntoMarkup", generator.new LinkMarkupLambda(tempFile.getParent()));
|
||||||
|
|
||||||
final String result = execute("{{#linkIntoMarkup}}my link text, " + tempFile.getName() + "{{/linkIntoMarkup}}",
|
final String result = execute("{{#linkIntoMarkup}}my link text, " + tempFile.getName() + "{{/linkIntoMarkup}}",
|
||||||
ctx);
|
ctx);
|
||||||
Assert.assertTrue(result.contains("link:"), "unexpected filtered: " + result);
|
Assert.assertTrue(result.contains("link:"), "unexpected filtered: " + result);
|
||||||
Assert.assertTrue(result.contains(tempFile.getName() + "[]"), "unexpected filtered: " + result);
|
Assert.assertTrue(result.contains(tempFile.getName() + "[]"), "unexpected filtered: " + result);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1,314 +1,314 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2018 OpenAPI-Generator Contributors (https://openapi-generator.tech)
|
* Copyright 2018 OpenAPI-Generator Contributors (https://openapi-generator.tech)
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
* You may obtain a copy of the License at
|
* You may obtain a copy of the License at
|
||||||
*
|
*
|
||||||
* https://www.apache.org/licenses/LICENSE-2.0
|
* https://www.apache.org/licenses/LICENSE-2.0
|
||||||
*
|
*
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
* See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package org.openapitools.codegen.mysql;
|
package org.openapitools.codegen.mysql;
|
||||||
|
|
||||||
import org.openapitools.codegen.languages.MysqlSchemaCodegen;
|
import org.openapitools.codegen.languages.MysqlSchemaCodegen;
|
||||||
import org.testng.Assert;
|
import org.testng.Assert;
|
||||||
import org.testng.annotations.Test;
|
import org.testng.annotations.Test;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
public class MysqlSchemaCodegenTest {
|
public class MysqlSchemaCodegenTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testGetMysqlMatchedIntegerDataType() {
|
public void testGetMysqlMatchedIntegerDataType() {
|
||||||
final MysqlSchemaCodegen codegen = new MysqlSchemaCodegen();
|
final MysqlSchemaCodegen codegen = new MysqlSchemaCodegen();
|
||||||
Assert.assertSame(codegen.getMysqlMatchedIntegerDataType(null, null, null), "INT");
|
Assert.assertSame(codegen.getMysqlMatchedIntegerDataType(null, null, null), "INT");
|
||||||
|
|
||||||
Assert.assertSame(codegen.getMysqlMatchedIntegerDataType(-128L, 127L, false), "TINYINT");
|
Assert.assertSame(codegen.getMysqlMatchedIntegerDataType(-128L, 127L, false), "TINYINT");
|
||||||
Assert.assertSame(codegen.getMysqlMatchedIntegerDataType(0L, 255L, true), "TINYINT");
|
Assert.assertSame(codegen.getMysqlMatchedIntegerDataType(0L, 255L, true), "TINYINT");
|
||||||
|
|
||||||
Assert.assertSame(codegen.getMysqlMatchedIntegerDataType(500L, 100L, null), "SMALLINT");
|
Assert.assertSame(codegen.getMysqlMatchedIntegerDataType(500L, 100L, null), "SMALLINT");
|
||||||
Assert.assertSame(codegen.getMysqlMatchedIntegerDataType(500L, 100L, true), "SMALLINT");
|
Assert.assertSame(codegen.getMysqlMatchedIntegerDataType(500L, 100L, true), "SMALLINT");
|
||||||
Assert.assertSame(codegen.getMysqlMatchedIntegerDataType(500L, 100L, false), "SMALLINT");
|
Assert.assertSame(codegen.getMysqlMatchedIntegerDataType(500L, 100L, false), "SMALLINT");
|
||||||
Assert.assertSame(codegen.getMysqlMatchedIntegerDataType(-32768L, 32767L, false), "SMALLINT");
|
Assert.assertSame(codegen.getMysqlMatchedIntegerDataType(-32768L, 32767L, false), "SMALLINT");
|
||||||
Assert.assertSame(codegen.getMysqlMatchedIntegerDataType(0L, 65535L, true), "SMALLINT");
|
Assert.assertSame(codegen.getMysqlMatchedIntegerDataType(0L, 65535L, true), "SMALLINT");
|
||||||
|
|
||||||
Assert.assertSame(codegen.getMysqlMatchedIntegerDataType(-8388608L, 8388607L, false), "MEDIUMINT");
|
Assert.assertSame(codegen.getMysqlMatchedIntegerDataType(-8388608L, 8388607L, false), "MEDIUMINT");
|
||||||
Assert.assertSame(codegen.getMysqlMatchedIntegerDataType(0L, 16777215L, true), "MEDIUMINT");
|
Assert.assertSame(codegen.getMysqlMatchedIntegerDataType(0L, 16777215L, true), "MEDIUMINT");
|
||||||
|
|
||||||
Assert.assertSame(codegen.getMysqlMatchedIntegerDataType(-2147483648L, 2147483647L, false), "INT");
|
Assert.assertSame(codegen.getMysqlMatchedIntegerDataType(-2147483648L, 2147483647L, false), "INT");
|
||||||
Assert.assertSame(codegen.getMysqlMatchedIntegerDataType(Long.parseLong(String.valueOf(Integer.MIN_VALUE)), Long.parseLong(String.valueOf(Integer.MAX_VALUE)), false), "INT");
|
Assert.assertSame(codegen.getMysqlMatchedIntegerDataType(Long.parseLong(String.valueOf(Integer.MIN_VALUE)), Long.parseLong(String.valueOf(Integer.MAX_VALUE)), false), "INT");
|
||||||
Assert.assertSame(codegen.getMysqlMatchedIntegerDataType(0L, 4294967295L, true), "INT");
|
Assert.assertSame(codegen.getMysqlMatchedIntegerDataType(0L, 4294967295L, true), "INT");
|
||||||
|
|
||||||
Assert.assertSame(codegen.getMysqlMatchedIntegerDataType(-2147483649L, 2147483648L, false), "BIGINT");
|
Assert.assertSame(codegen.getMysqlMatchedIntegerDataType(-2147483649L, 2147483648L, false), "BIGINT");
|
||||||
Assert.assertSame(codegen.getMysqlMatchedIntegerDataType(0L, 4294967296L, true), "BIGINT");
|
Assert.assertSame(codegen.getMysqlMatchedIntegerDataType(0L, 4294967296L, true), "BIGINT");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testGetMysqlMatchedStringDataType() {
|
public void testGetMysqlMatchedStringDataType() {
|
||||||
final MysqlSchemaCodegen codegen = new MysqlSchemaCodegen();
|
final MysqlSchemaCodegen codegen = new MysqlSchemaCodegen();
|
||||||
Assert.assertSame(codegen.getMysqlMatchedStringDataType(6, 6), "CHAR");
|
Assert.assertSame(codegen.getMysqlMatchedStringDataType(6, 6), "CHAR");
|
||||||
Assert.assertSame(codegen.getMysqlMatchedStringDataType(0, 0), "CHAR");
|
Assert.assertSame(codegen.getMysqlMatchedStringDataType(0, 0), "CHAR");
|
||||||
Assert.assertSame(codegen.getMysqlMatchedStringDataType(255, 255), "CHAR");
|
Assert.assertSame(codegen.getMysqlMatchedStringDataType(255, 255), "CHAR");
|
||||||
|
|
||||||
Assert.assertSame(codegen.getMysqlMatchedStringDataType(null, 100), "VARCHAR");
|
Assert.assertSame(codegen.getMysqlMatchedStringDataType(null, 100), "VARCHAR");
|
||||||
Assert.assertSame(codegen.getMysqlMatchedStringDataType(null, 255), "VARCHAR");
|
Assert.assertSame(codegen.getMysqlMatchedStringDataType(null, 255), "VARCHAR");
|
||||||
Assert.assertSame(codegen.getMysqlMatchedStringDataType(50, 255), "VARCHAR");
|
Assert.assertSame(codegen.getMysqlMatchedStringDataType(50, 255), "VARCHAR");
|
||||||
Assert.assertSame(codegen.getMysqlMatchedStringDataType(100, 20), "VARCHAR");
|
Assert.assertSame(codegen.getMysqlMatchedStringDataType(100, 20), "VARCHAR");
|
||||||
|
|
||||||
Assert.assertSame(codegen.getMysqlMatchedStringDataType(null, null), "TEXT");
|
Assert.assertSame(codegen.getMysqlMatchedStringDataType(null, null), "TEXT");
|
||||||
Assert.assertSame(codegen.getMysqlMatchedStringDataType(100, null), "TEXT");
|
Assert.assertSame(codegen.getMysqlMatchedStringDataType(100, null), "TEXT");
|
||||||
Assert.assertSame(codegen.getMysqlMatchedStringDataType(255, null), "TEXT");
|
Assert.assertSame(codegen.getMysqlMatchedStringDataType(255, null), "TEXT");
|
||||||
Assert.assertSame(codegen.getMysqlMatchedStringDataType(null, 256), "TEXT");
|
Assert.assertSame(codegen.getMysqlMatchedStringDataType(null, 256), "TEXT");
|
||||||
|
|
||||||
Assert.assertSame(codegen.getMysqlMatchedStringDataType(16777215, null), "MEDIUMTEXT");
|
Assert.assertSame(codegen.getMysqlMatchedStringDataType(16777215, null), "MEDIUMTEXT");
|
||||||
Assert.assertSame(codegen.getMysqlMatchedStringDataType(16777215, 100), "MEDIUMTEXT");
|
Assert.assertSame(codegen.getMysqlMatchedStringDataType(16777215, 100), "MEDIUMTEXT");
|
||||||
Assert.assertSame(codegen.getMysqlMatchedStringDataType(null, 16777215), "MEDIUMTEXT");
|
Assert.assertSame(codegen.getMysqlMatchedStringDataType(null, 16777215), "MEDIUMTEXT");
|
||||||
Assert.assertSame(codegen.getMysqlMatchedStringDataType(100, 16777215), "MEDIUMTEXT");
|
Assert.assertSame(codegen.getMysqlMatchedStringDataType(100, 16777215), "MEDIUMTEXT");
|
||||||
|
|
||||||
Assert.assertSame(codegen.getMysqlMatchedStringDataType(16777216, null), "LONGTEXT");
|
Assert.assertSame(codegen.getMysqlMatchedStringDataType(16777216, null), "LONGTEXT");
|
||||||
Assert.assertSame(codegen.getMysqlMatchedStringDataType(null, 16777216), "LONGTEXT");
|
Assert.assertSame(codegen.getMysqlMatchedStringDataType(null, 16777216), "LONGTEXT");
|
||||||
Assert.assertSame(codegen.getMysqlMatchedStringDataType(16777216, 16777216), "LONGTEXT");
|
Assert.assertSame(codegen.getMysqlMatchedStringDataType(16777216, 16777216), "LONGTEXT");
|
||||||
Assert.assertSame(codegen.getMysqlMatchedStringDataType(100, 16777216), "LONGTEXT");
|
Assert.assertSame(codegen.getMysqlMatchedStringDataType(100, 16777216), "LONGTEXT");
|
||||||
Assert.assertSame(codegen.getMysqlMatchedStringDataType(100, Integer.MAX_VALUE), "LONGTEXT");
|
Assert.assertSame(codegen.getMysqlMatchedStringDataType(100, Integer.MAX_VALUE), "LONGTEXT");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testToCodegenMysqlDataTypeArgument() {
|
public void testToCodegenMysqlDataTypeArgument() {
|
||||||
final MysqlSchemaCodegen codegen = new MysqlSchemaCodegen();
|
final MysqlSchemaCodegen codegen = new MysqlSchemaCodegen();
|
||||||
String strArgument = "HelloWorld";
|
String strArgument = "HelloWorld";
|
||||||
HashMap<String, Object> strProp = codegen.toCodegenMysqlDataTypeArgument(strArgument, true);
|
HashMap<String, Object> strProp = codegen.toCodegenMysqlDataTypeArgument(strArgument, true);
|
||||||
Assert.assertTrue((Boolean) strProp.get("isString"));
|
Assert.assertTrue((Boolean) strProp.get("isString"));
|
||||||
Assert.assertTrue((Boolean) strProp.get("hasMore"));
|
Assert.assertTrue((Boolean) strProp.get("hasMore"));
|
||||||
Assert.assertFalse((Boolean) strProp.get("isFloat"));
|
Assert.assertFalse((Boolean) strProp.get("isFloat"));
|
||||||
Assert.assertFalse((Boolean) strProp.get("isInteger"));
|
Assert.assertFalse((Boolean) strProp.get("isInteger"));
|
||||||
Assert.assertFalse((Boolean) strProp.get("isNumeric"));
|
Assert.assertFalse((Boolean) strProp.get("isNumeric"));
|
||||||
Assert.assertSame((String) strProp.get("argumentValue"), strArgument);
|
Assert.assertSame((String) strProp.get("argumentValue"), strArgument);
|
||||||
|
|
||||||
Integer intArgument = 10;
|
Integer intArgument = 10;
|
||||||
HashMap<String, Object> intProp = codegen.toCodegenMysqlDataTypeArgument(intArgument, true);
|
HashMap<String, Object> intProp = codegen.toCodegenMysqlDataTypeArgument(intArgument, true);
|
||||||
Assert.assertFalse((Boolean) intProp.get("isString"));
|
Assert.assertFalse((Boolean) intProp.get("isString"));
|
||||||
Assert.assertTrue((Boolean) intProp.get("hasMore"));
|
Assert.assertTrue((Boolean) intProp.get("hasMore"));
|
||||||
Assert.assertFalse((Boolean) intProp.get("isFloat"));
|
Assert.assertFalse((Boolean) intProp.get("isFloat"));
|
||||||
Assert.assertTrue((Boolean) intProp.get("isInteger"));
|
Assert.assertTrue((Boolean) intProp.get("isInteger"));
|
||||||
Assert.assertTrue((Boolean) intProp.get("isNumeric"));
|
Assert.assertTrue((Boolean) intProp.get("isNumeric"));
|
||||||
Assert.assertSame((Integer) intProp.get("argumentValue"), intArgument);
|
Assert.assertSame((Integer) intProp.get("argumentValue"), intArgument);
|
||||||
|
|
||||||
Double floatArgument = 3.14;
|
Double floatArgument = 3.14;
|
||||||
HashMap<String, Object> floatProp = codegen.toCodegenMysqlDataTypeArgument(floatArgument, false);
|
HashMap<String, Object> floatProp = codegen.toCodegenMysqlDataTypeArgument(floatArgument, false);
|
||||||
Assert.assertFalse((Boolean) floatProp.get("isString"));
|
Assert.assertFalse((Boolean) floatProp.get("isString"));
|
||||||
Assert.assertFalse((Boolean) floatProp.get("hasMore"));
|
Assert.assertFalse((Boolean) floatProp.get("hasMore"));
|
||||||
Assert.assertTrue((Boolean) floatProp.get("isFloat"));
|
Assert.assertTrue((Boolean) floatProp.get("isFloat"));
|
||||||
Assert.assertFalse((Boolean) floatProp.get("isInteger"));
|
Assert.assertFalse((Boolean) floatProp.get("isInteger"));
|
||||||
Assert.assertTrue((Boolean) floatProp.get("isNumeric"));
|
Assert.assertTrue((Boolean) floatProp.get("isNumeric"));
|
||||||
Assert.assertSame((Double) floatProp.get("argumentValue"), floatArgument);
|
Assert.assertSame((Double) floatProp.get("argumentValue"), floatArgument);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testToCodegenMysqlDataTypeDefault() {
|
public void testToCodegenMysqlDataTypeDefault() {
|
||||||
final MysqlSchemaCodegen codegen = new MysqlSchemaCodegen();
|
final MysqlSchemaCodegen codegen = new MysqlSchemaCodegen();
|
||||||
HashMap<String, Object> defaultMap = null;
|
HashMap<String, Object> defaultMap = null;
|
||||||
ArrayList<String> intFixture = new ArrayList<String>(Arrays.asList(
|
ArrayList<String> intFixture = new ArrayList<String>(Arrays.asList(
|
||||||
"TINYINT", "SmallInt", "Mediumint", "INT", "bigint"
|
"TINYINT", "SmallInt", "Mediumint", "INT", "bigint"
|
||||||
));
|
));
|
||||||
for(String intType : intFixture) {
|
for(String intType : intFixture) {
|
||||||
defaultMap = codegen.toCodegenMysqlDataTypeDefault("150", intType);
|
defaultMap = codegen.toCodegenMysqlDataTypeDefault("150", intType);
|
||||||
Assert.assertTrue((Boolean) defaultMap.get("isNumeric"));
|
Assert.assertTrue((Boolean) defaultMap.get("isNumeric"));
|
||||||
Assert.assertFalse((Boolean) defaultMap.get("isString"));
|
Assert.assertFalse((Boolean) defaultMap.get("isString"));
|
||||||
Assert.assertFalse((Boolean) defaultMap.get("isKeyword"));
|
Assert.assertFalse((Boolean) defaultMap.get("isKeyword"));
|
||||||
Assert.assertSame(defaultMap.get("defaultValue"), "150");
|
Assert.assertSame(defaultMap.get("defaultValue"), "150");
|
||||||
}
|
}
|
||||||
defaultMap = codegen.toCodegenMysqlDataTypeDefault("SERIAL DEFAULT VALUE", "TINYINT");
|
defaultMap = codegen.toCodegenMysqlDataTypeDefault("SERIAL DEFAULT VALUE", "TINYINT");
|
||||||
Assert.assertFalse((Boolean) defaultMap.get("isNumeric"));
|
Assert.assertFalse((Boolean) defaultMap.get("isNumeric"));
|
||||||
Assert.assertFalse((Boolean) defaultMap.get("isString"));
|
Assert.assertFalse((Boolean) defaultMap.get("isString"));
|
||||||
Assert.assertTrue((Boolean) defaultMap.get("isKeyword"));
|
Assert.assertTrue((Boolean) defaultMap.get("isKeyword"));
|
||||||
Assert.assertSame(defaultMap.get("defaultValue"), "SERIAL DEFAULT VALUE");
|
Assert.assertSame(defaultMap.get("defaultValue"), "SERIAL DEFAULT VALUE");
|
||||||
|
|
||||||
ArrayList<String> dateFixture = new ArrayList<String>(Arrays.asList(
|
ArrayList<String> dateFixture = new ArrayList<String>(Arrays.asList(
|
||||||
"Timestamp", "DateTime"
|
"Timestamp", "DateTime"
|
||||||
));
|
));
|
||||||
for(String dateType : dateFixture) {
|
for(String dateType : dateFixture) {
|
||||||
defaultMap = codegen.toCodegenMysqlDataTypeDefault("2018-08-12", dateType);
|
defaultMap = codegen.toCodegenMysqlDataTypeDefault("2018-08-12", dateType);
|
||||||
Assert.assertFalse((Boolean) defaultMap.get("isNumeric"));
|
Assert.assertFalse((Boolean) defaultMap.get("isNumeric"));
|
||||||
Assert.assertTrue((Boolean) defaultMap.get("isString"));
|
Assert.assertTrue((Boolean) defaultMap.get("isString"));
|
||||||
Assert.assertFalse((Boolean) defaultMap.get("isKeyword"));
|
Assert.assertFalse((Boolean) defaultMap.get("isKeyword"));
|
||||||
Assert.assertSame(defaultMap.get("defaultValue"), "2018-08-12");
|
Assert.assertSame(defaultMap.get("defaultValue"), "2018-08-12");
|
||||||
}
|
}
|
||||||
defaultMap = codegen.toCodegenMysqlDataTypeDefault("CURRENT_TIMESTAMP", "Timestamp");
|
defaultMap = codegen.toCodegenMysqlDataTypeDefault("CURRENT_TIMESTAMP", "Timestamp");
|
||||||
Assert.assertFalse((Boolean) defaultMap.get("isNumeric"));
|
Assert.assertFalse((Boolean) defaultMap.get("isNumeric"));
|
||||||
Assert.assertFalse((Boolean) defaultMap.get("isString"));
|
Assert.assertFalse((Boolean) defaultMap.get("isString"));
|
||||||
Assert.assertTrue((Boolean) defaultMap.get("isKeyword"));
|
Assert.assertTrue((Boolean) defaultMap.get("isKeyword"));
|
||||||
Assert.assertSame(defaultMap.get("defaultValue"), "CURRENT_TIMESTAMP");
|
Assert.assertSame(defaultMap.get("defaultValue"), "CURRENT_TIMESTAMP");
|
||||||
|
|
||||||
ArrayList<String> restFixture = new ArrayList<String>(Arrays.asList(
|
ArrayList<String> restFixture = new ArrayList<String>(Arrays.asList(
|
||||||
"VARCHAR", "CHAR", "ENUM", "UNKNOWN"
|
"VARCHAR", "CHAR", "ENUM", "UNKNOWN"
|
||||||
));
|
));
|
||||||
for(String restType : restFixture) {
|
for(String restType : restFixture) {
|
||||||
defaultMap = codegen.toCodegenMysqlDataTypeDefault("sometext", restType);
|
defaultMap = codegen.toCodegenMysqlDataTypeDefault("sometext", restType);
|
||||||
Assert.assertFalse((Boolean) defaultMap.get("isNumeric"));
|
Assert.assertFalse((Boolean) defaultMap.get("isNumeric"));
|
||||||
Assert.assertTrue((Boolean) defaultMap.get("isString"));
|
Assert.assertTrue((Boolean) defaultMap.get("isString"));
|
||||||
Assert.assertFalse((Boolean) defaultMap.get("isKeyword"));
|
Assert.assertFalse((Boolean) defaultMap.get("isKeyword"));
|
||||||
Assert.assertSame(defaultMap.get("defaultValue"), "sometext");
|
Assert.assertSame(defaultMap.get("defaultValue"), "sometext");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expectedExceptions = RuntimeException.class)
|
@Test(expectedExceptions = RuntimeException.class)
|
||||||
public void testToCodegenMysqlDataTypeDefaultWithExceptionalColumnType() {
|
public void testToCodegenMysqlDataTypeDefaultWithExceptionalColumnType() {
|
||||||
final MysqlSchemaCodegen codegen = new MysqlSchemaCodegen();
|
final MysqlSchemaCodegen codegen = new MysqlSchemaCodegen();
|
||||||
HashMap<String, Object> defaultMap = null;
|
HashMap<String, Object> defaultMap = null;
|
||||||
ArrayList<String> specialFixture = new ArrayList<String>(Arrays.asList(
|
ArrayList<String> specialFixture = new ArrayList<String>(Arrays.asList(
|
||||||
"TINYBLOB", "Blob", "MEDIUMBLOB", "LONGBLOB", "TINYTEXT", "TEXT", "MEDIUMTEXT", "LONGTEXT", "GEOMETRY", "JSON"
|
"TINYBLOB", "Blob", "MEDIUMBLOB", "LONGBLOB", "TINYTEXT", "TEXT", "MEDIUMTEXT", "LONGTEXT", "GEOMETRY", "JSON"
|
||||||
));
|
));
|
||||||
for(String specialType : specialFixture) {
|
for(String specialType : specialFixture) {
|
||||||
defaultMap = codegen.toCodegenMysqlDataTypeDefault("2018-08-12", specialType);
|
defaultMap = codegen.toCodegenMysqlDataTypeDefault("2018-08-12", specialType);
|
||||||
Assert.assertNull(defaultMap);
|
Assert.assertNull(defaultMap);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testIsMysqlDataType() {
|
public void testIsMysqlDataType() {
|
||||||
final MysqlSchemaCodegen codegen = new MysqlSchemaCodegen();
|
final MysqlSchemaCodegen codegen = new MysqlSchemaCodegen();
|
||||||
ArrayList<String> trueFixture = new ArrayList<String>(Arrays.asList(
|
ArrayList<String> trueFixture = new ArrayList<String>(Arrays.asList(
|
||||||
"INTEGER", "integer", "Integer", "DATETIME", "datetime", "DateTime", "VARCHAR", "varchar", "VarChar", "POINT", "Point", "point", "JSON", "json", "Json"
|
"INTEGER", "integer", "Integer", "DATETIME", "datetime", "DateTime", "VARCHAR", "varchar", "VarChar", "POINT", "Point", "point", "JSON", "json", "Json"
|
||||||
));
|
));
|
||||||
ArrayList<String> falseFixture = new ArrayList<String>(Arrays.asList(
|
ArrayList<String> falseFixture = new ArrayList<String>(Arrays.asList(
|
||||||
"unknown", "HashMap", "HASHMAP", "hashmap"
|
"unknown", "HashMap", "HASHMAP", "hashmap"
|
||||||
));
|
));
|
||||||
for(String trueValue : trueFixture) {
|
for(String trueValue : trueFixture) {
|
||||||
Assert.assertTrue(codegen.isMysqlDataType(trueValue), "'" + trueValue + "' isn't MySQL data type");
|
Assert.assertTrue(codegen.isMysqlDataType(trueValue), "'" + trueValue + "' isn't MySQL data type");
|
||||||
}
|
}
|
||||||
for(String falseValue : falseFixture) {
|
for(String falseValue : falseFixture) {
|
||||||
Assert.assertFalse(codegen.isMysqlDataType(falseValue), "'" + falseValue + "' is MySQL data type");
|
Assert.assertFalse(codegen.isMysqlDataType(falseValue), "'" + falseValue + "' is MySQL data type");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testToMysqlIdentifier() {
|
public void testToMysqlIdentifier() {
|
||||||
final MysqlSchemaCodegen codegen = new MysqlSchemaCodegen();
|
final MysqlSchemaCodegen codegen = new MysqlSchemaCodegen();
|
||||||
Assert.assertEquals(codegen.toMysqlIdentifier("table_name", "tbl_", ""), "table_name");
|
Assert.assertEquals(codegen.toMysqlIdentifier("table_name", "tbl_", ""), "table_name");
|
||||||
Assert.assertEquals(codegen.toMysqlIdentifier("table_name ", "tbl_", ""), "table_name");
|
Assert.assertEquals(codegen.toMysqlIdentifier("table_name ", "tbl_", ""), "table_name");
|
||||||
Assert.assertEquals(codegen.toMysqlIdentifier("12345678", "tbl_", ""), "tbl_12345678");
|
Assert.assertEquals(codegen.toMysqlIdentifier("12345678", "tbl_", ""), "tbl_12345678");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expectedExceptions = RuntimeException.class)
|
@Test(expectedExceptions = RuntimeException.class)
|
||||||
public void testToMysqlIdentifierWithEmptyString() {
|
public void testToMysqlIdentifierWithEmptyString() {
|
||||||
final MysqlSchemaCodegen codegen = new MysqlSchemaCodegen();
|
final MysqlSchemaCodegen codegen = new MysqlSchemaCodegen();
|
||||||
codegen.toMysqlIdentifier(" ", "tbl_", "");
|
codegen.toMysqlIdentifier(" ", "tbl_", "");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testEscapeMysqlUnquotedIdentifier() {
|
public void testEscapeMysqlUnquotedIdentifier() {
|
||||||
final MysqlSchemaCodegen codegen = new MysqlSchemaCodegen();
|
final MysqlSchemaCodegen codegen = new MysqlSchemaCodegen();
|
||||||
Assert.assertEquals(codegen.escapeMysqlUnquotedIdentifier("table1Z$_"), "table1Z$_");
|
Assert.assertEquals(codegen.escapeMysqlUnquotedIdentifier("table1Z$_"), "table1Z$_");
|
||||||
Assert.assertEquals(codegen.escapeMysqlUnquotedIdentifier("table1Z$_!#%~&?()*+-./"), "table1Z$_");
|
Assert.assertEquals(codegen.escapeMysqlUnquotedIdentifier("table1Z$_!#%~&?()*+-./"), "table1Z$_");
|
||||||
Assert.assertEquals(codegen.escapeMysqlUnquotedIdentifier("table1Z$_русскийтекст"), "table1Z$_русскийтекст");
|
Assert.assertEquals(codegen.escapeMysqlUnquotedIdentifier("table1Z$_русскийтекст"), "table1Z$_русскийтекст");
|
||||||
Assert.assertEquals(codegen.escapeMysqlQuotedIdentifier("table𐀀"), "table");
|
Assert.assertEquals(codegen.escapeMysqlQuotedIdentifier("table𐀀"), "table");
|
||||||
Assert.assertEquals(codegen.escapeMysqlQuotedIdentifier("table_name!'()<29>"), "table_name!'()<29>");
|
Assert.assertEquals(codegen.escapeMysqlQuotedIdentifier("table_name!'()<29>"), "table_name!'()<29>");
|
||||||
Assert.assertEquals(codegen.escapeMysqlQuotedIdentifier("table_name𐌅𐌌 |