-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(java): add WriteConsistency parameter (#52)
- Loading branch information
Showing
4 changed files
with
72 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
61 changes: 61 additions & 0 deletions
61
openapi-generator/src/main/java/com/influxdb/AppendCustomDefinitions.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
package com.influxdb; | ||
|
||
import java.io.FileInputStream; | ||
import java.io.FileWriter; | ||
import java.util.Arrays; | ||
import java.util.Collections; | ||
import java.util.LinkedHashMap; | ||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.logging.Logger; | ||
|
||
import org.yaml.snakeyaml.Yaml; | ||
|
||
/** | ||
* @author Jakub Bednar (04/08/2022 10:16) | ||
*/ | ||
public class AppendCustomDefinitions | ||
{ | ||
private static final Logger LOG = Logger.getLogger(AppendCustomDefinitions.class.getName()); | ||
|
||
public static void main(String[] args) throws Exception | ||
{ | ||
if (args.length < 2) | ||
{ | ||
LOG.info("You have to specify paths for 'oss.yml' and requested definition e.g. '--write-consistency'."); | ||
return; | ||
} | ||
|
||
Yaml yaml = new Yaml(); | ||
Map<String, Object> oss = yaml.load(new FileInputStream(args[0])); | ||
if (Arrays.asList(args).contains("--write-consistency")) | ||
{ | ||
// create WriteConsistency schema | ||
LinkedHashMap<String, Object> writeConsistencySchema = new LinkedHashMap<>(); | ||
writeConsistencySchema.put("type", "string"); | ||
writeConsistencySchema.put("enum", Arrays.asList("any","one","quorum","all")); | ||
|
||
Map<String, Object> schemas = AppendCloudDefinitions.mapValue(new String[]{"components", "schemas"}, oss); | ||
schemas.put("WriteConsistency", writeConsistencySchema); | ||
List<Map<String, Object>> parameters = AppendCloudDefinitions.mapValue(new String[]{"paths", "/write", "post", "parameters"}, oss); | ||
|
||
// append WriteConsistency parameter into /write | ||
boolean present = parameters.stream().anyMatch(it -> "consistency".equals(it.get("name"))); | ||
if (!present) | ||
{ | ||
LinkedHashMap<String, Object> writeConsistencyParam = new LinkedHashMap<>(); | ||
writeConsistencyParam.put("in", "query"); | ||
writeConsistencyParam.put("name", "consistency"); | ||
writeConsistencyParam.put("description", "Sets the write consistency for the point. InfluxDB assumes that the write consistency is 'one' if you do not specify. Available with InfluxDB Enterprise clusters only."); | ||
writeConsistencyParam.put("schema", Collections.singletonMap("$ref", "#/components/schemas/WriteConsistency")); | ||
|
||
parameters.add(writeConsistencyParam); | ||
} | ||
|
||
LOG.info("Appended 'write-consistency' to: " + args[0]); | ||
} | ||
|
||
// write to output | ||
yaml.dump(oss, new FileWriter(args[0])); | ||
} | ||
} |