Skip to content

Commit

Permalink
Merge pull request #379 from apivideo/watch-data-docs
Browse files Browse the repository at this point in the history
Add new analytics endpoints & livestream complete()
  • Loading branch information
olivierapivideo authored Jul 31, 2024
2 parents a932bad + e749875 commit 1000922
Show file tree
Hide file tree
Showing 42 changed files with 1,525 additions and 1,739 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,13 @@

public class Common {

public static void preprocessOpenAPI(OpenAPI openAPI) {
// remove paths that have the x-ignored flag
openAPI.getPaths().keySet().removeIf(path -> openAPI.getPaths().get(path).getExtensions() != null && openAPI.getPaths().get(path).getExtensions().containsKey("x-ignored"));
// remove models that have the x-ignored flag
openAPI.getComponents().getSchemas().keySet().removeIf(schema -> openAPI.getComponents().getSchemas().get(schema).getExtensions() != null && openAPI.getComponents().getSchemas().get(schema).getExtensions().containsKey("x-ignored"));
}

public static Comparator<CodegenOperation> getCodegenOperationComparator() {
Map<String, Integer> operationIndexes = new HashMap<>();
operationIndexes.put("create", 1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.samskivert.mustache.Mustache;
import com.samskivert.mustache.Template;
import io.swagger.util.Json;
import io.swagger.v3.oas.models.OpenAPI;
import org.apache.commons.lang3.StringUtils;
import org.openapitools.codegen.CodegenModel;
import org.openapitools.codegen.CodegenOperation;
Expand Down Expand Up @@ -37,6 +38,13 @@ public Csharp() {
packageGuid = "{" + java.util.UUID.nameUUIDFromBytes(this.packageVersion.getBytes()).toString().toUpperCase(Locale.ROOT) + "}";
}


@Override
public void preprocessOpenAPI(OpenAPI openAPI) {
super.preprocessOpenAPI(openAPI);
Common.preprocessOpenAPI(openAPI);
}

@Override
public void postProcessParameter(CodegenParameter parameter) {
super.postProcessParameter(parameter);
Expand Down Expand Up @@ -165,13 +173,17 @@ public Map<String, Object> postProcessOperationsWithModels(Map<String, Object> o
@Override
public Map<String, Object> postProcessModels(Map<String, Object> objs) {
Map<String, Object> res = super.postProcessModels(objs);
List<Map> models = (List<Map>) res.get("models");
ArrayList<HashMap<String, CodegenModel>> models = (ArrayList<HashMap<String, CodegenModel>>) res.get("models");

models.forEach(model -> {
((CodegenModel)model.get("model")).vars.forEach(var -> {
models.forEach(map -> {
CodegenModel model = map.get("model");
if(model.isMap) {
model.vendorExtensions.put("x-implements", Collections.singletonList("DeepObject"));
}
model.vars.forEach(var -> {
if(var.name.equals("_AccessToken")) var.name = "AccessToken";
if (var.defaultValue != null) {
((CodegenModel)model.get("model")).vendorExtensions.put("x-has-defaults", true);
model.vendorExtensions.put("x-has-defaults", true);
}
});
});
Expand All @@ -187,7 +199,7 @@ private void handlePagination(List<Object> allModels, CodegenOperation operation
System.out.println(model);
model.allVars.stream().filter(v -> v.name.equals("Data")).findFirst().ifPresent(codegenProperty -> {
Map<String, String> paginationProperties = new HashMap<>();
paginationProperties.put("type", codegenProperty.complexType);
paginationProperties.put("type", codegenProperty.dataType.substring(codegenProperty.dataType.indexOf("<") + 1, codegenProperty.dataType.indexOf(">")));
paginationProperties.put("getter", codegenProperty.getter);
operation.vendorExtensions.put("x-pagination", paginationProperties);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.fasterxml.jackson.core.JsonProcessingException;
import com.google.common.collect.Maps;
import io.swagger.util.Json;
import io.swagger.v3.oas.models.OpenAPI;
import io.swagger.v3.oas.models.media.Schema;
import org.apache.commons.lang3.StringUtils;
import org.openapitools.codegen.*;
Expand Down Expand Up @@ -40,6 +41,13 @@ public CodegenProperty fromProperty(String name, Schema p) {
return super.fromProperty(name, p);
}


@Override
public void preprocessOpenAPI(OpenAPI openAPI) {
super.preprocessOpenAPI(openAPI);
Common.preprocessOpenAPI(openAPI);
}

@Override
public Map<String, Object> postProcessOperationsWithModels(Map<String, Object> objs, List<Object> allModels) {
Common.replaceDescriptionsAndSamples(objs, "go");
Expand Down Expand Up @@ -82,7 +90,11 @@ public Map<String, Object> postProcessOperationsWithModels(Map<String, Object> o
}

operation.queryParams.forEach(queryParam -> {
if(queryParam.vendorExtensions.containsKey("x-is-deep-object")) additionalImports.add("fmt");
if(queryParam.dataFormat != null && queryParam.dataFormat.equalsIgnoreCase("date-time")) {
operation.allParams.stream().filter(p -> p.baseName.equals(queryParam.baseName)).forEach(p -> p.dataType = "time.Time");
queryParam.dataType = "time.Time";
}
//if(queryParam.vendorExtensions.containsKey("x-is-deep-object")) additionalImports.add("fmt");
});

// overwrite operationId & nickname values of the operation with the x-client-action
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package video.api.client.generator;

import io.swagger.v3.oas.models.OpenAPI;
import org.apache.commons.lang3.StringUtils;
import org.openapitools.codegen.CodegenModel;
import org.openapitools.codegen.CodegenOperation;
Expand Down Expand Up @@ -140,7 +141,11 @@ public void processOpts() {
supportingFiles.removeIf(e -> skippedFiles.contains(e.getTemplateFile()));
}


@Override
public void preprocessOpenAPI(OpenAPI openAPI) {
super.preprocessOpenAPI(openAPI);
Common.preprocessOpenAPI(openAPI);
}

private void handlePagination(List<Object> allModels, CodegenOperation operation) {
Optional<Map> map = allModels.stream().filter(m -> ((CodegenModel) ((Map) m).get("model")).classname.equals(operation.returnType)).map(a -> (Map) a).findFirst();
Expand All @@ -149,7 +154,11 @@ private void handlePagination(List<Object> allModels, CodegenOperation operation
System.out.println(model);
model.allVars.stream().filter(v -> v.name.equals("data")).findFirst().ifPresent(codegenProperty -> {
Map<String, String> paginationProperties = new HashMap<>();
paginationProperties.put("type", codegenProperty.complexType);
if(codegenProperty.dataType.contains("<") && codegenProperty.dataType.contains(">")) {
paginationProperties.put("type", codegenProperty.dataType.substring(codegenProperty.dataType.indexOf("<") + 1, codegenProperty.dataType.indexOf(">")));
} else {
paginationProperties.put("type", codegenProperty.dataType);
}
paginationProperties.put("getter", codegenProperty.getter);
operation.vendorExtensions.put("x-pagination", paginationProperties);
});
Expand All @@ -159,6 +168,14 @@ private void handlePagination(List<Object> allModels, CodegenOperation operation
@Override
public Map<String, Object> postProcessModels(Map<String, Object> objs) {
Map<String, Object> stringObjectMap = super.postProcessModels(objs);
ArrayList<HashMap<String, CodegenModel>> models = (ArrayList<HashMap<String, CodegenModel>>) stringObjectMap.get("models");
models.stream().forEach((map) -> {
CodegenModel model = map.get("model");
if(model.isMap) {
((List<String>)model.vendorExtensions.get("x-implements") ).add("DeepObject");
}
});

((ArrayList) stringObjectMap.get("imports")).removeIf((v) -> ((Map) v).values().contains("org.openapitools.jackson.nullable.JsonNullable"));
return stringObjectMap;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,15 @@ public void processOpts() {

}


/**
* Filter the OpenAPI description file entries in order to keep only stuff related to video upload & authentication
* @param openAPI
*/
@Override
public void preprocessOpenAPI(OpenAPI openAPI) {
super.preprocessOpenAPI(openAPI);
Common.preprocessOpenAPI(openAPI);

Set<String> pathsToRemove = new HashSet<>();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,10 @@ public String getHelp() {
return "Generates a PHP client library.";
}



public void preprocessOpenAPI(OpenAPI openAPI) {
Common.preprocessOpenAPI(openAPI);
Map<String, PathItem> pathItems = openAPI.getPaths();
io.swagger.v3.oas.models.Paths newPaths = new io.swagger.v3.oas.models.Paths();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ public CodegenProperty fromProperty(String name, Schema p) {
}

public void preprocessOpenAPI(OpenAPI openAPI) {
Common.preprocessOpenAPI(openAPI);
Map<String, PathItem> pathItems = openAPI.getPaths();
io.swagger.v3.oas.models.Paths newPaths = new io.swagger.v3.oas.models.Paths();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.fasterxml.jackson.core.JsonProcessingException;
import io.swagger.util.Json;
import io.swagger.v3.oas.models.OpenAPI;
import org.apache.commons.lang3.StringUtils;
import org.openapitools.codegen.*;
import org.openapitools.codegen.languages.Swift5ClientCodegen;
Expand All @@ -24,6 +25,11 @@ public class Swift5 extends Swift5ClientCodegen {
public static final String VENDOR_X_CLIENT_HIDDEN = "x-client-hidden";
public static final List<String> PARAMETERS_TO_HIDE_IN_CLIENT_DOC = Arrays.asList("currentPage", "pageSize");

@Override
public void preprocessOpenAPI(OpenAPI openAPI) {
super.preprocessOpenAPI(openAPI);
Common.preprocessOpenAPI(openAPI);
}
@Override
public Map<String, Object> postProcessOperationsWithModels(Map<String, Object> objs, List<Object> allModels) {
Common.replaceDescriptionsAndSamples(objs, "swift5");
Expand Down Expand Up @@ -53,7 +59,16 @@ public Map<String, Object> postProcessOperationsWithModels(Map<String, Object> o
}

applyToAllParams(operation, (params) -> params.forEach(pp -> {
if("deepObject".equals(pp.style)) pp.collectionFormat = "deepObject";
if(pp.vendorExtensions != null && pp.vendorExtensions.containsKey("x-is-deep-object")) {
if(!pp.getHasVars()) {
pp.vendorExtensions.remove("x-is-deep-object");
} else {
if("deepObject".equals(pp.style)) {
pp.collectionFormat = "deepObject";
}
}
}

}));
applyToAllParams(operation, (params) -> params.removeIf(pp -> getVendorExtensionBooleanValue(pp, VENDOR_X_CLIENT_IGNORE)) );

Expand All @@ -74,6 +89,7 @@ private void applyToAllParams(CodegenOperation operation, Consumer<List<CodegenP
consumer.accept(operation.formParams);
consumer.accept(operation.cookieParams);
consumer.accept(operation.allParams);
consumer.accept(operation.queryParams);
}
}

Expand All @@ -94,14 +110,19 @@ public void processOpts() {

}


@Override
public Map<String, Object> postProcessModels(Map<String, Object> objs) {
Map<String, Object> stringObjectMap = super.postProcessModels(objs);

List<Map<String, Object>> models = (List)objs.get("models");
models.forEach(map -> {
CodegenModel model = ((CodegenModel)map.get("model"));
if(model.vendorExtensions != null && model.vendorExtensions.containsKey("x-is-deep-object")) {
model.allVars.forEach(var -> {
String nameWithoutEndDigits = model.name.replaceAll("_\\d+$", "");
var.vendorExtensions.put("x-model-name", nameWithoutEndDigits);
});
}
model.vars.forEach(var -> {
if(var.vendorExtensions.containsKey("x-optional-nullable") && var.dataType.equals("String")) {
var.dataType = "NullableString";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ public class Swift5Uploader extends Swift5 {
@Override
public void preprocessOpenAPI(OpenAPI openAPI) {
super.preprocessOpenAPI(openAPI);
Common.preprocessOpenAPI(openAPI);

Set<String> pathsToRemove = new HashSet<>();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -475,6 +475,8 @@ public CodegenType getTag() {

@Override
public void preprocessOpenAPI(OpenAPI openAPI) {
Common.preprocessOpenAPI(openAPI);

if (additionalProperties.containsKey(NPM_NAME)) {
// If no npmVersion is provided in additional properties, version from API specification is used.
// If none of them is provided then fallbacks to default version
Expand Down Expand Up @@ -635,7 +637,20 @@ protected String getParameterDataType(Parameter parameter, Schema p) {
} else if (ModelUtils.isMapSchema(p)) {
inner = (Schema) p.getAdditionalProperties();
return "{ [key: string]: " + this.getParameterDataType(parameter, inner) + "; }";
} else if (ModelUtils.isStringSchema(p)) {
} else if (p != null &&
parameter.getName() != null &&
parameter.getIn().equalsIgnoreCase("query") &&
parameter.getExplode() &&
parameter.getExtensions() != null &&
parameter.get$ref() != null &&
parameter.getExtensions().containsKey("x-is-deep-object")) {
String refName = parameter.get$ref().substring(parameter.get$ref().lastIndexOf("/") + 1);
refName = refName.replace("_", "");
refName = refName.substring(0, 1).toUpperCase() + refName.substring(1);

return refName;
}
else if (ModelUtils.isStringSchema(p)) {
// Handle string enums
if (p.getEnum() != null) {
return enumValuesToEnumTypeUnion(p.getEnum(), "string");
Expand Down
3 changes: 3 additions & 0 deletions config/android.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
changelog:
- 1.6.0 (2024-07-29):
- Add new analytics methods
- Add livestream complete() method
- 1.5.7 (2024-04-25):
- Add API to get rate limiting headers
- 1.5.6 (2024-03-21):
Expand Down
3 changes: 3 additions & 0 deletions config/csharp.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
changelog:
- 1.6.0 (2024-07-29):
- Add new analytics methods
- Add livestream complete() method
- 1.5.0 (2024-07-19):
- fix nuget package (closes \#131)
- add *Async() methods (closes \#132)
Expand Down
3 changes: 3 additions & 0 deletions config/go.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
changelog:
- 1.4.0 (2024-07-29):
- Add new analytics methods
- Add livestream complete() method
- 1.3.1 (2024-02-19):
- Update VideoStatusIngest enum
- 1.3.0 (2023-06-28):
Expand Down
3 changes: 3 additions & 0 deletions config/java.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
changelog:
- 1.4.0 (2024-07-29):
- Add new analytics methods
- Add livestream complete() method
- 1.3.3 (2024-04-25):
- Add API to get rate limiting headers
- 1.3.2 (2024-02-19):
Expand Down
3 changes: 3 additions & 0 deletions config/nodejs.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
changelog:
- 2.6.0 (2024-07-29):
- Add new analytics methods
- Add livestream complete() method
- 2.5.7 (2024-04-23):
- Add *WithResponseHeaders() methods
- 2.5.6 (2024-02-19):
Expand Down
3 changes: 3 additions & 0 deletions config/php.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
changelog:
- 1.4.0 (2024-07-29):
- Add new analytics methods
- Add livestream complete() method
- 1.3.2 (2024-02-19):
- Update VideoStatusIngest enum
- 1.3.1 (2023-06-28):
Expand Down
3 changes: 3 additions & 0 deletions config/python.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
changelog:
- 1.4.0 (2024-07-29):
- Add new analytics methods
- Add livestream complete() method
- 1.3.2 (2024-07-01):
- Fix python "context" error
- 1.3.1 (2024-02-19):
Expand Down
3 changes: 3 additions & 0 deletions config/swift5.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
changelog:
- 1.3.0 (2024-07-29):
- Add new analytics methods
- Add livestream complete() method
- 1.2.3 (2024-04-25):
- Add API to get rate limiting headers
- 1.2.2 (2024-02-19):
Expand Down
Loading

0 comments on commit 1000922

Please sign in to comment.