Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move applySchemaResolution check to a method #4791

Merged
merged 1 commit into from
Nov 20, 2024
Merged
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 @@ -140,12 +140,6 @@ public ObjectMapper objectMapper() {

@Override
public Schema resolve(AnnotatedType annotatedType, ModelConverterContext context, Iterator<ModelConverter> next) {


boolean applySchemaResolution =
!openapi31 ||
(Boolean.parseBoolean(System.getProperty(Schema.APPLY_SCHEMA_RESOLUTION_PROPERTY, "false")) ||
Boolean.parseBoolean(System.getenv(Schema.APPLY_SCHEMA_RESOLUTION_PROPERTY)));
boolean isPrimitive = false;
Schema model = null;
List<String> requiredProps = new ArrayList<>();
Expand Down Expand Up @@ -477,7 +471,7 @@ public Schema resolve(AnnotatedType annotatedType, ModelConverterContext context
}
if (isObjectSchema(addPropertiesSchema) && pName != null) {
if (context.getDefinedModels().containsKey(pName)) {
if (Schema.SchemaResolution.INLINE.equals(containerResolvedSchemaResolution) && applySchemaResolution) {
if (Schema.SchemaResolution.INLINE.equals(containerResolvedSchemaResolution) && applySchemaResolution()) {
addPropertiesSchema = context.getDefinedModels().get(pName);
} else {
// create a reference for the items
Expand Down Expand Up @@ -529,7 +523,7 @@ public Schema resolve(AnnotatedType annotatedType, ModelConverterContext context
}
if (isObjectSchema(items) && pName != null) {
if (context.getDefinedModels().containsKey(pName)) {
if (Schema.SchemaResolution.INLINE.equals(containerResolvedSchemaResolution) && applySchemaResolution) {
if (Schema.SchemaResolution.INLINE.equals(containerResolvedSchemaResolution) && applySchemaResolution()) {
items = context.getDefinedModels().get(pName);
} else {
// create a reference for the items
Expand Down Expand Up @@ -751,7 +745,7 @@ public Schema resolve(AnnotatedType annotatedType, ModelConverterContext context
property = context.resolve(aType);
property = clone(property);
Schema ctxProperty = null;
if (!applySchemaResolution) {
if (!applySchemaResolution()) {
Optional<Schema> reResolvedProperty = AnnotationsUtils.getSchemaFromAnnotation(ctxSchema, annotatedType.getComponents(), null, openapi31, property, schemaResolution, context);
if (reResolvedProperty.isPresent()) {
property = reResolvedProperty.get();
Expand Down Expand Up @@ -835,7 +829,7 @@ public Schema resolve(AnnotatedType annotatedType, ModelConverterContext context
}
}
} else if (property.get$ref() != null) {
if (applySchemaResolution) {
if (applySchemaResolution()) {
if (Schema.SchemaResolution.ALL_OF.equals(resolvedSchemaResolution) && ctxProperty != null) {
property = new Schema()
.addAllOfItem(ctxProperty)
Expand Down Expand Up @@ -3126,4 +3120,10 @@ protected Schema buildRefSchemaIfObject(Schema schema, ModelConverterContext con
}
return result;
}

protected boolean applySchemaResolution() {
return !openapi31 ||
(Boolean.parseBoolean(System.getProperty(Schema.APPLY_SCHEMA_RESOLUTION_PROPERTY, "false")) ||
Boolean.parseBoolean(System.getenv(Schema.APPLY_SCHEMA_RESOLUTION_PROPERTY)));
}
}
Loading