use of io.swagger.codegen.CodegenModel in project okta-sdk-java by okta.
the class AbstractOktaJavaClientCodegen method fromModel.
@Override
public CodegenModel fromModel(String name, Model model, Map<String, Model> allDefinitions) {
CodegenModel codegenModel = super.fromModel(name, model, allDefinitions);
// super add these imports, and we don't want that dependency
codegenModel.imports.remove("ApiModel");
if (model.getVendorExtensions().containsKey("x-baseType")) {
String baseType = (String) model.getVendorExtensions().get("x-baseType");
codegenModel.vendorExtensions.put("baseType", toModelName(baseType));
codegenModel.imports.add(toModelName(baseType));
}
Collection<CodegenOperation> operations = (Collection<CodegenOperation>) codegenModel.vendorExtensions.get("operations");
if (operations != null) {
operations.forEach(op -> {
if (op.returnType != null) {
codegenModel.imports.add(op.returnType);
}
if (op.allParams != null) {
op.allParams.stream().filter(param -> needToImport(param.dataType)).forEach(param -> codegenModel.imports.add(param.dataType));
}
});
}
// force alias == false (likely only relevant for Lists, but something changed in swagger 2.2.3 to require this)
codegenModel.isAlias = false;
String parent = (String) model.getVendorExtensions().get("x-okta-parent");
if (StringUtils.isNotEmpty(parent)) {
codegenModel.parent = toApiName(parent.substring(parent.lastIndexOf("/")));
// figure out the resourceClass if this model has a parent
String discriminatorRoot = getRootDiscriminator(name);
if (discriminatorRoot != null) {
model.getVendorExtensions().put("discriminatorRoot", discriminatorRoot);
}
}
// We use '$ref' attributes with siblings, which isn't valid JSON schema (or swagger), so we need process
// additional attributes from the raw schema
Map<String, Object> modelDef = getRawSwaggerDefinition(name);
codegenModel.vars.forEach(codegenProperty -> {
Map<String, Object> rawPropertyMap = getRawSwaggerProperty(modelDef, codegenProperty.baseName);
codegenProperty.isReadOnly = Boolean.TRUE.equals(rawPropertyMap.get("readOnly"));
});
return codegenModel;
}
use of io.swagger.codegen.CodegenModel in project okta-sdk-java by okta.
the class AbstractOktaJavaClientCodegen method postProcessModelsEnum.
@Override
public Map<String, Object> postProcessModelsEnum(Map<String, Object> objs) {
objs = super.postProcessModelsEnum(objs);
// Needed import for Gson based libraries
if (additionalProperties.containsKey("gson")) {
List<Map<String, String>> imports = (List<Map<String, String>>) objs.get("imports");
List<Object> models = (List<Object>) objs.get("models");
for (Object _mo : models) {
Map<String, Object> mo = (Map<String, Object>) _mo;
CodegenModel cm = (CodegenModel) mo.get("model");
// for enum model
if (Boolean.TRUE.equals(cm.isEnum) && cm.allowableValues != null) {
cm.imports.add(importMapping.get("SerializedName"));
Map<String, String> item = new HashMap<String, String>();
item.put("import", importMapping.get("SerializedName"));
imports.add(item);
}
}
}
return objs;
}
use of io.swagger.codegen.CodegenModel in project okta-sdk-java by okta.
the class OktaJavaClientImplCodegen method fromModel.
@Override
public CodegenModel fromModel(String name, Model model, Map<String, Model> allDefinitions) {
CodegenModel codegenModel = super.fromModel(name, model, allDefinitions);
// The 'Default' gets added in the template
codegenModel.imports.add(toModelName(codegenModel.classname));
Map<String, String> defaultValuesMap = new LinkedHashMap<>();
ObjectNode rawDefaultValues = (ObjectNode) codegenModel.vendorExtensions.get("x-okta-defined-as");
if (rawDefaultValues != null) {
rawDefaultValues.fields().forEachRemaining(entry -> {
defaultValuesMap.put(entry.getKey(), entry.getValue().textValue());
});
}
// if the parent is set, we need to check for discrimination
String parent = (String) codegenModel.vendorExtensions.get("x-okta-parent");
if (parent != null) {
parent = parent.substring(parent.lastIndexOf('/') + 1);
if (discriminatorMap.containsKey(parent)) {
Discriminator discriminator = discriminatorMap.get(parent);
String fieldName = discriminator.getFieldName();
String defaultValue = discriminator.getDefaultFieldValue(name);
defaultValuesMap.put(fieldName, defaultValue);
}
}
List<KeyValuePair> defaultTypeSetter = defaultValuesMap.entrySet().stream().map(entry -> new KeyValuePair(entry.getKey(), entry.getValue())).collect(Collectors.toList());
codegenModel.vendorExtensions.put("defaultSetter", defaultTypeSetter);
return codegenModel;
}
Aggregations