mirror of
https://github.com/OpenAPITools/openapi-generator.git
synced 2025-06-29 12:10:54 +00:00
Adds missing items property to Java classes which store Schema info (#7621)
* Adds items getter and setter in IJsonSchemaValidationProperties * Adds isModel interface * Reverts file * Fixes issue_7613.yaml schema for /array_with_validations_in_items/{items} response body * Adds isModel to CodegenModel hash and print and comparison * Updates CodegenResponse hash and comparison and print
This commit is contained in:
parent
3d36d491df
commit
d5002f4beb
@ -149,6 +149,8 @@ public class CodegenModel implements IJsonSchemaValidationProperties {
|
||||
private String maximum;
|
||||
private String pattern;
|
||||
private Number multipleOf;
|
||||
private CodegenProperty items;
|
||||
private boolean isModel;
|
||||
|
||||
public String getAdditionalPropertiesType() {
|
||||
return additionalPropertiesType;
|
||||
@ -550,6 +552,24 @@ public class CodegenModel implements IJsonSchemaValidationProperties {
|
||||
this.multipleOf = multipleOf;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CodegenProperty getItems() {
|
||||
return items;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setItems(CodegenProperty items) {
|
||||
this.items = items;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean getIsModel() { return isModel; }
|
||||
|
||||
@Override
|
||||
public void setIsModel(boolean isModel) {
|
||||
this.isModel = isModel;
|
||||
}
|
||||
|
||||
// indicates if the model component has validation on the root level schema
|
||||
// this will be true when minItems or minProperties is set
|
||||
public boolean hasValidation() {
|
||||
@ -714,8 +734,9 @@ public class CodegenModel implements IJsonSchemaValidationProperties {
|
||||
Objects.equals(getMinimum(), that.getMinimum()) &&
|
||||
Objects.equals(getMaximum(), that.getMaximum()) &&
|
||||
Objects.equals(getPattern(), that.getPattern()) &&
|
||||
Objects.equals(getItems(), that.getItems()) &&
|
||||
Objects.equals(getIsModel(), that.getIsModel()) &&
|
||||
Objects.equals(getMultipleOf(), that.getMultipleOf());
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -731,7 +752,7 @@ public class CodegenModel implements IJsonSchemaValidationProperties {
|
||||
hasChildren, isMapModel, isDeprecated, hasOnlyReadOnly, getExternalDocumentation(), getVendorExtensions(),
|
||||
getAdditionalPropertiesType(), getMaxProperties(), getMinProperties(), getUniqueItems(), getMaxItems(),
|
||||
getMinItems(), getMaxLength(), getMinLength(), getExclusiveMinimum(), getExclusiveMaximum(), getMinimum(),
|
||||
getMaximum(), getPattern(), getMultipleOf());
|
||||
getMaximum(), getPattern(), getMultipleOf(), getItems(), getIsModel());
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -810,6 +831,8 @@ public class CodegenModel implements IJsonSchemaValidationProperties {
|
||||
sb.append(", maximum='").append(maximum).append('\'');
|
||||
sb.append(", pattern='").append(pattern).append('\'');
|
||||
sb.append(", multipleOf='").append(multipleOf).append('\'');
|
||||
sb.append(", items='").append(items).append('\'');
|
||||
sb.append(", isModel='").append(isModel).append('\'');
|
||||
sb.append('}');
|
||||
return sb.toString();
|
||||
}
|
||||
|
@ -478,5 +478,22 @@ public class CodegenParameter implements IJsonSchemaValidationProperties {
|
||||
this.multipleOf = multipleOf;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CodegenProperty getItems() {
|
||||
return items;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setItems(CodegenProperty items) {
|
||||
this.items = items;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean getIsModel() { return isModel; }
|
||||
|
||||
@Override
|
||||
public void setIsModel(boolean isModel) {
|
||||
this.isModel = isModel;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -451,14 +451,24 @@ public class CodegenProperty implements Cloneable, IJsonSchemaValidationProperti
|
||||
this.allowableValues = allowableValues;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CodegenProperty getItems() {
|
||||
return items;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setItems(CodegenProperty items) {
|
||||
this.items = items;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean getIsModel() { return isModel; }
|
||||
|
||||
@Override
|
||||
public void setIsModel(boolean isModel) {
|
||||
this.isModel = isModel;
|
||||
}
|
||||
|
||||
public Map<String, Object> getVendorExtensions() {
|
||||
return vendorExtensions;
|
||||
}
|
||||
|
@ -73,13 +73,14 @@ public class CodegenResponse implements IJsonSchemaValidationProperties {
|
||||
private String maximum;
|
||||
public String pattern;
|
||||
public Number multipleOf;
|
||||
public CodegenProperty items;
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(headers, code, message, hasMore, examples, dataType, baseType, containerType, hasHeaders,
|
||||
isString, isNumeric, isInteger, isLong, isNumber, isFloat, isDouble, isByteArray, isBoolean, isDate,
|
||||
isDateTime, isUuid, isEmail, isModel, isFreeFormObject, isAnyType, isDefault, simpleType, primitiveType,
|
||||
isMapContainer, isListContainer, isBinary, isFile, schema, jsonSchema, vendorExtensions,
|
||||
isMapContainer, isListContainer, isBinary, isFile, schema, jsonSchema, vendorExtensions, items,
|
||||
getMaxProperties(), getMinProperties(), uniqueItems, getMaxItems(), getMinItems(), getMaxLength(),
|
||||
getMinLength(), exclusiveMinimum, exclusiveMaximum, getMinimum(), getMaximum(), getPattern());
|
||||
}
|
||||
@ -114,6 +115,7 @@ public class CodegenResponse implements IJsonSchemaValidationProperties {
|
||||
isListContainer == that.isListContainer &&
|
||||
isBinary == that.isBinary &&
|
||||
isFile == that.isFile &&
|
||||
items == that.items &&
|
||||
Objects.equals(headers, that.headers) &&
|
||||
Objects.equals(code, that.code) &&
|
||||
Objects.equals(message, that.message) &&
|
||||
@ -270,6 +272,24 @@ public class CodegenResponse implements IJsonSchemaValidationProperties {
|
||||
this.multipleOf = multipleOf;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CodegenProperty getItems() {
|
||||
return items;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setItems(CodegenProperty items) {
|
||||
this.items = items;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean getIsModel() { return isModel; }
|
||||
|
||||
@Override
|
||||
public void setIsModel(boolean isModel) {
|
||||
this.isModel = isModel;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
final StringBuilder sb = new StringBuilder("CodegenResponse{");
|
||||
@ -321,6 +341,7 @@ public class CodegenResponse implements IJsonSchemaValidationProperties {
|
||||
sb.append(", maximum='").append(maximum).append('\'');
|
||||
sb.append(", pattern='").append(pattern).append('\'');
|
||||
sb.append(", multipleOf='").append(multipleOf).append('\'');
|
||||
sb.append(", items='").append(items).append('\'');
|
||||
sb.append('}');
|
||||
return sb.toString();
|
||||
}
|
||||
|
@ -2314,7 +2314,9 @@ public class DefaultCodegen implements CodegenConfig {
|
||||
}
|
||||
if (ModelUtils.isArraySchema(schema)) {
|
||||
m.isArrayModel = true;
|
||||
m.arrayModelType = fromProperty(name, schema).complexType;
|
||||
CodegenProperty arrayProperty = fromProperty(name, schema);
|
||||
m.setItems(arrayProperty.items);
|
||||
m.arrayModelType = arrayProperty.complexType;
|
||||
addParentContainer(m, name, schema);
|
||||
ModelUtils.syncValidationProperties(schema, m);
|
||||
} else if (schema instanceof ComposedSchema) {
|
||||
@ -4002,8 +4004,10 @@ public class DefaultCodegen implements CodegenConfig {
|
||||
|
||||
if (ModelUtils.isArraySchema(responseSchema)) {
|
||||
ArraySchema as = (ArraySchema) responseSchema;
|
||||
CodegenProperty innerProperty = fromProperty("response", getSchemaItems(as));
|
||||
CodegenProperty innerCp = innerProperty;
|
||||
CodegenProperty items = fromProperty("response", getSchemaItems(as));
|
||||
r.setItems(items);
|
||||
CodegenProperty innerCp = items;
|
||||
|
||||
while (innerCp != null) {
|
||||
r.baseType = innerCp.baseType;
|
||||
innerCp = innerCp.items;
|
||||
|
@ -52,4 +52,12 @@ public interface IJsonSchemaValidationProperties {
|
||||
Number getMultipleOf();
|
||||
|
||||
void setMultipleOf(Number multipleOf);
|
||||
|
||||
CodegenProperty getItems();
|
||||
|
||||
void setItems(CodegenProperty items);
|
||||
|
||||
boolean getIsModel();
|
||||
|
||||
void setIsModel(boolean isModel);
|
||||
}
|
||||
|
@ -2301,4 +2301,44 @@ public class DefaultCodegenTest {
|
||||
final List<String> flows = securities.stream().map(c -> c.flow).collect(Collectors.toList());
|
||||
assertTrue(flows.containsAll(Arrays.asList("password", "application")));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testItemsPresent() {
|
||||
final OpenAPI openAPI = TestUtils.parseFlattenSpec("src/test/resources/3_0/issue_7613.yaml");
|
||||
final DefaultCodegen codegen = new DefaultCodegen();
|
||||
codegen.setOpenAPI(openAPI);
|
||||
|
||||
String modelName;
|
||||
Schema sc;
|
||||
CodegenModel cm;
|
||||
|
||||
modelName = "ArrayWithValidationsInItems";
|
||||
sc = openAPI.getComponents().getSchemas().get(modelName);
|
||||
cm = codegen.fromModel(modelName, sc);
|
||||
assertEquals(cm.getItems().getMaximum(), "7");
|
||||
|
||||
modelName = "ObjectWithValidationsInArrayPropItems";
|
||||
sc = openAPI.getComponents().getSchemas().get(modelName);
|
||||
cm = codegen.fromModel(modelName, sc);
|
||||
assertEquals(cm.getVars().get(0).getItems().getMaximum(), "7");
|
||||
|
||||
String path;
|
||||
Operation operation;
|
||||
CodegenOperation co;
|
||||
|
||||
path = "/ref_array_with_validations_in_items/{items}";
|
||||
operation = openAPI.getPaths().get(path).getPost();
|
||||
co = codegen.fromOperation(path, "POST", operation, null);
|
||||
assertEquals(co.pathParams.get(0).getItems().getMaximum(), "7");
|
||||
assertEquals(co.bodyParams.get(0).getItems().getMaximum(), "7");
|
||||
assertEquals(co.responses.get(0).getItems().getMaximum(), "7");
|
||||
|
||||
path = "/array_with_validations_in_items/{items}";
|
||||
operation = openAPI.getPaths().get(path).getPost();
|
||||
co = codegen.fromOperation(path, "POST", operation, null);
|
||||
assertEquals(co.pathParams.get(0).getItems().getMaximum(), "7");
|
||||
assertEquals(co.bodyParams.get(0).getItems().getMaximum(), "7");
|
||||
assertEquals(co.responses.get(0).getItems().getMaximum(), "7");
|
||||
}
|
||||
|
||||
}
|
||||
|
113
modules/openapi-generator/src/test/resources/3_0/issue_7613.yaml
Normal file
113
modules/openapi-generator/src/test/resources/3_0/issue_7613.yaml
Normal file
@ -0,0 +1,113 @@
|
||||
openapi: 3.0.1
|
||||
info:
|
||||
title: OpenAPI Petstore
|
||||
description: "sample spec"
|
||||
license:
|
||||
name: Apache-2.0
|
||||
url: https://www.apache.org/licenses/LICENSE-2.0.html
|
||||
version: 1.0.0
|
||||
servers:
|
||||
- url: http://petstore.swagger.io:80/v2
|
||||
tags:
|
||||
- name: items
|
||||
description: Everything about your Pets
|
||||
paths:
|
||||
/ref_array_with_validations_in_items/{items}:
|
||||
post:
|
||||
tags:
|
||||
- items
|
||||
operationId: refArrayWithValidationsInItems
|
||||
parameters:
|
||||
- name: items
|
||||
in: path
|
||||
required: true
|
||||
schema:
|
||||
$ref: '#/components/schemas/ArrayWithValidationsInItems'
|
||||
requestBody:
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
$ref: '#/components/schemas/ArrayWithValidationsInItems'
|
||||
required: true
|
||||
responses:
|
||||
200:
|
||||
description: success
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
$ref: '#/components/schemas/ArrayWithValidationsInItems'
|
||||
/array_with_validations_in_items/{items}:
|
||||
post:
|
||||
tags:
|
||||
- items
|
||||
operationId: arrayWithValidationsInItems
|
||||
parameters:
|
||||
- name: items
|
||||
in: path
|
||||
required: true
|
||||
schema:
|
||||
type: array
|
||||
items:
|
||||
type: integer
|
||||
format: int64
|
||||
maximum: 7
|
||||
requestBody:
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
type: array
|
||||
items:
|
||||
type: integer
|
||||
format: int64
|
||||
maximum: 7
|
||||
required: true
|
||||
responses:
|
||||
200:
|
||||
description: success
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
type: array
|
||||
items:
|
||||
type: integer
|
||||
format: int64
|
||||
maximum: 7
|
||||
components:
|
||||
schemas:
|
||||
ArrayWithValidationsInItems:
|
||||
type: array
|
||||
items:
|
||||
type: integer
|
||||
format: int64
|
||||
maximum: 7
|
||||
ObjectWithValidationsInArrayPropItems:
|
||||
type: object
|
||||
properties:
|
||||
arrayProp:
|
||||
type: array
|
||||
items:
|
||||
type: integer
|
||||
format: int64
|
||||
maximum: 7
|
||||
ObjectWithValidationsInAdditionalProperties:
|
||||
type: object
|
||||
additionalProperties:
|
||||
type: integer
|
||||
format: int64
|
||||
maximum: 7
|
||||
ComposedOneOfInlineValidation:
|
||||
oneOf:
|
||||
- type: integer
|
||||
format: int64
|
||||
maximum: 7
|
||||
ComposedAnyOfInlineValidation:
|
||||
anyOf:
|
||||
- type: integer
|
||||
format: int64
|
||||
maximum: 7
|
||||
ComposedAllOfInlineValidation:
|
||||
allOf:
|
||||
- type: integer
|
||||
format: int64
|
||||
maximum: 7
|
||||
securitySchemes: {}
|
Loading…
x
Reference in New Issue
Block a user