Skip to content

Commit 19de558

Browse files
author
Ole Lensmar
committed
Merge branches 'develop_2.0' and 'jaxrs-interface-generation' of https://github.com/swagger-api/swagger-codegen into jaxrs-interface-generation
Conflicts: modules/swagger-codegen/src/main/java/com/wordnik/swagger/codegen/DefaultCodegen.java
2 parents a6876b8 + ef5cb50 commit 19de558

File tree

129 files changed

+6774
-23
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

129 files changed

+6774
-23
lines changed

.gitignore

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,17 @@ samples/server-generator/scalatra/output
2222
samples/server-generator/node/output/node_modules
2323
samples/server-generator/scalatra/target
2424
samples/server-generator/scalatra/output/.history
25-
25+
samples/client/petstore/qt5cpp/PetStore/moc_*
26+
samples/client/petstore/qt5cpp/PetStore/*.o
27+
samples/client/petstore/objc/PetstoreClient.xcworkspace/xcuserdata
28+
samples/client/petstore/qt5cpp/build-*
29+
samples/client/petstore/qt5cpp/PetStore/PetStore
30+
samples/client/petstore/qt5cpp/PetStore/Makefile
31+
samples/client/petstore/java/hello.txt
32+
samples/client/petstore/android-java/hello.txt
33+
samples/client/petstore/objc/Build
34+
samples/client/petstore/objc/Pods
35+
samples/server/petstore/nodejs/node_modules
2636
target
2737
.idea
2838
.lib

modules/swagger-codegen/src/main/java/com/wordnik/swagger/codegen/CodegenModel.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,6 @@ public class CodegenModel {
1111
public String defaultValue;
1212
public List<CodegenProperty> vars = new ArrayList<CodegenProperty>();
1313
public Set<String> imports = new HashSet<String>();
14-
public Boolean hasVars, emptyVars, hasMoreModels;
14+
public Boolean hasVars, emptyVars, hasMoreModels, hasEnums;
1515
public ExternalDocs externalDocs;
1616
}

modules/swagger-codegen/src/main/java/com/wordnik/swagger/codegen/CodegenResponse.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,12 @@ public class CodegenResponse {
88
public List<Map<String, String>> examples;
99
public final List<CodegenProperty> headers = new ArrayList<CodegenProperty>();
1010
public String dataType, baseType, containerType;
11+
public Boolean isDefault;
1112
public Boolean simpleType;
1213
public Boolean primitiveType;
1314
public Boolean isMapContainer;
1415
public Boolean isListContainer;
1516
public Object schema;
1617
public String jsonSchema;
18+
public boolean isWildcard() { return "0".equals(code) || "default".equals(code); }
1719
}
Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
package com.wordnik.swagger.codegen;
22

33
public class CodegenSecurity {
4-
String name;
5-
String type;
6-
Boolean hasMore, isBasic, isOAuth, isApiKey;
4+
public String name;
5+
public String type;
6+
public Boolean hasMore, isBasic, isOAuth, isApiKey;
77
// ApiKey specific
8-
String keyParamName;
9-
Boolean isKeyInQuery, isKeyInHeader;
10-
8+
public String keyParamName;
9+
public Boolean isKeyInQuery, isKeyInHeader;
1110
}

modules/swagger-codegen/src/main/java/com/wordnik/swagger/codegen/DefaultCodegen.java

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,9 @@ public String toParamName(String name) {
166166
return name;
167167
}
168168

169+
public String toEnumName(CodegenProperty property) {
170+
return StringUtils.capitalize(property.name) + "Enum";
171+
}
169172

170173
public String escapeReservedWord(String name) {
171174
throw new RuntimeException("reserved word " + name + " not allowed");
@@ -470,6 +473,7 @@ else if (model instanceof RefModel) {
470473
}
471474
if(impl.getProperties() != null && impl.getProperties().size() > 0) {
472475
m.hasVars = true;
476+
m.hasEnums = false;
473477
for(String key: impl.getProperties().keySet()) {
474478
Property prop = impl.getProperties().get(key);
475479

@@ -497,6 +501,8 @@ else if (model instanceof RefModel) {
497501
}
498502
m.vars.add(cp);
499503
count += 1;
504+
if (cp.isEnum)
505+
m.hasEnums = true;
500506
if(count != impl.getProperties().keySet().size())
501507
cp.hasMore = new Boolean(true);
502508
if(cp.isContainer != null) {
@@ -589,7 +595,7 @@ public CodegenProperty fromProperty(String name, Property p) {
589595

590596
// this can cause issues for clients which don't support enums
591597
if(property.isEnum)
592-
property.datatypeWithEnum = StringUtils.capitalize(property.name) + "Enum";
598+
property.datatypeWithEnum = toEnumName(property);
593599
else
594600
property.datatypeWithEnum = property.datatype;
595601

@@ -722,7 +728,6 @@ public CodegenOperation fromOperation(String path, String httpMethod, Operation
722728

723729
if (operation.getResponses() != null && !operation.getResponses().isEmpty()) {
724730
Response methodResponse = findMethodResponse(operation.getResponses());
725-
CodegenResponse methodCodegenResponse = null;
726731

727732
for (Map.Entry<String, Response> entry : operation.getResponses().entrySet()) {
728733
Response response = entry.getValue();
@@ -732,9 +737,7 @@ public CodegenOperation fromOperation(String path, String httpMethod, Operation
732737
!defaultIncludes.contains(r.baseType) &&
733738
!languageSpecificPrimitives.contains(r.baseType))
734739
imports.add(r.baseType);
735-
736-
if (response == methodResponse)
737-
methodCodegenResponse = r;
740+
r.isDefault = response == methodResponse;
738741
op.responses.add(r);
739742
}
740743
op.responses.get(op.responses.size() - 1).hasMore = false;
@@ -918,6 +921,19 @@ public CodegenParameter fromParameter(Parameter param, Set<String> imports) {
918921
collectionFormat = qp.getCollectionFormat();
919922
CodegenProperty pr = fromProperty("inner", inner);
920923
p.baseType = pr.datatype;
924+
p.isContainer = true;
925+
imports.add(pr.baseType);
926+
}
927+
else if("object".equals(qp.getType())) {
928+
Property inner = qp.getItems();
929+
if(inner == null) {
930+
LOGGER.warn("warning! No inner type supplied for map parameter \"" + qp.getName() + "\", using String");
931+
inner = new StringProperty().description("//TODO automatically added by swagger-codegen");
932+
}
933+
property = new MapProperty(inner);
934+
collectionFormat = qp.getCollectionFormat();
935+
CodegenProperty pr = fromProperty("inner", inner);
936+
p.baseType = pr.datatype;
921937
imports.add(pr.baseType);
922938
}
923939
else
@@ -926,6 +942,7 @@ public CodegenParameter fromParameter(Parameter param, Set<String> imports) {
926942
LOGGER.warn("warning! Property type \"" + qp.getType() + "\" not found for parameter \"" + param.getName() + "\", using String");
927943
property = new StringProperty().description("//TODO automatically added by swagger-codegen. Type was " + qp.getType() + " but not supported");
928944
}
945+
property.setRequired(param.getRequired());
929946
CodegenProperty model = fromProperty(qp.getName(), property);
930947
p.collectionFormat = collectionFormat;
931948
p.dataType = model.datatype;
@@ -949,6 +966,7 @@ public CodegenParameter fromParameter(Parameter param, Set<String> imports) {
949966
else {
950967
// TODO: missing format, so this will not always work
951968
Property prop = PropertyBuilder.build(impl.getType(), null, null);
969+
prop.setRequired(bp.getRequired());
952970
CodegenProperty cp = fromProperty("property", prop);
953971
if(cp != null) {
954972
p.dataType = cp.datatype;
@@ -962,6 +980,7 @@ else if(model instanceof ArrayModel) {
962980
CodegenModel cm = fromModel(bp.getName(), impl);
963981
// get the single property
964982
ArrayProperty ap = new ArrayProperty().items(impl.getItems());
983+
ap.setRequired(param.getRequired());
965984
CodegenProperty cp = fromProperty("inner", ap);
966985
if(cp.complexType != null) {
967986
imports.add(cp.complexType);

0 commit comments

Comments
 (0)