Skip to content

Commit

Permalink
migrate java clients from swagger-codegen to openapi-generator
Browse files Browse the repository at this point in the history
add reflection-equality config option

java: update openapi generator to 4.1.2

patch openapi-generator, format Quantity

Bring in a patched openapi-generator temporarily until
openapi-generator#4182 gets merged, and add a format to
resource.Quantity so it can have a custom typeMapping installed.

Also bring configuration of type and import mappings to the correct
(newer) format for the maven plugin.

remove the overrides

refactor

openapi-gen
  • Loading branch information
yue9944882 committed Oct 28, 2019
1 parent f14e0bb commit 4c7842c
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 16 deletions.
6 changes: 3 additions & 3 deletions openapi/java.sh
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,10 @@ pushd "${OUTPUT_DIR}" > /dev/null
OUTPUT_DIR=`pwd`
popd > /dev/null

source "${SCRIPT_ROOT}/swagger-codegen/client-generator.sh"
source "${SCRIPT_ROOT}/openapi-generator/client-generator.sh"
source "${SETTING_FILE}"

SWAGGER_CODEGEN_COMMIT="${SWAGGER_CODEGEN_COMMIT:-5d263e1c9cdd395d93adf061c63d5ef58a8e9ec5}"; \
OPENAPI_GENERATOR_COMMIT="${OPENAPI_GENERATOR_COMMIT:-v4.0.0}" \
CLIENT_LANGUAGE=java; \
CLEANUP_DIRS=(docs src/test/java/io/kubernetes/client/apis src/main/java/io/kubernetes/client/apis src/main/java/io/kubernetes/client/models src/main/java/io/kubernetes/client/auth gradle); \
CLEANUP_DIRS=(docs src/test/java/io/kubernetes/openapi/apis src/main/java/io/kubernetes/openapi/apis src/main/java/io/kubernetes/openapi/models src/main/java/io/kubernetes/openapi/auth gradle); \
kubeclient::generator::generate_client "${OUTPUT_DIR}"
25 changes: 12 additions & 13 deletions openapi/java.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<project
xmlns="http://maven.apache.org/POM/4.0.0"
<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>io.kubernetes</groupId>
Expand All @@ -10,9 +10,9 @@
<build>
<plugins>
<plugin>
<groupId>io.swagger</groupId>
<artifactId>swagger-codegen-maven-plugin</artifactId>
<version>${swagger-codegen-version}</version>
<groupId>org.openapitools</groupId>
<artifactId>openapi-generator-maven-plugin</artifactId>
<version>${openapi-generator-version}</version>
<executions>
<execution>
<goals>
Expand All @@ -23,6 +23,7 @@
<language>java</language>
<gitUserId>kubernetes-client</gitUserId>
<gitRepoId>client-java</gitRepoId>
<skipValidateSpec>true</skipValidateSpec>
<configOptions>
<projectName>kubernetes-java-client</projectName>
<projectDescription>Java client for Kubernetes.</projectDescription>
Expand All @@ -37,18 +38,16 @@
<artifactId>client-java</artifactId>
<artifactVersion>1.0-SNAPSHOT</artifactVersion>
<sourceFolder>src/main/java</sourceFolder>
<localVariablePrefix></localVariablePrefix>
<serializableModel>false</serializableModel>
<bigDecimalAsString>false</bigDecimalAsString>
<fullJavaUtil>false</fullJavaUtil>
<hideGenerationTimestamp>false</hideGenerationTimestamp>
<dateLibrary>joda</dateLibrary>
<useRxJava>false</useRxJava>
<library>okhttp-gson</library>
<type-mappings>intstr.IntOrString=IntOrString,resource.Quantity=Quantity</type-mappings>
<import-mappings>
IntOrString=io.kubernetes.client.custom.IntOrString,Quantity=io.kubernetes.client.custom.Quantity,V1Patch=io.kubernetes.client.custom.V1Patch
</import-mappings>
<typeMappings>int-or-string=IntOrString,quantity=Quantity</typeMappings>
<importMappings>IntOrString=io.kubernetes.client.custom.IntOrString,Quantity=io.kubernetes.client.custom.Quantity</importMappings>
<useReflectionEqualsHashCode>true</useReflectionEqualsHashCode>
</configOptions>
<output>${generator.output.path}</output>
</configuration>
Expand All @@ -65,9 +64,9 @@
<version>${swagger-annotations-version}</version>
</dependency>
<dependency>
<groupId>io.swagger</groupId>
<artifactId>swagger-codegen-maven-plugin</artifactId>
<version>2.2.2</version>
<groupId>org.openapitools</groupId>
<artifactId>openapi-generator-maven-plugin</artifactId>
<version>${openapi-generator-version}</version>
</dependency>
</dependencies>
<properties>
Expand Down
14 changes: 14 additions & 0 deletions openapi/preprocess_spec.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,8 @@ def process_swagger(spec, client_language):

inline_primitive_models(spec, preserved_primitives_for_language(client_language))

add_custom_formatting(spec, format_for_language(client_language))

remove_models(spec, removed_models_for_language(client_language))

return spec
Expand All @@ -150,6 +152,12 @@ def preserved_primitives_for_language(client_language):
else:
return []

def format_for_language(client_language):
if client_language == "java":
return {"resource.Quantity": "quantity"}
else:
return {}

def removed_models_for_language(client_language):
if client_language == "haskell-http-client":
return ["intstr.IntOrString", "resource.Quantity"]
Expand Down Expand Up @@ -298,6 +306,12 @@ def inline_primitive_models(spec, excluded_primitives):
for k in to_remove_models:
del spec['definitions'][k]

def add_custom_formatting(spec, custom_formats):
for k, v in spec['definitions'].items():
if k not in custom_formats:
continue
v["format"] = custom_formats[k]

def write_json(filename, object):
with open(filename, 'w') as out:
json.dump(object, out, sort_keys=False, indent=2, separators=(',', ': '), ensure_ascii=True)
Expand Down

0 comments on commit 4c7842c

Please sign in to comment.