Skip to content

Commit

Permalink
[templates] Update templates vendor ext standards (#5295)
Browse files Browse the repository at this point in the history
* [templates] Update to vendor extension standard keys

* Fix missed value in Java template, also implements=>x-implements. Evaluate Haskell Client changes

* Fix missing accept/content-type update for vendor extension format
  • Loading branch information
jimschubert authored Feb 15, 2020
1 parent 118b5e7 commit dc50585
Show file tree
Hide file tree
Showing 91 changed files with 346 additions and 336 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -486,7 +486,7 @@ public Map<String, Object> postProcessOperationsWithModels(Map<String, Object> o
StringBuilder sb = new StringBuilder(param.paramName);
sb.setCharAt(0, Character.toUpperCase(nameFirstChar));
param.vendorExtensions.put("x-exportParamName", sb.toString()); // TODO: 5.0 Remove
param.vendorExtensions.put("x-x-export-param-name", sb.toString());
param.vendorExtensions.put("x-export-param-name", sb.toString());
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,76 +87,65 @@ public class HaskellHttpClientCodegen extends DefaultCodegen implements CodegenC
static final String MIME_NO_CONTENT = "MimeNoContent";
static final String MIME_ANY = "MimeAny";

// vendor extensions
static final String X_ALL_UNIQUE_PARAMS = "x-allUniqueParams"; // TODO: 5.0 Remove
static final String X_ALL_IMPORT_MAPPINGS = "x-allImportMappings"; // TODO: 5.0 Remove
static final String X_ALL_UNIQUE_IMPORT_PATHS = "x-allUniqueImportPaths"; // TODO: 5.0 Remove
// vendor extensions. These must follow our convention of x- prefixed and lower-kebab cased.
static final String X_COLLECTION_FORMAT = "x-collectionFormat"; // TODO: 5.0 Remove
static final String X_HADDOCK_PATH = "x-haddockPath"; // TODO: 5.0 Remove
static final String X_HAS_BODY_OR_FORM_PARAM = "x-hasBodyOrFormParam"; // TODO: 5.0 Remove
static final String X_HAS_ENUM_SECTION = "x-hasEnumSection"; // TODO: 5.0 Remove
static final String X_HAS_IMPORT_MAPPINGS = "x-hasImportMappings"; // TODO: 5.0 Remove
static final String X_HAS_MIME_FORM_URL_ENCODED = "x-hasMimeFormUrlEncoded"; // TODO: 5.0 Remove
static final String X_HAS_NEW_TAG = "x-hasNewTag"; // TODO: 5.0 Remove
static final String X_HAS_OPTIONAL_PARAMS = "x-hasOptionalParams"; // TODO: 5.0 Remove
static final String X_HAS_UNKNOWN_MIME_TYPES = "x-hasUnknownMimeTypes"; // TODO: 5.0 Remove
static final String X_HAS_UNKNOWN_RETURN = "x-hasUnknownReturn"; // TODO: 5.0 Remove
static final String X_INLINE_CONTENT_TYPE = "x-inlineContentType"; // TODO: 5.0 Remove
static final String X_INLINE_ACCEPT = "x-inlineAccept"; // TODO: 5.0 Remove
static final String X_IS_BODY_OR_FORM_PARAM = "x-isBodyOrFormParam"; // TODO: 5.0 Remove
static final String X_IS_BODY_PARAM = "x-isBodyParam"; // TODO: 5.0 Remove
static final String X_IS_MAYBE_VALUE = "x-isMaybeValue"; // TODO: 5.0 Remove
static final String X_MEDIA_DATA_TYPE = "x-mediaDataType"; // TODO: 5.0 Remove
static final String X_DATA_TYPE = "x-dataType"; // TODO: 5.0 Remove
static final String X_ENUM_VALUES = "x-enumValues"; // TODO: 5.0 Remove
static final String X_MEDIA_IS_JSON = "x-mediaIsJson"; // TODO: 5.0 Remove
static final String X_MEDIA_IS_WILDCARD = "x-mediaIsWildcard"; // TODO: 5.0 Remove
static final String X_MIME_TYPES = "x-mimeTypes"; // TODO: 5.0 Remove
static final String X_OPERATION_TYPE = "x-operationType"; // TODO: 5.0 Remove
static final String X_PARAM_NAME_TYPE = "x-paramNameType"; // TODO: 5.0 Remove
static final String X_RETURN_TYPE = "x-returnType"; // TODO: 5.0 Remove
static final String X_STRICT_FIELDS = "x-strictFields"; // TODO: 5.0 Remove
static final String X_UNKNOWN_MIME_TYPES = "x-unknownMimeTypes"; // TODO: 5.0 Remove
static final String X_USE_KATIP = "x-useKatip"; // TODO: 5.0 Remove
static final String X_ALLOW_NONUNIQUE_OPERATION_IDS = "x-allowNonUniqueOperationIds"; // TODO: 5.0 Remove

static final String VENDOR_EXTENSION_X_ALL_UNIQUE_PARAMS = "x-all-unique-params";
static final String VENDOR_EXTENSION_X_ALL_IMPORT_MAPPINGS = "x-all-import-mappings";
static final String VENDOR_EXTENSION_X_ALL_UNIQUE_IMPORT_PATHS = "x-all-unique-import-paths";
static final String VENDOR_EXTENSION_X_COLLECTION_FORMAT = "x-collection-format";
static final String VENDOR_EXTENSION_X_HADDOCK_PATH = "x-haddock-path";
static final String VENDOR_EXTENSION_X_HAS_BODY_OR_FORM_PARAM = "x-has-body-or-form-param";
static final String VENDOR_EXTENSION_X_HAS_ENUM_SECTION = "x-has-enum-section";
static final String VENDOR_EXTENSION_X_HAS_IMPORT_MAPPINGS = "x-has-import-mappings";
static final String VENDOR_EXTENSION_X_HAS_MIME_FORM_URL_ENCODED = "x-has-mime-form-url-encoded";
static final String VENDOR_EXTENSION_X_HAS_NEW_TAG = "x-has-new-tag";
static final String VENDOR_EXTENSION_X_HAS_OPTIONAL_PARAMS = "x-has-optional-params";
static final String VENDOR_EXTENSION_X_HAS_UNKNOWN_MIME_TYPES = "x-has-unknown-mime-types";
static final String VENDOR_EXTENSION_X_HAS_UNKNOWN_RETURN = "x-has-unknown-return";
static final String VENDOR_EXTENSION_X_INLINE_CONTENT_TYPE = "x-inline-content-type";
static final String VENDOR_EXTENSION_X_INLINE_ACCEPT = "x-inline-accept";
static final String VENDOR_EXTENSION_X_IS_BODY_OR_FORM_PARAM = "x-is-body-or-form-param";
static final String VENDOR_EXTENSION_X_IS_BODY_PARAM = "x-is-body-param";
static final String VENDOR_EXTENSION_X_IS_MAYBE_VALUE = "x-is-maybe-value";
static final String VENDOR_EXTENSION_X_MEDIA_DATA_TYPE = "x-media-data-type";
static final String VENDOR_EXTENSION_X_DATA_TYPE = "x-data-type";
static final String VENDOR_EXTENSION_X_ENUM_VALUES = "x-enum-values";
static final String VENDOR_EXTENSION_X_MEDIA_IS_JSON = "x-media-is-json";
static final String VENDOR_EXTENSION_X_MEDIA_IS_WILDCARD = "x-media-is-wildcard";
static final String VENDOR_EXTENSION_X_MIME_TYPES = "x-mime-types";
static final String VENDOR_EXTENSION_X_OPERATION_TYPE = "x-operation-type";
static final String VENDOR_EXTENSION_X_PARAM_NAME_TYPE = "x-param-name-type";
static final String VENDOR_EXTENSION_X_RETURN_TYPE = "x-return-type";
static final String VENDOR_EXTENSION_X_STRICT_FIELDS = "x-strict-fields";
static final String VENDOR_EXTENSION_X_UNKNOWN_MIME_TYPES = "x-unknown-mime-types";
static final String VENDOR_EXTENSION_X_USE_KATIP = "x-use-katip";
static final String VENDOR_EXTENSION_X_ALLOW_NONUNIQUE_OPERATION_IDS = "x-allow-non-unique-operation-ids";

// note; newtype is a single lowercase word in Haskell (not separated by hyphen)
static final String X_NEWTYPE = "x-newtype";
static final String VENDOR_EXTENSION_X_ENUM = "x-enum";
static final String VENDOR_EXTENSION_X_PATH = "x-path";


// additional properties
// FIXME: These appear to be used as vendor extensions in the additional properties collection.
static final String X_ALL_UNIQUE_PARAMS = "x-allUniqueParams";
static final String X_ALL_IMPORT_MAPPINGS = "x-allImportMappings";
static final String X_HAS_ENUM_SECTION = "x-hasEnumSection";
static final String X_HAS_IMPORT_MAPPINGS = "x-hasImportMappings";
static final String X_HAS_UNKNOWN_MIME_TYPES = "x-hasUnknownMimeTypes";
static final String X_IS_BODY_PARAM = "x-isBodyParam";
static final String X_MEDIA_DATA_TYPE = "x-mediaDataType";
static final String X_ENUM_VALUES = "x-enumValues";
static final String X_MEDIA_IS_JSON = "x-mediaIsJson";
static final String X_MEDIA_IS_WILDCARD = "x-mediaIsWildcard";
static final String X_STRICT_FIELDS = "x-strictFields";
static final String X_ALL_UNIQUE_IMPORT_PATHS = "x-allUniqueImportPaths";
static final String X_USE_KATIP = "x-useKatip";
static final String X_ALLOW_NONUNIQUE_OPERATION_IDS = "x-allowNonUniqueOperationIds";

protected ArrayList<Map<String, String>> unknownMimeTypes = new ArrayList<>();
protected Map<String, Map<String, Object>> uniqueParamNameTypes = new HashMap<>();
protected Map<String, Set<String>> modelMimeTypes = new HashMap<>();
Expand Down Expand Up @@ -742,8 +731,9 @@ public void addOperationToGroup(String tag, String resourcePath, Operation opera
op.vendorExtensions.put(VENDOR_EXTENSION_X_OPERATION_TYPE, operationType);
typeNames.add(operationType);

op.vendorExtensions.put(X_HADDOCK_PATH, String.format(Locale.ROOT, "%s %s", op.httpMethod, op.path.replace("/", "\\/"))); // TODO: 5.0 Remove
op.vendorExtensions.put(VENDOR_EXTENSION_X_HADDOCK_PATH, String.format(Locale.ROOT, "%s %s", op.httpMethod, op.path.replace("/", "\\/")));
String xHaddockPath = String.format(Locale.ROOT, "%s %s", op.httpMethod, op.path.replace("/", "\\/"));
op.vendorExtensions.put(X_HADDOCK_PATH, xHaddockPath); // TODO: 5.0 Remove
op.vendorExtensions.put(VENDOR_EXTENSION_X_HADDOCK_PATH, xHaddockPath);
op.vendorExtensions.put(X_HAS_BODY_OR_FORM_PARAM, op.getHasBodyParam() || op.getHasFormParams()); // TODO: 5.0 Remove
op.vendorExtensions.put(VENDOR_EXTENSION_X_HAS_BODY_OR_FORM_PARAM, op.getHasBodyParam() || op.getHasFormParams());

Expand Down Expand Up @@ -937,6 +927,9 @@ private void processReturnType(CodegenOperation op) {
if (!op.vendorExtensions.containsKey(X_INLINE_ACCEPT)) {
SetNoContent(op, X_INLINE_ACCEPT);
}
if (!op.vendorExtensions.containsKey(VENDOR_EXTENSION_X_INLINE_ACCEPT)) {
SetNoContent(op, VENDOR_EXTENSION_X_INLINE_ACCEPT);
}
}
}
if (returnType.contains(" ")) {
Expand All @@ -948,7 +941,8 @@ private void processReturnType(CodegenOperation op) {

private void processProducesConsumes(CodegenOperation op) {
if (!(Boolean) op.vendorExtensions.get(X_HAS_BODY_OR_FORM_PARAM)) {
SetNoContent(op, X_INLINE_CONTENT_TYPE);
SetNoContent(op, X_INLINE_CONTENT_TYPE); // TODO: 5.0 Remove
SetNoContent(op, VENDOR_EXTENSION_X_INLINE_CONTENT_TYPE);
}
if (op.hasConsumes) {
// deduplicate
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -723,6 +723,9 @@ public Map<String, Object> postProcessModels(Map<String, Object> objs) {
objs = super.postProcessModels(objs);
List<Object> models = (List<Object>) objs.get("models");

// TODO: 5.0: Remove the camelCased vendorExtension below and ensure templates use the newer property naming.
once(LOGGER).warn("4.3.0 has deprecated the use of vendor extensions which don't follow lower-kebab casing standards with x- prefix.");

if (additionalProperties.containsKey(SERIALIZATION_LIBRARY_JACKSON) && !JERSEY1.equals(getLibrary())) {
List<Map<String, String>> imports = (List<Map<String, String>>) objs.get("imports");
for (Object _mo : models) {
Expand All @@ -733,7 +736,8 @@ public Map<String, Object> postProcessModels(Map<String, Object> objs) {
boolean isOptionalNullable = Boolean.FALSE.equals(var.required) && Boolean.TRUE.equals(var.isNullable);
// only add JsonNullable and related imports to optional and nullable values
addImports |= isOptionalNullable;
var.getVendorExtensions().put("isJacksonOptionalNullable", isOptionalNullable);
var.getVendorExtensions().put("isJacksonOptionalNullable", isOptionalNullable); // TODO: 5.0 Remove
var.getVendorExtensions().put("x-is-jackson-optional-nullable", isOptionalNullable);
}
if (addImports) {
Map<String, String> imports2Classnames = new HashMap<String, String>() {{
Expand All @@ -755,7 +759,8 @@ public Map<String, Object> postProcessModels(Map<String, Object> objs) {
for (Object _mo : models) {
Map<String, Object> mo = (Map<String, Object>) _mo;
CodegenModel cm = (CodegenModel) mo.get("model");
cm.getVendorExtensions().putIfAbsent("implements", new ArrayList<String>());
cm.getVendorExtensions().putIfAbsent("implements", new ArrayList<String>()); // TODO: 5.0 Remove
cm.getVendorExtensions().putIfAbsent("x-implements", cm.getVendorExtensions().get("implements"));
List<String> impl = (List<String>) cm.getVendorExtensions().get("implements");
if (this.parcelableModel) {
impl.add("Parcelable");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,16 @@
import org.openapitools.codegen.CodegenConfig;
import org.openapitools.codegen.CodegenModel;
import org.openapitools.codegen.CodegenProperty;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import static org.openapitools.codegen.utils.OnceLogger.once;

/**
* This class holds data to add to `oneOf` members. Let's consider this example:
*
Expand Down Expand Up @@ -44,6 +48,7 @@ public class OneOfImplementorAdditionalData {
private List<String> additionalInterfaces = new ArrayList<String>();
private List<CodegenProperty> additionalProps = new ArrayList<CodegenProperty>();
private List<Map<String, String>> additionalImports = new ArrayList<Map<String, String>>();
private static final Logger LOGGER = LoggerFactory.getLogger(OneOfImplementorAdditionalData.class);

public OneOfImplementorAdditionalData(String implementorName) {
this.implementorName = implementorName;
Expand Down Expand Up @@ -97,7 +102,13 @@ public void addFromInterfaceModel(CodegenModel cm, List<Map<String, String>> mod
* @param addInterfaceImports whether or not to add the interface model as import (will vary by language)
*/
public void addToImplementor(CodegenConfig cc, CodegenModel implcm, List<Map<String, String>> implImports, boolean addInterfaceImports) {
implcm.getVendorExtensions().putIfAbsent("implements", new ArrayList<String>());

// TODO: 5.0: Remove the camelCased vendorExtension below and ensure templates use the newer property naming.
once(LOGGER).warn("4.3.0 has deprecated the use of vendor extensions which don't follow lower-kebab casing standards with x- prefix.");


implcm.getVendorExtensions().putIfAbsent("implements", new ArrayList<String>()); // TODO: 5.0 Remove
implcm.getVendorExtensions().putIfAbsent("x-implements", implcm.getVendorExtensions().get("implements"));

// Add implemented interfaces
for (String intf : additionalInterfaces) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,9 @@ public class {{classname}} {{#parent}}extends {{{parent}}}{{/parent}}{{#serializ
* @return {{name}}
**/
@JsonbProperty("{{baseName}}")
{{#vendorExtensions.extraAnnotation}}
{{{vendorExtensions.extraAnnotation}}}
{{/vendorExtensions.extraAnnotation}}
{{#vendorExtensions.x-extra-annotation}}
{{{vendorExtensions.x-extra-annotation}}}
{{/vendorExtensions.x-extra-annotation}}
{{#useBeanValidation}}{{>beanValidation}}{{/useBeanValidation}} {{#isEnum}}{{^isListContainer}}{{^isMapContainer}}public {{dataType}} {{getter}}() {
if ({{name}} == null) {
return null;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{{>additionalModelTypeAnnotations}}{{>generatedAnnotation}}{{>typeInfoAnnotation}}{{>xmlAnnotation}}
public interface {{classname}} {{#vendorExtensions.implements}}{{#-first}}extends {{{.}}}{{/-first}}{{^-first}}, {{{.}}}{{/-first}}{{/vendorExtensions.implements}} {
public interface {{classname}} {{#vendorExtensions.x-implements}}{{#-first}}extends {{{.}}}{{/-first}}{{^-first}}, {{{.}}}{{/-first}}{{/vendorExtensions.x-implements}} {
{{#discriminator}}
public {{propertyType}} {{propertyGetter}}();
{{/discriminator}}
Expand Down
Loading

0 comments on commit dc50585

Please sign in to comment.