Skip to content
This repository was archived by the owner on Dec 25, 2024. It is now read-only.

Commit 5bb87f7

Browse files
committed
v2 use name for module name (#109)
* Adds CodegenRequestBody * Java updates where header extends requestbody * Java updates to use getters * Removes comment * Updates fromRequestBody java code * Regenerates petstore using fixed fromRequestBody * Removes unused java helper methods for fromRequestBody * Removes unused java code * Adds and uses toHeader, toRequestBody * Uses setRefAndComponentModuleInfo in fromHeader * Uses helper methods in fromParameter * Improves code readability, dedents java code * Removes hasHeaders from CodegenResponse, adds getName to OpenapiComponent interface * Adds more methods to OpenapiComponent * Uses setLocationInfo, getKey updated to use component type * Stops using paramName in response headers * Stops using parameterName for headers * Adds request body doc generation back in, it fell out * Switches back to baseName * Removes all paramName * Removes paramName and uses name.getSnakeCaseName * Moves component types from soffuxes to module prefixes * Samples regenerated * Samples regenerated * Fixes some java tests * Fixes java test, sets schema example also * Reverts version file
1 parent 60d63b1 commit 5bb87f7

File tree

182 files changed

+757
-1161
lines changed

Some content is hidden

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

182 files changed

+757
-1161
lines changed

modules/openapi-json-schema-generator/src/main/java/org/openapitools/codegen/CodegenConfig.java

+1-3
Original file line numberDiff line numberDiff line change
@@ -396,9 +396,7 @@ public interface CodegenConfig {
396396

397397
String toRefClass(String ref, String sourceJsonPath);
398398

399-
CodegenParameter fromRequestBody(RequestBody body, String bodyParameterName, String sourceJsonPath);
400-
401-
String getBodyParameterName(CodegenOperation co);
399+
CodegenRequestBody fromRequestBody(RequestBody body, String sourceJsonPath);
402400

403401
CodegenResponse fromResponse(ApiResponse response, String sourceJsonPath);
404402

modules/openapi-json-schema-generator/src/main/java/org/openapitools/codegen/CodegenHeader.java

+9-74
Original file line numberDiff line numberDiff line change
@@ -31,41 +31,24 @@
3131
* A unique parameter is defined by a combination of a name and location.
3232
* Parameters may be located in a path, query, header or cookie.
3333
*/
34-
public class CodegenHeader implements OpenapiComponent {
34+
public class CodegenHeader extends CodegenRequestBody {
3535
public boolean isExplode;
36-
public String paramName,
37-
description, unescapedDescription, style;
36+
public String style;
3837

39-
public String nameInLowerCase; // property name in lower case
40-
public String example; // example value (x-example)
41-
public String jsonSchema;
42-
public Map<String, Object> vendorExtensions = new HashMap<String, Object>();
4338
public boolean isDeprecated;
4439
protected CodegenSchema schema;
45-
/**
46-
* Determines whether this parameter is mandatory. If the parameter is in "path",
47-
* this property is required and its value MUST be true. Otherwise, the property
48-
* MAY be included and its default value is false.
49-
*/
50-
public boolean required;
51-
protected boolean hasMultipleTypes = false;
52-
protected LinkedHashMap<String, CodegenMediaType> content;
53-
protected String ref;
54-
protected String refModule;
55-
56-
public Set<String> imports = new HashSet<String>();
57-
58-
protected String componentModule;
5940

6041
public CodegenHeader copy() {
6142
CodegenHeader output = new CodegenHeader();
62-
output.paramName = this.paramName;
6343
output.description = this.description;
6444
output.unescapedDescription = this.unescapedDescription;
6545
output.required = this.required;
6646
output.jsonSchema = this.jsonSchema;
6747
output.example = this.example;
6848

49+
if (this.name != null) {
50+
output.setName(this.name);
51+
}
6952
if (this.content != null) {
7053
output.setContent(this.content);
7154
}
@@ -120,60 +103,29 @@ public String getSetSchemaJsonPath(String jsonPath) {
120103
}
121104
return null;
122105
}
123-
public String getComponentModule() {
124-
return componentModule;
125-
}
126-
127-
public void setComponentModule(String componentModule) {
128-
this.componentModule = componentModule;
129-
}
130-
131106
@Override
132107
public int hashCode() {
133-
return Objects.hash(isExplode, paramName, description, unescapedDescription, style, example, jsonSchema, vendorExtensions, isDeprecated, required, hasMultipleTypes, schema, content, ref, refModule, imports, componentModule);
108+
return Objects.hash(name, isExplode, description, unescapedDescription, style, example, jsonSchema, vendorExtensions, isDeprecated, required, schema, content, ref, refModule, imports, componentModule);
134109
}
135110

136111
@Override
137112
public boolean equals(Object o) {
138113
if (this == o) return true;
139114
if (!(o instanceof CodegenHeader)) return false;
115+
if (! super.equals(o)) return false;
140116
CodegenHeader that = (CodegenHeader) o;
141117
return isExplode == that.isExplode &&
142118
isDeprecated == that.isDeprecated &&
143-
required == that.required &&
144-
Objects.equals(componentModule, that.componentModule) &&
145-
Objects.equals(ref, that.getRef()) &&
146-
Objects.equals(imports, that.imports) &&
147-
Objects.equals(refModule, that.getRefModule()) &&
148-
Objects.equals(content, that.getContent()) &&
149119
Objects.equals(schema, that.getSchema()) &&
150-
Objects.equals(paramName, that.paramName) &&
151-
Objects.equals(description, that.description) &&
152-
Objects.equals(unescapedDescription, that.unescapedDescription) &&
153-
Objects.equals(style, that.style) &&
154-
Objects.equals(example, that.example) &&
155-
Objects.equals(jsonSchema, that.jsonSchema) &&
156-
Objects.equals(vendorExtensions, that.vendorExtensions);
120+
Objects.equals(style, that.style);
157121
}
158122

159123
protected void addInstanceInfo(StringBuilder sb) {
124+
super.addInstanceInfo(sb);
160125
sb.append(", isExplode=").append(isExplode);
161-
sb.append(", paramName='").append(paramName).append('\'');
162-
sb.append(", description='").append(description).append('\'');
163-
sb.append(", unescapedDescription='").append(unescapedDescription).append('\'');
164126
sb.append(", style='").append(style).append('\'');
165-
sb.append(", example='").append(example).append('\'');
166-
sb.append(", jsonSchema='").append(jsonSchema).append('\'');
167-
sb.append(", vendorExtensions=").append(vendorExtensions);
168127
sb.append(", isDeprecated=").append(isDeprecated);
169-
sb.append(", required=").append(required);
170-
sb.append(", hasMultipleTypes=").append(hasMultipleTypes);
171128
sb.append(", schema=").append(schema);
172-
sb.append(", content=").append(content);
173-
sb.append(", ref=").append(ref);
174-
sb.append(", refModule=").append(refModule);
175-
sb.append(", imports=").append(imports);
176-
sb.append(", componentModule=").append(componentModule);
177129
}
178130

179131
@Override
@@ -191,22 +143,5 @@ public CodegenSchema getSchema() {
191143
public void setSchema(CodegenSchema schema) {
192144
this.schema = schema;
193145
}
194-
195-
public LinkedHashMap<String, CodegenMediaType> getContent() {
196-
return content;
197-
}
198-
199-
public void setContent(LinkedHashMap<String, CodegenMediaType> content) {
200-
this.content = content;
201-
}
202-
203-
204-
public String getRef() { return ref; }
205-
206-
public void setRef(String ref) { this.ref=ref; }
207-
208-
public String getRefModule() { return refModule; }
209-
210-
public void setRefModule(String refModule) { this.refModule=refModule; }
211146
}
212147

modules/openapi-json-schema-generator/src/main/java/org/openapitools/codegen/CodegenOperation.java

+7-32
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
import java.util.stream.Collectors;
2424

2525
public class CodegenOperation {
26-
public boolean hasAuthMethods, hasConsumes, hasProduces, hasParams, hasOptionalParams, hasRequiredParams,
26+
public boolean hasAuthMethods, hasConsumes, hasProduces, hasParams,
2727
subresourceOperation, isMultipart,
2828
isRestfulIndex, isRestfulShow, isRestfulCreate, isRestfulUpdate, isRestfulDestroy,
2929
isRestful, isDeprecated, isCallbackRequest, uniqueItems, hasDefaultResponse = false,
@@ -32,16 +32,15 @@ public class CodegenOperation {
3232
summary, unescapedNotes, notes, baseName;
3333
public List<Map<String, String>> consumes, produces, prioritizedContentTypes;
3434
public List<CodegenServer> servers = new ArrayList<CodegenServer>();
35-
public CodegenParameter requestBody;
35+
public CodegenRequestBody requestBody;
3636
public List<CodegenParameter> allParams = new ArrayList<CodegenParameter>();
37-
public List<CodegenParameter> bodyParams = new ArrayList<CodegenParameter>();
3837
public List<CodegenParameter> pathParams = new ArrayList<CodegenParameter>();
3938
public List<CodegenParameter> queryParams = new ArrayList<CodegenParameter>();
4039
public List<CodegenParameter> headerParams = new ArrayList<CodegenParameter>();
4140
public List<CodegenParameter> implicitHeadersParams = new ArrayList<CodegenParameter>();
4241
public List<CodegenParameter> cookieParams = new ArrayList<CodegenParameter>();
43-
public List<CodegenParameter> requiredParams = new ArrayList<CodegenParameter>();
44-
public List<CodegenParameter> optionalParams = new ArrayList<CodegenParameter>();
42+
public List<CodegenRequestBody> requiredParams = new ArrayList<CodegenRequestBody>();
43+
public List<CodegenRequestBody> optionalParams = new ArrayList<CodegenRequestBody>();
4544
public List<CodegenSecurity> authMethods;
4645
public Map<String, CodegenTag> tags;
4746
public TreeMap<String, CodegenResponse> responses = null;
@@ -75,15 +74,6 @@ private static boolean nonEmpty(Map<?, ?> params) {
7574
return params != null && !params.isEmpty();
7675
}
7776

78-
/**
79-
* Check if there's at least one body parameter
80-
*
81-
* @return true if body parameter exists, false otherwise
82-
*/
83-
public boolean getHasBodyParam() {
84-
return nonEmpty(bodyParams);
85-
}
86-
8777
/**
8878
* Check if there's at least one query parameter
8979
*
@@ -120,15 +110,6 @@ public boolean getHasPathParams() {
120110
return nonEmpty(pathParams);
121111
}
122112

123-
/**
124-
* Check if there's at least one body parameter or at least one form parameter
125-
*
126-
* @return true if body or form parameter exists, false otherwise
127-
*/
128-
public boolean getHasBodyOrFormParams() {
129-
return getHasBodyParam();
130-
}
131-
132113
/**
133114
* Check if there's at least one form parameter
134115
*
@@ -299,8 +280,6 @@ public String toString() {
299280
sb.append(", hasConsumes=").append(hasConsumes);
300281
sb.append(", hasProduces=").append(hasProduces);
301282
sb.append(", hasParams=").append(hasParams);
302-
sb.append(", hasOptionalParams=").append(hasOptionalParams);
303-
sb.append(", hasRequiredParams=").append(hasRequiredParams);
304283
sb.append(", subresourceOperation=").append(subresourceOperation);
305284
sb.append(", isMultipart=").append(isMultipart);
306285
sb.append(", hasDefaultResponse=").append(hasDefaultResponse);
@@ -327,7 +306,6 @@ public String toString() {
327306
sb.append(", servers=").append(servers);
328307
sb.append(", requestBody=").append(requestBody);
329308
sb.append(", allParams=").append(allParams);
330-
sb.append(", bodyParams=").append(bodyParams);
331309
sb.append(", pathParams=").append(pathParams);
332310
sb.append(", queryParams=").append(queryParams);
333311
sb.append(", headerParams=").append(headerParams);
@@ -364,8 +342,6 @@ public boolean equals(Object o) {
364342
hasConsumes == that.hasConsumes &&
365343
hasProduces == that.hasProduces &&
366344
hasParams == that.hasParams &&
367-
hasOptionalParams == that.hasOptionalParams &&
368-
hasRequiredParams == that.hasRequiredParams &&
369345
subresourceOperation == that.subresourceOperation &&
370346
isMultipart == that.isMultipart &&
371347
hasDefaultResponse == that.hasDefaultResponse &&
@@ -392,7 +368,6 @@ public boolean equals(Object o) {
392368
Objects.equals(servers, that.servers) &&
393369
Objects.equals(requestBody, that.requestBody) &&
394370
Objects.equals(allParams, that.allParams) &&
395-
Objects.equals(bodyParams, that.bodyParams) &&
396371
Objects.equals(pathParams, that.pathParams) &&
397372
Objects.equals(queryParams, that.queryParams) &&
398373
Objects.equals(headerParams, that.headerParams) &&
@@ -421,13 +396,13 @@ public boolean equals(Object o) {
421396
@Override
422397
public int hashCode() {
423398

424-
return Objects.hash(hasAuthMethods, hasConsumes, hasProduces, hasParams, hasOptionalParams,
425-
hasRequiredParams, subresourceOperation,
399+
return Objects.hash(hasAuthMethods, hasConsumes, hasProduces, hasParams,
400+
subresourceOperation,
426401
isMultipart,
427402
hasDefaultResponse, isRestfulIndex, isRestfulShow, isRestfulCreate, isRestfulUpdate, isRestfulDestroy,
428403
isRestful, isDeprecated, isCallbackRequest, uniqueItems, path, operationId, httpMethod,
429404
summary, unescapedNotes, notes, baseName, defaultResponse,
430-
consumes, produces, prioritizedContentTypes, servers, requestBody, allParams, bodyParams,
405+
consumes, produces, prioritizedContentTypes, servers, requestBody, allParams,
431406
pathParams, queryParams, headerParams, cookieParams, requiredParams, optionalParams,
432407
authMethods, tags, responses, callbacks, imports, examples, requestBodyExamples, externalDocs,
433408
vendorExtensions, nickname, operationIdOriginal, operationIdLowerCase, operationIdCamelCase,

modules/openapi-json-schema-generator/src/main/java/org/openapitools/codegen/CodegenParameter.java

+5-2
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,12 @@
2727
public class CodegenParameter extends CodegenHeader {
2828
public boolean isFormParam, isQueryParam, isPathParam, isHeaderParam,
2929
isCookieParam, isBodyParam, isAllowEmptyValue, isDeepObject;
30+
// stores the openapi name property
3031
public String baseName;
3132

3233
public CodegenParameter copy() {
3334
CodegenParameter output = new CodegenParameter();
3435
output.baseName = this.baseName;
35-
output.paramName = this.paramName;
3636
output.description = this.description;
3737
output.unescapedDescription = this.unescapedDescription;
3838
output.isFormParam = this.isFormParam;
@@ -45,6 +45,9 @@ public CodegenParameter copy() {
4545
output.jsonSchema = this.jsonSchema;
4646
output.example = this.example;
4747

48+
if (this.name != null) {
49+
output.name = this.name;
50+
}
4851
if (this.content != null) {
4952
output.setContent(this.content);
5053
}
@@ -77,7 +80,7 @@ public CodegenParameter copy() {
7780

7881
@Override
7982
public int hashCode() {
80-
return Objects.hash(isFormParam, isQueryParam, isPathParam, isHeaderParam, isCookieParam, isBodyParam, isExplode, baseName, paramName, description, unescapedDescription, style, isDeepObject, isAllowEmptyValue, example, jsonSchema, vendorExtensions, isDeprecated, required, hasMultipleTypes, schema, content, ref, refModule, imports, componentModule);
83+
return Objects.hash(name, isFormParam, isQueryParam, isPathParam, isHeaderParam, isCookieParam, isBodyParam, isExplode, baseName, description, unescapedDescription, style, isDeepObject, isAllowEmptyValue, example, jsonSchema, vendorExtensions, isDeprecated, required, schema, content, ref, refModule, imports, componentModule);
8184
}
8285

8386
@Override

0 commit comments

Comments
 (0)