forked from loafle/openapi-generator-original
beter code format for protobuf java files (#7857)
This commit is contained in:
parent
4f2f80766e
commit
ca6fcaf92a
@ -86,20 +86,6 @@ public class ProtobufSchemaCodegen extends DefaultCodegen implements CodegenConf
|
||||
modelPackage = "messages";
|
||||
apiPackage = "services";
|
||||
|
||||
/*setReservedWordsLowerCase(
|
||||
Arrays.asList(
|
||||
// data type
|
||||
"nil", "string", "boolean", "number", "userdata", "thread",
|
||||
"table",
|
||||
|
||||
// reserved words: http://www.lua.org/manual/5.1/manual.html#2.1
|
||||
"and", "break", "do", "else", "elseif",
|
||||
"end", "false", "for", "function", "if",
|
||||
"in", "local", "nil", "not", "or",
|
||||
"repeat", "return", "then", "true", "until", "while"
|
||||
)
|
||||
);*/
|
||||
|
||||
defaultIncludes = new HashSet<String>(
|
||||
Arrays.asList(
|
||||
"map",
|
||||
@ -129,7 +115,6 @@ public class ProtobufSchemaCodegen extends DefaultCodegen implements CodegenConf
|
||||
|
||||
instantiationTypes.clear();
|
||||
instantiationTypes.put("array", "repeat");
|
||||
//instantiationTypes.put("map", "map");
|
||||
|
||||
// ref: https://developers.google.com/protocol-buffers/docs/proto
|
||||
typeMapping.clear();
|
||||
@ -154,23 +139,11 @@ public class ProtobufSchemaCodegen extends DefaultCodegen implements CodegenConf
|
||||
typeMapping.put("object", "TODO_OBJECT_MAPPING");
|
||||
|
||||
importMapping.clear();
|
||||
/*
|
||||
importMapping = new HashMap<String, String>();
|
||||
importMapping.put("time.Time", "time");
|
||||
importMapping.put("*os.File", "os");
|
||||
importMapping.put("os", "io/ioutil");
|
||||
*/
|
||||
|
||||
modelDocTemplateFiles.put("model_doc.mustache", ".md");
|
||||
apiDocTemplateFiles.put("api_doc.mustache", ".md");
|
||||
|
||||
cliOptions.clear();
|
||||
/*cliOptions.add(new CliOption(CodegenConstants.PACKAGE_NAME, "GraphQL package name (convention: lowercase).")
|
||||
.defaultValue("openapi2graphql"));
|
||||
cliOptions.add(new CliOption(CodegenConstants.PACKAGE_VERSION, "GraphQL package version.")
|
||||
.defaultValue("1.0.0"));
|
||||
cliOptions.add(new CliOption(CodegenConstants.HIDE_GENERATION_TIMESTAMP, CodegenConstants.HIDE_GENERATION_TIMESTAMP_DESC)
|
||||
.defaultValue(Boolean.TRUE.toString()));*/
|
||||
|
||||
}
|
||||
|
||||
@ -192,10 +165,6 @@ public class ProtobufSchemaCodegen extends DefaultCodegen implements CodegenConf
|
||||
}
|
||||
|
||||
supportingFiles.add(new SupportingFile("README.mustache", "", "README.md"));
|
||||
//supportingFiles.add(new SupportingFile("root.mustache", "", packageName + ".proto"));
|
||||
//supportingFiles.add(new SupportingFile("git_push.sh.mustache", "", "git_push.sh"));
|
||||
//supportingFiles.add(new SupportingFile("gitignore.mustache", "", ".gitignore"))
|
||||
//supportingFiles.add(new SupportingFile(".travis.yml", "", ".travis.yml"));
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -295,14 +264,14 @@ public class ProtobufSchemaCodegen extends DefaultCodegen implements CodegenConf
|
||||
this.addImport(cm, importValue);
|
||||
Map<String, Object> importItem = new HashMap<>();
|
||||
importItem.put(IMPORT, modelFileName);
|
||||
((List<Map<String, Object>>)((Map<String, Object>)objs.get(cm.getName())).get(IMPORTS)).add(importItem);
|
||||
((List<Map<String, Object>>) ((Map<String, Object>) objs.get(cm.getName())).get(IMPORTS)).add(importItem);
|
||||
}
|
||||
}
|
||||
|
||||
private boolean isImportAlreadyPresentInModel(Map<String, Object> objs, CodegenModel cm, String importValue) {
|
||||
boolean skipImport = false;
|
||||
List<Map<String, Object>> cmImports = ((List<Map<String, Object>>)((Map<String, Object>)objs.get(cm.getName())).get(IMPORTS));
|
||||
for (Map<String, Object> cmImportItem: cmImports) {
|
||||
List<Map<String, Object>> cmImports = ((List<Map<String, Object>>) ((Map<String, Object>) objs.get(cm.getName())).get(IMPORTS));
|
||||
for (Map<String, Object> cmImportItem : cmImports) {
|
||||
for (Entry<String, Object> cmImportItemEntry : cmImportItem.entrySet()) {
|
||||
if (importValue.equals(cmImportItemEntry.getValue())) {
|
||||
skipImport = true;
|
||||
@ -528,8 +497,8 @@ public class ProtobufSchemaCodegen extends DefaultCodegen implements CodegenConf
|
||||
|
||||
private int generateFieldNumberFromString(String name) throws ProtoBufIndexComputationException {
|
||||
// Max value from developers.google.com/protocol-buffers/docs/proto3#assigning_field_numbers
|
||||
int fieldNumber = Math.abs(name.hashCode()%536870911);
|
||||
if (19000 <= fieldNumber && fieldNumber <= 19999 ) {
|
||||
int fieldNumber = Math.abs(name.hashCode() % 536870911);
|
||||
if (19000 <= fieldNumber && fieldNumber <= 19999) {
|
||||
LOGGER.error("Generated field number is in reserved range (19000, 19999) for %s, %d", name, fieldNumber);
|
||||
throw new ProtoBufIndexComputationException("Generated field number is in reserved range (19000, 19999).");
|
||||
}
|
||||
@ -538,6 +507,7 @@ public class ProtobufSchemaCodegen extends DefaultCodegen implements CodegenConf
|
||||
|
||||
/**
|
||||
* Checks if the var provided is already in the list of the parent's vars, matching the type and the name
|
||||
*
|
||||
* @param parentVars list of parent's vars
|
||||
* @param var var to compare
|
||||
* @return true if the var is already in the parent's list, false otherwise
|
||||
|
@ -15,10 +15,10 @@ package petstore;
|
||||
|
||||
message ApiResponse {
|
||||
|
||||
int32 code = 1;
|
||||
int32 code = 3059181;
|
||||
|
||||
string type = 2;
|
||||
string type = 3575610;
|
||||
|
||||
string message = 3;
|
||||
string message = 418054152;
|
||||
|
||||
}
|
||||
|
@ -15,8 +15,8 @@ package petstore;
|
||||
|
||||
message Category {
|
||||
|
||||
int64 id = 1;
|
||||
int64 id = 3355;
|
||||
|
||||
string name = 2;
|
||||
string name = 3373707;
|
||||
|
||||
}
|
||||
|
@ -16,9 +16,9 @@ package petstore;
|
||||
message InlineObject {
|
||||
|
||||
// Updated name of the pet
|
||||
string name = 1;
|
||||
string name = 3373707;
|
||||
|
||||
// Updated status of the pet
|
||||
string status = 2;
|
||||
string status = 355610639;
|
||||
|
||||
}
|
||||
|
@ -16,9 +16,9 @@ package petstore;
|
||||
message InlineObject1 {
|
||||
|
||||
// Additional data to pass to server
|
||||
string additionalMetadata = 1;
|
||||
string additionalMetadata = 400408697;
|
||||
|
||||
// file to upload
|
||||
string file = 2;
|
||||
string file = 3143036;
|
||||
|
||||
}
|
||||
|
@ -15,13 +15,13 @@ package petstore;
|
||||
|
||||
message Order {
|
||||
|
||||
int64 id = 1;
|
||||
int64 id = 3355;
|
||||
|
||||
int64 petId = 2;
|
||||
int64 petId = 106557082;
|
||||
|
||||
int32 quantity = 3;
|
||||
int32 quantity = 211262327;
|
||||
|
||||
string shipDate = 4;
|
||||
string shipDate = 517554166;
|
||||
|
||||
// Order Status
|
||||
enum StatusEnum {
|
||||
@ -30,8 +30,8 @@ message Order {
|
||||
DELIVERED = 2;
|
||||
}
|
||||
|
||||
StatusEnum status = 5;
|
||||
StatusEnum status = 355610639;
|
||||
|
||||
bool complete = 6;
|
||||
bool complete = 62574280;
|
||||
|
||||
}
|
||||
|
@ -17,15 +17,15 @@ import public "models/tag.proto";
|
||||
|
||||
message Pet {
|
||||
|
||||
int64 id = 1;
|
||||
int64 id = 3355;
|
||||
|
||||
Category category = 2;
|
||||
Category category = 50511102;
|
||||
|
||||
string name = 3;
|
||||
string name = 3373707;
|
||||
|
||||
repeated string photoUrls = 4;
|
||||
repeated string photoUrls = 311086539;
|
||||
|
||||
repeated Tag tags = 5;
|
||||
repeated Tag tags = 3552281;
|
||||
|
||||
// pet status in the store
|
||||
enum StatusEnum {
|
||||
@ -34,6 +34,6 @@ message Pet {
|
||||
SOLD = 2;
|
||||
}
|
||||
|
||||
StatusEnum status = 6;
|
||||
StatusEnum status = 355610639;
|
||||
|
||||
}
|
||||
|
@ -15,8 +15,8 @@ package petstore;
|
||||
|
||||
message Tag {
|
||||
|
||||
int64 id = 1;
|
||||
int64 id = 3355;
|
||||
|
||||
string name = 2;
|
||||
string name = 3373707;
|
||||
|
||||
}
|
||||
|
@ -15,21 +15,21 @@ package petstore;
|
||||
|
||||
message User {
|
||||
|
||||
int64 id = 1;
|
||||
int64 id = 3355;
|
||||
|
||||
string username = 2;
|
||||
string username = 265713450;
|
||||
|
||||
string firstName = 3;
|
||||
string firstName = 132835675;
|
||||
|
||||
string lastName = 4;
|
||||
string lastName = 385857985;
|
||||
|
||||
string email = 5;
|
||||
string email = 96619420;
|
||||
|
||||
string password = 6;
|
||||
string password = 143243933;
|
||||
|
||||
string phone = 7;
|
||||
string phone = 106642798;
|
||||
|
||||
// User Status
|
||||
int32 userStatus = 8;
|
||||
int32 userStatus = 517890975;
|
||||
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user