Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#
# Copyright 2020-Present Okta, Inc.
#
# 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.
#

Args = -H:ReflectionConfigurationResources=${.}/generated-reflection-config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#
# Copyright 2020-Present Okta, Inc.
#
# 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.
#

Args = -H:ReflectionConfigurationResources=${.}/generated-reflection-config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
[
{
"name": "org.yaml.snakeyaml.Yaml",
"allDeclaredConstructors" : true
},
{
"name": "com.okta.sdk.impl.cache.DefaultCacheManagerBuilder",
"allDeclaredConstructors" : true
},
{
"name": "com.okta.sdk.impl.client.DefaultClientBuilder",
"allDeclaredConstructors" : true
},
{
"name": "com.okta.sdk.impl.ds.DiscriminatorConfig",
"allDeclaredFields": true,
"allDeclaredMethods": true,
"allDeclaredConstructors": true
},
{
"name": "com.okta.sdk.impl.ds.DiscriminatorConfig$ClassConfig",
"allDeclaredFields": true,
"allDeclaredMethods": true,
"allDeclaredConstructors": true
},
{
"name": "com.okta.sdk.impl.http.authc.SswsAuthenticator",
"allDeclaredConstructors" : true
},
{
"name": "com.okta.sdk.impl.resource.DefaultExtensibleResource",
"allDeclaredConstructors" : true
},
{
"name": "com.okta.sdk.impl.resource.DefaultVoidResource",
"allDeclaredConstructors" : true
}
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"resources":[
{"pattern":"\\QMETA-INF/okta/version.properties\\E"},
{"pattern":"\\QMETA-INF/services/com.okta.sdk.impl.ds.ResourceFactoryConfig\\E"},
{"pattern":"\\QMETA-INF/services/com.okta.sdk.impl.http.RequestExecutorFactory\\E"},
{"pattern":"\\Qcom/okta/sdk/config/okta.properties\\E"},
{"pattern":"\\Qcom/okta/sdk/resource/discrimination.json\\E"}
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ public void preprocessSwagger(Swagger swagger) {
moveOperationsToSingleClient(swagger);
handleOktaLinkedOperations(swagger);
buildDiscriminationMap(swagger);
buildGraalVMReflectionConfig(swagger);
}

/**
Expand Down Expand Up @@ -227,6 +228,33 @@ protected void buildDiscriminationMap(Swagger swagger) {
});
}

protected void buildGraalVMReflectionConfig(Swagger swagger) {

try {
List<Map<String, ?>> reflectionConfig = swagger.getDefinitions().keySet().stream()
.filter(it -> !enumList.contains(it)) // ignore enums
.map(this::fqcn)
.map(this::reflectionConfig)
.collect(Collectors.toList());

// this is slightly error prone, but this project only has `api` and `impl`
File projectDir = new File(outputFolder(), "../../..").getCanonicalFile();
String projectName = projectDir.getName();

File reflectionConfigFile = new File(projectDir, "target/classes/META-INF/native-image/com.okta.sdk/okta-sdk-" + projectName + "/generated-reflection-config.json");
if (!(reflectionConfigFile.getParentFile().exists() || reflectionConfigFile.getParentFile().mkdirs())) {
throw new IllegalStateException("Failed to create directory: "+ reflectionConfigFile.getParent());
}
new ObjectMapper().writerWithDefaultPrettyPrinter().writeValue(reflectionConfigFile, reflectionConfig);
} catch (IOException e) {
throw new IllegalStateException("Failed to write generated-reflection-config.json file", e);
}
}

protected Map<String, ?> reflectionConfig(String fqcn) {
return Collections.singletonMap("name", fqcn);
}

protected void tagEnums(Swagger swagger) {
swagger.getDefinitions().forEach((name, model) -> {

Expand Down Expand Up @@ -522,6 +550,14 @@ public String toModelImport(String name) {
return super.toModelImport(name);
}

protected String fqcn(String name) {
String className = toApiName(name);
if (modelTagMap.containsKey(className)) {
return modelPackage() +"."+ modelTagMap.get(className) +"."+ className;
}
return super.toModelImport(className);
}

@Override
public CodegenModel fromModel(String name, Model model, Map<String, Model> allDefinitions) {
CodegenModel codegenModel = super.fromModel(name, model, allDefinitions);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -313,4 +313,11 @@ protected void buildDiscriminationMap(Swagger swagger) {
throw new RuntimeException("Failed to write discrimination map to json: "+ destFileJson.getAbsolutePath(), e);
}
}

@Override
protected Map<String, ?> reflectionConfig(String fqcn) {
Map<String, Object> data = new HashMap<>(super.reflectionConfig(fqcn));
data.put("allDeclaredConstructors", true);
return data;
}
}