forked from loafle/openapi-generator-original
Support vendor extensions on more objects as per the OAS spec (#15975)
This commit is contained in:
parent
00fcaa15c0
commit
cfc14565ae
@ -37,6 +37,8 @@ public class CodegenDiscriminator {
|
||||
// see the method createDiscriminator in DefaultCodegen.java
|
||||
|
||||
private Set<MappedModel> mappedModels = new TreeSet<>();
|
||||
private Map<String, Object> vendorExtensions = new HashMap<>();
|
||||
|
||||
|
||||
public String getPropertyName() {
|
||||
return propertyName;
|
||||
@ -94,6 +96,14 @@ public class CodegenDiscriminator {
|
||||
this.isEnum = isEnum;
|
||||
}
|
||||
|
||||
public Map<String, Object> getVendorExtensions() {
|
||||
return vendorExtensions;
|
||||
}
|
||||
|
||||
public void setVendorExtensions(Map<String, Object> vendorExtensions) {
|
||||
this.vendorExtensions = vendorExtensions;
|
||||
}
|
||||
|
||||
/**
|
||||
* An object to hold discriminator mappings between payload values and schema names or
|
||||
* references.
|
||||
@ -173,13 +183,14 @@ public class CodegenDiscriminator {
|
||||
return Objects.equals(propertyName, that.propertyName) &&
|
||||
Objects.equals(propertyBaseName, that.propertyBaseName) &&
|
||||
Objects.equals(mapping, that.mapping) &&
|
||||
Objects.equals(mappedModels, that.mappedModels);
|
||||
Objects.equals(mappedModels, that.mappedModels) &&
|
||||
Objects.equals(vendorExtensions, that.vendorExtensions);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
|
||||
return Objects.hash(propertyName, propertyBaseName, mapping, mappedModels);
|
||||
return Objects.hash(propertyName, propertyBaseName, mapping, mappedModels, vendorExtensions);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -189,7 +200,8 @@ public class CodegenDiscriminator {
|
||||
sb.append(", propertyBaseName='").append(propertyBaseName).append('\'');
|
||||
sb.append(", mapping=").append(mapping);
|
||||
sb.append(", mappedModels=").append(mappedModels);
|
||||
sb.append(", vendorExtensions=").append(vendorExtensions);
|
||||
sb.append('}');
|
||||
return sb.toString();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,6 +1,8 @@
|
||||
package org.openapitools.codegen;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
|
||||
public class CodegenEncoding {
|
||||
@ -9,6 +11,7 @@ public class CodegenEncoding {
|
||||
private String style;
|
||||
private boolean explode;
|
||||
private boolean allowReserved;
|
||||
public Map<String, Object> vendorExtensions = new HashMap<>();
|
||||
|
||||
public CodegenEncoding(String contentType, List<CodegenParameter> headers, String style, boolean explode, boolean allowReserved) {
|
||||
this.contentType = contentType;
|
||||
@ -38,6 +41,10 @@ public class CodegenEncoding {
|
||||
return allowReserved;
|
||||
}
|
||||
|
||||
public Map<String, Object> getVendorExtensions() {
|
||||
return vendorExtensions;
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
final StringBuilder sb = new StringBuilder("CodegenEncoding{");
|
||||
sb.append("contentType=").append(contentType);
|
||||
@ -45,6 +52,7 @@ public class CodegenEncoding {
|
||||
sb.append(", style=").append(style);
|
||||
sb.append(", explode=").append(explode);
|
||||
sb.append(", allowReserved=").append(allowReserved);
|
||||
sb.append(", vendorExtensions=").append(vendorExtensions);
|
||||
sb.append('}');
|
||||
return sb.toString();
|
||||
}
|
||||
@ -57,11 +65,12 @@ public class CodegenEncoding {
|
||||
Objects.equals(headers, that.getHeaders()) &&
|
||||
style == that.getStyle() &&
|
||||
explode == that.getExplode() &&
|
||||
allowReserved == that.getAllowReserved();
|
||||
allowReserved == that.getAllowReserved() &&
|
||||
Objects.equals(vendorExtensions, that.vendorExtensions);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(contentType, headers, style, explode, allowReserved);
|
||||
return Objects.hash(contentType, headers, style, explode, allowReserved, vendorExtensions);
|
||||
}
|
||||
}
|
||||
|
@ -13,6 +13,7 @@ public class CodegenMediaType {
|
||||
private HashMap<String, SchemaTestCase> testCases = new HashMap<>();
|
||||
private Map<String, Example> examples = null;
|
||||
private Object example = null;
|
||||
public Map<String, Object> vendorExtensions = new HashMap<>();
|
||||
|
||||
public CodegenMediaType(CodegenProperty schema, LinkedHashMap<String, CodegenEncoding> encoding, HashMap<String, SchemaTestCase> testCases) {
|
||||
this.schema = schema;
|
||||
@ -50,10 +51,15 @@ public class CodegenMediaType {
|
||||
return example;
|
||||
}
|
||||
|
||||
public Map<String, Object> getVendorExtensions() {
|
||||
return vendorExtensions;
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
final StringBuilder sb = new StringBuilder("CodegenMediaType{");
|
||||
sb.append("schema=").append(schema);
|
||||
sb.append(", encoding=").append(encoding);
|
||||
sb.append(", vendorExtensions=").append(vendorExtensions);
|
||||
sb.append('}');
|
||||
return sb.toString();
|
||||
}
|
||||
@ -63,12 +69,13 @@ public class CodegenMediaType {
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
CodegenMediaType that = (CodegenMediaType) o;
|
||||
return Objects.equals(schema,that.getSchema()) &&
|
||||
Objects.equals(encoding, that.getEncoding());
|
||||
Objects.equals(encoding, that.getEncoding()) &&
|
||||
Objects.equals(vendorExtensions, that.vendorExtensions);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(schema, encoding);
|
||||
return Objects.hash(schema, encoding, vendorExtensions);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,12 +1,15 @@
|
||||
package org.openapitools.codegen;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
|
||||
public class CodegenServer {
|
||||
public String url;
|
||||
public String description;
|
||||
public List<CodegenServerVariable> variables;
|
||||
public Map<String, Object> vendorExtensions = new HashMap<>();
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
@ -15,13 +18,14 @@ public class CodegenServer {
|
||||
CodegenServer that = (CodegenServer) o;
|
||||
return Objects.equals(url, that.url) &&
|
||||
Objects.equals(description, that.description) &&
|
||||
Objects.equals(variables, that.variables);
|
||||
Objects.equals(variables, that.variables) &&
|
||||
Objects.equals(vendorExtensions, that.vendorExtensions);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
|
||||
return Objects.hash(url, description, variables);
|
||||
return Objects.hash(url, description, variables, vendorExtensions);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -30,6 +34,7 @@ public class CodegenServer {
|
||||
sb.append("url='").append(url).append('\'');
|
||||
sb.append(", description='").append(description).append('\'');
|
||||
sb.append(", variables=").append(variables);
|
||||
sb.append(", vendorExtensions=").append(vendorExtensions);
|
||||
sb.append('}');
|
||||
return sb.toString();
|
||||
}
|
||||
|
@ -1,6 +1,8 @@
|
||||
package org.openapitools.codegen;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
|
||||
public class CodegenServerVariable {
|
||||
@ -9,6 +11,7 @@ public class CodegenServerVariable {
|
||||
public String description;
|
||||
public List<String> enumValues;
|
||||
public String value;
|
||||
public Map<String, Object> vendorExtensions = new HashMap<>();
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
@ -19,13 +22,14 @@ public class CodegenServerVariable {
|
||||
Objects.equals(defaultValue, that.defaultValue) &&
|
||||
Objects.equals(description, that.description) &&
|
||||
Objects.equals(enumValues, that.enumValues) &&
|
||||
Objects.equals(value, that.value);
|
||||
Objects.equals(value, that.value) &&
|
||||
Objects.equals(vendorExtensions, that.vendorExtensions);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
|
||||
return Objects.hash(name, defaultValue, description, enumValues, value);
|
||||
return Objects.hash(name, defaultValue, description, enumValues, value, vendorExtensions);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -36,6 +40,7 @@ public class CodegenServerVariable {
|
||||
sb.append(", description='").append(description).append('\'');
|
||||
sb.append(", enumValues=").append(enumValues);
|
||||
sb.append(", value='").append(value).append('\'');
|
||||
sb.append(", vendorExtensions=").append(vendorExtensions);
|
||||
sb.append('}');
|
||||
return sb.toString();
|
||||
}
|
||||
|
@ -3531,6 +3531,10 @@ public class DefaultCodegen implements CodegenConfig {
|
||||
discriminator.setPropertyBaseName(sourceDiscriminator.getPropertyName());
|
||||
discriminator.setPropertyGetter(toGetter(discriminator.getPropertyName()));
|
||||
|
||||
if (sourceDiscriminator.getExtensions() != null) {
|
||||
discriminator.setVendorExtensions(sourceDiscriminator.getExtensions());
|
||||
}
|
||||
|
||||
// FIXME: for now, we assume that the discriminator property is String
|
||||
discriminator.setPropertyType(typeMapping.get("string"));
|
||||
|
||||
@ -7381,6 +7385,11 @@ public class DefaultCodegen implements CodegenConfig {
|
||||
enc.getExplode() == null ? false : enc.getExplode().booleanValue(),
|
||||
enc.getAllowReserved() == null ? false : enc.getAllowReserved().booleanValue()
|
||||
);
|
||||
|
||||
if (enc.getExtensions() != null) {
|
||||
ce.vendorExtensions = enc.getExtensions();
|
||||
}
|
||||
|
||||
String propName = encodingEntry.getKey();
|
||||
ceMap.put(propName, ce);
|
||||
}
|
||||
@ -7412,6 +7421,10 @@ public class DefaultCodegen implements CodegenConfig {
|
||||
codegenMt = new CodegenMediaType(schemaProp, ceMap, schemaTestCases);
|
||||
}
|
||||
|
||||
if (mt.getExtensions() != null) {
|
||||
codegenMt.vendorExtensions = mt.getExtensions();
|
||||
}
|
||||
|
||||
cmtContent.put(contentType, codegenMt);
|
||||
if (schemaProp != null) {
|
||||
addImports(imports, schemaProp.getImports(true, importBaseType, generatorMetadata.getFeatureSet()));
|
||||
@ -7683,6 +7696,11 @@ public class DefaultCodegen implements CodegenConfig {
|
||||
cs.description = escapeText(server.getDescription());
|
||||
cs.url = server.getUrl();
|
||||
cs.variables = this.fromServerVariables(server.getVariables());
|
||||
|
||||
if (server.getExtensions() != null) {
|
||||
cs.vendorExtensions = server.getExtensions();
|
||||
}
|
||||
|
||||
codegenServers.add(cs);
|
||||
}
|
||||
return codegenServers;
|
||||
@ -7707,6 +7725,10 @@ public class DefaultCodegen implements CodegenConfig {
|
||||
codegenServerVariable.enumValues = enums;
|
||||
codegenServerVariable.name = variableEntry.getKey();
|
||||
|
||||
if (variable.getExtensions() != null) {
|
||||
codegenServerVariable.vendorExtensions = variable.getExtensions();
|
||||
}
|
||||
|
||||
// Sets the override value for a server variable pattern.
|
||||
// NOTE: OpenAPI Specification doesn't prevent multiple server URLs with variables. If multiple objects have the same
|
||||
// variables pattern, user overrides will apply to _all_ of these patterns. We may want to consider indexed overrides.
|
||||
|
Loading…
x
Reference in New Issue
Block a user