forked from loafle/openapi-generator-original
Compare commits
133 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
3259bf71e6 | ||
|
|
526e980a69 | ||
|
|
ab09909f99 | ||
|
|
d8b597b168 | ||
|
|
9bc335b35e | ||
|
|
227f2779d7 | ||
|
|
2ffda45adf | ||
|
|
bb2712fe45 | ||
|
|
cbf61d5524 | ||
|
|
39763a8ca7 | ||
|
|
aa19369466 | ||
|
|
3f65d6c350 | ||
|
|
99646e6436 | ||
|
|
450d624474 | ||
|
|
ca0c35aa15 | ||
|
|
fcfd8ea76e | ||
|
|
2044c36398 | ||
|
|
d374e1c160 | ||
|
|
ee491a0e5e | ||
|
|
e605882451 | ||
|
|
b91c8e17a7 | ||
|
|
dcc622d374 | ||
|
|
a3e5edc367 | ||
|
|
bd7c9e30d3 | ||
|
|
62dfb749f1 | ||
|
|
3b9de3baa3 | ||
|
|
d593988e5d | ||
|
|
0191210145 | ||
|
|
0f30a052b2 | ||
|
|
1c6ab3f831 | ||
|
|
5ffc297a69 | ||
|
|
e7340bfe5b | ||
|
|
ca651becf8 | ||
|
|
6de09688ad | ||
|
|
94806b8036 | ||
|
|
fa52826c24 | ||
|
|
7b8f51a465 | ||
|
|
79b993e6d5 | ||
|
|
56bba880e7 | ||
|
|
7acba8a4d8 | ||
|
|
08ca54d3d5 | ||
|
|
7b04732f09 | ||
|
|
b64864f47d | ||
|
|
c237fe9f1c | ||
|
|
5e1c4cde50 | ||
|
|
1559c4fadd | ||
|
|
0cd6d8c139 | ||
|
|
ddb0920fed | ||
|
|
21777f2759 | ||
|
|
afdef8f890 | ||
|
|
d019bbd2c7 | ||
|
|
748d1d70cb | ||
|
|
987fd77042 | ||
|
|
a0984a9be8 | ||
|
|
9920c435ca | ||
|
|
4060fcbb8b | ||
|
|
d0ccac5663 | ||
|
|
06263d7606 | ||
|
|
3245c0a139 | ||
|
|
0809d8f527 | ||
|
|
baf16cf834 | ||
|
|
629608c573 | ||
|
|
e143214685 | ||
|
|
2340d83a33 | ||
|
|
90a8b81728 | ||
|
|
30fb22fffa | ||
|
|
f329872ce7 | ||
|
|
05db32fea2 | ||
|
|
c116c8fb9b | ||
|
|
1ab4fe43b5 | ||
|
|
f6c21057e1 | ||
|
|
c9085b4f2b | ||
|
|
f6146b212f | ||
|
|
2b429ee43b | ||
|
|
a258cf3fc6 | ||
|
|
07a5715b9f | ||
|
|
f32398a708 | ||
|
|
f0425d77ef | ||
|
|
e0020b41da | ||
|
|
375c26ccb3 | ||
|
|
40024ac72a | ||
|
|
ab08dd1d26 | ||
|
|
21141f682f | ||
|
|
d8ea28e147 | ||
|
|
82156b6639 | ||
|
|
3085bf1df5 | ||
|
|
58e0946b1e | ||
|
|
f793ac25c7 | ||
|
|
d1fc923b66 | ||
|
|
f1897c4462 | ||
|
|
d8ec6b2003 | ||
|
|
824654964b | ||
|
|
0c52fcd5ff | ||
|
|
926b971497 | ||
|
|
1e95d36809 | ||
|
|
a3e5185e39 | ||
|
|
1cbfca4887 | ||
|
|
b0909ade6f | ||
|
|
036fa6918c | ||
|
|
b587052de4 | ||
|
|
cb9a734ebb | ||
|
|
01dbb8b693 | ||
|
|
68d80ab67d | ||
|
|
14ab3d763e | ||
|
|
3c3ac0a071 | ||
|
|
0b88889cdf | ||
|
|
b33f1f945b | ||
|
|
c7953ac137 | ||
|
|
534b6b5978 | ||
|
|
b6fc29050d | ||
|
|
7e494e52ab | ||
|
|
7624a1ff85 | ||
|
|
1d72edddf6 | ||
|
|
c9b934147a | ||
|
|
65bad61abb | ||
|
|
77df3d6770 | ||
|
|
a8e8acead7 | ||
|
|
44d419c1a1 | ||
|
|
60c81eae0a | ||
|
|
00246f3ea0 | ||
|
|
70cdd27e75 | ||
|
|
27a356dacf | ||
|
|
667e3130fe | ||
|
|
8867d2b34c | ||
|
|
71ef6a0a2b | ||
|
|
888da52181 | ||
|
|
45ed374b62 | ||
|
|
baaa335664 | ||
|
|
0a52f56ba4 | ||
|
|
478d6ced4e | ||
|
|
0cc60d39d2 | ||
|
|
8f6bb8d9ec | ||
|
|
23c04e2e66 |
2
.github/PULL_REQUEST_TEMPLATE.md
vendored
2
.github/PULL_REQUEST_TEMPLATE.md
vendored
@@ -2,7 +2,7 @@
|
||||
|
||||
- [ ] Read the [contribution guidelines](https://github.com/openapitools/openapi-generator/blob/master/CONTRIBUTING.md).
|
||||
- [ ] Ran the shell script under `./bin/` to update Petstore sample so that CIs can verify the change. (For instance, only need to run `./bin/{LANG}-petstore.sh` and `./bin/security/{LANG}-petstore.sh` if updating the {LANG} (e.g. php, ruby, python, etc) code generator or {LANG} client's mustache templates). Windows batch files can be found in `.\bin\windows\`.
|
||||
- [ ] Filed the PR against the [correct branch](https://github.com/OpenAPITools/openapi-generator/wiki/Git-Branches): `master`, `3.2.x`, `4.0.x`. Default: `master`.
|
||||
- [ ] Filed the PR against the [correct branch](https://github.com/OpenAPITools/openapi-generator/wiki/Git-Branches): `master`, `3.3.x`, `4.0.x`. Default: `master`.
|
||||
- [ ] Copied the [technical committee](https://github.com/openapitools/openapi-generator/#62---openapi-generator-technical-committee) to review the pull request if your PR is targeting a particular programming language.
|
||||
|
||||
### Description of the PR
|
||||
|
||||
19
.gitignore
vendored
19
.gitignore
vendored
@@ -59,6 +59,12 @@ samples/client/petstore/qt5cpp/PetStore/PetStore
|
||||
samples/client/petstore/qt5cpp/PetStore/Makefile
|
||||
samples/client/petstore/qt5cpp/PetStore/PetStore.pro.user
|
||||
|
||||
# cpprestsdk
|
||||
samples/client/petstore/cpp-restsdk/CMakeCache.txt
|
||||
samples/client/petstore/cpp-restsdk/CMakeFiles/
|
||||
samples/client/petstore/cpp-restsdk/Makefile
|
||||
samples/client/petstore/cpp-restsdk/cmake_install.cmake
|
||||
|
||||
#Java/Android
|
||||
**/.gradle
|
||||
samples/client/petstore/java/hello.txt
|
||||
@@ -87,19 +93,6 @@ samples/client/petstore/java/jersey2-java6/project/
|
||||
samples/client/petstore/java/jersey2-java8/project/
|
||||
samples/client/petstore/java/jersey2/project/
|
||||
|
||||
#PHP
|
||||
samples/client/petstore/php/OpenAPIToolsClient-php/composer.lock
|
||||
samples/client/petstore/php/OpenAPIToolsClient-php/vendor/
|
||||
samples/client/petstore/silex/SwaggerServer/composer.lock
|
||||
samples/client/petstore/silex/SwaggerServer/venodr/
|
||||
**/vendor/
|
||||
**/composer.lock
|
||||
|
||||
#PHP-Symfony
|
||||
samples/server/petstore/php-symfony/SymfonyBundle-php/Tests/cache/
|
||||
samples/server/petstore/php-symfony/SymfonyBundle-php/Tests/logs/
|
||||
|
||||
|
||||
# Perl
|
||||
samples/client/petstore/perl/deep_module_test/
|
||||
|
||||
|
||||
36
.hub.cli.dockerfile
Normal file
36
.hub.cli.dockerfile
Normal file
@@ -0,0 +1,36 @@
|
||||
## The builder labeled image acts as a transient container which is meant to
|
||||
## hold all non-artifact code.
|
||||
##
|
||||
## You can build _just_ this part with:
|
||||
## docker --target builder -t container-name:builder -f .hub.cli.dockerfile .
|
||||
FROM jimschubert/8-jdk-alpine-mvn:1.0 as builder
|
||||
|
||||
RUN set -x && \
|
||||
apk add --no-cache bash
|
||||
|
||||
ENV GEN_DIR /opt/openapi-generator
|
||||
WORKDIR ${GEN_DIR}
|
||||
COPY . ${GEN_DIR}
|
||||
|
||||
# Pre-compile openapi-generator-cli
|
||||
RUN mvn -am -pl "modules/openapi-generator-cli" package
|
||||
|
||||
## The final (release) image
|
||||
## The resulting container here only needs the target jar
|
||||
## and ca-certificates (to be able to query HTTPS hosted specs)
|
||||
FROM openjdk:8-jre-alpine
|
||||
|
||||
ENV GEN_DIR /opt/openapi-generator
|
||||
|
||||
RUN apk --no-cache add ca-certificates bash
|
||||
RUN mkdir -p ${GEN_DIR}/modules/openapi-generator-cli/target
|
||||
|
||||
WORKDIR ${GEN_DIR}/modules/openapi-generator-cli/target
|
||||
|
||||
COPY --from=builder ${GEN_DIR}/modules/openapi-generator-cli/target/openapi-generator-cli.jar ${GEN_DIR}/modules/openapi-generator-cli/target/openapi-generator-cli.jar
|
||||
|
||||
COPY docker-entrypoint.sh /usr/local/bin/
|
||||
|
||||
ENTRYPOINT ["docker-entrypoint.sh"]
|
||||
|
||||
CMD ["help"]
|
||||
35
.hub.online.dockerfile
Normal file
35
.hub.online.dockerfile
Normal file
@@ -0,0 +1,35 @@
|
||||
## The builder labeled image acts as a transient container which is meant to
|
||||
## hold all non-artifact code.
|
||||
##
|
||||
## You can build _just_ this part with:
|
||||
## docker --target builder -t container-name:builder -f .hub.online.dockerfile .
|
||||
FROM jimschubert/8-jdk-alpine-mvn:1.0 as builder
|
||||
|
||||
RUN set -x && \
|
||||
apk add --no-cache bash
|
||||
|
||||
ENV GEN_DIR /opt/openapi-generator
|
||||
WORKDIR ${GEN_DIR}
|
||||
COPY . ${GEN_DIR}
|
||||
|
||||
# Pre-compile openapi-generator-online
|
||||
RUN mvn -am -pl "modules/openapi-generator-online" package
|
||||
|
||||
## The final (release) image
|
||||
## The resulting container here only needs the target jar
|
||||
FROM openjdk:8-jre-alpine
|
||||
|
||||
ENV GEN_DIR /opt/openapi-generator
|
||||
ENV TARGET_DIR /generator
|
||||
|
||||
RUN mkdir -p ${TARGET_DIR}
|
||||
|
||||
WORKDIR ${TARGET_DIR}
|
||||
|
||||
COPY --from=builder ${GEN_DIR}/modules/openapi-generator-online/target/openapi-generator-*.jar ${TARGET_DIR}/openapi-generator-online.jar
|
||||
|
||||
ENV GENERATOR_HOST=http://localhost
|
||||
|
||||
EXPOSE 8080
|
||||
|
||||
CMD ["java", "-jar", "/generator/openapi-generator-online.jar"]
|
||||
@@ -123,7 +123,7 @@ after_success:
|
||||
./gradlew -Psigning.keyId="$SIGNING_KEY" -Psigning.password="$SIGNING_PASSPHRASE" -Psigning.secretKeyRingFile="${TRAVIS_BUILD_DIR}/sec.gpg" -PossrhUsername="${SONATYPE_USERNAME}" -PossrhPassword="${SONATYPE_PASSWORD}" uploadArchives --no-daemon;
|
||||
echo "Finished ./gradlew uploadArchives";
|
||||
popd;
|
||||
elif ([ "$TRAVIS_BRANCH" == "3.1.x" ] || [ "$TRAVIS_BRANCH" == "4.0.x" ]) ; then
|
||||
elif ([ "$TRAVIS_BRANCH" == "4.0.x" ]) ; then
|
||||
mvn clean deploy --settings CI/settings.xml;
|
||||
echo "Finished mvn clean deploy for $TRAVIS_BRANCH";
|
||||
pushd .;
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
<artifactId>openapi-generator-project</artifactId>
|
||||
<packaging>pom</packaging>
|
||||
<name>openapi-generator-project</name>
|
||||
<version>3.1.2</version>
|
||||
<version>3.2.2</version>
|
||||
<url>https://github.com/openapi-tools/openapi-generator</url>
|
||||
<scm>
|
||||
<connection>scm:git:git@github.com:openapi-tools/openapi-generator.git</connection>
|
||||
@@ -920,7 +920,7 @@
|
||||
</repository>
|
||||
</repositories>
|
||||
<properties>
|
||||
<swagger-parser-version>2.0.1</swagger-parser-version>
|
||||
<swagger-parser-version>2.0.2-OpenAPITools.org-1</swagger-parser-version>
|
||||
<swagger-core-version>2.0.1</swagger-core-version>
|
||||
<scala-version>2.11.1</scala-version>
|
||||
<felix-version>3.3.0</felix-version>
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
<artifactId>openapi-generator-project</artifactId>
|
||||
<packaging>pom</packaging>
|
||||
<name>openapi-generator-project</name>
|
||||
<version>3.1.2</version>
|
||||
<version>3.2.2</version>
|
||||
<url>https://github.com/openapitools/openapi-generator</url>
|
||||
<scm>
|
||||
<connection>scm:git:git@github.com:openapitools/openapi-generator.git</connection>
|
||||
@@ -607,6 +607,55 @@
|
||||
<module>samples/server/petstore/jaxrs/jersey1</module>
|
||||
</modules>
|
||||
</profile>
|
||||
<profile>
|
||||
<!-- openapi v3's one -->
|
||||
<id>jaxrs-jersey</id>
|
||||
<activation>
|
||||
<property>
|
||||
<name>env</name>
|
||||
<value>java</value>
|
||||
</property>
|
||||
</activation>
|
||||
<modules>
|
||||
<module>samples/server/petstore/jaxrs-jersey</module>
|
||||
</modules>
|
||||
</profile>
|
||||
<profile>
|
||||
<id>jaxrs-spec</id>
|
||||
<activation>
|
||||
<property>
|
||||
<name>env</name>
|
||||
<value>java</value>
|
||||
</property>
|
||||
</activation>
|
||||
<modules>
|
||||
<module>samples/server/petstore/jaxrs-spec</module>
|
||||
</modules>
|
||||
</profile>
|
||||
<profile>
|
||||
<id>jaxrs-spec-interface</id>
|
||||
<activation>
|
||||
<property>
|
||||
<name>env</name>
|
||||
<value>java</value>
|
||||
</property>
|
||||
</activation>
|
||||
<modules>
|
||||
<module>samples/server/petstore/jaxrs-spec-interface</module>
|
||||
</modules>
|
||||
</profile>
|
||||
<profile>
|
||||
<id>jaxrs-spec-interface-response</id>
|
||||
<activation>
|
||||
<property>
|
||||
<name>env</name>
|
||||
<value>java</value>
|
||||
</property>
|
||||
</activation>
|
||||
<modules>
|
||||
<module>samples/server/petstore/jaxrs-spec-interface-response</module>
|
||||
</modules>
|
||||
</profile>
|
||||
<profile>
|
||||
<id>typescript-fetch-client-tests-default</id>
|
||||
<activation>
|
||||
@@ -862,6 +911,10 @@
|
||||
<module>samples/client/petstore/kotlin-threetenbp/</module>
|
||||
<module>samples/client/petstore/kotlin-string/</module>
|
||||
<!-- servers -->
|
||||
<module>samples/server/petstore/jaxrs-jersey</module>
|
||||
<module>samples/server/petstore/jaxrs-spec</module>
|
||||
<module>samples/server/petstore/jaxrs-spec-interface</module>
|
||||
<module>samples/server/petstore/jaxrs-spec-interface-response</module>
|
||||
<module>samples/server/petstore/java-vertx/rx</module>
|
||||
<module>samples/server/petstore/java-vertx/async</module>
|
||||
<module>samples/server/petstore/java-inflector</module>
|
||||
@@ -901,7 +954,6 @@
|
||||
<module>samples/server/petstore/jaxrs-cxf-cdi</module>
|
||||
<module>samples/server/petstore/jaxrs-cxf-non-spring-app</module>
|
||||
<module>samples/server/petstore/java-msf4j</module>
|
||||
<module>samples/server/petstore/jaxrs-spec-interface</module>
|
||||
<module>samples/server/petstore/scala-lagom-server</module>
|
||||
<module>samples/server/petstore/scalatra</module>
|
||||
<module>samples/server/petstore/finch</module>
|
||||
@@ -976,7 +1028,7 @@
|
||||
</repository>
|
||||
</repositories>
|
||||
<properties>
|
||||
<swagger-parser-version>2.0.1</swagger-parser-version>
|
||||
<swagger-parser-version>2.0.2-OpenAPITools.org-1</swagger-parser-version>
|
||||
<swagger-core-version>2.0.1</swagger-core-version>
|
||||
<scala-version>2.11.1</scala-version>
|
||||
<felix-version>3.3.0</felix-version>
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
<artifactId>openapi-generator-project</artifactId>
|
||||
<packaging>pom</packaging>
|
||||
<name>openapi-generator-project</name>
|
||||
<version>3.1.2</version>
|
||||
<version>3.2.2</version>
|
||||
<url>https://github.com/openapitools/openapi-generator</url>
|
||||
<scm>
|
||||
<connection>scm:git:git@github.com:openapitools/openapi-generator.git</connection>
|
||||
@@ -607,6 +607,55 @@
|
||||
<module>samples/server/petstore/jaxrs/jersey1</module>
|
||||
</modules>
|
||||
</profile>
|
||||
<profile>
|
||||
<!-- openapi v3's one -->
|
||||
<id>jaxrs-jersey</id>
|
||||
<activation>
|
||||
<property>
|
||||
<name>env</name>
|
||||
<value>java</value>
|
||||
</property>
|
||||
</activation>
|
||||
<modules>
|
||||
<module>samples/server/petstore/jaxrs-jersey</module>
|
||||
</modules>
|
||||
</profile>
|
||||
<profile>
|
||||
<id>jaxrs-spec</id>
|
||||
<activation>
|
||||
<property>
|
||||
<name>env</name>
|
||||
<value>java</value>
|
||||
</property>
|
||||
</activation>
|
||||
<modules>
|
||||
<module>samples/server/petstore/jaxrs-spec</module>
|
||||
</modules>
|
||||
</profile>
|
||||
<profile>
|
||||
<id>jaxrs-spec-interface</id>
|
||||
<activation>
|
||||
<property>
|
||||
<name>env</name>
|
||||
<value>java</value>
|
||||
</property>
|
||||
</activation>
|
||||
<modules>
|
||||
<module>samples/server/petstore/jaxrs-spec-interface</module>
|
||||
</modules>
|
||||
</profile>
|
||||
<profile>
|
||||
<id>jaxrs-spec-interface-response</id>
|
||||
<activation>
|
||||
<property>
|
||||
<name>env</name>
|
||||
<value>java</value>
|
||||
</property>
|
||||
</activation>
|
||||
<modules>
|
||||
<module>samples/server/petstore/jaxrs-spec-interface-response</module>
|
||||
</modules>
|
||||
</profile>
|
||||
<profile>
|
||||
<id>typescript-fetch-client-tests-default</id>
|
||||
<activation>
|
||||
@@ -853,6 +902,10 @@
|
||||
<module>samples/client/petstore/java/google-api-client</module>
|
||||
<module>samples/client/petstore/kotlin/</module>
|
||||
<!-- servers -->
|
||||
<module>samples/server/petstore/jaxrs-jersey</module>
|
||||
<module>samples/server/petstore/jaxrs-spec</module>
|
||||
<module>samples/server/petstore/jaxrs-spec-interface</module>
|
||||
<module>samples/server/petstore/jaxrs-spec-interface-response</module>
|
||||
<module>samples/server/petstore/java-vertx/rx</module>
|
||||
<module>samples/server/petstore/java-vertx/async</module>
|
||||
<module>samples/server/petstore/java-inflector</module>
|
||||
@@ -876,7 +929,6 @@
|
||||
<module>samples/server/petstore/jaxrs-cxf-cdi</module>
|
||||
<module>samples/server/petstore/jaxrs-cxf-non-spring-app</module>
|
||||
<module>samples/server/petstore/java-msf4j</module>
|
||||
<module>samples/server/petstore/jaxrs-spec-interface</module>
|
||||
</modules>
|
||||
</profile>
|
||||
</profiles>
|
||||
@@ -948,7 +1000,7 @@
|
||||
</repository>
|
||||
</repositories>
|
||||
<properties>
|
||||
<swagger-parser-version>2.0.1</swagger-parser-version>
|
||||
<swagger-parser-version>2.0.2-OpenAPITools.org-1</swagger-parser-version>
|
||||
<swagger-core-version>2.0.1</swagger-core-version>
|
||||
<scala-version>2.11.1</scala-version>
|
||||
<felix-version>3.3.0</felix-version>
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
<artifactId>openapi-generator-project</artifactId>
|
||||
<packaging>pom</packaging>
|
||||
<name>openapi-generator-project</name>
|
||||
<version>3.1.2</version>
|
||||
<version>3.2.2</version>
|
||||
<url>https://github.com/openapitools/openapi-generator</url>
|
||||
<scm>
|
||||
<connection>scm:git:git@github.com:openapitools/openapi-generator.git</connection>
|
||||
@@ -928,7 +928,7 @@
|
||||
</repository>
|
||||
</repositories>
|
||||
<properties>
|
||||
<swagger-parser-version>2.0.1</swagger-parser-version>
|
||||
<swagger-parser-version>2.0.2-OpenAPITools.org-1</swagger-parser-version>
|
||||
<swagger-core-version>2.0.1</swagger-core-version>
|
||||
<scala-version>2.11.1</scala-version>
|
||||
<felix-version>3.3.0</felix-version>
|
||||
|
||||
@@ -28,7 +28,7 @@ public class ApiClientTest {
|
||||
assertEquals(dateStr, apiClient.formatDate(apiClient.parseDate("2015-11-07T02:49:09.356-01:00")));
|
||||
|
||||
// custom date format: without milli-seconds, custom time zone
|
||||
DateFormat format = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssXXX");
|
||||
DateFormat format = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssXXX", Locale.ROOT);
|
||||
format.setTimeZone(TimeZone.getTimeZone("GMT+10"));
|
||||
apiClient.setDateFormat(format);
|
||||
dateStr = "2015-11-07T13:49:09+10:00";
|
||||
|
||||
@@ -28,7 +28,7 @@ public class ApiClientTest {
|
||||
assertEquals(dateStr, apiClient.formatDate(apiClient.parseDate("2015-11-07T02:49:09.356-01:00")));
|
||||
|
||||
// custom date format: without milli-seconds, custom time zone
|
||||
DateFormat format = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssXXX");
|
||||
DateFormat format = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssXXX", Locale.ROOT);
|
||||
format.setTimeZone(TimeZone.getTimeZone("GMT+10"));
|
||||
apiClient.setDateFormat(format);
|
||||
dateStr = "2015-11-07T13:49:09+10:00";
|
||||
|
||||
@@ -12,6 +12,7 @@ import java.text.SimpleDateFormat;
|
||||
import java.util.Calendar;
|
||||
import java.util.Date;
|
||||
import java.util.GregorianCalendar;
|
||||
import java.util.Locale;
|
||||
import java.util.TimeZone;
|
||||
|
||||
import okio.ByteString;
|
||||
@@ -46,7 +47,7 @@ public class JSONTest {
|
||||
assertEquals(json.deserialize("\"2015-11-07T03:49:09.356" + getCurrentTimezoneOffset() + "\"", java.sql.Date.class).toString(), date.toString());
|
||||
|
||||
// custom date format: without day
|
||||
DateFormat format = new SimpleDateFormat("yyyy-MM");
|
||||
DateFormat format = new SimpleDateFormat("yyyy-MM", Locale.ROOT);
|
||||
apiClient.setSqlDateFormat(format);
|
||||
String dateStr = "\"2015-11\"";
|
||||
assertEquals(dateStr, json.serialize(json.deserialize("\"2015-11-07T03:49:09Z\"", java.sql.Date.class)));
|
||||
@@ -79,7 +80,7 @@ public class JSONTest {
|
||||
assertEquals(utcDate, json.serialize(date));
|
||||
|
||||
// custom datetime format: without milli-seconds, custom time zone
|
||||
DateFormat format = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssXXX");
|
||||
DateFormat format = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssXXX", Locale.ROOT);
|
||||
format.setTimeZone(TimeZone.getTimeZone("GMT+10"));
|
||||
apiClient.setDateFormat(format);
|
||||
|
||||
@@ -190,10 +191,10 @@ public class JSONTest {
|
||||
public static String getCurrentTimezoneOffset() {
|
||||
|
||||
TimeZone tz = TimeZone.getDefault();
|
||||
Calendar cal = GregorianCalendar.getInstance(tz);
|
||||
Calendar cal = GregorianCalendar.getInstance(tz, Locale.ROOT);
|
||||
int offsetInMillis = tz.getOffset(cal.getTimeInMillis());
|
||||
|
||||
String offset = String.format("%02d:%02d", Math.abs(offsetInMillis / 3600000), Math.abs((offsetInMillis / 60000) % 60));
|
||||
String offset = String.format(Locale.ROOT,"%02d:%02d", Math.abs(offsetInMillis / 3600000), Math.abs((offsetInMillis / 60000) % 60));
|
||||
offset = (offsetInMillis >= 0 ? "+" : "-") + offset;
|
||||
|
||||
return offset;
|
||||
|
||||
@@ -34,7 +34,7 @@ public class ApiClientTest {
|
||||
assertEquals(dateStr, apiClient.formatDate(apiClient.parseDate("2015-11-07T02:49:09.356-01:00")));
|
||||
|
||||
// custom date format: without milli-seconds, custom time zone
|
||||
DateFormat format = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssXXX");
|
||||
DateFormat format = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssXXX", Locale.ROOT);
|
||||
format.setTimeZone(TimeZone.getTimeZone("GMT+10"));
|
||||
apiClient.setDateFormat(format);
|
||||
dateStr = "2015-11-07T13:49:09+10:00";
|
||||
|
||||
@@ -14,8 +14,9 @@ COPY ./LICENSE ${GEN_DIR}
|
||||
COPY ./google_checkstyle.xml ${GEN_DIR}
|
||||
|
||||
# Modules are copied individually here to allow for caching of docker layers between major.minor versions
|
||||
# NOTE: openapi-generator-online is not included here
|
||||
COPY ./modules/openapi-generator-gradle-plugin ${GEN_DIR}/modules/openapi-generator-gradle-plugin
|
||||
COPY ./modules/openapi-generator-maven-plugin ${GEN_DIR}/modules/openapi-generator-maven-plugin
|
||||
COPY ./modules/openapi-generator-online ${GEN_DIR}/modules/openapi-generator-online
|
||||
COPY ./modules/openapi-generator-cli ${GEN_DIR}/modules/openapi-generator-cli
|
||||
COPY ./modules/openapi-generator ${GEN_DIR}/modules/openapi-generator
|
||||
COPY ./pom.xml ${GEN_DIR}
|
||||
|
||||
64
README.md
64
README.md
@@ -2,16 +2,11 @@
|
||||
|
||||
<div align="center">
|
||||
|
||||
[Master](https://github.com/OpenAPITools/openapi-generator/tree/master) (`3.1.2`): [](https://travis-ci.org/OpenAPITools/openapi-generator)
|
||||
[Master](https://github.com/OpenAPITools/openapi-generator/tree/master) (`3.2.3`): [](https://travis-ci.org/OpenAPITools/openapi-generator)
|
||||
[](https://circleci.com/gh/OpenAPITools/openapi-generator)
|
||||
[](https://app.shippable.com/github/OpenAPITools/openapi-generator)
|
||||
[](https://ci.appveyor.com/project/WilliamCheng/openapi-generator-wh2wu)
|
||||
|
||||
[`3.2.x`](https://github.com/OpenAPITools/openapi-generator/tree/3.2.x) branch: [](https://travis-ci.org/OpenAPITools/openapi-generator)
|
||||
[](https://circleci.com/gh/OpenAPITools/openapi-generator)
|
||||
[](https://app.shippable.com/github/OpenAPITools/openapi-generator)
|
||||
[](https://ci.appveyor.com/project/WilliamCheng/openapi-generator-wh2wu)
|
||||
|
||||
[`4.0.x`](https://github.com/OpenAPITools/openapi-generator/tree/4.0.x) branch: [](https://travis-ci.org/OpenAPITools/openapi-generator)
|
||||
[](https://circleci.com/gh/OpenAPITools/openapi-generator)
|
||||
[](https://app.shippable.com/github/OpenAPITools/openapi-generator)
|
||||
@@ -85,19 +80,18 @@ OpenAPI Generator allows generation of API client libraries (SDK generation), se
|
||||
|
||||
The OpenAPI Specification has undergone 3 revisions since initial creation in 2010. The openapi-generator project has the following compatibilities with the OpenAPI Specification:
|
||||
|
||||
OpenAPI Generator Version | Release Date | OpenAPI Spec compatibility | Notes
|
||||
---------------------------- | ------------ | -------------------------- | -----
|
||||
4.0.0 (upcoming major release) [SNAPSHOT](https://oss.sonatype.org/content/repositories/snapshots/org/openapitools/openapi-generator-cli/4.0.0-SNAPSHOT/)| TBD | 1.0, 1.1, 1.2, 2.0, 3.0 | Major release with breaking changes (no fallback)
|
||||
3.2.0 (upcoming minor release) [SNAPSHOT](https://oss.sonatype.org/content/repositories/snapshots/org/openapitools/openapi-generator-cli/3.2.0-SNAPSHOT/)| TBD | 1.0, 1.1, 1.2, 2.0, 3.0 | Minor release with breaking changes (with fallbacks)
|
||||
[3.1.2](https://github.com/OpenAPITools/openapi-generator/releases/tag/v3.1.2) | 25.07.2018 | 1.0, 1.1, 1.2, 2.0, 3.0 | Bugfix release
|
||||
[3.1.1](https://github.com/OpenAPITools/openapi-generator/releases/tag/v3.1.1) | 18.07.2018 | 1.0, 1.1, 1.2, 2.0, 3.0 | Bugfix release
|
||||
[3.1.0](https://github.com/OpenAPITools/openapi-generator/releases/tag/v3.1.0) | 06.07.2018 | 1.0, 1.1, 1.2, 2.0, 3.0 | Minor release with breaking changes (with fallbacks)
|
||||
[3.0.3](https://github.com/OpenAPITools/openapi-generator/releases/tag/v3.0.3) | 27.06.2018 | 1.0, 1.1, 1.2, 2.0, 3.0 | Bugfix release
|
||||
[3.0.2](https://github.com/OpenAPITools/openapi-generator/releases/tag/v3.0.2) | 18.06.2018 | 1.0, 1.1, 1.2, 2.0, 3.0 | Bugfix release
|
||||
[3.0.1](https://github.com/OpenAPITools/openapi-generator/releases/tag/v3.0.1) | 11.06.2018 | 1.0, 1.1, 1.2, 2.0, 3.0 | Bugfix release
|
||||
[3.0.0](https://github.com/OpenAPITools/openapi-generator/releases/tag/v3.0.0) | 01.06.2018 | 1.0, 1.1, 1.2, 2.0, 3.0 | First release with breaking changes
|
||||
OpenAPI Generator Version | Release Date | Notes
|
||||
---------------------------- | ------------ | -----
|
||||
4.0.0 (upcoming major release) [SNAPSHOT](https://oss.sonatype.org/content/repositories/snapshots/org/openapitools/openapi-generator-cli/4.0.0-SNAPSHOT/)| TBD | Major release with breaking changes (no fallback)
|
||||
3.3.0 (upcoming minor release)| TBD | Minor release (breaking changes with fallbacks)
|
||||
3.2.3 (current master, upcoming patch release) [SNAPSHOT](https://oss.sonatype.org/content/repositories/snapshots/org/openapitools/openapi-generator-cli/3.2.3-SNAPSHOT/)| TBD | Bugfix release
|
||||
[3.2.2](https://github.com/OpenAPITools/openapi-generator/releases/tag/v3.2.2) (latest stable release) | 22.08.2018 | Bugfix release
|
||||
|
||||
### [1.2 - Artifacts on Maven Central](#table-of-contents)
|
||||
OpenAPI Spec compatibility: 1.0, 1.1, 1.2, 2.0, 3.0
|
||||
|
||||
For old releases, please refer to the [**Release**](https://github.com/OpenAPITools/openapi-generator/releases) page.
|
||||
|
||||
## [1.2 - Artifacts on Maven Central](#table-of-contents)
|
||||
|
||||
You can find our released artefacts on maven central:
|
||||
|
||||
@@ -147,16 +141,16 @@ See the different versions of the [openapi-generator-cli](https://mvnrepository.
|
||||
|
||||
If you're looking for the latest stable version, you can grab it directly from Maven.org (Java 8 runtime at a minimum):
|
||||
|
||||
JAR location: `http://central.maven.org/maven2/org/openapitools/openapi-generator-cli/3.1.2/openapi-generator-cli-3.1.2.jar`
|
||||
JAR location: `http://central.maven.org/maven2/org/openapitools/openapi-generator-cli/3.2.2/openapi-generator-cli-3.2.2.jar`
|
||||
|
||||
For **Mac/Linux** users:
|
||||
```sh
|
||||
wget http://central.maven.org/maven2/org/openapitools/openapi-generator-cli/3.1.2/openapi-generator-cli-3.1.2.jar -O openapi-generator-cli.jar
|
||||
wget http://central.maven.org/maven2/org/openapitools/openapi-generator-cli/3.2.2/openapi-generator-cli-3.2.2.jar -O openapi-generator-cli.jar
|
||||
```
|
||||
|
||||
For **Windows** users, you will need to install [wget](http://gnuwin32.sourceforge.net/packages/wget.htm) or you can use Invoke-WebRequest in PowerShell (3.0+), e.g.
|
||||
```
|
||||
Invoke-WebRequest -OutFile openapi-generator-cli.jar http://central.maven.org/maven2/org/openapitools/openapi-generator-cli/3.1.2/openapi-generator-cli-3.1.2.jar
|
||||
Invoke-WebRequest -OutFile openapi-generator-cli.jar http://central.maven.org/maven2/org/openapitools/openapi-generator-cli/3.2.2/openapi-generator-cli-3.2.2.jar
|
||||
```
|
||||
|
||||
After downloading the JAR, run `java -jar openapi-generator-cli.jar help` to show the usage.
|
||||
@@ -169,7 +163,7 @@ export PATH=${JAVA_HOME}/bin:$PATH
|
||||
|
||||
### Launcher Script
|
||||
|
||||
One downside to manual jar downloads is that you don't keep up-to-date with the latest released version. We have a Bash launcher script at [bin/utils/openapi-generator.cli.sh](./bin/utils/openapi-generator.cli.sh) which resolves this issue.
|
||||
One downside to manual jar downloads is that you don't keep up-to-date with the latest released version. We have a Bash launcher script at [bin/utils/openapi-generator.cli.sh](./bin/utils/openapi-generator-cli.sh) which resolves this issue.
|
||||
|
||||
To install the launcher script, copy the contents of the script to a location on your path and make the script executable.
|
||||
|
||||
@@ -177,7 +171,7 @@ An example of setting this up (NOTE: Always evaluate scripts curled from externa
|
||||
|
||||
```
|
||||
mkdir -p ~/bin/openapitools
|
||||
curl https://raw.githubusercontent.com/OpenAPITools/openapi-generator/master/bin/utils/openapi-generator.cli.sh > ~/bin/openapitools/openapi-generator-cli
|
||||
curl https://raw.githubusercontent.com/OpenAPITools/openapi-generator/master/bin/utils/openapi-generator-cli.sh > ~/bin/openapitools/openapi-generator-cli
|
||||
chmod u+x ~/bin/openapitools/openapi-generator-cli
|
||||
export PATH=$PATH:~/bin/openapitools/
|
||||
```
|
||||
@@ -322,6 +316,20 @@ Once built, `run-in-docker.sh` will act as an executable for openapi-generator-c
|
||||
-g go -o /gen/out/go-petstore -DpackageName=petstore # generates go client, outputs locally to ./out/go-petstore
|
||||
```
|
||||
|
||||
##### Troubleshooting
|
||||
|
||||
If an error like this occurs, just execute the **mvn clean install -U** command:
|
||||
|
||||
> org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.19.1:test (default-test) on project openapi-generator: A type incompatibility occurred while executing org.apache.maven.plugins:maven-surefire-plugin:2.19.1:test: java.lang.ExceptionInInitializerError cannot be cast to java.io.IOException
|
||||
|
||||
```sh
|
||||
./run-in-docker.sh mvn clean install -U
|
||||
```
|
||||
|
||||
> Failed to execute goal org.fortasoft:gradle-maven-plugin:1.0.8:invoke (default) on project openapi-generator-gradle-plugin-mvn-wrapper: org.gradle.tooling.BuildException: Could not execute build using Gradle distribution 'https://services.gradle.org/distributions/gradle-4.7-bin.zip'
|
||||
|
||||
Right now: no solution for this one :|
|
||||
|
||||
#### Run Docker in Vagrant
|
||||
Prerequisite: install [Vagrant](https://www.vagrantup.com/downloads.html) and [VirtualBox](https://www.virtualbox.org/wiki/Downloads).
|
||||
```sh
|
||||
@@ -398,13 +406,14 @@ SYNOPSIS
|
||||
[--invoker-package <invoker package>]
|
||||
[(-l <language> | --lang <language>)]
|
||||
[--language-specific-primitives <language specific primitives>...]
|
||||
[--library <library>] [--model-name-prefix <model name prefix>]
|
||||
[--library <library>] [--log-to-stderr]
|
||||
[--model-name-prefix <model name prefix>]
|
||||
[--model-name-suffix <model name suffix>]
|
||||
[--model-package <model package>]
|
||||
[(-o <output directory> | --output <output directory>)]
|
||||
[--release-note <release note>] [--remove-operation-id-prefix]
|
||||
[--reserved-words-mappings <reserved word mappings>...]
|
||||
[(-s | --skip-overwrite)]
|
||||
[(-s | --skip-overwrite)] [--skip-validate-spec]
|
||||
[(-t <template directory> | --template-dir <template directory>)]
|
||||
[--type-mappings <type mappings>...] [(-v | --verbose)]
|
||||
|
||||
@@ -464,6 +473,7 @@ Here are some companies/projects (alphabetical order) using OpenAPI Generator in
|
||||
- [Raiffeisen Schweiz Genossenschaft](https://www.raiffeisen.ch)
|
||||
- [RepreZen API Studio](https://www.reprezen.com/swagger-openapi-code-generation-api-first-microservices-enterprise-development)
|
||||
- [REST United](https://restunited.com)
|
||||
- [Suva](https://www.suva.ch/)
|
||||
- [Telstra](https://dev.telstra.com)
|
||||
- [unblu inc.](https://www.unblu.com/)
|
||||
|
||||
@@ -474,7 +484,7 @@ Here are some companies/projects (alphabetical order) using OpenAPI Generator in
|
||||
- 2018/05/15 - [REST API仕様からAPIクライアントやスタブサーバを自動生成する「OpenAPI Generator」オープンソースで公開。Swagger Codegenからのフォーク](https://www.publickey1.jp/blog/18/rest_apiapiopenapi_generatorswagger_generator.html) by [Publickey](https://www.publickey1.jp)
|
||||
- 2018/06/08 - [Swagger Codegen is now OpenAPI Generator](https://angular.schule/blog/2018-06-swagger-codegen-is-now-openapi-generator) by [JohannesHoppe](https://github.com/JohannesHoppe)
|
||||
- 2018/06/21 - [Connect your JHipster apps to the world of APIs with OpenAPI and gRPC](https://fr.slideshare.net/chbornet/jhipster-conf-2018-connect-your-jhipster-apps-to-the-world-of-apis-with-openapi-and-grpc) by [Christophe Bornet](https://github.com/cbornet) at [JHipster Conf 2018](https://jhipster-conf.github.io/)
|
||||
- 2018/06/27 - [Lessons Learned from Leading an Open-Source Project Supporting 30+ Programming Languages](https://speakerdeck.com/wing328/lessons-learned-from-leading-an-open-source-project-supporting-30-plus-programming-languages) - [William Cheng](https://github.com/wing328) at [LinuxCon + ContainerCon + CloudOpen China 2018](https://www.lfasiallc.com/events/lc3-2018/)
|
||||
- 2018/06/27 - [Lessons Learned from Leading an Open-Source Project Supporting 30+ Programming Languages](https://speakerdeck.com/wing328/lessons-learned-from-leading-an-open-source-project-supporting-30-plus-programming-languages) - [William Cheng](https://github.com/wing328) at [LinuxCon + ContainerCon + CloudOpen China 2018](http://bit.ly/2waDKKX)
|
||||
- 2018/07/19 - [OpenAPI Generator Contribution Quickstart - RingCentral Go SDK](https://medium.com/ringcentral-developers/openapi-generator-for-go-contribution-quickstart-8cc72bf37b53) by [John Wang](https://github.com/grokify)
|
||||
|
||||
## [6 - About Us](#table-of-contents)
|
||||
@@ -550,6 +560,7 @@ Here is a list of template creators:
|
||||
* Ada: @stcarrez
|
||||
* C# ASP.NET5: @jimschubert
|
||||
* C# NancyFX: @mstefaniuk
|
||||
* C++ (Qt5 QHttpEngine): @etherealjoy
|
||||
* C++ Pistache: @sebymiano
|
||||
* C++ Restbed: @stkrwork
|
||||
* Erlang Server: @galaxie
|
||||
@@ -565,6 +576,7 @@ Here is a list of template creators:
|
||||
* JAX-RS CXF (CDI): @nickcmaynard
|
||||
* JAX-RS RestEasy (JBoss EAP): @jfiala
|
||||
* Kotlin: @jimschubert
|
||||
* PHP Laravel: @renepardon
|
||||
* PHP Lumen: @abcsun
|
||||
* PHP Slim: @jfastnacht
|
||||
* PHP Symfony: @ksm2
|
||||
|
||||
@@ -35,6 +35,8 @@ build_script:
|
||||
# install openapi-generator locally
|
||||
- mvn clean install --quiet
|
||||
test_script:
|
||||
# restore test-related files
|
||||
- copy /b/v/y CI\samples.ci\client\petstore\csharp\OpenAPIClient\src\Org.OpenAPITools.Test\Org.OpenAPITools.Test.csproj samples\client\petstore\csharp\OpenAPIClient\src\Org.OpenAPITools.Test\Org.OpenAPITools.Test.csproj
|
||||
# test c# API client
|
||||
- nunit-console samples\client\petstore\csharp\OpenAPIClient\src\Org.OpenAPITools.Test\bin\Debug\Org.OpenAPITools.Test.dll --result=myresults.xml;format=AppVeyor
|
||||
# test c# API client (with PropertyChanged)
|
||||
@@ -42,6 +44,10 @@ test_script:
|
||||
|
||||
# generate all petstore clients
|
||||
- .\bin\windows\run-all-petstore.cmd
|
||||
|
||||
# generate all petstore clients (openapi3)
|
||||
- .\bin\openapi3\windows\run-all-petstore.cmd
|
||||
|
||||
cache:
|
||||
- C:\maven\
|
||||
- C:\Users\appveyor\.m2
|
||||
|
||||
32
bin/cpp-qt5-qhttpengine-server-petstore.sh
Executable file
32
bin/cpp-qt5-qhttpengine-server-petstore.sh
Executable file
@@ -0,0 +1,32 @@
|
||||
#!/bin/sh
|
||||
|
||||
SCRIPT="$0"
|
||||
echo "# START SCRIPT: $SCRIPT"
|
||||
|
||||
while [ -h "$SCRIPT" ] ; do
|
||||
ls=`ls -ld "$SCRIPT"`
|
||||
link=`expr "$ls" : '.*-> \(.*\)$'`
|
||||
if expr "$link" : '/.*' > /dev/null; then
|
||||
SCRIPT="$link"
|
||||
else
|
||||
SCRIPT=`dirname "$SCRIPT"`/"$link"
|
||||
fi
|
||||
done
|
||||
|
||||
if [ ! -d "${APP_DIR}" ]; then
|
||||
APP_DIR=`dirname "$SCRIPT"`/..
|
||||
APP_DIR=`cd "${APP_DIR}"; pwd`
|
||||
fi
|
||||
|
||||
executable="./modules/openapi-generator-cli/target/openapi-generator-cli.jar"
|
||||
|
||||
if [ ! -f "$executable" ]
|
||||
then
|
||||
mvn -B clean package
|
||||
fi
|
||||
|
||||
# if you've executed sbt assembly previously it will use that instead.
|
||||
export JAVA_OPTS="${JAVA_OPTS} -XX:MaxPermSize=256M -Xmx1024M -DloggerPath=conf/log4j.properties"
|
||||
ags="generate -t modules/openapi-generator/src/main/resources/cpp-qt5-qhttpengine-server -i modules/openapi-generator/src/test/resources/2_0/petstore.yaml -g cpp-qt5-qhttpengine-server -o samples/server/petstore/cpp-qt5-qhttpengine-server $@"
|
||||
|
||||
java $JAVA_OPTS -jar $executable $ags
|
||||
@@ -29,8 +29,9 @@ fi
|
||||
export JAVA_OPTS="${JAVA_OPTS} -XX:MaxPermSize=256M -Xmx1024M -DloggerPath=conf/log4j.properties"
|
||||
ags="generate -i modules/openapi-generator/src/test/resources/2_0/petstore-with-fake-endpoints-models-for-testing.yaml -g csharp -o samples/client/petstore/csharp/OpenAPIClient --additional-properties packageGuid={321C8C3F-0156-40C1-AE42-D59761FB9B6C} $@"
|
||||
|
||||
java $JAVA_OPTS -jar $executable $ags
|
||||
|
||||
# restore csproj file
|
||||
echo "restore csproject file: CI/samples/client/petstore/csharp/OpenAPIClient/src/Org.OpenAPITools.Test/Org.OpenAPITools.Test.csproj"
|
||||
cp ./CI/samples/client/petstore/csharp/OpenAPIClient/src/Org.OpenAPITools.Test/Org.OpenAPITools.Test.csproj ./samples/client/petstore/csharp/OpenAPIClient/src/Org.OpenAPITools.Test/
|
||||
cp ./CI/samples.ci/client/petstore/csharp/OpenAPIClient/src/Org.OpenAPITools.Test/Org.OpenAPITools.Test.csproj ./samples/client/petstore/csharp/OpenAPIClient/src/Org.OpenAPITools.Test/
|
||||
|
||||
java $JAVA_OPTS -jar $executable $ags
|
||||
|
||||
@@ -27,6 +27,6 @@ fi
|
||||
|
||||
# if you've executed sbt assembly previously it will use that instead.
|
||||
export JAVA_OPTS="${JAVA_OPTS} -XX:MaxPermSize=256M -Xmx1024M -DloggerPath=conf/log4j.properties"
|
||||
ags="generate -i modules/openapi-generator/src/test/resources/2_0/petstore.yaml -g dynamic-html -o samples/dynamic-html $@"
|
||||
ags="generate -i modules/openapi-generator/src/test/resources/2_0/petstore.yaml -g dynamic-html -o samples/documentation/dynamic-html $@"
|
||||
|
||||
java $JAVA_OPTS -jar $executable $ags
|
||||
|
||||
@@ -27,6 +27,6 @@ fi
|
||||
|
||||
# if you've executed sbt assembly previously it will use that instead.
|
||||
export JAVA_OPTS="${JAVA_OPTS} -XX:MaxPermSize=256M -Xmx1024M -DloggerPath=conf/log4j.properties"
|
||||
ags="generate -i modules/openapi-generator/src/test/resources/2_0/petstore.yaml -g elm -o samples/client/petstore/elm $@"
|
||||
ags="generate -i modules/openapi-generator/src/test/resources/2_0/petstore.yaml -g elm -t modules/openapi-generator/src/main/resources/elm -o samples/client/petstore/elm $@"
|
||||
|
||||
java $JAVA_OPTS -jar $executable $ags
|
||||
|
||||
@@ -27,6 +27,6 @@ fi
|
||||
|
||||
# if you've executed sbt assembly previously it will use that instead.
|
||||
export JAVA_OPTS="${JAVA_OPTS} -XX:MaxPermSize=256M -Xmx1024M -DloggerPath=conf/log4j.properties"
|
||||
ags="generate -i modules/openapi-generator/src/test/resources/2_0/markdown.yaml -g html -o samples/html.md $@"
|
||||
ags="generate -i modules/openapi-generator/src/test/resources/2_0/markdown.yaml -g html -o samples/documentation/html.md $@"
|
||||
|
||||
java $JAVA_OPTS -jar $executable $ags
|
||||
|
||||
@@ -27,6 +27,6 @@ fi
|
||||
|
||||
# if you've executed sbt assembly previously it will use that instead.
|
||||
export JAVA_OPTS="${JAVA_OPTS} -XX:MaxPermSize=256M -Xmx1024M -DloggerPath=conf/log4j.properties"
|
||||
ags="generate -i modules/openapi-generator/src/test/resources/2_0/petstore.yaml -g html -o samples/html $@"
|
||||
ags="generate -i modules/openapi-generator/src/test/resources/2_0/petstore.yaml -g html -o samples/documentation/html $@"
|
||||
|
||||
java $JAVA_OPTS -jar $executable $ags
|
||||
|
||||
@@ -27,6 +27,6 @@ fi
|
||||
|
||||
# if you've executed sbt assembly previously it will use that instead.
|
||||
export JAVA_OPTS="${JAVA_OPTS} -XX:MaxPermSize=256M -Xmx1024M -DloggerPath=conf/log4j.properties"
|
||||
ags="generate -i modules/openapi-generator/src/test/resources/2_0/petstore.yaml -g html2 -o samples/html2 --additional-properties hideGenerationTimestamp=true $@"
|
||||
ags="generate -i modules/openapi-generator/src/test/resources/2_0/petstore.yaml -g html2 -o samples/documentation/html2 --additional-properties hideGenerationTimestamp=true $@"
|
||||
|
||||
java $JAVA_OPTS -jar $executable $ags
|
||||
|
||||
@@ -27,7 +27,7 @@ fi
|
||||
|
||||
# if you've executed sbt assembly previously it will use that instead.
|
||||
export JAVA_OPTS="${JAVA_OPTS} -XX:MaxPermSize=256M -Xmx1024M -DloggerPath=conf/log4j.properties"
|
||||
ags="generate --artifact-id petstore-java-client-jersey1 -t modules/openapi-generator/src/main/resources/Java -i modules/openapi-generator/src/test/resources/2_0/petstore-with-fake-endpoints-models-for-testing.yaml -g java -o samples/client/petstore/java/jersey1 -DhideGenerationTimestamp=true --library=jersey1 $@"
|
||||
ags="generate --artifact-id petstore-java-client-jersey1 -t modules/openapi-generator/src/main/resources/Java -i modules/openapi-generator/src/test/resources/2_0/petstore-with-fake-endpoints-models-for-testing.yaml -g java -o samples/client/petstore/java/jersey1 -DhideGenerationTimestamp=true --library=jersey1 --additional-properties useNullForUnknownEnumValue=true $@"
|
||||
|
||||
echo "Removing files and folders under samples/client/petstore/java/jersey1/src/main"
|
||||
rm -rf samples/client/petstore/java/jersey1/src/main
|
||||
|
||||
@@ -1,4 +1,7 @@
|
||||
{
|
||||
"library": "jersey2",
|
||||
"artifactId": "petstore-jersey2"
|
||||
"artifactId": "petstore-jersey2",
|
||||
"additionalProperties" : {
|
||||
"useNullForUnknownEnumValue" : true
|
||||
}
|
||||
}
|
||||
|
||||
32
bin/openapi3/cpp-qt5-qhttpengine-server-petstore.sh
Executable file
32
bin/openapi3/cpp-qt5-qhttpengine-server-petstore.sh
Executable file
@@ -0,0 +1,32 @@
|
||||
#!/bin/sh
|
||||
|
||||
SCRIPT="$0"
|
||||
echo "# START SCRIPT: $SCRIPT"
|
||||
|
||||
while [ -h "$SCRIPT" ] ; do
|
||||
ls=`ls -ld "$SCRIPT"`
|
||||
link=`expr "$ls" : '.*-> \(.*\)$'`
|
||||
if expr "$link" : '/.*' > /dev/null; then
|
||||
SCRIPT="$link"
|
||||
else
|
||||
SCRIPT=`dirname "$SCRIPT"`/"$link"
|
||||
fi
|
||||
done
|
||||
|
||||
if [ ! -d "${APP_DIR}" ]; then
|
||||
APP_DIR=`dirname "$SCRIPT"`/..
|
||||
APP_DIR=`cd "${APP_DIR}"; pwd`
|
||||
fi
|
||||
|
||||
executable="./modules/openapi-generator-cli/target/openapi-generator-cli.jar"
|
||||
|
||||
if [ ! -f "$executable" ]
|
||||
then
|
||||
mvn clean package
|
||||
fi
|
||||
|
||||
# if you've executed sbt assembly previously it will use that instead.
|
||||
export JAVA_OPTS="${JAVA_OPTS} -XX:MaxPermSize=256M -Xmx1024M -DloggerPath=conf/log4j.properties"
|
||||
ags="generate -t modules/openapi-generator/src/main/resources/cpp-qt5-qhttpengine-server -i modules/openapi-generator/src/test/resources/3_0/petstore.yaml -g cpp-qt5-qhttpengine-server -o samples/client/petstore/cpp-qt5-qhttpengine-server $@"
|
||||
|
||||
java $JAVA_OPTS -jar $executable $ags
|
||||
@@ -27,6 +27,6 @@ fi
|
||||
|
||||
# if you've executed sbt assembly previously it will use that instead.
|
||||
export JAVA_OPTS="${JAVA_OPTS} -XX:MaxPermSize=256M -Xmx1024M -DloggerPath=conf/log4j.properties"
|
||||
ags="generate $@ -i modules/openapi-generator/src/test/resources/3_0/petstore-with-fake-endpoints-models-for-testing.yaml -g csharp -o samples/client/petstore/csharp/OpenAPIClient --additional-properties packageGuid={321C8C3F-0156-40C1-AE42-D59761FB9B6C}"
|
||||
ags="generate $@ -i modules/openapi-generator/src/test/resources/3_0/petstore-with-fake-endpoints-models-for-testing.yaml -g csharp -o samples/openapi3/client/petstore/csharp/OpenAPIClient --additional-properties packageGuid={321C8C3F-0156-40C1-AE42-D59761FB9B6C}"
|
||||
|
||||
java $JAVA_OPTS -jar $executable $ags
|
||||
|
||||
32
bin/openapi3/jaxrs-jersey-petstore.sh
Normal file
32
bin/openapi3/jaxrs-jersey-petstore.sh
Normal file
@@ -0,0 +1,32 @@
|
||||
#!/bin/sh
|
||||
|
||||
SCRIPT="$0"
|
||||
echo "# START SCRIPT: $SCRIPT"
|
||||
|
||||
while [ -h "$SCRIPT" ] ; do
|
||||
ls=`ls -ld "$SCRIPT"`
|
||||
link=`expr "$ls" : '.*-> \(.*\)$'`
|
||||
if expr "$link" : '/.*' > /dev/null; then
|
||||
SCRIPT="$link"
|
||||
else
|
||||
SCRIPT=`dirname "$SCRIPT"`/"$link"
|
||||
fi
|
||||
done
|
||||
|
||||
if [ ! -d "${APP_DIR}" ]; then
|
||||
APP_DIR=`dirname "$SCRIPT"`/..
|
||||
APP_DIR=`cd "${APP_DIR}"; pwd`
|
||||
fi
|
||||
|
||||
executable="./modules/openapi-generator-cli/target/openapi-generator-cli.jar"
|
||||
|
||||
if [ ! -f "$executable" ]
|
||||
then
|
||||
mvn clean package
|
||||
fi
|
||||
|
||||
# if you've executed sbt assembly previously it will use that instead.
|
||||
export JAVA_OPTS="${JAVA_OPTS} -XX:MaxPermSize=256M -Xmx1024M -DloggerPath=conf/log4j.properties"
|
||||
ags="generate --artifact-id "openapiv3-jaxrs-jersey-petstore-server" -t modules/openapi-generator/src/main/resources/JavaJaxRS/ -i modules/openapi-generator/src/test/resources/3_0/petstore.yaml -g jaxrs-jersey -o samples/server/petstore/jaxrs-jersey $@"
|
||||
|
||||
java $JAVA_OPTS -jar $executable $ags
|
||||
42
bin/openapi3/php-laravel-petstore.sh
Executable file
42
bin/openapi3/php-laravel-petstore.sh
Executable file
@@ -0,0 +1,42 @@
|
||||
#!/bin/bash
|
||||
|
||||
SCRIPT="$0"
|
||||
echo "# START SCRIPT: $SCRIPT"
|
||||
|
||||
while [ -h "$SCRIPT" ] ; do
|
||||
ls=`ls -ld "$SCRIPT"`
|
||||
link=`expr "$ls" : '.*-> \(.*\)$'`
|
||||
if expr "$link" : '/.*' > /dev/null; then
|
||||
SCRIPT="$link"
|
||||
else
|
||||
SCRIPT=`dirname "$SCRIPT"`/"$link"
|
||||
fi
|
||||
done
|
||||
|
||||
# Make sure that the working directory is the root dir
|
||||
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
|
||||
cd "${SCRIPT_DIR}/../"
|
||||
|
||||
if [ ! -d "${APP_DIR}" ]; then
|
||||
APP_DIR=`dirname "$SCRIPT"`/..
|
||||
APP_DIR=`cd "${APP_DIR}"; pwd`
|
||||
fi
|
||||
|
||||
# Make sure that we are regenerating the sample by removing any existing target directory
|
||||
TARGET_DIR="$SCRIPT_DIR/../../samples/server/petstore/php-laravel"
|
||||
if [ -d "$TARGET_DIR" ]; then
|
||||
rm -rf $TARGET_DIR
|
||||
fi
|
||||
|
||||
executable="$SCRIPT_DIR/../../modules/openapi-generator-cli/target/openapi-generator-cli.jar"
|
||||
|
||||
if [ ! -f "$executable" ]
|
||||
then
|
||||
mvn clean package
|
||||
fi
|
||||
|
||||
# if you've executed sbt assembly previously it will use that instead.
|
||||
export JAVA_OPTS="${JAVA_OPTS} -XX:MaxPermSize=256M -Xmx1024M -DloggerPath=conf/log4j.properties"
|
||||
ags="generate -t $SCRIPT_DIR/../../modules/openapi-generator/src/main/resources/php-laravel -i $SCRIPT_DIR/../../modules/openapi-generator/src/test/resources/3_0/petstore.yaml -g php-laravel -o $TARGET_DIR $@"
|
||||
|
||||
java $JAVA_OPTS -jar $executable $ags
|
||||
@@ -33,6 +33,6 @@ fi
|
||||
|
||||
# if you've executed sbt assembly previously it will use that instead.
|
||||
export JAVA_OPTS="${JAVA_OPTS} -XX:MaxPermSize=256M -Xmx1024M -DloggerPath=conf/log4j.properties"
|
||||
ags="generate -t modules/openapi-generator/src/main/resources/php -i modules/openapi-generator/src/test/resources/3_0/petstore-with-fake-endpoints-models-for-testing.yaml -g php -o samples/openapi3/client/petstore/php $@"
|
||||
ags="generate -t modules/openapi-generator/src/main/resources/php -i modules/openapi-generator/src/test/resources/3_0/petstore-with-fake-endpoints-models-for-testing.yaml -g php -o samples/openapi3/client/petstore/php/OpenAPIClient-php $@"
|
||||
|
||||
java $JAVA_OPTS -jar $executable $ags
|
||||
|
||||
@@ -27,6 +27,6 @@ fi
|
||||
|
||||
# if you've executed sbt assembly previously it will use that instead.
|
||||
export JAVA_OPTS="${JAVA_OPTS} -XX:MaxPermSize=256M -Xmx1024M -DloggerPath=conf/log4j.properties"
|
||||
ags="generate -t modules/openapi-generator/src/main/resources/php-silex -i modules/openapi-generator/src/test/resources/3_0/petstore.yaml -g php-silex -o samples/server/petstore/php-silex $@"
|
||||
ags="generate -t modules/openapi-generator/src/main/resources/php-silex -i modules/openapi-generator/src/test/resources/3_0/petstore.yaml -g php-silex -o samples/server/petstore/php-silex/OpenAPIServer $@"
|
||||
|
||||
java $JAVA_OPTS -jar $executable $ags
|
||||
|
||||
@@ -23,7 +23,7 @@ if [ ! -d "${APP_DIR}" ]; then
|
||||
fi
|
||||
|
||||
# Make sure that we are regenerating the sample by removing any existing target directory
|
||||
TARGET_DIR="$SCRIPT_DIR/../../samples/server/petstore/php-symfony"
|
||||
TARGET_DIR="$SCRIPT_DIR/../../samples/server/petstore/php-symfony/SymfonyBundle-php"
|
||||
if [ -d "$TARGET_DIR" ]; then
|
||||
rm -rf $TARGET_DIR
|
||||
fi
|
||||
|
||||
33
bin/openapi3/run-all-petstore
Executable file
33
bin/openapi3/run-all-petstore
Executable file
@@ -0,0 +1,33 @@
|
||||
#!/bin/bash
|
||||
# this bash script will loop through all the .sh files under bin
|
||||
# execute the script and check the result (exit code) to see if
|
||||
# there's any error
|
||||
|
||||
echo "IMPORTANT: this script should be run by the CI (e.g. Shippable) only. There's no need to run this script to update Petstore samples for all generators."
|
||||
echo "Please press CTRL+C to stop or the script will continue in 10 seconds."
|
||||
|
||||
sleep 10
|
||||
|
||||
successes=0
|
||||
failures=0
|
||||
for SCRIPT in $(ls -l ./bin/openapi3/*.sh | grep -v all)
|
||||
do
|
||||
if [ -f ${SCRIPT} -a -x ${SCRIPT} ]; then
|
||||
echo "Running $SCRIPT (output to /dev/null)"
|
||||
${SCRIPT} 2>&1 > /dev/null
|
||||
rc=$?
|
||||
if [[ ${rc} != 0 ]]; then
|
||||
>&2 echo "ERROR!! FAILED TO RUN ${SCRIPT}"
|
||||
((failures+=1))
|
||||
else
|
||||
((successes+=1))
|
||||
fi
|
||||
fi
|
||||
done
|
||||
|
||||
if (( failures > 0 )); then
|
||||
>&2 echo "[ERROR] ${failures} out of $((failures+successes)) scripts failed."
|
||||
exit 1
|
||||
else
|
||||
echo "[SUCCESS] ${successes} generators finished."
|
||||
fi
|
||||
14
bin/openapi3/windows/csharp-petstore.bat
Executable file
14
bin/openapi3/windows/csharp-petstore.bat
Executable file
@@ -0,0 +1,14 @@
|
||||
set executable=.\modules\openapi-generator-cli\target\openapi-generator-cli.jar
|
||||
|
||||
If Not Exist %executable% (
|
||||
mvn clean package
|
||||
)
|
||||
|
||||
REM set JAVA_OPTS=%JAVA_OPTS% -Xmx1024M
|
||||
set ags=generate -i modules\openapi-generator\src\test/resources\2_0\petstore-with-fake-endpoints-models-for-testing.yaml -g csharp -o samples\openapi3\client\petstore\csharp\SwaggerClient --additional-properties packageGuid={321C8C3F-0156-40C1-AE42-D59761FB9B6C}
|
||||
|
||||
java %JAVA_OPTS% -jar %executable% %ags%
|
||||
|
||||
REM restore csproj file
|
||||
echo "restore csproject file: CI\samples.ci\client\petstore\csharp\OpenAPIClient\src\Org.OpenAPITools.Test\Org.OpenAPITools.Test.csproj"
|
||||
copy /b/v/y CI\samples.ci\client\petstore\csharp\OpenAPIClient\src\Org.OpenAPITools.Test\Org.OpenAPITools.Test.csproj samples\openapi3\client\petstore\csharp\OpenAPIClient\src\Org.OpenAPITools.Test\
|
||||
15
bin/openapi3/windows/run-all-petstore.cmd
Normal file
15
bin/openapi3/windows/run-all-petstore.cmd
Normal file
@@ -0,0 +1,15 @@
|
||||
REM this batch file will loop through all the .bat files under bin\openapi3\windows\
|
||||
REM execute the script and check the error level to see if there's any error
|
||||
|
||||
echo IMPORTANT: this script should be run by the CI (e.g. appveyor) only. There's no need to run this script to update Petstore samples for all generators.
|
||||
echo Please press CTRL+C to stop or the script will continue in 10 seconds.
|
||||
|
||||
timeout 10
|
||||
|
||||
for /f "delims=" %%i in ('dir /b ".\bin\openapi3\windows\*.bat"') do (
|
||||
|
||||
CALL .\bin\openapi3\windows\%%i
|
||||
|
||||
IF ERRORLEVEL 1 IF NOT ERRORLEVEL 2 exit /b 1
|
||||
|
||||
)
|
||||
32
bin/php-laravel-petstore-server.sh
Executable file
32
bin/php-laravel-petstore-server.sh
Executable file
@@ -0,0 +1,32 @@
|
||||
#!/bin/sh
|
||||
|
||||
SCRIPT="$0"
|
||||
echo "# START SCRIPT: $SCRIPT"
|
||||
|
||||
while [ -h "$SCRIPT" ] ; do
|
||||
ls=`ls -ld "$SCRIPT"`
|
||||
link=`expr "$ls" : '.*-> \(.*\)$'`
|
||||
if expr "$link" : '/.*' > /dev/null; then
|
||||
SCRIPT="$link"
|
||||
else
|
||||
SCRIPT=`dirname "$SCRIPT"`/"$link"
|
||||
fi
|
||||
done
|
||||
|
||||
if [ ! -d "${APP_DIR}" ]; then
|
||||
APP_DIR=`dirname "$SCRIPT"`/..
|
||||
APP_DIR=`cd "${APP_DIR}"; pwd`
|
||||
fi
|
||||
|
||||
executable="./modules/openapi-generator-cli/target/openapi-generator-cli.jar"
|
||||
|
||||
if [ ! -f "$executable" ]
|
||||
then
|
||||
mvn -B clean package
|
||||
fi
|
||||
|
||||
# if you've executed sbt assembly previously it will use that instead.
|
||||
export JAVA_OPTS="${JAVA_OPTS} -XX:MaxPermSize=256M -Xmx1024M -DloggerPath=conf/log4j.properties"
|
||||
ags="generate -t modules/openapi-generator/src/main/resources/php-laravel -i modules/openapi-generator/src/test/resources/2_0/petstore-with-fake-endpoints-models-for-testing.yaml -g php-laravel -o samples/server/petstore/php-laravel $@"
|
||||
|
||||
java $JAVA_OPTS -jar $executable $ags
|
||||
@@ -33,6 +33,6 @@ fi
|
||||
|
||||
# if you've executed sbt assembly previously it will use that instead.
|
||||
export JAVA_OPTS="${JAVA_OPTS} -XX:MaxPermSize=256M -Xmx1024M -DloggerPath=conf/log4j.properties"
|
||||
ags="generate -t modules/openapi-generator/src/main/resources/php -i modules/openapi-generator/src/test/resources/2_0/petstore-with-fake-endpoints-models-for-testing.yaml -g php -o samples/client/petstore/php $@"
|
||||
ags="generate -t modules/openapi-generator/src/main/resources/php -i modules/openapi-generator/src/test/resources/2_0/petstore-with-fake-endpoints-models-for-testing.yaml -g php -o samples/client/petstore/php/OpenAPIClient-php $@"
|
||||
|
||||
java $JAVA_OPTS -jar $executable $ags
|
||||
|
||||
@@ -27,6 +27,6 @@ fi
|
||||
|
||||
# if you've executed sbt assembly previously it will use that instead.
|
||||
export JAVA_OPTS="${JAVA_OPTS} -XX:MaxPermSize=256M -Xmx1024M -DloggerPath=conf/log4j.properties"
|
||||
ags="generate -t modules/openapi-generator/src/main/resources/php-silex -i modules/openapi-generator/src/test/resources/2_0/petstore.yaml -g php-silex -o samples/server/petstore/php-silex $@"
|
||||
ags="generate -t modules/openapi-generator/src/main/resources/php-silex -i modules/openapi-generator/src/test/resources/2_0/petstore.yaml -g php-silex -o samples/server/petstore/php-silex/OpenAPIServer $@"
|
||||
|
||||
java $JAVA_OPTS -jar $executable $ags
|
||||
|
||||
@@ -23,7 +23,7 @@ if [ ! -d "${APP_DIR}" ]; then
|
||||
fi
|
||||
|
||||
# Make sure that we are regenerating the sample by removing any existing target directory
|
||||
TARGET_DIR="$SCRIPT_DIR/../samples/server/petstore/php-symfony"
|
||||
TARGET_DIR="$SCRIPT_DIR/../samples/server/petstore/php-symfony/SymfonyBundle-php"
|
||||
if [ -d "$TARGET_DIR" ]; then
|
||||
rm -rf $TARGET_DIR
|
||||
fi
|
||||
|
||||
@@ -13,8 +13,8 @@ failures=0
|
||||
for SCRIPT in $(ls -l ./bin/*.sh | grep -v all)
|
||||
do
|
||||
if [ -f ${SCRIPT} -a -x ${SCRIPT} ]; then
|
||||
echo "Running $SCRIPT"
|
||||
${SCRIPT}
|
||||
echo "Running $SCRIPT (output to /dev/null)"
|
||||
${SCRIPT} 2>&1 > /dev/null
|
||||
rc=$?
|
||||
if [[ ${rc} != 0 ]]; then
|
||||
>&2 echo "ERROR!! FAILED TO RUN ${SCRIPT}"
|
||||
@@ -30,4 +30,4 @@ if (( failures > 0 )); then
|
||||
exit 1
|
||||
else
|
||||
echo "[SUCCESS] ${successes} generators finished."
|
||||
fi
|
||||
fi
|
||||
|
||||
@@ -25,8 +25,10 @@ then
|
||||
mvn -B clean package
|
||||
fi
|
||||
|
||||
# if you've executed sbt assembly previously it will use that instead.
|
||||
export JAVA_OPTS="${JAVA_OPTS} -XX:MaxPermSize=256M -Xmx1024M -DloggerPath=conf/log4j.properties"
|
||||
ags="generate -t modules/openapi-generator/src/main/resources/rust-server -i modules/openapi-generator/src/test/resources/2_0/rust-server/petstore-with-fake-endpoints-models-for-testing.yaml -g rust-server -o samples/server/petstore/rust-server -DpackageName=petstore_api --additional-properties hideGenerationTimestamp=true $@"
|
||||
for spec_path in modules/openapi-generator/src/test/resources/2_0/rust-server/* ; do
|
||||
export JAVA_OPTS="${JAVA_OPTS} -XX:MaxPermSize=256M -Xmx1024M -DloggerPath=conf/log4j.properties"
|
||||
spec=$(basename "$spec_path" | sed 's/.yaml//')
|
||||
ags="generate -t modules/openapi-generator/src/main/resources/rust-server -i $spec_path -g rust-server -o samples/server/petstore/rust-server/output/$spec -DpackageName=$spec --additional-properties hideGenerationTimestamp=true $@"
|
||||
|
||||
java $JAVA_OPTS -jar $executable $ags
|
||||
java $JAVA_OPTS -jar $executable $ags
|
||||
done
|
||||
|
||||
@@ -27,6 +27,6 @@ fi
|
||||
|
||||
# if you've executed sbt assembly previously it will use that instead.
|
||||
export JAVA_OPTS="${JAVA_OPTS} -XX:MaxPermSize=256M -Xmx1024M -DloggerPath=conf/log4j.properties"
|
||||
ags="generate -t modules/openapi-generator/src/main/resources/php-silex -i modules/openapi-generator/src/test/resources/2_0/petstore-security-test.yaml -g php-silex -o samples/server/petstore-security-test/silex $@"
|
||||
ags="generate -t modules/openapi-generator/src/main/resources/php-silex -i modules/openapi-generator/src/test/resources/2_0/petstore-security-test.yaml -g php-silex -o samples/server/petstore-security-test/silex/SwaggerServer $@"
|
||||
|
||||
java $JAVA_OPTS -jar $executable $ags
|
||||
|
||||
@@ -10,7 +10,7 @@ echo "Please press CTRL+C to stop or the script will continue in 5 seconds."
|
||||
sleep 5
|
||||
|
||||
# LIST OF SCRIPTS:
|
||||
./bin/ruby-petstore.sh > /dev/null 2>&1
|
||||
./bin/ruby-client-petstore.sh > /dev/null 2>&1
|
||||
./bin/java-petstore-all.sh > /dev/null 2>&1
|
||||
./bin/java-jaxrs-petstore-server-all.sh > /dev/null 2>&1
|
||||
./bin/spring-all-pestore.sh > /dev/null 2>&1
|
||||
@@ -30,7 +30,8 @@ sleep 5
|
||||
./bin/typescript-node-petstore-all.sh > /dev/null 2>&1
|
||||
./bin/typescript-inversify-petstore.sh > /dev/null 2>&1
|
||||
./bin/rust-server-petstore.sh > /dev/null 2>&1
|
||||
|
||||
./bin/openapi3/haskell-http-client-petstore.sh > /dev/null 2>&1
|
||||
./bin/csharp-petstore.sh > /dev/null 2>&1
|
||||
|
||||
# Check:
|
||||
if [ -n "$(git status --porcelain)" ]; then
|
||||
|
||||
@@ -40,16 +40,13 @@ declare -a files=("CI/pom.xml.bash"
|
||||
"CI/pom.xml.circleci.java7"
|
||||
"CI/pom.xml.ios"
|
||||
"modules/openapi-generator-cli/pom.xml"
|
||||
"modules/openapi-generator-gradle-plugin/README.adoc"
|
||||
"modules/openapi-generator-gradle-plugin/gradle.properties"
|
||||
"modules/openapi-generator-gradle-plugin/pom.xml"
|
||||
"modules/openapi-generator-gradle-plugin/samples/local-spec/build.gradle"
|
||||
"modules/openapi-generator-maven-plugin/pom.xml"
|
||||
"modules/openapi-generator-online/pom.xml"
|
||||
"modules/openapi-generator/pom.xml"
|
||||
"modules/openapi-generator-online/Dockerfile"
|
||||
"pom.xml"
|
||||
"README.md")
|
||||
"pom.xml")
|
||||
|
||||
for filename in "${files[@]}"; do
|
||||
# e.g. sed -i '' "s/3.0.1-SNAPSHOT/3.0.1/g" CI/pom.xml.bash
|
||||
|
||||
57
bin/utils/release_version_update_docs.sh
Executable file
57
bin/utils/release_version_update_docs.sh
Executable file
@@ -0,0 +1,57 @@
|
||||
#!/bin/bash
|
||||
#
|
||||
# usage: ./bin/utils/release_version_update.sh 3.0.1-SNAPSHOT 3.0.1
|
||||
#
|
||||
# Copyright 2018 OpenAPI-Generator Contributors (https://openapi-generator.tech)
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
#
|
||||
|
||||
if [[ "$1" != "" ]]; then
|
||||
FROM="$1"
|
||||
else
|
||||
echo "Missing argument. Usage e.g.: ./bin/utils/release_version_update.sh 3.0.1-SNAPSHOT 3.0.1"
|
||||
exit 1;
|
||||
fi
|
||||
|
||||
if [[ "$2" != "" ]]; then
|
||||
TO="$2"
|
||||
else
|
||||
echo "Missing argument. Usage e.g.: ./bin/utils/release_version_update.sh 3.0.1-SNAPSHOT 3.0.1"
|
||||
exit 1;
|
||||
fi
|
||||
|
||||
|
||||
echo "IMPORTANT: this script works on Mac only"
|
||||
echo "Release preparation: replacing $FROM with $TO in different files"
|
||||
|
||||
declare -a files=("modules/openapi-generator-maven-plugin/README.md"
|
||||
"modules/openapi-generator-maven-plugin/examples/java-client.xml"
|
||||
"modules/openapi-generator-maven-plugin/examples/non-java-invalid-spec.xml"
|
||||
"modules/openapi-generator-maven-plugin/examples/non-java.xml"
|
||||
"modules/openapi-generator-gradle-plugin/README.adoc"
|
||||
"modules/openapi-generator-gradle-plugin/samples/local-spec/gradle.properties"
|
||||
"modules/openapi-generator-gradle-plugin/samples/local-spec/build.gradle"
|
||||
"modules/openapi-generator-gradle-plugin/samples/local-spec/README.md"
|
||||
"README.md")
|
||||
|
||||
for filename in "${files[@]}"; do
|
||||
# e.g. sed -i '' "s/3.0.1-SNAPSHOT/3.0.1/g" CI/pom.xml.bash
|
||||
#echo "Running command: sed -i '' "s/$FROM/$TO/g" $filename"
|
||||
if sed -i '' "s/$FROM/$TO/g" $filename; then
|
||||
echo "Updated $filename successfully!"
|
||||
else
|
||||
echo "ERROR: Failed to update $filename with the following command"
|
||||
echo "sed -i '' \"s/$FROM/$TO/g\" $filename"
|
||||
fi
|
||||
done
|
||||
10
bin/windows/cpp-qt5-qhttpengine-server-petstore.bat
Normal file
10
bin/windows/cpp-qt5-qhttpengine-server-petstore.bat
Normal file
@@ -0,0 +1,10 @@
|
||||
set executable=.\modules\openapi-generator-cli\target\openapi-generator-cli.jar
|
||||
|
||||
If Not Exist %executable% (
|
||||
mvn clean package
|
||||
)
|
||||
|
||||
REM set JAVA_OPTS=%JAVA_OPTS% -Xmx1024M
|
||||
set ags=generate -i modules\openapi-generator\src\test\resources\2_0\petstore.yaml -g cpp-qt5-qhttpengine-server -o samples\server\petstore\cpp-qt5-qhttpengine-server
|
||||
|
||||
java %JAVA_OPTS% -jar %executable% %ags%
|
||||
@@ -5,6 +5,6 @@ If Not Exist %executable% (
|
||||
)
|
||||
|
||||
REM set JAVA_OPTS=%JAVA_OPTS% -Xmx1024M
|
||||
set ags=generate -i modules/openapi-generator/src/test/resources/2_0/petstore-with-fake-endpoints-models-for-testing.yaml -g csharp -o samples/client/petstore/csharp/SwaggerClientNet40 --additional-properties packageGuid={321C8C3F-0156-40C1-AE42-D59761FB9B6C} -c ./bin/csharp-petstore-net-40.json
|
||||
set ags=generate -i modules\openapi-generator\src\test\resources\2_0\petstore-with-fake-endpoints-models-for-testing.yaml -g csharp -o samples\client\petstore\csharp\SwaggerClientNet40 --additional-properties packageGuid={321C8C3F-0156-40C1-AE42-D59761FB9B6C} -c .\bin\csharp-petstore-net-40.json
|
||||
|
||||
java %JAVA_OPTS% -jar %executable% %ags%
|
||||
|
||||
@@ -5,6 +5,6 @@ If Not Exist %executable% (
|
||||
)
|
||||
|
||||
REM set JAVA_OPTS=%JAVA_OPTS% -Xmx1024M
|
||||
set ags=generate -i modules/openapi-generator/src/test/resources/2_0/petstore-with-fake-endpoints-models-for-testing.yaml -g csharp -o samples\client\petstore\csharp\SwaggerClientNetStandard --additional-properties targetFramework=v5.0,packageGuid={3AB1F259-1769-484B-9411-84505FCCBD55}
|
||||
set ags=generate -i modules\openapi-generator\src\test\resources\2_0\petstore-with-fake-endpoints-models-for-testing.yaml -g csharp -o samples\client\petstore\csharp\SwaggerClientNetStandard --additional-properties targetFramework=v5.0,packageGuid={3AB1F259-1769-484B-9411-84505FCCBD55}
|
||||
|
||||
java %JAVA_OPTS% -jar %executable% %ags%
|
||||
|
||||
@@ -9,7 +9,7 @@ set ags=generate -i modules\openapi-generator\src\test/resources\2_0\petstore-wi
|
||||
|
||||
java %JAVA_OPTS% -jar %executable% %ags%
|
||||
|
||||
# restore csproj file
|
||||
echo "restore csproject file: CI\samples\client\petstore\csharp\OpenAPIClient\src\Org.OpenAPITools.Test\Org.OpenAPITools.Test.csproj"
|
||||
copy .\CI\samples\client\petstore\csharp\OpenAPIClient\src\Org.OpenAPITools.Test\Org.OpenAPITools.Test.csproj .\samples\client\petstore\csharp\OpenAPIClient\src\Org.OpenAPITools.Test\
|
||||
REM restore csproj file
|
||||
echo "restore csproject file: CI\samples.ci\client\petstore\csharp\OpenAPIClient\src\Org.OpenAPITools.Test\Org.OpenAPITools.Test.csproj"
|
||||
copy /b/v/y CI\samples.ci\client\petstore\csharp\OpenAPIClient\src\Org.OpenAPITools.Test\Org.OpenAPITools.Test.csproj samples\client\petstore\csharp\OpenAPIClient\src\Org.OpenAPITools.Test\
|
||||
|
||||
|
||||
@@ -5,6 +5,6 @@ If Not Exist %executable% (
|
||||
)
|
||||
|
||||
REM set JAVA_OPTS=%JAVA_OPTS% -Xmx1024M -DloggerPath=conf/log4j.properties
|
||||
set ags=generate -i modules\openapi-generator\src\test\resources\2_0\petstore.yaml -g html -o samples\client\petstore\html
|
||||
set ags=generate -i modules\openapi-generator\src\test\resources\2_0\petstore.yaml -g html -o samples\documentation\html
|
||||
|
||||
java %JAVA_OPTS% -jar %executable% %ags%
|
||||
|
||||
@@ -5,6 +5,6 @@ If Not Exist %executable% (
|
||||
)
|
||||
|
||||
REM set JAVA_OPTS=%JAVA_OPTS% -Xmx1024M -DloggerPath=conf/log4j.properties
|
||||
set ags=generate -i modules\openapi-generator\src\test\resources\2_0\petstore.yaml -g html2 -o samples\html2
|
||||
set ags=generate -i modules\openapi-generator\src\test\resources\2_0\petstore.yaml -g html2 -o samples\documentation\html2
|
||||
|
||||
java %JAVA_OPTS% -jar %executable% %ags%
|
||||
|
||||
@@ -5,6 +5,6 @@ If Not Exist %executable% (
|
||||
)
|
||||
|
||||
REM set JAVA_OPTS=%JAVA_OPTS% -Xmx1024M
|
||||
set ags=generate -i modules\openapi-generator\src\test\resources\2_0\petstore.yaml -g php -o samples\client\petstore\php
|
||||
set ags=generate -i modules\openapi-generator\src\test\resources\2_0\petstore.yaml -g php -o samples\client\petstore\php\OpenAPIClient-php
|
||||
|
||||
java %JAVA_OPTS% -jar %executable% %ags%
|
||||
|
||||
@@ -5,6 +5,6 @@ If Not Exist %executable% (
|
||||
)
|
||||
|
||||
REM set JAVA_OPTS=%JAVA_OPTS% -Xmx1024M
|
||||
set ags=generate -i modules\openapi-generator\src\test\resources\2_0\petstore.yaml -g php-silex -o samples\server\petstore\php-silex
|
||||
set ags=generate -i modules\openapi-generator\src\test\resources\2_0\petstore.yaml -g php-silex -o samples\server\petstore\php-silex\OpenAPIServer
|
||||
|
||||
java %JAVA_OPTS% -jar %executable% %ags%
|
||||
|
||||
@@ -5,6 +5,6 @@ If Not Exist %executable% (
|
||||
)
|
||||
|
||||
REM set JAVA_OPTS=%JAVA_OPTS% -Xmx1024M
|
||||
set ags=generate -i modules\openapi-generator\src\test\resources\2_0\petstore.yaml -g php-symfony -o samples\server\petstore\php-symfony
|
||||
set ags=generate -i modules\openapi-generator\src\test\resources\2_0\petstore.yaml -g php-symfony -o samples\server\petstore\php-symfony\SymfonyBundle-php
|
||||
|
||||
java %JAVA_OPTS% -jar %executable% %ags%
|
||||
|
||||
@@ -35,6 +35,8 @@ These names can be anything you like. If you are building a client for the white
|
||||
|
||||
**NOTE** Convention is to use kebab casing for names passed to `-n`. Example, `scala-finatra` would become `ScalaFinatraGenerator`.
|
||||
|
||||
#### Use your new generator with the CLI
|
||||
|
||||
To compile your library, enter the `out/generators/my-codegen` directory, run `mvn package` and execute the generator:
|
||||
|
||||
```sh
|
||||
@@ -50,11 +52,59 @@ Note the `my-codegen` is an option for `-g` now, and you can use the usual argum
|
||||
|
||||
```sh
|
||||
java -cp out/codegens/customCodegen/target/my-codegen-openapi-generator-1.0.0.jar:modules/openapi-generator-cli/target/openapi-generator-cli.jar \
|
||||
io.openapitools.codegen.OpenAPIGenerator generate -g my-codegen \
|
||||
org.openapitools.codegen.OpenAPIGenerator generate -g my-codegen \
|
||||
-i https://raw.githubusercontent.com/openapitools/openapi-generator/master/modules/openapi-generator/src/test/resources/2_0/petstore.yaml \
|
||||
-o ./out/myClient
|
||||
```
|
||||
|
||||
For Windows users:
|
||||
```
|
||||
java -cp out/codegens/customCodegen/target/my-codegen-openapi-generator-1.0.0.jar;modules/openapi-generator-cli/target/openapi-generator-cli.jar \
|
||||
org.openapitools.codegen.OpenAPIGenerator generate -g my-codegen \
|
||||
-i https://raw.githubusercontent.com/openapitools/openapi-generator/master/modules/openapi-generator/src/test/resources/2_0/petstore.yaml \
|
||||
-o ./out/myClient
|
||||
```
|
||||
|
||||
#### Use your new generator with the maven plugin
|
||||
|
||||
Install your library to your local maven repository by running:
|
||||
|
||||
```
|
||||
mvn clean install -f out/generators/my-codegen
|
||||
```
|
||||
|
||||
This will install `org.openapitools:my-codegen-openapi-generator:1.0.0` to your local maven repository.
|
||||
|
||||
You can use this as additional dependency of the `openapi-generator-maven-plugin` plugin and use `my-codegen` as `generatorName` value:
|
||||
|
||||
```xml
|
||||
<plugin>
|
||||
<groupId>org.openapitools</groupId>
|
||||
<artifactId>openapi-generator-maven-plugin</artifactId>
|
||||
<version>${openapi-generator-version}</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>generate-client-code</id>
|
||||
<goals>
|
||||
<goal>generate</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<generatorName>my-codegen</generatorName>
|
||||
<!-- other configuration ... -->
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.openapitools</groupId>
|
||||
<artifactId>my-codegen-openapi-generator</artifactId>
|
||||
<version>1.0.0</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</plugin>
|
||||
```
|
||||
|
||||
If you publish your artifact to a distant maven repository, do not forget to add this repository as `pluginRepository` for your project.
|
||||
|
||||
### Selective generation
|
||||
You may not want to generate *all* models in your project. Likewise you may want just one or two apis to be written. If that's the case, you can use system properties to control the output:
|
||||
@@ -106,6 +156,14 @@ java -Dapis -DmodelTests=false {opts}
|
||||
|
||||
When using selective generation, _only_ the templates needed for the specific generation will be used.
|
||||
|
||||
To skip models defined as the form parameters in "requestBody", please use `skipFormModel` (default to false) (this option is introduced at v3.2.2)
|
||||
|
||||
```sh
|
||||
java -DskipFormModel=true
|
||||
```
|
||||
|
||||
This option will be helpful to skip model generation due to the form parameter, which is defined differently in OAS3 as there's no form parameter in OAS3
|
||||
|
||||
### Ignore file format
|
||||
|
||||
OpenAPI Generator supports a `.openapi-generator-ignore` file, similar to `.gitignore` or `.dockerignore` you're probably already familiar with.
|
||||
|
||||
@@ -11,6 +11,42 @@ Another approach to find breaking changes is to look at issue and pull requests
|
||||
* link:https://github.com/OpenAPITools/openapi-generator/labels/Breaking%20change%20%28with%20fallback%29[Breaking change (with fallback)]
|
||||
* link:https://github.com/OpenAPITools/openapi-generator/labels/Breaking%20change%20%28without%20fallback%29[Breaking change (without fallback)]
|
||||
|
||||
=== From 3.1.x to 3.2.0
|
||||
|
||||
Version `3.2.0` is a minor version of OpenAPI-Generator, in comparison to `3.1.x` it contains some breaking changes, but with the possibility to fallback to the old behavior.
|
||||
The default value of some options might change.
|
||||
Projects relying on generated code might need to be adapted.
|
||||
|
||||
==== Validate spec on generation by default
|
||||
|
||||
The default is to validate the spec during generation. If the spec has errors,
|
||||
they will appear as errors or warnings to the user. This prevent generation of the project.
|
||||
|
||||
If you want to switch back to the `3.1.x` behavior you can use:
|
||||
|
||||
* Set the `validateSpec` option to `false` if you are using the Maven or Gradle plugin
|
||||
* Use the command line option `--skip-validate-spec` if you are using the CLI
|
||||
|
||||
|
||||
==== Model (all languages)
|
||||
|
||||
In `CodegenModel` and in `CodegenOperation` we use now our own class `org.openapitools.codegen.CodegenDiscriminator` instead of `io.swagger.v3.oas.models.media.Discriminator`.
|
||||
|
||||
For the templates, this is not an API change, because the same values are available.
|
||||
|
||||
If you have your own `Codegen` class (to support your own generator for example) then you might get some compile error due to the change.
|
||||
|
||||
==== Java
|
||||
|
||||
Schema with enum values are mapped to java enum in the generated code.
|
||||
In previous version, when an unknown value was deserialized, the value was set to `null`.
|
||||
|
||||
With `3.2.0` a new option is introduced: `useNullForUnknownEnumValue`.
|
||||
|
||||
* When set to `false` (default value), an Exception (`IllegalArgumentException`) is thrown when the value not available in the enum.
|
||||
* When set to `true`, unknown values are mapped to `null` as it was the case in previous versions.
|
||||
|
||||
|
||||
=== From 3.0.x to 3.1.0
|
||||
|
||||
Version `3.1.0` is the first minor version of OpenAPI-Generator, in comparison to `3.0.3` it contains some breaking changes, but with the possibility to fallback to the old behavior.
|
||||
|
||||
45
docs/qna.md
45
docs/qna.md
@@ -2,41 +2,40 @@
|
||||
|
||||
#### What is the governance structure of the OpenAPI Generator project?
|
||||
|
||||
OpenAPI generator (openapi-generator) is managed by the [core team members](../README.md#openapi-generator-core-team).
|
||||
OpenAPI generator (openapi-generator) is managed by the members of the [core team](../README.md#openapi-generator-core-team).
|
||||
|
||||
|
||||
#### What is the difference between Swagger Codegen and OpenAPI Generator?
|
||||
|
||||
Swagger Codegen is driven by SmartBear while OpenAPI Generator is driven by the community. More than 40 top contributors and template creators of Swagger Codegen have joined OpenAPI Generator as the founding team members.
|
||||
|
||||
Swagger is a trademark owned by SmartBear and the use of the term "Swagger" in this project is for demo (reference) purposes only.
|
||||
|
||||
|
||||
#### Why was it decided to fork Swagger Codegen and to maintain a community-driven version?
|
||||
|
||||
There are several reasons:
|
||||
|
||||
1. The founding members came to the conclusion that Swagger Codegen 3.0.0 beta contains too many breaking changes while they strongly believe 3.0.0 release should only focus on one thing: OpenAPI specification 3.0 support.
|
||||
1. Swagger Codegen 3.0.0 beta was evaluated as unstable. Changes made directly to 3.0.0 branch without reviews or tests, were breaking the builds from time to time (e.g. a simple `mvn clean package` failed).
|
||||
1. Reviews of code changes in the 3.0.0 branch highlighted a lot of code block removal without any reason. This might produce regressions for edge cases discovered previously.
|
||||
1. Most of the test cases in the generators have been commented out as part of the migration to support OpenAPI 3.0. Test cases are the most valuable assets of the project and should be maintained to ensure a good quality.
|
||||
1. According to SmartBear, [Swagger Codegen 2.x and 3.x should be supported in parallel for a while](https://github.com/swagger-api/swagger-codegen/issues/7754#issuecomment-375039048) without the possibility to work with git branches to merge the fixes from one branch to the next. Having to implement everything twice is not a good idea and the best use of the Swagger Codegen community resources.
|
||||
1. Having a community-driven version can bring the project to the next level.
|
||||
1. The founding members came to the conclusion that Swagger Codegen 3.0.0 beta contains too many breaking changes. They also strongly believe the 3.0.0 release should only focus on one thing: OpenAPI 3.0 support.
|
||||
1. The founding members had concerns about the development practices, which seemed to be contributing to an unstable and insufficiently tested codebase.
|
||||
1. There was a disagreement on the evolutionary strategy for Swagger Codegen. The founding members felt it was important to move forward with OpenAPI 3.0 support, while maintaining backward compatibility with OpenAPI 2.0 in the same codebase.
|
||||
1. The founding members found that the enhancements and bug fixes submitted for Swagger Codegen 2.x need to be submitted again for Swagger Codegen 3.0.0 branch (otherwise, these changes would not appear in the 3.0.0 branch. Having to do the pull request twice is not the best use of community resources).
|
||||
1. The community-driven version has a more rapid [release cycle](https://github.com/OpenAPITools/openapi-generator/releases/) (weekly patch release, monthly minor release) so users do not need to wait for several months to get a stable release.
|
||||
1. Having a community-driven version _can_ bring the project to the next level with reliable releases and a clear [roadmap](https://github.com/OpenAPITools/openapi-generator/blob/master/docs/roadmap.adoc).
|
||||
|
||||
UPDATE: After the public launch of OpenAPI Generator, some of the core team members were contacted by Ron (SmartBear) and we explained to him the reasons of the fork as explained above. We also asked him to contact team@openapitools.org if he wants to discuss further but so far we don't see any email from him to team@openapitools.org.
|
||||
#### Was anything done to attempt to address the issues before deciding to fork Swagger Codegen and maintain a community-driven version?
|
||||
|
||||
#### Has anything been done in attempt to address the issues before deciding to fork Swagger Codegen and maintain a community-driven version?
|
||||
|
||||
There were several conversations with SmartBear (Ron, Hugo) via emails, gitter, Skype call and GitHub issues.
|
||||
There were several conversations with the project owners of Swagger Codegen via emails, Gitter, Skype call and GitHub issues to discuss the state of Swagger Codegen 3.0.0.
|
||||
But there was no consensus on the next steps and on the direction for Swagger Codegen 3.0.0.
|
||||
|
||||
#### Is there any change to the project license?
|
||||
#### Are there any changes to the project license?
|
||||
|
||||
No, OpenAPI Generator is still using [Apache license (version 2)](https://www.apache.org/licenses/LICENSE-2.0).
|
||||
No, OpenAPI Generator is still using the [Apache license (version 2)](https://www.apache.org/licenses/LICENSE-2.0).
|
||||
|
||||
#### What is the difference between Swagger Codegen and OpenAPI Generator?
|
||||
#### I am currently using Swagger Codegen 2.x. How can I upgrade the generator to OpenAPI Generator?
|
||||
|
||||
Swagger Codegen is driven by SmartBear while OpenAPI Generator is driven by the community. More than 40 top contributors and template creators of Swagger Codegen have joined OpenAPI Generator as the founding team members.
|
||||
OpenAPI Generator is based on Swagger Codegen `2.4.0-SNAPSHOT` version so the migration should be relatively straightforward. Refer to the [migration guide](migration-from-swagger-codegen.md) for more information.
|
||||
|
||||
Swagger is a trademark owned by SmartBear and the use of the term "Swagger" found in this project is for demo purpose (reference) only.
|
||||
#### Who maintains this Q&A page?
|
||||
|
||||
#### I’m currently using Swagger Codegen 2.x. How can I upgrade the generator to OpenAPI Generator?
|
||||
|
||||
OpenAPI Generator is based on Swagger Codegen 2.4.0-SNAPSHOT version so the migration should be easy, straightforward and almost seamless. Please refer to the [migration guide](migration-from-swagger-codegen.md) for more information.
|
||||
|
||||
#### May I know who maintains this Q&A page?
|
||||
|
||||
This Q&A page is maintained by the [core team members](../README.md#openapi-generator-core-team). It's not maintained by a single person nor do these Q&As represent the view of an individual.
|
||||
This Q&A page is maintained by the [core team members](../README.md#openapi-generator-core-team). It is not maintained by a single person nor do these Q&As represent the views of any individual or person.
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
<parent>
|
||||
<groupId>org.openapitools</groupId>
|
||||
<artifactId>openapi-generator-project</artifactId>
|
||||
<version>3.1.2</version>
|
||||
<version>3.2.2</version>
|
||||
<relativePath>../..</relativePath>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
@@ -24,6 +24,8 @@ import io.airlift.airline.ParseOptionMissingException;
|
||||
import io.airlift.airline.ParseOptionMissingValueException;
|
||||
import org.openapitools.codegen.cmd.*;
|
||||
|
||||
import java.util.Locale;
|
||||
|
||||
/**
|
||||
* User: lanwen Date: 24.03.15 Time: 17:56
|
||||
* <p>
|
||||
@@ -40,6 +42,7 @@ public class OpenAPIGenerator {
|
||||
Cli.<Runnable>builder("openapi-generator-cli")
|
||||
.withDescription(
|
||||
String.format(
|
||||
Locale.ROOT,
|
||||
"OpenAPI generator CLI (version %s).",
|
||||
version))
|
||||
.withDefaultCommand(ListGenerators.class)
|
||||
@@ -69,10 +72,10 @@ public class OpenAPIGenerator {
|
||||
System.exit(1);
|
||||
}
|
||||
} catch (ParseArgumentsUnexpectedException e) {
|
||||
System.err.printf("[error] %s%n%nSee 'openapi-generator-cli help' for usage.%n", e.getMessage());
|
||||
System.err.printf(Locale.ROOT,"[error] %s%n%nSee 'openapi-generator-cli help' for usage.%n", e.getMessage());
|
||||
System.exit(1);
|
||||
} catch (ParseOptionMissingException | ParseOptionMissingValueException e) {
|
||||
System.err.printf("[error] %s%n", e.getMessage());
|
||||
System.err.printf(Locale.ROOT,"[error] %s%n", e.getMessage());
|
||||
System.exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -72,4 +72,4 @@ public class ConfigHelp implements Runnable {
|
||||
System.exit(1);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,6 +17,8 @@
|
||||
|
||||
package org.openapitools.codegen.cmd;
|
||||
|
||||
import ch.qos.logback.classic.LoggerContext;
|
||||
import ch.qos.logback.core.spi.FilterAttachable;
|
||||
import io.airlift.airline.Command;
|
||||
import io.airlift.airline.Option;
|
||||
import org.openapitools.codegen.ClientOptInput;
|
||||
@@ -32,6 +34,7 @@ import static org.apache.commons.lang3.StringUtils.isNotEmpty;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
/**
|
||||
* User: lanwen Date: 24.03.15 Time: 20:22
|
||||
@@ -194,8 +197,28 @@ public class Generate implements Runnable {
|
||||
description = CodegenConstants.REMOVE_OPERATION_ID_PREFIX_DESC)
|
||||
private Boolean removeOperationIdPrefix;
|
||||
|
||||
@Option(name = {"--skip-validate-spec"},
|
||||
title = "skip spec validation",
|
||||
description = "Skips the default behavior of validating an input specification.")
|
||||
private Boolean skipValidateSpec;
|
||||
|
||||
@Option(name = {"--log-to-stderr"},
|
||||
title = "Log to STDERR",
|
||||
description = "write all log messages (not just errors) to STDOUT."
|
||||
+ " Useful for piping the JSON output of debug options (e.g. `-DdebugOperations`) to an external parser directly while testing a generator.")
|
||||
private Boolean logToStderr;
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
if (logToStderr != null) {
|
||||
LoggerContext lc = (LoggerContext) LoggerFactory.getILoggerFactory();
|
||||
Stream.of(Logger.ROOT_LOGGER_NAME, "io.swagger", "org.openapitools")
|
||||
.map(lc::getLogger)
|
||||
.peek(logger -> logger.detachAppender("STDOUT"))
|
||||
.reduce((logger, next) -> logger.getName().equals(Logger.ROOT_LOGGER_NAME) ? logger : next)
|
||||
.map(root -> root.getAppender("STDERR"))
|
||||
.ifPresent(FilterAttachable::clearAllFilters);
|
||||
}
|
||||
|
||||
// attempt to read from config file
|
||||
CodegenConfigurator configurator = CodegenConfigurator.fromFile(configFile);
|
||||
@@ -207,6 +230,10 @@ public class Generate implements Runnable {
|
||||
}
|
||||
|
||||
// now override with any specified parameters
|
||||
if (skipValidateSpec != null) {
|
||||
configurator.setValidateSpec(false);
|
||||
}
|
||||
|
||||
if (verbose != null) {
|
||||
configurator.setVerbose(verbose);
|
||||
}
|
||||
|
||||
@@ -21,6 +21,8 @@ import ch.lambdaj.collection.LambdaIterable;
|
||||
import io.airlift.airline.Command;
|
||||
import org.openapitools.codegen.CodegenConfig;
|
||||
|
||||
import java.util.Locale;
|
||||
|
||||
import static ch.lambdaj.Lambda.on;
|
||||
import static ch.lambdaj.collection.LambdaCollections.with;
|
||||
import static java.util.ServiceLoader.load;
|
||||
@@ -34,6 +36,6 @@ public class Langs implements Runnable {
|
||||
public void run() {
|
||||
LambdaIterable<String> langs =
|
||||
with(load(CodegenConfig.class)).extract(on(CodegenConfig.class).getName());
|
||||
System.out.printf("Available languages (generators): %s%n", langs);
|
||||
System.out.printf(Locale.ROOT, "Available languages (generators): %s%n", langs);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,6 +9,7 @@ import org.openapitools.codegen.CodegenType;
|
||||
import java.util.Arrays;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
|
||||
// NOTE: List can later have subcommands such as list languages, list types, list frameworks, etc.
|
||||
@Command(name = "list", description = "Lists the available generators")
|
||||
@@ -53,6 +54,6 @@ public class ListGenerators implements Runnable {
|
||||
}
|
||||
}
|
||||
|
||||
System.out.printf("%s%n", sb.toString());
|
||||
System.out.printf(Locale.ROOT,"%s%n", sb.toString());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,6 +2,9 @@
|
||||
|
||||
This document describes the gradle plugin for OpenAPI Generator.
|
||||
|
||||
This gradle plugin offers a declarative DSL via _extensions_ (these are Gradle project extensions).
|
||||
These map almost fully 1:1 with the options you'd pass to the CLI or Maven plugin. The plugin maps the extensions to a task of the same name to provide a clean API. If you're interested in the extension/task mapping concept from a high-level, you can https://docs.gradle.org/current/userguide/custom_plugins.html#sec:mapping_extension_properties_to_task_properties[check out Gradle's docs].
|
||||
|
||||
== Tasks
|
||||
|
||||
Tasks are listed under the "OpenAPI Tools" tasks heading.
|
||||
@@ -24,6 +27,17 @@ Tasks are listed under the "OpenAPI Tools" tasks heading.
|
||||
|Validates an Open API 2.0 or 3.x specification document.
|
||||
|===
|
||||
|
||||
|
||||
[NOTE]
|
||||
====
|
||||
The plugin implements the above tasks as project extensions of the same name. If you'd like to declare
|
||||
these tasks as dependencies to other tasks (using `dependsOn`), you'll need a task reference. e.g.:
|
||||
|
||||
```
|
||||
compileJava.dependsOn tasks.openApiGenerate
|
||||
```
|
||||
====
|
||||
|
||||
== Plugin Setup
|
||||
|
||||
[source,groovy]
|
||||
@@ -34,7 +48,7 @@ buildscript {
|
||||
mavenCentral()
|
||||
}
|
||||
dependencies {
|
||||
classpath "org.openapitools:openapi-generator-gradle-plugin:3.1.2"
|
||||
classpath "org.openapitools:openapi-generator-gradle-plugin:3.2.2"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -59,6 +73,11 @@ The gradle plugin is not currently published to https://plugins.gradle.org/m2/.
|
||||
|false
|
||||
|The verbosity of generation
|
||||
|
||||
|validateSpec
|
||||
|Boolean
|
||||
|true
|
||||
|Whether or not we should validate the input spec before generation. Invalid specs result in an error.
|
||||
|
||||
|generatorName
|
||||
|String
|
||||
|None
|
||||
@@ -450,3 +469,65 @@ Run with --stacktrace option to get the stack trace. Run with --info or --debug
|
||||
----
|
||||
$ ./gradlew openApiValidate --input=/Users/jim/projects/openapi-generator/modules/openapi-generator/src/test/resources/3_0/petstore.yaml
|
||||
----
|
||||
|
||||
=== Generate multiple sources
|
||||
|
||||
If you want to perform multiple generation tasks, you'd want to create a task that inherits from the `GenerateTask`.
|
||||
Examples can be found in https://github.com/OpenAPITools/openapi-generator/blob/master/modules/openapi-generator-gradle-plugin/samples/local-spec/build.gradle[samples/local-spec/build.gradle].
|
||||
|
||||
You can define any number of generator tasks; the generated code does _not_ need to be a JVM language.
|
||||
|
||||
```gradle
|
||||
task buildGoClient(type: org.openapitools.generator.gradle.plugin.tasks.GenerateTask){
|
||||
generatorName = "go"
|
||||
inputSpec = "$rootDir/petstore-v3.0.yaml".toString()
|
||||
additionalProperties = [
|
||||
packageName: "petstore"
|
||||
]
|
||||
outputDir = "$buildDir/go".toString()
|
||||
configOptions = [
|
||||
dateLibrary: "threetenp"
|
||||
]
|
||||
}
|
||||
task buildKotlinClient(type: org.openapitools.generator.gradle.plugin.tasks.GenerateTask){
|
||||
generatorName = "kotlin"
|
||||
inputSpec = "$rootDir/petstore-v3.0.yaml".toString()
|
||||
outputDir = "$buildDir/kotlin".toString()
|
||||
apiPackage = "org.openapitools.example.api"
|
||||
invokerPackage = "org.openapitools.example.invoker"
|
||||
modelPackage = "org.openapitools.example.model"
|
||||
configOptions = [
|
||||
dateLibrary: "java8"
|
||||
]
|
||||
systemProperties = [
|
||||
modelDocs: "false"
|
||||
]
|
||||
}
|
||||
```
|
||||
|
||||
To execute your specs, you'd then do:
|
||||
|
||||
```
|
||||
./gradlew buildGoClient buildKotlinClient
|
||||
```
|
||||
|
||||
If you want to simplify the execution, you could create a new task with `dependsOn`.
|
||||
|
||||
```gradle
|
||||
task codegen(dependsOn: ['buildGoClient', 'buildKotlinClient'])
|
||||
```
|
||||
|
||||
Or, if you're generating the code on compile, you can add these as a dependency to `compileJava` or any other existing task.
|
||||
You can also mix the default task `openApiGenerate` with custom tasks:
|
||||
|
||||
```gradle
|
||||
compileJava.dependsOn buildKotlinClient, tasks.openApiGenerate
|
||||
```
|
||||
|
||||
[NOTE]
|
||||
====
|
||||
`openApiGenerate` is a project extension _and_ a task. If you want to use this in `dependsOn`,
|
||||
you need a task reference or instance. One way to do this is to access it as `tasks.openApiGenerate`.
|
||||
|
||||
You can run `gradle tasks --debug` to see this registration.
|
||||
====
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
openApiGeneratorVersion=3.1.2
|
||||
openApiGeneratorVersion=3.2.2
|
||||
|
||||
# BEGIN placeholders
|
||||
# these are just placeholders to allow contributors to build directly
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
<parent>
|
||||
<groupId>org.openapitools</groupId>
|
||||
<artifactId>openapi-generator-project</artifactId>
|
||||
<version>3.1.2</version>
|
||||
<version>3.2.2</version>
|
||||
<relativePath>../..</relativePath>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
@@ -11,10 +11,11 @@ gradle openApiGenerate
|
||||
gradle openApiMeta
|
||||
gradle openApiValidate
|
||||
gradle buildGoSdk
|
||||
gradle generateGoWithInvalidSpec
|
||||
```
|
||||
|
||||
The samples can be tested against other versions of the plugin using the `openApiGeneratorVersion` property. For example:
|
||||
|
||||
```bash
|
||||
gradle -PopenApiGeneratorVersion=3.1.2 openApiValidate
|
||||
gradle -PopenApiGeneratorVersion=3.2.2 openApiValidate
|
||||
```
|
||||
|
||||
@@ -41,6 +41,9 @@ openApiGenerate {
|
||||
configOptions = [
|
||||
dateLibrary: "java8"
|
||||
]
|
||||
systemProperties = [
|
||||
modelDocs: "false"
|
||||
]
|
||||
}
|
||||
|
||||
task buildGoSdk(type: org.openapitools.generator.gradle.plugin.tasks.GenerateTask){
|
||||
@@ -54,3 +57,16 @@ task buildGoSdk(type: org.openapitools.generator.gradle.plugin.tasks.GenerateTas
|
||||
dateLibrary: "threetenp"
|
||||
]
|
||||
}
|
||||
|
||||
task generateGoWithInvalidSpec(type: org.openapitools.generator.gradle.plugin.tasks.GenerateTask){
|
||||
validateSpec = true
|
||||
generatorName = "go"
|
||||
inputSpec = "$rootDir/petstore-v3.0-invalid.yaml".toString()
|
||||
additionalProperties = [
|
||||
packageName: "petstore"
|
||||
]
|
||||
outputDir = "$buildDir/go".toString()
|
||||
configOptions = [
|
||||
dateLibrary: "threetenp"
|
||||
]
|
||||
}
|
||||
|
||||
@@ -1 +1 @@
|
||||
openApiGeneratorVersion=3.1.2
|
||||
openApiGeneratorVersion=3.2.2
|
||||
|
||||
@@ -80,6 +80,7 @@ class OpenApiGeneratorPlugin : Plugin<Project> {
|
||||
description = "Generate code via Open API Tools Generator for Open API 2.0 or 3.x specification documents."
|
||||
|
||||
verbose.set(generate.verbose)
|
||||
validateSpec.set(generate.validateSpec)
|
||||
generatorName.set(generate.generatorName)
|
||||
outputDir.set(generate.outputDir)
|
||||
inputSpec.set(generate.inputSpec)
|
||||
|
||||
@@ -32,6 +32,11 @@ open class OpenApiGeneratorGenerateExtension(project: Project) {
|
||||
*/
|
||||
val verbose = project.objects.property<Boolean>()
|
||||
|
||||
/**
|
||||
* Whether or not an input specification should be validated upon generation.
|
||||
*/
|
||||
val validateSpec = project.objects.property<Boolean>()
|
||||
|
||||
/**
|
||||
* The name of the generator which will handle codegen. (see "openApiGenerators" task)
|
||||
*/
|
||||
@@ -262,6 +267,11 @@ open class OpenApiGeneratorGenerateExtension(project: Project) {
|
||||
val configOptions = project.objects.property<Map<String, String>>()
|
||||
|
||||
init {
|
||||
applyDefaults()
|
||||
}
|
||||
|
||||
@Suppress("MemberVisibilityCanBePrivate")
|
||||
fun applyDefaults(){
|
||||
releaseNote.set("Minor update")
|
||||
modelNamePrefix.set("")
|
||||
modelNameSuffix.set("")
|
||||
@@ -271,5 +281,6 @@ open class OpenApiGeneratorGenerateExtension(project: Project) {
|
||||
generateApiDocumentation.set(true)
|
||||
withXml.set(false)
|
||||
configOptions.set(mapOf())
|
||||
validateSpec.set(true)
|
||||
}
|
||||
}
|
||||
@@ -28,7 +28,6 @@ import org.gradle.kotlin.dsl.property
|
||||
import org.openapitools.codegen.CodegenConstants
|
||||
import org.openapitools.codegen.DefaultGenerator
|
||||
import org.openapitools.codegen.config.CodegenConfigurator
|
||||
import org.openapitools.codegen.config.CodegenConfiguratorUtils.*
|
||||
|
||||
|
||||
/**
|
||||
@@ -48,6 +47,12 @@ open class GenerateTask : DefaultTask() {
|
||||
@get:Internal
|
||||
val verbose = project.objects.property<Boolean>()
|
||||
|
||||
/**
|
||||
* Whether or not an input specification should be validated upon generation.
|
||||
*/
|
||||
@get:Internal
|
||||
val validateSpec = project.objects.property<Boolean>()
|
||||
|
||||
/**
|
||||
* The name of the generator which will handle codegen. (see "openApiGenerators" task)
|
||||
*/
|
||||
@@ -318,7 +323,7 @@ open class GenerateTask : DefaultTask() {
|
||||
@get:Internal
|
||||
val configOptions = project.objects.property<Map<String, String>>()
|
||||
|
||||
private val originalEnvironmentVariables = mutableMapOf<String, String>()
|
||||
private val originalEnvironmentVariables = mutableMapOf<String, String?>()
|
||||
|
||||
private fun <T : Any?> Property<T>.ifNotEmpty(block: Property<T>.(T) -> Unit) {
|
||||
if (isPresent) {
|
||||
@@ -347,8 +352,9 @@ open class GenerateTask : DefaultTask() {
|
||||
try {
|
||||
if (systemProperties.isPresent) {
|
||||
systemProperties.get().forEach { (key, value) ->
|
||||
originalEnvironmentVariables[key] = System.getProperty(key)
|
||||
System.setProperty(key, value)
|
||||
// System.setProperty returns the original value for a key, or null.
|
||||
// Cache the original value or null…we will late put the properties back in their original state.
|
||||
originalEnvironmentVariables[key] = System.setProperty(key, value)
|
||||
configurator.addSystemProperty(key, value)
|
||||
}
|
||||
}
|
||||
@@ -382,6 +388,10 @@ open class GenerateTask : DefaultTask() {
|
||||
configurator.isVerbose = value
|
||||
}
|
||||
|
||||
validateSpec.ifNotEmpty { value ->
|
||||
configurator.isValidateSpec = value
|
||||
}
|
||||
|
||||
skipOverwrite.ifNotEmpty { value ->
|
||||
configurator.isSkipOverwrite = value ?: false
|
||||
}
|
||||
@@ -528,12 +538,15 @@ open class GenerateTask : DefaultTask() {
|
||||
|
||||
out.println("Successfully generated code to ${configurator.outputDir}")
|
||||
} catch (e: RuntimeException) {
|
||||
logger.error(e.message)
|
||||
throw GradleException("Code generation failed.")
|
||||
throw GradleException("Code generation failed.", e)
|
||||
}
|
||||
} finally {
|
||||
originalEnvironmentVariables.forEach { entry ->
|
||||
System.setProperty(entry.key, entry.value)
|
||||
// Reset all modified system properties back to their original state
|
||||
originalEnvironmentVariables.forEach {
|
||||
when {
|
||||
it.value == null -> System.clearProperty(it.key)
|
||||
else -> System.setProperty(it.key, it.value)
|
||||
}
|
||||
}
|
||||
originalEnvironmentVariables.clear()
|
||||
}
|
||||
|
||||
@@ -31,7 +31,7 @@ class GenerateTaskDslTest : TestBase() {
|
||||
fun `openApiGenerate should create an expected file structure from DSL config`() {
|
||||
// Arrange
|
||||
val projectFiles = mapOf(
|
||||
"spec.yaml" to javaClass.classLoader.getResourceAsStream("specs/petstore-v3.0-invalid.yaml")
|
||||
"spec.yaml" to javaClass.classLoader.getResourceAsStream("specs/petstore-v3.0.yaml")
|
||||
)
|
||||
withProject(defaultBuildGradle, projectFiles)
|
||||
|
||||
|
||||
@@ -11,7 +11,7 @@ Add to your `build->plugins` section (default phase is `generate-sources` phase)
|
||||
<plugin>
|
||||
<groupId>org.openapitools</groupId>
|
||||
<artifactId>openapi-generator-maven-plugin</artifactId>
|
||||
<version>3.1.2</version>
|
||||
<version>3.2.2</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<goals>
|
||||
@@ -37,7 +37,10 @@ mvn clean compile
|
||||
|
||||
### General Configuration parameters
|
||||
|
||||
:bulb: These **general** configurations should be in the same level
|
||||
|
||||
- `inputSpec` - OpenAPI Spec file path
|
||||
- `validateSpec` - Whether or not to validate the input spec prior to generation. Invalid specifications will result in an error.
|
||||
- `language` - target generation language (deprecated, replaced by `generatorName` as values here don't represent only 'language' any longer)
|
||||
- `generatorName` - target generator name
|
||||
- `output` - target output path (default is `${project.build.directory}/generated-sources/swagger`)
|
||||
@@ -48,7 +51,7 @@ mvn clean compile
|
||||
- `invokerPackage` - the package to use for the generated invoker objects
|
||||
- `modelNamePrefix` and `modelNameSuffix` - Sets the pre- or suffix for model classes and enums
|
||||
- `withXml` - enable XML annotations inside the generated models and API (only works with Java `language` and libraries that provide support for JSON and XML)
|
||||
- `configOptions` - a map of language-specific parameters (see below)
|
||||
- `configOptions` - a map of language-specific parameters. To show a full list of generator-specified parameters (options), please use `configHelp` (explained below)
|
||||
- `configHelp` - dumps the configuration help for the specified library (generates no sources)
|
||||
- `ignoreFileOverride` - specifies the full path to a `.openapi-generator-ignore` used for pattern based overrides of generated outputs
|
||||
- `generateApis` - generate the apis (`true` by default)
|
||||
@@ -102,4 +105,8 @@ Specifying a custom generator is a bit different. It doesn't support the classpa
|
||||
|
||||
### Sample configuration
|
||||
|
||||
- Please see [an example configuration](examples) for using the plugin
|
||||
Please see [an example configuration](examples) for using the plugin. To run these examples, explicitly pass the file to maven. Example:
|
||||
|
||||
```bash
|
||||
mvn -f non-java.xml compile
|
||||
```
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
<plugin>
|
||||
<groupId>org.openapitools</groupId>
|
||||
<artifactId>openapi-generator-maven-plugin</artifactId>
|
||||
<version>3.0.1-SNAPSHOT</version>
|
||||
<version>3.2.2</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<goals>
|
||||
@@ -20,7 +20,7 @@
|
||||
</goals>
|
||||
<configuration>
|
||||
<!-- specify the swagger yaml -->
|
||||
<inputSpec>swagger.yaml</inputSpec>
|
||||
<inputSpec>${project.basedir}/swagger.yaml</inputSpec>
|
||||
|
||||
<!-- target to generate java client code -->
|
||||
<generatorName>java</generatorName>
|
||||
@@ -39,13 +39,22 @@
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<version>3.6.1</version>
|
||||
<configuration>
|
||||
<source>1.7</source>
|
||||
<target>1.7</target>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
<dependencies>
|
||||
<!-- dependencies are needed for the client being generated -->
|
||||
|
||||
<dependency>
|
||||
<groupId>org.openapitools</groupId>
|
||||
<groupId>io.swagger</groupId>
|
||||
<artifactId>swagger-annotations</artifactId>
|
||||
<version>${swagger-annotations-version}</version>
|
||||
</dependency>
|
||||
@@ -55,13 +64,8 @@
|
||||
|
||||
<!-- HTTP client: jersey-client -->
|
||||
<dependency>
|
||||
<groupId>org.glassfish.jersey.core</groupId>
|
||||
<artifactId>jersey-client</artifactId>
|
||||
<version>${jersey-version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.glassfish.jersey.media</groupId>
|
||||
<artifactId>jersey-media-json-jackson</artifactId>
|
||||
<groupId>org.glassfish.jersey.core</groupId>
|
||||
<artifactId>jersey-client</artifactId>
|
||||
<version>${jersey-version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
@@ -69,6 +73,11 @@
|
||||
<artifactId>jersey-media-multipart</artifactId>
|
||||
<version>${jersey-version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.glassfish.jersey.media</groupId>
|
||||
<artifactId>jersey-media-json-jackson</artifactId>
|
||||
<version>${jersey-version}</version>
|
||||
</dependency>
|
||||
|
||||
<!-- JSON processing: jackson -->
|
||||
<dependency>
|
||||
@@ -96,7 +105,7 @@
|
||||
<artifactId>jackson-jaxrs-json-provider</artifactId>
|
||||
<version>${jackson-version}</version>
|
||||
</dependency>
|
||||
|
||||
|
||||
<!-- Joda time: if you use it -->
|
||||
<dependency>
|
||||
<groupId>com.fasterxml.jackson.datatype</groupId>
|
||||
@@ -107,19 +116,19 @@
|
||||
<groupId>joda-time</groupId>
|
||||
<artifactId>joda-time</artifactId>
|
||||
<version>${jodatime-version}</version>
|
||||
</dependency>
|
||||
</dependency>
|
||||
|
||||
<!-- Base64 encoding that works in both JVM and Android -->
|
||||
<dependency>
|
||||
<groupId>com.brsanthu</groupId>
|
||||
<artifactId>migbase64</artifactId>
|
||||
<version>2.2</version>
|
||||
</dependency>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<properties>
|
||||
<swagger-annotations-version>1.5.8</swagger-annotations-version>
|
||||
<jersey-version>2.22.2</jersey-version>
|
||||
<jersey-version>2.27</jersey-version>
|
||||
<jackson-version>2.8.9</jackson-version>
|
||||
<jodatime-version>2.7</jodatime-version>
|
||||
<maven-plugin-version>1.0.0</maven-plugin-version>
|
||||
|
||||
@@ -0,0 +1,34 @@
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>org.openapitools</groupId>
|
||||
<artifactId>sample-project</artifactId>
|
||||
<packaging>jar</packaging>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
<name>sample-project</name>
|
||||
<url>http://maven.apache.org</url>
|
||||
<build>
|
||||
<plugins>
|
||||
<!-- activate the plugin -->
|
||||
<plugin>
|
||||
<groupId>org.openapitools</groupId>
|
||||
<artifactId>openapi-generator-maven-plugin</artifactId>
|
||||
<version>3.2.2</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<goals>
|
||||
<goal>generate</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<validateSpec>false</validateSpec>
|
||||
<inputSpec>${project.basedir}/petstore-v3.0-invalid.yaml</inputSpec>
|
||||
<generatorName>aspnetcore</generatorName>
|
||||
<configOptions>
|
||||
<additional-properties>optionalProjectFile=true</additional-properties>
|
||||
</configOptions>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
</project>
|
||||
@@ -12,14 +12,14 @@
|
||||
<plugin>
|
||||
<groupId>org.openapitools</groupId>
|
||||
<artifactId>openapi-generator-maven-plugin</artifactId>
|
||||
<version>3.0.1-SNAPSHOT</version>
|
||||
<version>3.2.2</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<goals>
|
||||
<goal>generate</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<inputSpec>swagger.yaml</inputSpec>
|
||||
<inputSpec>${project.basedir}/swagger.yaml</inputSpec>
|
||||
<generatorName>aspnetcore</generatorName>
|
||||
<configOptions>
|
||||
<additional-properties>optionalProjectFile=true</additional-properties>
|
||||
|
||||
@@ -0,0 +1,103 @@
|
||||
openapi: "3.0.0"
|
||||
servers:
|
||||
- url: http://petstore.swagger.io/v1
|
||||
paths:
|
||||
/pets:
|
||||
get:
|
||||
summary: List all pets
|
||||
operationId: listPets
|
||||
tags:
|
||||
- pets
|
||||
parameters:
|
||||
- name: limit
|
||||
in: query
|
||||
description: How many items to return at one time (max 100)
|
||||
required: false
|
||||
schema:
|
||||
type: integer
|
||||
format: int32
|
||||
responses:
|
||||
'200':
|
||||
description: A paged array of pets
|
||||
headers:
|
||||
x-next:
|
||||
description: A link to the next page of responses
|
||||
schema:
|
||||
type: string
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
$ref: "#/components/schemas/Pets"
|
||||
default:
|
||||
description: unexpected error
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
$ref: "#/components/schemas/Error"
|
||||
post:
|
||||
summary: Create a pet
|
||||
tags:
|
||||
- pets
|
||||
responses:
|
||||
'201':
|
||||
description: Null response
|
||||
default:
|
||||
description: unexpected error
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
$ref: "#/components/schemas/Error"
|
||||
/pets/{petId}:
|
||||
get:
|
||||
summary: Info for a specific pet
|
||||
operationId: showPetById
|
||||
tags:
|
||||
- pets
|
||||
parameters:
|
||||
- name: petId
|
||||
in: path
|
||||
required: true
|
||||
description: The id of the pet to retrieve
|
||||
schema:
|
||||
type: string
|
||||
responses:
|
||||
'200':
|
||||
description: Expected response to a valid request
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
$ref: "#/components/schemas/Pets"
|
||||
default:
|
||||
description: unexpected error
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
$ref: "#/components/schemas/Error"
|
||||
components:
|
||||
schemas:
|
||||
Pet:
|
||||
required:
|
||||
- id
|
||||
- name
|
||||
properties:
|
||||
id:
|
||||
type: integer
|
||||
format: int64
|
||||
name:
|
||||
type: string
|
||||
tag:
|
||||
type: string
|
||||
Pets:
|
||||
type: array
|
||||
items:
|
||||
$ref: "#/components/schemas/Pet"
|
||||
Error:
|
||||
required:
|
||||
- code
|
||||
- message
|
||||
properties:
|
||||
code:
|
||||
type: integer
|
||||
format: int32
|
||||
message:
|
||||
type: string
|
||||
@@ -4,7 +4,7 @@
|
||||
<parent>
|
||||
<groupId>org.openapitools</groupId>
|
||||
<artifactId>openapi-generator-project</artifactId>
|
||||
<version>3.1.2</version>
|
||||
<version>3.2.2</version>
|
||||
<relativePath>../..</relativePath>
|
||||
</parent>
|
||||
<artifactId>openapi-generator-maven-plugin</artifactId>
|
||||
|
||||
@@ -60,6 +60,9 @@ public class CodeGenMojo extends AbstractMojo {
|
||||
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(CodeGenMojo.class);
|
||||
|
||||
@Parameter(name="validateSpec", required = false, defaultValue = "true")
|
||||
private Boolean validateSpec;
|
||||
|
||||
@Parameter(name = "verbose", required = false, defaultValue = "false")
|
||||
private boolean verbose;
|
||||
|
||||
@@ -348,6 +351,11 @@ public class CodeGenMojo extends AbstractMojo {
|
||||
|
||||
configurator.setVerbose(verbose);
|
||||
|
||||
// now override with any specified parameters
|
||||
if (validateSpec != null) {
|
||||
configurator.setValidateSpec(validateSpec);
|
||||
}
|
||||
|
||||
if (skipOverwrite != null) {
|
||||
configurator.setSkipOverwrite(skipOverwrite);
|
||||
}
|
||||
|
||||
@@ -2,7 +2,7 @@ FROM openjdk:8-jre-alpine
|
||||
|
||||
WORKDIR /generator
|
||||
|
||||
COPY target/openapi-generator-online-3.1.2.jar /generator/openapi-generator-online.jar
|
||||
COPY target/openapi-generator-online-3.2.2.jar /generator/openapi-generator-online.jar
|
||||
|
||||
ENV GENERATOR_HOST=http://localhost
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
<parent>
|
||||
<groupId>org.openapitools</groupId>
|
||||
<artifactId>openapi-generator-project</artifactId>
|
||||
<version>3.1.2</version>
|
||||
<version>3.2.2</version>
|
||||
<relativePath>../..</relativePath>
|
||||
</parent>
|
||||
<artifactId>openapi-generator-online</artifactId>
|
||||
|
||||
@@ -19,11 +19,16 @@ package org.openapitools.codegen.online.service;
|
||||
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import io.swagger.parser.OpenAPIParser;
|
||||
import io.swagger.v3.oas.models.OpenAPI;
|
||||
import io.swagger.v3.parser.core.models.ParseOptions;
|
||||
import org.openapitools.codegen.*;
|
||||
import io.swagger.v3.parser.core.models.AuthorizationValue;
|
||||
import io.swagger.v3.core.util.Json;
|
||||
import io.swagger.v3.oas.models.OpenAPI;
|
||||
import io.swagger.v3.parser.core.models.AuthorizationValue;
|
||||
import io.swagger.v3.parser.core.models.ParseOptions;
|
||||
import org.openapitools.codegen.CliOption;
|
||||
import org.openapitools.codegen.ClientOptInput;
|
||||
import org.openapitools.codegen.ClientOpts;
|
||||
import org.openapitools.codegen.CodegenConfig;
|
||||
import org.openapitools.codegen.CodegenConfigLoader;
|
||||
import org.openapitools.codegen.DefaultGenerator;
|
||||
import org.openapitools.codegen.online.model.GeneratorInput;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
@@ -34,6 +39,7 @@ import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
|
||||
public class Generator {
|
||||
@@ -44,7 +50,7 @@ public class Generator {
|
||||
try {
|
||||
config = CodegenConfigLoader.forName(language);
|
||||
} catch (Exception e) {
|
||||
throw new ResponseStatusException(HttpStatus.BAD_REQUEST, String.format("Unsupported target %s supplied. %s",
|
||||
throw new ResponseStatusException(HttpStatus.BAD_REQUEST, String.format(Locale.ROOT,"Unsupported target %s supplied. %s",
|
||||
language, e));
|
||||
}
|
||||
Map<String, CliOption> map = new LinkedHashMap<>();
|
||||
@@ -77,7 +83,7 @@ public class Generator {
|
||||
}
|
||||
|
||||
private static String generate(String language, GeneratorInput opts, Type type) {
|
||||
LOGGER.debug(String.format("generate %s for %s", type.getTypeName(), language));
|
||||
LOGGER.debug(String.format(Locale.ROOT,"generate %s for %s", type.getTypeName(), language));
|
||||
if (opts == null) {
|
||||
throw new ResponseStatusException(HttpStatus.BAD_REQUEST, "No options were supplied");
|
||||
}
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
<parent>
|
||||
<groupId>org.openapitools</groupId>
|
||||
<artifactId>openapi-generator-project</artifactId>
|
||||
<version>3.1.2</version>
|
||||
<version>3.2.2</version>
|
||||
<relativePath>../..</relativePath>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
@@ -204,9 +204,9 @@
|
||||
<version>${swagger-core-version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.swagger.parser.v3</groupId>
|
||||
<artifactId>swagger-parser</artifactId>
|
||||
<version>${swagger-parser-version}</version>
|
||||
<groupId>org.openapitools.swagger.parser</groupId>
|
||||
<artifactId>swagger-parser</artifactId>
|
||||
<version>${swagger-parser-version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.samskivert</groupId>
|
||||
|
||||
@@ -23,6 +23,8 @@ import io.swagger.v3.oas.models.OpenAPI;
|
||||
import io.swagger.v3.oas.models.Operation;
|
||||
import io.swagger.v3.oas.models.media.Schema;
|
||||
import io.swagger.v3.oas.models.security.SecurityScheme;
|
||||
import io.swagger.v3.oas.models.servers.Server;
|
||||
import io.swagger.v3.oas.models.servers.ServerVariable;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
@@ -113,6 +115,10 @@ public interface CodegenConfig {
|
||||
|
||||
List<CodegenSecurity> fromSecurity(Map<String, SecurityScheme> schemas);
|
||||
|
||||
List<CodegenServer> fromServers(List<Server> servers);
|
||||
|
||||
List<CodegenServerVariable> fromServerVariables(Map<String, ServerVariable> variables);
|
||||
|
||||
Set<String> defaultIncludes();
|
||||
|
||||
Map<String, String> typeMapping();
|
||||
|
||||
@@ -31,6 +31,7 @@ public class CodegenConstants {
|
||||
public static final String API_TESTS = "apiTests";
|
||||
public static final String API_DOCS = "apiDocs";
|
||||
public static final String WITH_XML = "withXml";
|
||||
public static final String SKIP_FORM_MODEL = "skipFormModel";
|
||||
/* /end System Properties */
|
||||
|
||||
public static final String API_PACKAGE = "apiPackage";
|
||||
@@ -257,4 +258,8 @@ public class CodegenConstants {
|
||||
|
||||
public static final String DOCEXTENSION = "docExtension";
|
||||
public static final String DOCEXTENSION_DESC = "The extension of the generated documentation files, defaults to markdown, .md";
|
||||
|
||||
public static final String DATABASE_ADAPTER = "databaseAdapter";
|
||||
public static final String DATABASE_ADAPTER_DESC = "The adapter for database (e.g. mysql, sqlite). Default: sqlite";
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,88 @@
|
||||
package org.openapitools.codegen;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
public class CodegenDiscriminator {
|
||||
private String propertyName;
|
||||
private Map<String, String> mapping;
|
||||
private Set<MappedModel> mappedModels = new LinkedHashSet<>();
|
||||
|
||||
public String getPropertyName() {
|
||||
return propertyName;
|
||||
}
|
||||
|
||||
public void setPropertyName(String propertyName) {
|
||||
this.propertyName = propertyName;
|
||||
}
|
||||
|
||||
public Map<String, String> getMapping() {
|
||||
return mapping;
|
||||
}
|
||||
|
||||
public void setMapping(Map<String, String> mapping) {
|
||||
this.mapping = mapping;
|
||||
}
|
||||
|
||||
public Set<MappedModel> getMappedModels() {
|
||||
return mappedModels;
|
||||
}
|
||||
|
||||
public void setMappedModels(Set<MappedModel> mappedModels) {
|
||||
this.mappedModels = mappedModels;
|
||||
}
|
||||
|
||||
public static class MappedModel {
|
||||
private String mappingName;
|
||||
private String modelName;
|
||||
|
||||
public MappedModel(String mappingName, String modelName) {
|
||||
this.mappingName = mappingName;
|
||||
this.modelName = modelName;
|
||||
}
|
||||
|
||||
public String getMappingName() {
|
||||
return mappingName;
|
||||
}
|
||||
|
||||
public void setMappingName(String mappingName) {
|
||||
this.mappingName = mappingName;
|
||||
}
|
||||
|
||||
public String getModelName() {
|
||||
return modelName;
|
||||
}
|
||||
|
||||
public void setModelName(String modelName) {
|
||||
this.modelName = modelName;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
MappedModel that = (MappedModel) o;
|
||||
return Objects.equals(mappingName, that.mappingName) &&
|
||||
Objects.equals(modelName, that.modelName);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(mappingName, modelName);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
CodegenDiscriminator that = (CodegenDiscriminator) o;
|
||||
return Objects.equals(propertyName, that.propertyName) &&
|
||||
Objects.equals(mapping, that.mapping) &&
|
||||
Objects.equals(mappedModels, that.mappedModels);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(propertyName, mapping, mappedModels);
|
||||
}
|
||||
}
|
||||
@@ -18,15 +18,15 @@
|
||||
package org.openapitools.codegen;
|
||||
|
||||
import io.swagger.v3.oas.models.ExternalDocumentation;
|
||||
import io.swagger.v3.oas.models.media.Discriminator;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
import java.util.TreeSet;
|
||||
import java.util.Objects;
|
||||
|
||||
public class CodegenModel {
|
||||
public String parent, parentSchema;
|
||||
@@ -40,7 +40,7 @@ public class CodegenModel {
|
||||
public String name, classname, title, description, classVarName, modelJson, dataType, xmlPrefix, xmlNamespace, xmlName;
|
||||
public String classFilename; // store the class file name, mainly used for import
|
||||
public String unescapedDescription;
|
||||
public Discriminator discriminator;
|
||||
public CodegenDiscriminator discriminator;
|
||||
public String defaultValue;
|
||||
public String arrayModelType;
|
||||
public boolean isAlias; // Is this effectively an alias of another simple type
|
||||
@@ -77,7 +77,7 @@ public class CodegenModel {
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return String.format("%s(%s)", name, classname);
|
||||
return String.format(Locale.ROOT, "%s(%s)", name, classname);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -349,7 +349,7 @@ public class CodegenModel {
|
||||
this.unescapedDescription = unescapedDescription;
|
||||
}
|
||||
|
||||
public Discriminator getDiscriminator() {
|
||||
public CodegenDiscriminator getDiscriminator() {
|
||||
return discriminator;
|
||||
}
|
||||
|
||||
@@ -357,7 +357,7 @@ public class CodegenModel {
|
||||
return discriminator == null ? null : discriminator.getPropertyName();
|
||||
}
|
||||
|
||||
public void setDiscriminator(Discriminator discriminator) {
|
||||
public void setDiscriminator(CodegenDiscriminator discriminator) {
|
||||
this.discriminator = discriminator;
|
||||
}
|
||||
|
||||
|
||||
@@ -18,17 +18,16 @@
|
||||
package org.openapitools.codegen;
|
||||
|
||||
import io.swagger.v3.oas.models.ExternalDocumentation;
|
||||
import io.swagger.v3.oas.models.media.Discriminator;
|
||||
import io.swagger.v3.oas.models.parameters.RequestBody;
|
||||
import io.swagger.v3.oas.models.tags.Tag;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.Arrays;
|
||||
|
||||
public class CodegenOperation {
|
||||
public final List<CodegenProperty> responseHeaders = new ArrayList<CodegenProperty>();
|
||||
@@ -40,7 +39,7 @@ public class CodegenOperation {
|
||||
isRestful, isDeprecated;
|
||||
public String path, operationId, returnType, httpMethod, returnBaseType,
|
||||
returnContainer, summary, unescapedNotes, notes, baseName, defaultResponse;
|
||||
public Discriminator discriminator;
|
||||
public CodegenDiscriminator discriminator;
|
||||
public List<Map<String, String>> consumes, produces, prioritizedContentTypes;
|
||||
public CodegenParameter bodyParam;
|
||||
public List<CodegenParameter> allParams = new ArrayList<CodegenParameter>();
|
||||
@@ -198,7 +197,7 @@ public class CodegenOperation {
|
||||
* @return true if act as Restful update method, false otherwise
|
||||
*/
|
||||
public boolean isRestfulUpdate() {
|
||||
return Arrays.asList("PUT", "PATCH").contains(httpMethod.toUpperCase()) && isMemberPath();
|
||||
return Arrays.asList("PUT", "PATCH").contains(httpMethod.toUpperCase(Locale.ROOT)) && isMemberPath();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -207,7 +206,7 @@ public class CodegenOperation {
|
||||
* @return true request method is PUT, PATCH or POST; false otherwise
|
||||
*/
|
||||
public boolean isBodyAllowed() {
|
||||
return Arrays.asList("PUT", "PATCH", "POST").contains(httpMethod.toUpperCase());
|
||||
return Arrays.asList("PUT", "PATCH", "POST").contains(httpMethod.toUpperCase(Locale.ROOT));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -234,7 +233,7 @@ public class CodegenOperation {
|
||||
* @return the substring
|
||||
*/
|
||||
private String pathWithoutBaseName() {
|
||||
return baseName != null ? path.replace("/" + baseName.toLowerCase(), "") : path;
|
||||
return baseName != null ? path.replace("/" + baseName.toLowerCase(Locale.ROOT), "") : path;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -250,7 +249,7 @@ public class CodegenOperation {
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return String.format("%s(%s)", baseName, path);
|
||||
return String.format(Locale.ROOT, "%s(%s)", baseName, path);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -20,6 +20,7 @@ package org.openapitools.codegen;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
|
||||
public class CodegenResponse {
|
||||
@@ -47,7 +48,7 @@ public class CodegenResponse {
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return String.format("%s(%s)", code, containerType);
|
||||
return String.format(Locale.ROOT, "%s(%s)", code, containerType);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -21,6 +21,7 @@ import io.swagger.v3.oas.models.security.Scopes;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
|
||||
public class CodegenSecurity {
|
||||
@@ -38,7 +39,7 @@ public class CodegenSecurity {
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return String.format("%s(%s)", name, type);
|
||||
return String.format(Locale.ROOT, "%s(%s)", name, type);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
package org.openapitools.codegen;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class CodegenServer {
|
||||
public String url;
|
||||
public String description;
|
||||
public List<CodegenServerVariable> variables;
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
package org.openapitools.codegen;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class CodegenServerVariable {
|
||||
public String name;
|
||||
public String defaultValue;
|
||||
public String description;
|
||||
public List<String> enumValues;
|
||||
}
|
||||
@@ -21,6 +21,7 @@ import com.fasterxml.jackson.annotation.JsonCreator;
|
||||
import com.fasterxml.jackson.annotation.JsonValue;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
|
||||
public enum CodegenType {
|
||||
@@ -30,7 +31,7 @@ public enum CodegenType {
|
||||
|
||||
@JsonCreator
|
||||
public static CodegenType forValue(String value) {
|
||||
return names.get(value.toLowerCase());
|
||||
return names.get(value.toLowerCase(Locale.ROOT));
|
||||
}
|
||||
|
||||
@JsonValue
|
||||
@@ -50,4 +51,4 @@ public enum CodegenType {
|
||||
names.put("documentation", DOCUMENTATION);
|
||||
names.put("other", OTHER);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -26,7 +26,12 @@ import io.swagger.v3.oas.models.OpenAPI;
|
||||
import io.swagger.v3.oas.models.Operation;
|
||||
import io.swagger.v3.oas.models.examples.Example;
|
||||
import io.swagger.v3.oas.models.headers.Header;
|
||||
import io.swagger.v3.oas.models.media.*;
|
||||
import io.swagger.v3.oas.models.media.ArraySchema;
|
||||
import io.swagger.v3.oas.models.media.ComposedSchema;
|
||||
import io.swagger.v3.oas.models.media.Content;
|
||||
import io.swagger.v3.oas.models.media.MediaType;
|
||||
import io.swagger.v3.oas.models.media.Schema;
|
||||
import io.swagger.v3.oas.models.media.StringSchema;
|
||||
import io.swagger.v3.oas.models.parameters.CookieParameter;
|
||||
import io.swagger.v3.oas.models.parameters.HeaderParameter;
|
||||
import io.swagger.v3.oas.models.parameters.Parameter;
|
||||
@@ -38,11 +43,14 @@ import io.swagger.v3.oas.models.responses.ApiResponses;
|
||||
import io.swagger.v3.oas.models.security.OAuthFlow;
|
||||
import io.swagger.v3.oas.models.security.OAuthFlows;
|
||||
import io.swagger.v3.oas.models.security.SecurityScheme;
|
||||
import io.swagger.v3.oas.models.servers.Server;
|
||||
import io.swagger.v3.oas.models.servers.ServerVariable;
|
||||
import io.swagger.v3.parser.util.SchemaTypeUtil;
|
||||
|
||||
import org.apache.commons.lang3.ObjectUtils;
|
||||
import org.apache.commons.lang3.StringEscapeUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.openapitools.codegen.CodegenDiscriminator.MappedModel;
|
||||
import org.openapitools.codegen.examples.ExampleGenerator;
|
||||
import org.openapitools.codegen.serializer.SerializerUtils;
|
||||
import org.openapitools.codegen.utils.ModelUtils;
|
||||
@@ -58,7 +66,9 @@ import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.Set;
|
||||
@@ -348,7 +358,7 @@ public class DefaultCodegen implements CodegenConfig {
|
||||
return "EMPTY";
|
||||
}
|
||||
|
||||
String var = value.replaceAll("\\W+", "_").toUpperCase();
|
||||
String var = value.replaceAll("\\W+", "_").toUpperCase(Locale.ROOT);
|
||||
if (var.matches("\\d.*")) {
|
||||
return "_" + var;
|
||||
} else {
|
||||
@@ -1084,7 +1094,7 @@ public class DefaultCodegen implements CodegenConfig {
|
||||
*/
|
||||
public String toInstantiationType(Schema schema) {
|
||||
if (ModelUtils.isMapSchema(schema)) {
|
||||
Schema additionalProperties = (Schema) schema.getAdditionalProperties();
|
||||
Schema additionalProperties = ModelUtils.getAdditionalProperties(schema);
|
||||
String type = additionalProperties.getType();
|
||||
if (null == type) {
|
||||
LOGGER.error("No Type defined for Additional Property " + additionalProperties + "\n" //
|
||||
@@ -1506,6 +1516,10 @@ public class DefaultCodegen implements CodegenConfig {
|
||||
|
||||
// unalias schema
|
||||
schema = ModelUtils.unaliasSchema(allDefinitions, schema);
|
||||
if (schema == null) {
|
||||
LOGGER.warn("Schema {} not found", name);
|
||||
return null;
|
||||
}
|
||||
|
||||
CodegenModel m = CodegenModelFactory.newInstance(CodegenModelType.MODEL);
|
||||
|
||||
@@ -1526,7 +1540,7 @@ public class DefaultCodegen implements CodegenConfig {
|
||||
m.getVendorExtensions().putAll(schema.getExtensions());
|
||||
}
|
||||
m.isAlias = typeAliases.containsKey(name);
|
||||
m.discriminator = schema.getDiscriminator();
|
||||
m.discriminator = createDiscriminator(name, schema, allDefinitions);
|
||||
|
||||
if (schema.getXml() != null) {
|
||||
m.xmlPrefix = schema.getXml().getPrefix();
|
||||
@@ -1553,7 +1567,7 @@ public class DefaultCodegen implements CodegenConfig {
|
||||
int modelImplCnt = 0; // only one inline object allowed in a ComposedModel
|
||||
for (Schema innerModel : composed.getAllOf()) {
|
||||
if (m.discriminator == null) {
|
||||
m.discriminator = schema.getDiscriminator();
|
||||
m.discriminator = createDiscriminator(name, schema, allDefinitions);
|
||||
}
|
||||
if (innerModel.getXml() != null) {
|
||||
m.xmlPrefix = innerModel.getXml().getPrefix();
|
||||
@@ -1668,6 +1682,34 @@ public class DefaultCodegen implements CodegenConfig {
|
||||
return m;
|
||||
}
|
||||
|
||||
private CodegenDiscriminator createDiscriminator(String schemaName, Schema schema, Map<String, Schema> allDefinitions) {
|
||||
if(schema.getDiscriminator() == null) {
|
||||
return null;
|
||||
}
|
||||
CodegenDiscriminator discriminator = new CodegenDiscriminator();
|
||||
discriminator.setPropertyName(schema.getDiscriminator().getPropertyName());
|
||||
discriminator.setMapping(schema.getDiscriminator().getMapping());
|
||||
if(schema.getDiscriminator().getMapping() != null && !schema.getDiscriminator().getMapping().isEmpty()) {
|
||||
for (Entry<String, String> e : schema.getDiscriminator().getMapping().entrySet()) {
|
||||
String name = ModelUtils.getSimpleRef(e.getValue());
|
||||
discriminator.getMappedModels().add(new MappedModel(e.getKey(), name));
|
||||
}
|
||||
} else {
|
||||
allDefinitions.forEach((childName, child) -> {
|
||||
if (child instanceof ComposedSchema && ((ComposedSchema) child).getAllOf() != null) {
|
||||
Set<String> parentSchemas = ((ComposedSchema) child).getAllOf().stream()
|
||||
.filter(s -> s.get$ref() != null)
|
||||
.map(s -> ModelUtils.getSimpleRef(s.get$ref()))
|
||||
.collect(Collectors.toSet());
|
||||
if (parentSchemas.contains(schemaName)) {
|
||||
discriminator.getMappedModels().add(new MappedModel(childName, childName));
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
return discriminator;
|
||||
}
|
||||
|
||||
protected void addAdditionPropertiesToCodeGenModel(CodegenModel codegenModel, Schema schema) {
|
||||
addParentContainer(codegenModel, codegenModel.name, schema);
|
||||
}
|
||||
@@ -1956,7 +1998,7 @@ public class DefaultCodegen implements CodegenConfig {
|
||||
property.maxItems = p.getMaxProperties();
|
||||
|
||||
// handle inner property
|
||||
CodegenProperty cp = fromProperty("inner", (Schema) p.getAdditionalProperties());
|
||||
CodegenProperty cp = fromProperty("inner", ModelUtils.getAdditionalProperties(p));
|
||||
updatePropertyForMap(property, cp);
|
||||
} else { // model
|
||||
// TODO revise the logic below
|
||||
@@ -2218,7 +2260,7 @@ public class DefaultCodegen implements CodegenConfig {
|
||||
for (String key : operation.getResponses().keySet()) {
|
||||
ApiResponse response = operation.getResponses().get(key);
|
||||
addProducesInfo(openAPI, response, op);
|
||||
CodegenResponse r = fromResponse(key, response);
|
||||
CodegenResponse r = fromResponse(openAPI, key, response);
|
||||
r.hasMore = true;
|
||||
if (r.baseType != null &&
|
||||
!defaultIncludes.contains(r.baseType) &&
|
||||
@@ -2246,7 +2288,7 @@ public class DefaultCodegen implements CodegenConfig {
|
||||
CodegenProperty innerProperty = fromProperty("response", as.getItems());
|
||||
op.returnBaseType = innerProperty.baseType;
|
||||
} else if (ModelUtils.isMapSchema(responseSchema)) {
|
||||
CodegenProperty innerProperty = fromProperty("response", (Schema) responseSchema.getAdditionalProperties());
|
||||
CodegenProperty innerProperty = fromProperty("response", ModelUtils.getAdditionalProperties(responseSchema));
|
||||
op.returnBaseType = innerProperty.baseType;
|
||||
} else {
|
||||
if (cm.complexType != null) {
|
||||
@@ -2287,7 +2329,7 @@ public class DefaultCodegen implements CodegenConfig {
|
||||
op.returnTypeIsPrimitive = true;
|
||||
}
|
||||
}
|
||||
addHeaders(methodResponse, op.responseHeaders);
|
||||
addHeaders(openAPI, methodResponse, op.responseHeaders);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2327,7 +2369,7 @@ public class DefaultCodegen implements CodegenConfig {
|
||||
bodyParameterName = (String) op.vendorExtensions.get("x-codegen-request-body-name");
|
||||
}
|
||||
bodyParam = fromRequestBody(requestBody, schemas, imports, bodyParameterName);
|
||||
bodyParam.description = requestBody.getDescription();
|
||||
bodyParam.description = escapeText(requestBody.getDescription());
|
||||
postProcessParameter(bodyParam);
|
||||
|
||||
bodyParams.add(bodyParam);
|
||||
@@ -2351,6 +2393,13 @@ public class DefaultCodegen implements CodegenConfig {
|
||||
|
||||
CodegenParameter p = fromParameter(param, imports);
|
||||
|
||||
// ensure unique params
|
||||
if (ensureUniqueParams) {
|
||||
if (!isParameterNameUnique(p, allParams)) {
|
||||
p.paramName = generateNextName(p.paramName);
|
||||
}
|
||||
}
|
||||
|
||||
allParams.add(p);
|
||||
|
||||
if (param instanceof QueryParameter || "query".equalsIgnoreCase(param.getIn())) {
|
||||
@@ -2379,17 +2428,6 @@ public class DefaultCodegen implements CodegenConfig {
|
||||
}
|
||||
}
|
||||
|
||||
// ensure unique parameter name
|
||||
for (CodegenParameter cp : allParams) {
|
||||
if (ensureUniqueParams) {
|
||||
if (isParameterNameUnique(cp, allParams)) {
|
||||
continue;
|
||||
} else {
|
||||
cp.paramName = generateNextName(cp.paramName);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// create optional, required parameters
|
||||
for (CodegenParameter cp : allParams) {
|
||||
if (cp.required) { //required parameters
|
||||
@@ -2408,7 +2446,7 @@ public class DefaultCodegen implements CodegenConfig {
|
||||
}
|
||||
|
||||
op.bodyParam = bodyParam;
|
||||
op.httpMethod = httpMethod.toUpperCase();
|
||||
op.httpMethod = httpMethod.toUpperCase(Locale.ROOT);
|
||||
|
||||
// move "required" parameters in front of "optional" parameters
|
||||
if (sortParamsByRequiredFlag) {
|
||||
@@ -2468,11 +2506,12 @@ public class DefaultCodegen implements CodegenConfig {
|
||||
/**
|
||||
* Convert OAS Response object to Codegen Response object
|
||||
*
|
||||
* @param openAPI a OAS object representing the spec
|
||||
* @param responseCode HTTP response code
|
||||
* @param response OAS Response object
|
||||
* @return Codegen Response object
|
||||
*/
|
||||
public CodegenResponse fromResponse(String responseCode, ApiResponse response) {
|
||||
public CodegenResponse fromResponse(OpenAPI openAPI, String responseCode, ApiResponse response) {
|
||||
CodegenResponse r = CodegenModelFactory.newInstance(CodegenModelType.RESPONSE);
|
||||
if ("default".equals(responseCode)) {
|
||||
r.code = "0";
|
||||
@@ -2489,7 +2528,7 @@ public class DefaultCodegen implements CodegenConfig {
|
||||
if (response.getExtensions() != null && !response.getExtensions().isEmpty()) {
|
||||
r.vendorExtensions.putAll(response.getExtensions());
|
||||
}
|
||||
addHeaders(response, r.headers);
|
||||
addHeaders(openAPI, response, r.headers);
|
||||
r.hasHeaders = !r.headers.isEmpty();
|
||||
|
||||
if (r.schema != null) {
|
||||
@@ -2636,7 +2675,7 @@ public class DefaultCodegen implements CodegenConfig {
|
||||
}
|
||||
|
||||
} else if (ModelUtils.isMapSchema(parameterSchema)) { // for map parameter
|
||||
CodegenProperty codegenProperty = fromProperty("inner", (Schema) parameterSchema.getAdditionalProperties());
|
||||
CodegenProperty codegenProperty = fromProperty("inner", ModelUtils.getAdditionalProperties(parameterSchema));
|
||||
codegenParameter.items = codegenProperty;
|
||||
codegenParameter.mostInnerItems = codegenProperty.mostInnerItems;
|
||||
codegenParameter.baseType = codegenProperty.dataType;
|
||||
@@ -2861,7 +2900,7 @@ public class DefaultCodegen implements CodegenConfig {
|
||||
// TODO revise below as it should be replaced by ModelUtils.isByteArraySchema(parameterSchema)
|
||||
public boolean isDataTypeBinary(String dataType) {
|
||||
if (dataType != null) {
|
||||
return dataType.toLowerCase().startsWith("byte");
|
||||
return dataType.toLowerCase(Locale.ROOT).startsWith("byte");
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
@@ -2870,7 +2909,7 @@ public class DefaultCodegen implements CodegenConfig {
|
||||
// TODO revise below as it should be replaced by ModelUtils.isFileSchema(parameterSchema)
|
||||
public boolean isDataTypeFile(String dataType) {
|
||||
if (dataType != null) {
|
||||
return dataType.toLowerCase().equals("file");
|
||||
return dataType.toLowerCase(Locale.ROOT).equals("file");
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
@@ -2958,12 +2997,12 @@ public class DefaultCodegen implements CodegenConfig {
|
||||
protected void setReservedWordsLowerCase(List<String> words) {
|
||||
reservedWords = new HashSet<String>();
|
||||
for (String word : words) {
|
||||
reservedWords.add(word.toLowerCase());
|
||||
reservedWords.add(word.toLowerCase(Locale.ROOT));
|
||||
}
|
||||
}
|
||||
|
||||
protected boolean isReservedWord(String word) {
|
||||
return word != null && reservedWords.contains(word.toLowerCase());
|
||||
return word != null && reservedWords.contains(word.toLowerCase(Locale.ROOT));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -3035,12 +3074,15 @@ public class DefaultCodegen implements CodegenConfig {
|
||||
* @param response API response
|
||||
* @param properties list of codegen property
|
||||
*/
|
||||
private void addHeaders(ApiResponse response, List<CodegenProperty> properties) {
|
||||
private void addHeaders(OpenAPI openAPI, ApiResponse response, List<CodegenProperty> properties) {
|
||||
if (response.getHeaders() != null) {
|
||||
for (Map.Entry<String, Header> headers : response.getHeaders().entrySet()) {
|
||||
CodegenProperty cp = fromProperty(headers.getKey(), headers.getValue().getSchema());
|
||||
cp.setDescription(escapeText(headers.getValue().getDescription()));
|
||||
cp.setUnescapedDescription(headers.getValue().getDescription());
|
||||
String description = headers.getValue().getDescription();
|
||||
// follow the $ref
|
||||
Header header = ModelUtils.getReferencedHeader(openAPI, headers.getValue());
|
||||
CodegenProperty cp = fromProperty(headers.getKey(), header.getSchema());
|
||||
cp.setDescription(escapeText(description));
|
||||
cp.setUnescapedDescription(description);
|
||||
properties.add(cp);
|
||||
}
|
||||
}
|
||||
@@ -3089,7 +3131,7 @@ public class DefaultCodegen implements CodegenConfig {
|
||||
LOGGER.warn("generated unique operationId `" + uniqueName + "`");
|
||||
}
|
||||
co.operationId = uniqueName;
|
||||
co.operationIdLowerCase = uniqueName.toLowerCase();
|
||||
co.operationIdLowerCase = uniqueName.toLowerCase(Locale.ROOT);
|
||||
co.operationIdCamelCase = DefaultCodegen.camelize(uniqueName);
|
||||
co.operationIdSnakeCase = DefaultCodegen.underscore(uniqueName);
|
||||
opList.add(co);
|
||||
@@ -3135,7 +3177,7 @@ public class DefaultCodegen implements CodegenConfig {
|
||||
word = word.replace('-', '_');
|
||||
// replace space with underscore
|
||||
word = word.replace(' ', '_');
|
||||
word = word.toLowerCase();
|
||||
word = word.toLowerCase(Locale.ROOT);
|
||||
return word;
|
||||
}
|
||||
|
||||
@@ -3299,7 +3341,7 @@ public class DefaultCodegen implements CodegenConfig {
|
||||
* @param schemas The complete set of model definitions (schemas).
|
||||
* @return A mapping from model name to type alias
|
||||
*/
|
||||
private static Map<String, String> getAllAliases(Map<String, Schema> schemas) {
|
||||
static Map<String, String> getAllAliases(Map<String, Schema> schemas) {
|
||||
if (schemas == null || schemas.isEmpty()) {
|
||||
return new HashMap<>();
|
||||
}
|
||||
@@ -3342,7 +3384,7 @@ public class DefaultCodegen implements CodegenConfig {
|
||||
.map(StringUtils::capitalize)
|
||||
.collect(Collectors.joining(""));
|
||||
if (result.length() > 0) {
|
||||
result = result.substring(0, 1).toLowerCase() + result.substring(1);
|
||||
result = result.substring(0, 1).toLowerCase(Locale.ROOT) + result.substring(1);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
@@ -3371,7 +3413,7 @@ public class DefaultCodegen implements CodegenConfig {
|
||||
Pattern p = Pattern.compile("\\/(.?)");
|
||||
Matcher m = p.matcher(word);
|
||||
while (m.find()) {
|
||||
word = m.replaceFirst("." + m.group(1)/*.toUpperCase()*/); // FIXME: a parameter should not be assigned. Also declare the methods parameters as 'final'.
|
||||
word = m.replaceFirst("." + m.group(1)/*.toUpperCase(Locale.ROOT)*/); // FIXME: a parameter should not be assigned. Also declare the methods parameters as 'final'.
|
||||
m = p.matcher(word);
|
||||
}
|
||||
|
||||
@@ -3387,7 +3429,7 @@ public class DefaultCodegen implements CodegenConfig {
|
||||
|
||||
m = p.matcher(word);
|
||||
while (m.find()) {
|
||||
word = m.replaceFirst("" + Character.toUpperCase(m.group(1).charAt(0)) + m.group(1).substring(1)/*.toUpperCase()*/);
|
||||
word = m.replaceFirst("" + Character.toUpperCase(m.group(1).charAt(0)) + m.group(1).substring(1)/*.toUpperCase(Locale.ROOT)*/);
|
||||
m = p.matcher(word);
|
||||
}
|
||||
|
||||
@@ -3395,7 +3437,7 @@ public class DefaultCodegen implements CodegenConfig {
|
||||
p = Pattern.compile("(\\.?)(\\w)([^\\.]*)$");
|
||||
m = p.matcher(word);
|
||||
if (m.find()) {
|
||||
String rep = m.group(1) + m.group(2).toUpperCase() + m.group(3);
|
||||
String rep = m.group(1) + m.group(2).toUpperCase(Locale.ROOT) + m.group(3);
|
||||
rep = rep.replaceAll("\\$", "\\\\\\$");
|
||||
word = m.replaceAll(rep);
|
||||
}
|
||||
@@ -3405,7 +3447,7 @@ public class DefaultCodegen implements CodegenConfig {
|
||||
m = p.matcher(word);
|
||||
while (m.find()) {
|
||||
String original = m.group(2);
|
||||
String upperCase = original.toUpperCase();
|
||||
String upperCase = original.toUpperCase(Locale.ROOT);
|
||||
if (original.equals(upperCase)) {
|
||||
word = word.replaceFirst("_", "");
|
||||
} else {
|
||||
@@ -3418,7 +3460,7 @@ public class DefaultCodegen implements CodegenConfig {
|
||||
p = Pattern.compile("(-)(.)");
|
||||
m = p.matcher(word);
|
||||
while (m.find()) {
|
||||
word = m.replaceFirst(m.group(2).toUpperCase());
|
||||
word = m.replaceFirst(m.group(2).toUpperCase(Locale.ROOT));
|
||||
m = p.matcher(word);
|
||||
}
|
||||
|
||||
@@ -3430,7 +3472,7 @@ public class DefaultCodegen implements CodegenConfig {
|
||||
charAt = word.charAt(i);
|
||||
}
|
||||
i = i + 1;
|
||||
word = word.substring(0, i).toLowerCase() + word.substring(i);
|
||||
word = word.substring(0, i).toLowerCase(Locale.ROOT) + word.substring(i);
|
||||
}
|
||||
|
||||
// remove all underscore
|
||||
@@ -4204,7 +4246,7 @@ public class DefaultCodegen implements CodegenConfig {
|
||||
codegenParameter.isPrimitiveType = false;
|
||||
codegenParameter.isContainer = true;
|
||||
codegenParameter.isListContainer = true;
|
||||
codegenParameter.description = s.getDescription();
|
||||
codegenParameter.description = escapeText(s.getDescription());
|
||||
codegenParameter.dataType = getTypeDeclaration(s);
|
||||
if (codegenParameter.baseType != null && codegenParameter.enumName != null) {
|
||||
codegenParameter.datatypeWithEnum = codegenParameter.dataType.replace(codegenParameter.baseType, codegenParameter.enumName);
|
||||
@@ -4330,7 +4372,7 @@ public class DefaultCodegen implements CodegenConfig {
|
||||
CodegenParameter codegenParameter = CodegenModelFactory.newInstance(CodegenModelType.PARAMETER);
|
||||
codegenParameter.baseName = "UNKNOWN_BASE_NAME";
|
||||
codegenParameter.paramName = "UNKNOWN_PARAM_NAME";
|
||||
codegenParameter.description = body.getDescription();
|
||||
codegenParameter.description = escapeText(body.getDescription());
|
||||
codegenParameter.required = body.getRequired() != null ? body.getRequired() : Boolean.FALSE;
|
||||
codegenParameter.isBodyParam = Boolean.TRUE;
|
||||
|
||||
@@ -4343,7 +4385,7 @@ public class DefaultCodegen implements CodegenConfig {
|
||||
}
|
||||
|
||||
if (ModelUtils.isMapSchema(schema)) {
|
||||
Schema inner = (Schema) schema.getAdditionalProperties();
|
||||
Schema inner = ModelUtils.getAdditionalProperties(schema);
|
||||
if (inner == null) {
|
||||
inner = new StringSchema().description("//TODO automatically added by openapi-generator");
|
||||
schema.setAdditionalProperties(inner);
|
||||
@@ -4388,7 +4430,11 @@ public class DefaultCodegen implements CodegenConfig {
|
||||
}
|
||||
|
||||
if (StringUtils.isEmpty(bodyParameterName)) {
|
||||
codegenParameter.baseName = mostInnerItem.complexType;
|
||||
if(StringUtils.isEmpty(mostInnerItem.complexType)) {
|
||||
codegenParameter.baseName = "request_body";
|
||||
} else {
|
||||
codegenParameter.baseName = mostInnerItem.complexType;
|
||||
}
|
||||
} else {
|
||||
codegenParameter.baseName = bodyParameterName;
|
||||
}
|
||||
@@ -4427,7 +4473,7 @@ public class DefaultCodegen implements CodegenConfig {
|
||||
imports.add(codegenParameter.baseType);
|
||||
} else {
|
||||
CodegenProperty codegenProperty = fromProperty("property", schema);
|
||||
if (schema.getAdditionalProperties() != null) {// http body is map
|
||||
if (ModelUtils.getAdditionalProperties(schema) != null) {// http body is map
|
||||
LOGGER.error("Map should be supported. Please report to openapi-generator github repo about the issue.");
|
||||
} else if (codegenProperty != null) {
|
||||
String codegenModelName, codegenModelDescription;
|
||||
@@ -4538,7 +4584,49 @@ public class DefaultCodegen implements CodegenConfig {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* checks if the data should be classified as "string" in enum
|
||||
* e.g. double in C# needs to be double-quoted (e.g. "2.8") by treating it as a string
|
||||
* In the future, we may rename this function to "isEnumString"
|
||||
*
|
||||
* @param dataType data type
|
||||
* @return true if it's a enum string
|
||||
*/
|
||||
public boolean isDataTypeString(String dataType) {
|
||||
return "String".equals(dataType);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<CodegenServer> fromServers(List<Server> servers) {
|
||||
if (servers == null) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
List<CodegenServer> codegenServers = new LinkedList<>();
|
||||
for (Server server: servers) {
|
||||
CodegenServer cs = new CodegenServer();
|
||||
cs.description = escapeText(server.getDescription());
|
||||
cs.url = server.getUrl();
|
||||
cs.variables = this.fromServerVariables(server.getVariables());
|
||||
codegenServers.add(cs);
|
||||
}
|
||||
return codegenServers;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<CodegenServerVariable> fromServerVariables(Map<String, ServerVariable> variables) {
|
||||
if (variables == null) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
List<CodegenServerVariable> codegenServerVariables = new LinkedList<>();
|
||||
for (Entry<String, ServerVariable> variableEntry: variables.entrySet()) {
|
||||
CodegenServerVariable codegenServerVariable = new CodegenServerVariable();
|
||||
ServerVariable variable = variableEntry.getValue();
|
||||
codegenServerVariable.defaultValue = variable.getDefault();
|
||||
codegenServerVariable.description = escapeText(variable.getDescription());
|
||||
codegenServerVariable.enumValues = variable.getEnum();
|
||||
codegenServerVariable.name = variableEntry.getKey();
|
||||
codegenServerVariables.add(codegenServerVariable);
|
||||
}
|
||||
return codegenServerVariables;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -95,7 +95,7 @@ public class DefaultGenerator extends AbstractGenerator implements Generator {
|
||||
|
||||
/**
|
||||
* Programmatically disable the output of .openapi-generator/VERSION, .openapi-generator-ignore,
|
||||
* or other metadata files used by Swagger Codegen.
|
||||
* or other metadata files used by OpenAPI Generator.
|
||||
*
|
||||
* @param generateMetadata true: enable outputs, false: disable outputs
|
||||
*/
|
||||
@@ -169,14 +169,15 @@ public class DefaultGenerator extends AbstractGenerator implements Generator {
|
||||
if (!generateApiTests && !generateModelTests) {
|
||||
config.additionalProperties().put(CodegenConstants.EXCLUDE_TESTS, true);
|
||||
}
|
||||
// for backward compatibility
|
||||
if (System.getProperty("debugSwagger") != null) {
|
||||
LOGGER.info("Please use system property 'debugOpenAPI' instead of 'debugSwagger'.");
|
||||
Json.prettyPrint(openAPI);
|
||||
}
|
||||
|
||||
|
||||
if (System.getProperty("debugOpenAPI") != null) {
|
||||
Json.prettyPrint(openAPI);
|
||||
} else if (System.getProperty("debugSwagger") != null) {
|
||||
// This exists for backward compatibility
|
||||
// We fall to this block only if debugOpenAPI is null. No need to dump this twice.
|
||||
LOGGER.info("Please use system property 'debugOpenAPI' instead of 'debugSwagger'.");
|
||||
Json.prettyPrint(openAPI);
|
||||
}
|
||||
|
||||
config.processOpts();
|
||||
@@ -193,8 +194,14 @@ public class DefaultGenerator extends AbstractGenerator implements Generator {
|
||||
|
||||
URL url = URLPathUtils.getServerURL(openAPI);
|
||||
contextPath = config.escapeText(url.getPath());
|
||||
basePath = config.escapeText(URLPathUtils.getHost(openAPI));
|
||||
basePathWithoutHost = contextPath; // for backward compatibility
|
||||
basePath = config.escapeText(URLPathUtils.getHost(openAPI));
|
||||
if ("/".equals(basePath.substring(basePath.length() - 1))) {
|
||||
// remove trailing "/"
|
||||
// https://host.example.com/ => https://host.example.com
|
||||
basePath = basePath.substring(0, basePath.length() - 1);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void configureOpenAPIInfo() {
|
||||
@@ -279,7 +286,7 @@ public class DefaultGenerator extends AbstractGenerator implements Generator {
|
||||
private void generateModelDocumentation(List<File> files, Map<String, Object> models, String modelName) throws IOException {
|
||||
for (String templateName : config.modelDocTemplateFiles().keySet()) {
|
||||
String docExtension = config.getDocExtension();
|
||||
String suffix = docExtension!=null ? docExtension : config.modelDocTemplateFiles().get(templateName);
|
||||
String suffix = docExtension != null ? docExtension : config.modelDocTemplateFiles().get(templateName);
|
||||
String filename = config.modelDocFileFolder() + File.separator + config.toModelDocFilename(modelName) + suffix;
|
||||
if (!config.shouldOverwrite(filename)) {
|
||||
LOGGER.info("Skipped overwriting " + filename);
|
||||
@@ -375,6 +382,10 @@ public class DefaultGenerator extends AbstractGenerator implements Generator {
|
||||
} */
|
||||
});
|
||||
|
||||
Boolean skipFormModel = System.getProperty(CodegenConstants.SKIP_FORM_MODEL) != null ?
|
||||
Boolean.valueOf(System.getProperty(CodegenConstants.SKIP_FORM_MODEL)) :
|
||||
getGeneratorPropertyDefaultSwitch(CodegenConstants.SKIP_FORM_MODEL, false);
|
||||
|
||||
// process models only
|
||||
for (String name : modelKeys) {
|
||||
try {
|
||||
@@ -386,8 +397,13 @@ public class DefaultGenerator extends AbstractGenerator implements Generator {
|
||||
|
||||
// don't generate models that are not used as object (e.g. form parameters)
|
||||
if (unusedModels.contains(name)) {
|
||||
LOGGER.debug("Model " + name + " not generated since it's marked as unused (due to form parameters)");
|
||||
continue;
|
||||
if (Boolean.FALSE.equals(skipFormModel)) {
|
||||
// if skipFormModel sets to true, still generate the model and log the result
|
||||
LOGGER.info("Model " + name + " (marked as unused due to form parameters) is generated due to skipFormModel=false (default)");
|
||||
} else {
|
||||
LOGGER.info("Model " + name + " not generated since it's marked as unused (due to form parameters) and skipFormModel set to true");
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
Schema schema = schemas.get(name);
|
||||
@@ -746,6 +762,12 @@ public class DefaultGenerator extends AbstractGenerator implements Generator {
|
||||
bundle.put("authMethods", authMethods);
|
||||
bundle.put("hasAuthMethods", 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());
|
||||
@@ -781,8 +803,8 @@ public class DefaultGenerator extends AbstractGenerator implements Generator {
|
||||
configureOpenAPIInfo();
|
||||
|
||||
// resolve inline models
|
||||
//InlineModelResolver inlineModelResolver = new InlineModelResolver();
|
||||
//inlineModelResolver.flatten(openAPI);
|
||||
InlineModelResolver inlineModelResolver = new InlineModelResolver();
|
||||
inlineModelResolver.flatten(openAPI);
|
||||
|
||||
List<File> files = new ArrayList<File>();
|
||||
// models
|
||||
|
||||
@@ -0,0 +1,560 @@
|
||||
/*
|
||||
* Copyright 2018 OpenAPI-Generator Contributors (https://openapi-generator.tech)
|
||||
* Copyright 2018 SmartBear Software
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.openapitools.codegen;
|
||||
|
||||
import io.swagger.v3.oas.models.OpenAPI;
|
||||
import io.swagger.v3.oas.models.media.Schema;
|
||||
import io.swagger.v3.oas.models.media.ArraySchema;
|
||||
import io.swagger.v3.oas.models.media.ObjectSchema;
|
||||
import io.swagger.v3.oas.models.media.*;
|
||||
import io.swagger.v3.oas.models.responses.ApiResponse;
|
||||
import io.swagger.v3.oas.models.Operation;
|
||||
import io.swagger.v3.oas.models.PathItem;
|
||||
import io.swagger.v3.oas.models.parameters.Parameter;
|
||||
import io.swagger.v3.oas.models.parameters.RequestBody;
|
||||
import io.swagger.v3.oas.models.Paths;
|
||||
import io.swagger.v3.core.util.Json;
|
||||
import org.openapitools.codegen.utils.ModelUtils;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import io.swagger.v3.oas.models.media.Content;
|
||||
import io.swagger.v3.oas.models.media.MediaType;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
import io.swagger.v3.oas.models.media.XML;
|
||||
|
||||
public class InlineModelResolver {
|
||||
private OpenAPI openapi;
|
||||
private boolean skipMatches;
|
||||
static Logger LOGGER = LoggerFactory.getLogger(InlineModelResolver.class);
|
||||
Map<String, Schema> addedModels = new HashMap<String, Schema>();
|
||||
Map<String, String> generatedSignature = new HashMap<String, String>();
|
||||
|
||||
public void flatten(OpenAPI openapi) {
|
||||
this.openapi = openapi;
|
||||
|
||||
if (openapi.getComponents() == null) {
|
||||
return; // There's nothing here
|
||||
}
|
||||
|
||||
if (openapi.getComponents().getSchemas() == null) {
|
||||
openapi.getComponents().setSchemas(new HashMap<String, Schema>());
|
||||
}
|
||||
// operations
|
||||
Map<String, PathItem> paths = openapi.getPaths();
|
||||
Map<String, Schema> models = openapi.getComponents().getSchemas();
|
||||
if (paths != null) {
|
||||
for (String pathname : paths.keySet()) {
|
||||
PathItem path = paths.get(pathname);
|
||||
for (Operation operation : path.readOperations()) {
|
||||
RequestBody requestBody = operation.getRequestBody();
|
||||
if (requestBody != null) {
|
||||
Schema model = ModelUtils.getSchemaFromRequestBody(requestBody);
|
||||
if (model instanceof ObjectSchema) {
|
||||
Schema obj = (Schema) model;
|
||||
if (obj.getType() == null || "object".equals(obj.getType())) {
|
||||
if (obj.getProperties() != null && obj.getProperties().size() > 0) {
|
||||
flattenProperties(obj.getProperties(), pathname);
|
||||
// for model name, use "title" if defined, otherwise default to 'inline_object'
|
||||
String modelName = resolveModelName(obj.getTitle(), "inline_object");
|
||||
addGenerated(modelName, model);
|
||||
openapi.getComponents().addSchemas(modelName, model);
|
||||
|
||||
// create request body
|
||||
RequestBody rb = new RequestBody();
|
||||
Content content = new Content();
|
||||
MediaType mt = new MediaType();
|
||||
Schema schema = new Schema();
|
||||
schema.set$ref(modelName);
|
||||
mt.setSchema(schema);
|
||||
|
||||
// get "consumes", e.g. application/xml, application/json
|
||||
Set<String> consumes;
|
||||
if (requestBody == null || requestBody.getContent() == null || requestBody.getContent().isEmpty()) {
|
||||
consumes = new HashSet<>();
|
||||
consumes.add("application/json"); // default to application/json
|
||||
LOGGER.info("Default to application/json for inline body schema");
|
||||
} else {
|
||||
consumes = requestBody.getContent().keySet();
|
||||
}
|
||||
|
||||
for (String consume : consumes) {
|
||||
content.addMediaType(consume, mt);
|
||||
}
|
||||
|
||||
rb.setContent(content);
|
||||
|
||||
// add to openapi "components"
|
||||
if (openapi.getComponents().getRequestBodies() == null) {
|
||||
Map<String, RequestBody> requestBodies = new HashMap<String, RequestBody>();
|
||||
requestBodies.put(modelName, rb);
|
||||
openapi.getComponents().setRequestBodies(requestBodies);
|
||||
} else {
|
||||
openapi.getComponents().getRequestBodies().put(modelName, rb);
|
||||
}
|
||||
|
||||
// update requestBody to use $ref instead of inline def
|
||||
requestBody.set$ref(modelName);
|
||||
|
||||
}
|
||||
}
|
||||
} else if (model instanceof ArraySchema) {
|
||||
ArraySchema am = (ArraySchema) model;
|
||||
Schema inner = am.getItems();
|
||||
if (inner instanceof ObjectSchema) {
|
||||
ObjectSchema op = (ObjectSchema) inner;
|
||||
if (op.getProperties() != null && op.getProperties().size() > 0) {
|
||||
flattenProperties(op.getProperties(), pathname);
|
||||
String modelName = resolveModelName(op.getTitle(), null);
|
||||
Schema innerModel = modelFromProperty(op, modelName);
|
||||
String existing = matchGenerated(innerModel);
|
||||
if (existing != null) {
|
||||
Schema schema = new Schema().$ref(existing);
|
||||
schema.setRequired(op.getRequired());
|
||||
am.setItems(schema);
|
||||
} else {
|
||||
Schema schema = new Schema().$ref(modelName);
|
||||
schema.setRequired(op.getRequired());
|
||||
am.setItems(schema);
|
||||
addGenerated(modelName, innerModel);
|
||||
openapi.getComponents().addSchemas(modelName, innerModel);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
List<Parameter> parameters = operation.getParameters();
|
||||
if (parameters != null) {
|
||||
for (Parameter parameter : parameters) {
|
||||
if (parameter.getSchema() != null) {
|
||||
Schema model = parameter.getSchema();
|
||||
if (model instanceof ObjectSchema) {
|
||||
Schema obj = (Schema) model;
|
||||
if (obj.getType() == null || "object".equals(obj.getType())) {
|
||||
if (obj.getProperties() != null && obj.getProperties().size() > 0) {
|
||||
flattenProperties(obj.getProperties(), pathname);
|
||||
String modelName = resolveModelName(obj.getTitle(), parameter.getName());
|
||||
|
||||
parameter.$ref(modelName);
|
||||
addGenerated(modelName, model);
|
||||
openapi.getComponents().addSchemas(modelName, model);
|
||||
}
|
||||
}
|
||||
} else if (model instanceof ArraySchema) {
|
||||
ArraySchema am = (ArraySchema) model;
|
||||
Schema inner = am.getItems();
|
||||
if (inner instanceof ObjectSchema) {
|
||||
ObjectSchema op = (ObjectSchema) inner;
|
||||
if (op.getProperties() != null && op.getProperties().size() > 0) {
|
||||
flattenProperties(op.getProperties(), pathname);
|
||||
String modelName = resolveModelName(op.getTitle(), parameter.getName());
|
||||
Schema innerModel = modelFromProperty(op, modelName);
|
||||
String existing = matchGenerated(innerModel);
|
||||
if (existing != null) {
|
||||
Schema schema = new Schema().$ref(existing);
|
||||
schema.setRequired(op.getRequired());
|
||||
am.setItems(schema);
|
||||
} else {
|
||||
Schema schema = new Schema().$ref(modelName);
|
||||
schema.setRequired(op.getRequired());
|
||||
am.setItems(schema);
|
||||
addGenerated(modelName, innerModel);
|
||||
openapi.getComponents().addSchemas(modelName, innerModel);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Map<String, ApiResponse> responses = operation.getResponses();
|
||||
if (responses != null) {
|
||||
for (String key : responses.keySet()) {
|
||||
ApiResponse response = responses.get(key);
|
||||
if (ModelUtils.getSchemaFromResponse(response) != null) {
|
||||
Schema property = ModelUtils.getSchemaFromResponse(response);
|
||||
if (property instanceof ObjectSchema) {
|
||||
ObjectSchema op = (ObjectSchema) property;
|
||||
if (op.getProperties() != null && op.getProperties().size() > 0) {
|
||||
String modelName = resolveModelName(op.getTitle(), "inline_response_" + key);
|
||||
Schema model = modelFromProperty(op, modelName);
|
||||
String existing = matchGenerated(model);
|
||||
Content content = response.getContent();
|
||||
for (MediaType mediaType : content.values()) {
|
||||
if (existing != null) {
|
||||
Schema schema = this.makeSchema(existing, property);
|
||||
schema.setRequired(op.getRequired());
|
||||
mediaType.setSchema(schema);
|
||||
} else {
|
||||
Schema schema = this.makeSchema(modelName, property);
|
||||
schema.setRequired(op.getRequired());
|
||||
mediaType.setSchema(schema);
|
||||
addGenerated(modelName, model);
|
||||
openapi.getComponents().addSchemas(modelName, model);
|
||||
}
|
||||
}
|
||||
}
|
||||
} else if (property instanceof ArraySchema) {
|
||||
ArraySchema ap = (ArraySchema) property;
|
||||
Schema inner = ap.getItems();
|
||||
if (inner instanceof ObjectSchema) {
|
||||
ObjectSchema op = (ObjectSchema) inner;
|
||||
if (op.getProperties() != null && op.getProperties().size() > 0) {
|
||||
flattenProperties(op.getProperties(), pathname);
|
||||
String modelName = resolveModelName(op.getTitle(),
|
||||
"inline_response_" + key);
|
||||
Schema innerModel = modelFromProperty(op, modelName);
|
||||
String existing = matchGenerated(innerModel);
|
||||
if (existing != null) {
|
||||
Schema schema = this.makeSchema(existing, op);
|
||||
schema.setRequired(op.getRequired());
|
||||
ap.setItems(schema);
|
||||
} else {
|
||||
Schema schema = this.makeSchema(modelName, op);
|
||||
schema.setRequired(op.getRequired());
|
||||
ap.setItems(schema);
|
||||
addGenerated(modelName, innerModel);
|
||||
openapi.getComponents().addSchemas(modelName, innerModel);
|
||||
}
|
||||
}
|
||||
}
|
||||
} else if (property instanceof MapSchema) {
|
||||
MapSchema mp = (MapSchema) property;
|
||||
Schema innerProperty = ModelUtils.getAdditionalProperties(mp);
|
||||
if (innerProperty instanceof ObjectSchema) {
|
||||
ObjectSchema op = (ObjectSchema) innerProperty;
|
||||
if (op.getProperties() != null && op.getProperties().size() > 0) {
|
||||
flattenProperties(op.getProperties(), pathname);
|
||||
String modelName = resolveModelName(op.getTitle(),
|
||||
"inline_response_" + key);
|
||||
Schema innerModel = modelFromProperty(op, modelName);
|
||||
String existing = matchGenerated(innerModel);
|
||||
if (existing != null) {
|
||||
Schema schema = new Schema().$ref(existing);
|
||||
schema.setRequired(op.getRequired());
|
||||
mp.setAdditionalProperties(schema);
|
||||
} else {
|
||||
Schema schema = new Schema().$ref(modelName);
|
||||
schema.setRequired(op.getRequired());
|
||||
mp.setAdditionalProperties(schema);
|
||||
addGenerated(modelName, innerModel);
|
||||
openapi.getComponents().addSchemas(modelName, innerModel);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
// definitions
|
||||
if (models != null) {
|
||||
List<String> modelNames = new ArrayList<String>(models.keySet());
|
||||
for (String modelName : modelNames) {
|
||||
Schema model = models.get(modelName);
|
||||
if (model instanceof Schema) {
|
||||
Schema m = (Schema) model;
|
||||
Map<String, Schema> properties = m.getProperties();
|
||||
flattenProperties(properties, modelName);
|
||||
fixStringModel(m);
|
||||
} else if (ModelUtils.isArraySchema(model)) {
|
||||
ArraySchema m = (ArraySchema) model;
|
||||
Schema inner = m.getItems();
|
||||
if (inner instanceof ObjectSchema) {
|
||||
ObjectSchema op = (ObjectSchema) inner;
|
||||
if (op.getProperties() != null && op.getProperties().size() > 0) {
|
||||
String innerModelName = resolveModelName(op.getTitle(), modelName + "_inner");
|
||||
Schema innerModel = modelFromProperty(op, innerModelName);
|
||||
String existing = matchGenerated(innerModel);
|
||||
if (existing == null) {
|
||||
openapi.getComponents().addSchemas(innerModelName, innerModel);
|
||||
addGenerated(innerModelName, innerModel);
|
||||
Schema schema = new Schema().$ref(innerModelName);
|
||||
schema.setRequired(op.getRequired());
|
||||
m.setItems(schema);
|
||||
} else {
|
||||
Schema schema = new Schema().$ref(existing);
|
||||
schema.setRequired(op.getRequired());
|
||||
m.setItems(schema);
|
||||
}
|
||||
}
|
||||
}
|
||||
} else if (ModelUtils.isComposedSchema(model)) {
|
||||
ComposedSchema m = (ComposedSchema) model;
|
||||
if (m.getAllOf() != null && !m.getAllOf().isEmpty()) {
|
||||
Schema child = null;
|
||||
for (Schema component : m.getAllOf()) {
|
||||
if (component.get$ref() == null) {
|
||||
child = component;
|
||||
}
|
||||
}
|
||||
if (child != null) {
|
||||
Map<String, Schema> properties = child.getProperties();
|
||||
flattenProperties(properties, modelName);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* This function fix models that are string (mostly enum). Before this fix, the
|
||||
* example would look something like that in the doc: "\"example from def\""
|
||||
*
|
||||
* @param m Schema implementation
|
||||
*/
|
||||
private void fixStringModel(Schema m) {
|
||||
if (m.getType() != null && m.getType().equals("string") && m.getExample() != null) {
|
||||
String example = m.getExample().toString();
|
||||
if (example.substring(0, 1).equals("\"") && example.substring(example.length() - 1).equals("\"")) {
|
||||
m.setExample(example.substring(1, example.length() - 1));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private String resolveModelName(String title, String key) {
|
||||
if (title == null) {
|
||||
return uniqueName(key);
|
||||
} else {
|
||||
return uniqueName(title);
|
||||
}
|
||||
}
|
||||
|
||||
public String matchGenerated(Schema model) {
|
||||
if (this.skipMatches) {
|
||||
return null;
|
||||
}
|
||||
String json = Json.pretty(model);
|
||||
if (generatedSignature.containsKey(json)) {
|
||||
return generatedSignature.get(json);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public void addGenerated(String name, Schema model) {
|
||||
generatedSignature.put(Json.pretty(model), name);
|
||||
}
|
||||
|
||||
public String uniqueName(String key) {
|
||||
if (key == null) {
|
||||
key = "NULL_UNIQUE_NAME";
|
||||
LOGGER.warn("null key found. Default to NULL_UNIQUE_NAME");
|
||||
}
|
||||
int count = 0;
|
||||
boolean done = false;
|
||||
key = key.replaceAll("[^a-z_\\.A-Z0-9 ]", ""); // FIXME: a parameter
|
||||
// should not be assigned. Also declare the methods parameters as 'final'.
|
||||
while (!done) {
|
||||
String name = key;
|
||||
if (count > 0) {
|
||||
name = key + "_" + count;
|
||||
}
|
||||
if (openapi.getComponents().getSchemas() == null) {
|
||||
return name;
|
||||
} else if (!openapi.getComponents().getSchemas().containsKey(name)) {
|
||||
return name;
|
||||
}
|
||||
count += 1;
|
||||
}
|
||||
return key;
|
||||
}
|
||||
|
||||
public void flattenProperties(Map<String, Schema> properties, String path) {
|
||||
if (properties == null) {
|
||||
return;
|
||||
}
|
||||
Map<String, Schema> propsToUpdate = new HashMap<String, Schema>();
|
||||
Map<String, Schema> modelsToAdd = new HashMap<String, Schema>();
|
||||
for (String key : properties.keySet()) {
|
||||
Schema property = properties.get(key);
|
||||
if (property instanceof ObjectSchema && ((ObjectSchema) property).getProperties() != null
|
||||
&& ((ObjectSchema) property).getProperties().size() > 0) {
|
||||
ObjectSchema op = (ObjectSchema) property;
|
||||
String modelName = resolveModelName(op.getTitle(), path + "_" + key);
|
||||
Schema model = modelFromProperty(op, modelName);
|
||||
String existing = matchGenerated(model);
|
||||
if (existing != null) {
|
||||
Schema schema = new Schema().$ref(existing);
|
||||
schema.setRequired(op.getRequired());
|
||||
propsToUpdate.put(key, schema);
|
||||
} else {
|
||||
Schema schema = new Schema().$ref(modelName);
|
||||
schema.setRequired(op.getRequired());
|
||||
propsToUpdate.put(key, schema);
|
||||
modelsToAdd.put(modelName, model);
|
||||
addGenerated(modelName, model);
|
||||
openapi.getComponents().addSchemas(modelName, model);
|
||||
}
|
||||
} else if (property instanceof ArraySchema) {
|
||||
ArraySchema ap = (ArraySchema) property;
|
||||
Schema inner = ap.getItems();
|
||||
if (inner instanceof ObjectSchema) {
|
||||
ObjectSchema op = (ObjectSchema) inner;
|
||||
if (op.getProperties() != null && op.getProperties().size() > 0) {
|
||||
flattenProperties(op.getProperties(), path);
|
||||
String modelName = resolveModelName(op.getTitle(), path + "_" + key);
|
||||
Schema innerModel = modelFromProperty(op, modelName);
|
||||
String existing = matchGenerated(innerModel);
|
||||
if (existing != null) {
|
||||
Schema schema = new Schema().$ref(existing);
|
||||
schema.setRequired(op.getRequired());
|
||||
ap.setItems(schema);
|
||||
} else {
|
||||
Schema schema = new Schema().$ref(modelName);
|
||||
schema.setRequired(op.getRequired());
|
||||
ap.setItems(schema);
|
||||
addGenerated(modelName, innerModel);
|
||||
openapi.getComponents().addSchemas(modelName, innerModel);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (ModelUtils.isMapSchema(property)) {
|
||||
Schema inner = ModelUtils.getAdditionalProperties(property);
|
||||
if (inner instanceof ObjectSchema) {
|
||||
ObjectSchema op = (ObjectSchema) inner;
|
||||
if (op.getProperties() != null && op.getProperties().size() > 0) {
|
||||
flattenProperties(op.getProperties(), path);
|
||||
String modelName = resolveModelName(op.getTitle(), path + "_" + key);
|
||||
Schema innerModel = modelFromProperty(op, modelName);
|
||||
String existing = matchGenerated(innerModel);
|
||||
if (existing != null) {
|
||||
Schema schema = new Schema().$ref(existing);
|
||||
schema.setRequired(op.getRequired());
|
||||
property.setAdditionalProperties(schema);
|
||||
} else {
|
||||
Schema schema = new Schema().$ref(modelName);
|
||||
schema.setRequired(op.getRequired());
|
||||
property.setAdditionalProperties(schema);
|
||||
addGenerated(modelName, innerModel);
|
||||
openapi.getComponents().addSchemas(modelName, innerModel);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (propsToUpdate.size() > 0) {
|
||||
for (String key : propsToUpdate.keySet()) {
|
||||
properties.put(key, propsToUpdate.get(key));
|
||||
}
|
||||
}
|
||||
for (String key : modelsToAdd.keySet()) {
|
||||
openapi.getComponents().addSchemas(key, modelsToAdd.get(key));
|
||||
this.addedModels.put(key, modelsToAdd.get(key));
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("static-method")
|
||||
public Schema modelFromProperty(ArraySchema object, @SuppressWarnings("unused") String path) {
|
||||
String description = object.getDescription();
|
||||
String example = null;
|
||||
Object obj = object.getExample();
|
||||
|
||||
if (obj != null) {
|
||||
example = obj.toString();
|
||||
}
|
||||
Schema inner = object.getItems();
|
||||
if (inner instanceof ObjectSchema) {
|
||||
ArraySchema model = new ArraySchema();
|
||||
model.setDescription(description);
|
||||
model.setExample(example);
|
||||
model.setItems(object.getItems());
|
||||
model.setName(object.getName());
|
||||
return model;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public Schema modelFromProperty(ObjectSchema object, String path) {
|
||||
String description = object.getDescription();
|
||||
String example = null;
|
||||
Object obj = object.getExample();
|
||||
if (obj != null) {
|
||||
example = obj.toString();
|
||||
}
|
||||
XML xml = object.getXml();
|
||||
Map<String, Schema> properties = object.getProperties();
|
||||
Schema model = new Schema();
|
||||
model.setDescription(description);
|
||||
model.setExample(example);
|
||||
model.setName(object.getName());
|
||||
model.setXml(xml);
|
||||
if (properties != null) {
|
||||
flattenProperties(properties, path);
|
||||
model.setProperties(properties);
|
||||
}
|
||||
return model;
|
||||
}
|
||||
|
||||
@SuppressWarnings("static-method")
|
||||
public Schema modelFromProperty(MapSchema object, @SuppressWarnings("unused") String path) {
|
||||
String description = object.getDescription();
|
||||
String example = null;
|
||||
Object obj = object.getExample();
|
||||
if (obj != null) {
|
||||
example = obj.toString();
|
||||
}
|
||||
ArraySchema model = new ArraySchema();
|
||||
model.setDescription(description);
|
||||
model.setName(object.getName());
|
||||
model.setExample(example);
|
||||
model.setItems(ModelUtils.getAdditionalProperties(object));
|
||||
return model;
|
||||
}
|
||||
|
||||
/**
|
||||
* Make a Schema
|
||||
*
|
||||
* @param ref new property name
|
||||
* @param property Schema
|
||||
* @return {@link Schema} A constructed OpenAPI property
|
||||
*/
|
||||
public Schema makeSchema(String ref, Schema property) {
|
||||
Schema newProperty = new Schema().$ref(ref);
|
||||
this.copyVendorExtensions(property, newProperty);
|
||||
return newProperty;
|
||||
}
|
||||
|
||||
/**
|
||||
* Copy vendor extensions from Model to another Model
|
||||
*
|
||||
* @param source source property
|
||||
* @param target target property
|
||||
*/
|
||||
|
||||
public void copyVendorExtensions(Schema source, Schema target) {
|
||||
Map<String, Object> vendorExtensions = source.getExtensions();
|
||||
for (String extName : vendorExtensions.keySet()) {
|
||||
target.addExtension(extName, vendorExtensions.get(extName));
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isSkipMatches() {
|
||||
return skipMatches;
|
||||
}
|
||||
|
||||
public void setSkipMatches(boolean skipMatches) {
|
||||
this.skipMatches = skipMatches;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,133 @@
|
||||
package org.openapitools.codegen;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
public class SpecValidationException extends RuntimeException {
|
||||
|
||||
private Set<String> errors;
|
||||
private Set<String> warnings;
|
||||
|
||||
/**
|
||||
* Constructs a new runtime exception with {@code null} as its
|
||||
* detail message. The cause is not initialized, and may subsequently be
|
||||
* initialized by a call to {@link #initCause}.
|
||||
*/
|
||||
public SpecValidationException() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs a new runtime exception with the specified detail message.
|
||||
* The cause is not initialized, and may subsequently be initialized by a
|
||||
* call to {@link #initCause}.
|
||||
*
|
||||
* @param message the detail message. The detail message is saved for
|
||||
* later retrieval by the {@link #getMessage()} method.
|
||||
*/
|
||||
public SpecValidationException(String message) {
|
||||
super(message);
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs a new runtime exception with the specified detail message and
|
||||
* cause. <p>Note that the detail message associated with
|
||||
* {@code cause} is <i>not</i> automatically incorporated in
|
||||
* this runtime exception's detail message.
|
||||
*
|
||||
* @param message the detail message (which is saved for later retrieval
|
||||
* by the {@link #getMessage()} method).
|
||||
* @param cause the cause (which is saved for later retrieval by the
|
||||
* {@link #getCause()} method). (A <tt>null</tt> value is
|
||||
* permitted, and indicates that the cause is nonexistent or
|
||||
* unknown.)
|
||||
* @since 1.4
|
||||
*/
|
||||
public SpecValidationException(String message, Throwable cause) {
|
||||
super(message, cause);
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs a new runtime exception with the specified cause and a
|
||||
* detail message of <tt>(cause==null ? null : cause.toString())</tt>
|
||||
* (which typically contains the class and detail message of
|
||||
* <tt>cause</tt>). This constructor is useful for runtime exceptions
|
||||
* that are little more than wrappers for other throwables.
|
||||
*
|
||||
* @param cause the cause (which is saved for later retrieval by the
|
||||
* {@link #getCause()} method). (A <tt>null</tt> value is
|
||||
* permitted, and indicates that the cause is nonexistent or
|
||||
* unknown.)
|
||||
* @since 1.4
|
||||
*/
|
||||
public SpecValidationException(Throwable cause) {
|
||||
super(cause);
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs a new runtime exception with the specified detail
|
||||
* message, cause, suppression enabled or disabled, and writable
|
||||
* stack trace enabled or disabled.
|
||||
*
|
||||
* @param message the detail message.
|
||||
* @param cause the cause. (A {@code null} value is permitted,
|
||||
* and indicates that the cause is nonexistent or unknown.)
|
||||
* @param enableSuppression whether or not suppression is enabled
|
||||
* or disabled
|
||||
* @param writableStackTrace whether or not the stack trace should
|
||||
* be writable
|
||||
* @since 1.7
|
||||
*/
|
||||
public SpecValidationException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) {
|
||||
super(message, cause, enableSuppression, writableStackTrace);
|
||||
}
|
||||
|
||||
public Set<String> getErrors() {
|
||||
return errors;
|
||||
}
|
||||
|
||||
public Set<String> getWarnings() {
|
||||
return warnings;
|
||||
}
|
||||
|
||||
public void setErrors(Set<String> errors) {
|
||||
this.errors = errors;
|
||||
}
|
||||
|
||||
public void setWarnings(Set<String> warnings) {
|
||||
this.warnings = warnings;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the detail message string of this throwable.
|
||||
*
|
||||
* @return the detail message string of this {@code Throwable} instance
|
||||
* (which may be {@code null}).
|
||||
*/
|
||||
@Override
|
||||
public String getMessage() {
|
||||
int errorCount = 0;
|
||||
if (errors != null) {
|
||||
errorCount = errors.size();
|
||||
}
|
||||
int warningCount = 0;
|
||||
if (warnings != null) {
|
||||
warningCount = warnings.size();
|
||||
}
|
||||
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append(System.lineSeparator())
|
||||
.append("Errors: ")
|
||||
.append(System.lineSeparator());
|
||||
errors.forEach(msg ->
|
||||
sb.append("\t-").append(msg).append(System.lineSeparator())
|
||||
);
|
||||
|
||||
if (!warnings.isEmpty()) {
|
||||
sb.append("Warnings: ").append(System.lineSeparator());
|
||||
warnings.forEach(msg ->
|
||||
sb.append("\t-").append(msg).append(System.lineSeparator())
|
||||
);
|
||||
}
|
||||
return super.getMessage() + " | " +
|
||||
"Error count: " + errorCount + ", Warning count: " + warningCount + sb.toString();
|
||||
}
|
||||
}
|
||||
@@ -21,6 +21,7 @@ import io.swagger.v3.parser.core.models.AuthorizationValue;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.net.URLDecoder;
|
||||
import java.net.URLEncoder;
|
||||
import java.util.ArrayList;
|
||||
@@ -39,8 +40,11 @@ public class AuthParser {
|
||||
for (String part : parts) {
|
||||
String[] kvPair = part.split(":");
|
||||
if (kvPair.length == 2) {
|
||||
// FIXME replace the deprecated method by decode(string, encoding). Which encoding is used ? Default UTF-8 ?
|
||||
auths.add(new AuthorizationValue(URLDecoder.decode(kvPair[0]), URLDecoder.decode(kvPair[1]), "header"));
|
||||
try {
|
||||
auths.add(new AuthorizationValue(URLDecoder.decode(kvPair[0], "UTF-8"), URLDecoder.decode(kvPair[1], "UTF-8"), "header"));
|
||||
} catch (UnsupportedEncodingException e) {
|
||||
LOGGER.warn(e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user