Add isRange in CodegenResponse (#7854)

* add isRange

* undo changes to spec
This commit is contained in:
William Cheng 2020-11-23 17:16:44 +08:00 committed by GitHub
parent 4984f9c3d5
commit 33f4827a06
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 24 additions and 1 deletions

View File

@ -86,7 +86,8 @@ public class CodegenResponse implements IJsonSchemaValidationProperties {
isMap, isArray, isBinary, isFile, schema, jsonSchema, vendorExtensions, items, additionalProperties,
vars, requiredVars,
getMaxProperties(), getMinProperties(), uniqueItems, getMaxItems(), getMinItems(), getMaxLength(),
getMinLength(), exclusiveMinimum, exclusiveMaximum, getMinimum(), getMaximum(), getPattern());
getMinLength(), exclusiveMinimum, exclusiveMaximum, getMinimum(), getMaximum(), getPattern(),
is1xx, is2xx, is3xx, is4xx, is5xx);
}
@Override
@ -121,6 +122,11 @@ public class CodegenResponse implements IJsonSchemaValidationProperties {
isFile == that.isFile &&
items == that.items &&
additionalProperties == that.additionalProperties &&
is1xx == that.is1xx &&
is2xx == that.is2xx &&
is3xx == that.is3xx &&
is4xx == that.is4xx &&
is5xx == that.is5xx &&
Objects.equals(vars, that.vars) &&
Objects.equals(requiredVars, that.requiredVars) &&
Objects.equals(headers, that.headers) &&
@ -362,6 +368,11 @@ public class CodegenResponse implements IJsonSchemaValidationProperties {
final StringBuilder sb = new StringBuilder("CodegenResponse{");
sb.append("headers=").append(headers);
sb.append(", code='").append(code).append('\'');
sb.append(", is1xx='").append(is1xx).append('\'');
sb.append(", is2xx='").append(is2xx).append('\'');
sb.append(", is3xx='").append(is3xx).append('\'');
sb.append(", is4xx='").append(is4xx).append('\'');
sb.append(", is5xx='").append(is5xx).append('\'');
sb.append(", message='").append(message).append('\'');
sb.append(", examples=").append(examples);
sb.append(", dataType='").append(dataType).append('\'');
@ -421,4 +432,15 @@ public class CodegenResponse implements IJsonSchemaValidationProperties {
public boolean isWildcard() {
return "0".equals(code) || "default".equals(code);
}
/*
* Boolean value indicating whether the status code is a range
*
* @return True if the status code is a range (e.g. 2XX)
*/
public boolean isRange() {
if (code != null && code.length() == 3 && "XX".equalsIgnoreCase(code.substring(1)))
return true;
return false;
}
}

View File

@ -4011,6 +4011,7 @@ public class DefaultCodegen implements CodegenConfig {
throw new RuntimeException("Invalid response code " + responseCode);
}
}
Schema responseSchema;
if (this.openAPI != null && this.openAPI.getComponents() != null) {
responseSchema = unaliasSchema(ModelUtils.getSchemaFromResponse(response), importMapping);