Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ public Schema resolve(AnnotatedType type) {
processedTypes.add(type);
}
if (LOGGER.isDebugEnabled()) {
LOGGER.debug(String.format("resolve %s", type.getType()));
LOGGER.debug(String.format("resolve %s from %s", type.getType(), System.identityHashCode(this)));
}
Iterator<ModelConverter> converters = this.getConverters();
Schema resolved = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -821,7 +821,7 @@ public Schema resolve(AnnotatedType annotatedType, ModelConverterContext context
property = reResolvedProperty.get();
}

reResolvedProperty = resolveArraySchemaWithCycleGuard(ctxArraySchema, annotatedType, openapi31, property);
reResolvedProperty = resolveArraySchemaWithCycleGuard(ctxArraySchema, annotatedType, openapi31, property, context);
if (reResolvedProperty.isPresent()) {
property = reResolvedProperty.get();
}
Expand Down Expand Up @@ -3547,15 +3547,15 @@ private Optional<Schema> resolveArraySchemaWithCycleGuard(
io.swagger.v3.oas.annotations.media.ArraySchema ctxArraySchema,
AnnotatedType annotatedType,
boolean openapi31,
Schema<?> property) {
Schema<?> property, ModelConverterContext context) {
boolean processSchemaImplementation = !typesBeingResolved.contains(annotatedType);
Optional<Schema> reResolvedProperty;
if (processSchemaImplementation) {
typesBeingResolved.add(annotatedType);
}
try {
reResolvedProperty = AnnotationsUtils.getArraySchema(ctxArraySchema, annotatedType.getComponents(), null,
openapi31, property, processSchemaImplementation);
openapi31, property, processSchemaImplementation, context);
} finally {
if (processSchemaImplementation) {
typesBeingResolved.remove(annotatedType);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -493,6 +493,10 @@ public static Optional<Schema> getArraySchema(io.swagger.v3.oas.annotations.medi
}

public static Optional<Schema> getArraySchema(io.swagger.v3.oas.annotations.media.ArraySchema arraySchema, Components components, JsonView jsonViewAnnotation, boolean openapi31, Schema existingSchema, boolean processSchemaImplementation) {
return getArraySchema(arraySchema, components, jsonViewAnnotation, openapi31, existingSchema, processSchemaImplementation, null);
}

public static Optional<Schema> getArraySchema(io.swagger.v3.oas.annotations.media.ArraySchema arraySchema, Components components, JsonView jsonViewAnnotation, boolean openapi31, Schema existingSchema, boolean processSchemaImplementation, ModelConverterContext context) {
if (arraySchema == null || !hasArrayAnnotation(arraySchema)) {
if (existingSchema == null) {
return Optional.empty();
Expand Down Expand Up @@ -525,8 +529,8 @@ public static Optional<Schema> getArraySchema(io.swagger.v3.oas.annotations.medi
arraySchemaObject.setMinItems(arraySchema.minItems());
}

getSchemaFromAnnotation(arraySchema.contains(), components, jsonViewAnnotation, openapi31).ifPresent(arraySchemaObject::setContains);
getSchemaFromAnnotation(arraySchema.unevaluatedItems(), components, jsonViewAnnotation, openapi31).ifPresent(arraySchemaObject::setUnevaluatedItems);
getSchemaFromAnnotation(arraySchema.contains(), components, jsonViewAnnotation, openapi31, null, context).ifPresent(arraySchemaObject::setContains);
getSchemaFromAnnotation(arraySchema.unevaluatedItems(), components, jsonViewAnnotation, openapi31, null, context).ifPresent(arraySchemaObject::setUnevaluatedItems);

if (arraySchema.maxContains() > 0) {
arraySchemaObject.setMaxContains(arraySchema.maxContains());
Expand All @@ -536,7 +540,7 @@ public static Optional<Schema> getArraySchema(io.swagger.v3.oas.annotations.medi
}
if (arraySchema.prefixItems().length > 0) {
for (io.swagger.v3.oas.annotations.media.Schema prefixItem : arraySchema.prefixItems()) {
getSchemaFromAnnotation(prefixItem, components, jsonViewAnnotation, openapi31).ifPresent(arraySchemaObject::addPrefixItem);
getSchemaFromAnnotation(prefixItem, components, jsonViewAnnotation, openapi31, null, context).ifPresent(arraySchemaObject::addPrefixItem);
}
}

Expand All @@ -550,10 +554,10 @@ public static Optional<Schema> getArraySchema(io.swagger.v3.oas.annotations.medi

if (arraySchema.schema() != null) {
if (arraySchema.schema().implementation().equals(Void.class)) {
getSchemaFromAnnotation(arraySchema.schema(), components, jsonViewAnnotation, openapi31, arraySchemaObject.getItems())
getSchemaFromAnnotation(arraySchema.schema(), components, jsonViewAnnotation, openapi31, arraySchemaObject.getItems(), context)
.ifPresent(arraySchemaObject::setItems);
} else if (processSchemaImplementation) {
getSchema(arraySchema.schema(), arraySchema, false, arraySchema.schema().implementation(), components, jsonViewAnnotation, openapi31)
getSchema(arraySchema.schema(), arraySchema, false, arraySchema.schema().implementation(), components, jsonViewAnnotation, openapi31, context)
.ifPresent(arraySchemaObject::setItems);
}
}
Expand Down Expand Up @@ -622,7 +626,7 @@ public static Optional<Schema> getSchemaFromAnnotation(
boolean openapi31,
Schema existingSchema,
ModelConverterContext context) {
return getSchemaFromAnnotation(schema, components, jsonViewAnnotation, openapi31, existingSchema, Schema.SchemaResolution.DEFAULT, null);
return getSchemaFromAnnotation(schema, components, jsonViewAnnotation, openapi31, existingSchema, Schema.SchemaResolution.DEFAULT, context);
}

public static Optional<Schema> getSchemaFromAnnotation(
Expand Down Expand Up @@ -1888,21 +1892,31 @@ public static Optional<? extends Schema> getSchema(io.swagger.v3.oas.annotations
return getSchema(schemaAnnotation, arrayAnnotation, isArray, schemaImplementation, components, jsonViewAnnotation, false);

}

public static Optional<? extends Schema> getSchema(io.swagger.v3.oas.annotations.media.Schema schemaAnnotation,
io.swagger.v3.oas.annotations.media.ArraySchema arrayAnnotation,
boolean isArray,
Class<?> schemaImplementation,
Components components,
JsonView jsonViewAnnotation,
boolean openapi31) {
return getSchema(schemaAnnotation, arrayAnnotation, isArray, schemaImplementation, components, jsonViewAnnotation, openapi31, null);
}

public static Optional<? extends Schema> getSchema(io.swagger.v3.oas.annotations.media.Schema schemaAnnotation,
io.swagger.v3.oas.annotations.media.ArraySchema arrayAnnotation,
boolean isArray,
Class<?> schemaImplementation,
Components components,
JsonView jsonViewAnnotation,
boolean openapi31,
ModelConverterContext context) {
if (schemaImplementation != Void.class) {
Schema schemaObject = resolveSchemaFromType(schemaImplementation, components, jsonViewAnnotation, openapi31, schemaAnnotation, arrayAnnotation, null);
Schema schemaObject = resolveSchemaFromType(schemaImplementation, components, jsonViewAnnotation, openapi31, schemaAnnotation, arrayAnnotation, context);
if (StringUtils.isNotBlank(schemaAnnotation.format())) {
schemaObject.setFormat(schemaAnnotation.format());
}
if (isArray) {
Optional<Schema> arraySchema = AnnotationsUtils.getArraySchema(arrayAnnotation, components, jsonViewAnnotation, openapi31, null);
Optional<Schema> arraySchema = AnnotationsUtils.getArraySchema(arrayAnnotation, components, jsonViewAnnotation, openapi31, null, false, context);
if (arraySchema.isPresent()) {
arraySchema.get().setItems(schemaObject);
return arraySchema;
Expand All @@ -1914,15 +1928,15 @@ public static Optional<? extends Schema> getSchema(io.swagger.v3.oas.annotations
}

} else {
Optional<Schema> schemaFromAnnotation = AnnotationsUtils.getSchemaFromAnnotation(schemaAnnotation, components, jsonViewAnnotation, openapi31);
Optional<Schema> schemaFromAnnotation = AnnotationsUtils.getSchemaFromAnnotation(schemaAnnotation, components, jsonViewAnnotation, openapi31, null, context);
if (schemaFromAnnotation.isPresent()) {
if (StringUtils.isBlank(schemaFromAnnotation.get().get$ref()) && StringUtils.isBlank(schemaFromAnnotation.get().getType()) && !(schemaFromAnnotation.get() instanceof ComposedSchema)) {
// default to string
schemaFromAnnotation.get().setType("string");
}
return Optional.of(schemaFromAnnotation.get());
} else {
Optional<Schema> arraySchemaFromAnnotation = AnnotationsUtils.getArraySchema(arrayAnnotation, components, jsonViewAnnotation, openapi31, null);
Optional<Schema> arraySchemaFromAnnotation = AnnotationsUtils.getArraySchema(arrayAnnotation, components, jsonViewAnnotation, openapi31, null, false, context);
if (arraySchemaFromAnnotation.isPresent()) {
if (arraySchemaFromAnnotation.get().getItems() != null && StringUtils.isBlank(arraySchemaFromAnnotation.get().getItems().get$ref()) && StringUtils.isBlank(arraySchemaFromAnnotation.get().getItems().getType())) {
// default to string
Expand Down
Loading
Loading