Skip to content

Commit e470c21

Browse files
committed
Refactor Replace hardcoded schema prefix length
1 parent 71a0684 commit e470c21

File tree

3 files changed

+7
-6
lines changed

3 files changed

+7
-6
lines changed

Diff for: springdoc-openapi-starter-common/src/main/java/org/springdoc/core/customizers/JavadocPropertyCustomizer.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424

2525
package org.springdoc.core.customizers;
2626

27+
import io.swagger.v3.oas.models.Components;
2728
import java.beans.IntrospectionException;
2829
import java.beans.Introspector;
2930
import java.beans.PropertyDescriptor;
@@ -95,7 +96,7 @@ public Schema resolve(AnnotatedType type, ModelConverterContext context, Iterato
9596
setJavadocDescription(cls, fields, clsProperties, existingSchema, false);
9697
}
9798
else if (resolvedSchema != null && resolvedSchema.get$ref() != null && resolvedSchema.get$ref().contains(AnnotationsUtils.COMPONENTS_REF)) {
98-
String schemaName = resolvedSchema.get$ref().substring(21);
99+
String schemaName = resolvedSchema.get$ref().substring(Components.COMPONENTS_SCHEMAS_REF.length());
99100
Schema existingSchema = context.getDefinedModels().get(schemaName);
100101
setJavadocDescription(cls, fields, clsProperties, existingSchema, false);
101102
}

Diff for: springdoc-openapi-starter-common/src/main/java/org/springdoc/core/service/GenericParameterService.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -407,7 +407,7 @@ private Schema calculateRequestBodySchema(Components components, ParameterInfo p
407407
if (schemaN != null && StringUtils.isEmpty(schemaN.getDescription()) && parameterInfo.getParameterModel() != null) {
408408
String description = parameterInfo.getParameterModel().getDescription();
409409
if (schemaN.get$ref() != null && schemaN.get$ref().contains(AnnotationsUtils.COMPONENTS_REF)) {
410-
String key = schemaN.get$ref().substring(21);
410+
String key = schemaN.get$ref().substring(Components.COMPONENTS_SCHEMAS_REF.length());
411411
Schema existingSchema = components.getSchemas().get(key);
412412
if (!StringUtils.isEmpty(description))
413413
existingSchema.setDescription(description);

Diff for: springdoc-openapi-starter-common/src/main/java/org/springdoc/core/utils/SpringDocDataRestUtils.java

+4-4
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ private void updateApiResponse(OpenAPI openAPI, Components components, ApiRespon
161161
apiResponse.getContent().values().forEach(mediaType -> {
162162
Schema schema = mediaType.getSchema();
163163
if (schema.get$ref() != null && !schema.get$ref().endsWith(RESPONSE)) {
164-
String key = schema.get$ref().substring(21);
164+
String key = schema.get$ref().substring(Components.COMPONENTS_SCHEMAS_REF.length());
165165
Set<String> entitiesNames = entityInoMap.keySet();
166166
entitiesNames.forEach(entityName -> {
167167
if (key.endsWith(entityName))
@@ -184,7 +184,7 @@ private void updateRequestBody(OpenAPI openAPI, RequestBody requestBody, boolean
184184
requestBody.getContent().values().forEach(mediaType -> {
185185
Schema schema = mediaType.getSchema();
186186
if (schema.get$ref() != null && !schema.get$ref().endsWith(REQUEST_BODY)) {
187-
String key = schema.get$ref().substring(21);
187+
String key = schema.get$ref().substring(Components.COMPONENTS_SCHEMAS_REF.length());
188188
if (entityInoMap.containsKey(key))
189189
updateRequestBodySchema(key, schema, openAPI.getComponents(), openapi31);
190190
}
@@ -285,7 +285,7 @@ private void updateResponseSchemaEmbedded(Components components, EntityInfo enti
285285
Schema itemsSchema = arraySchema.getItems();
286286
Set<String> entitiesNames = entityInoMap.keySet();
287287
if (itemsSchema.get$ref() != null && !itemsSchema.get$ref().endsWith(RESPONSE)) {
288-
String key = itemsSchema.get$ref().substring(21);
288+
String key = itemsSchema.get$ref().substring(Components.COMPONENTS_SCHEMAS_REF.length());
289289
if (entitiesNames.contains(key)) {
290290
String newKey = itemsSchema.get$ref() + RESPONSE;
291291
createNewResponseSchema(key, components, openapi31);
@@ -380,7 +380,7 @@ private void updateKey(List<Schema> allSchemas, String suffix, Components compon
380380
if (!CollectionUtils.isEmpty(allSchemas))
381381
for (Schema allSchema : allSchemas) {
382382
if (allSchema.get$ref() != null) {
383-
String allKey = allSchema.get$ref().substring(21);
383+
String allKey = allSchema.get$ref().substring(Components.COMPONENTS_SCHEMAS_REF.length());
384384
updateSingleKey(suffix, components, allSchema, allKey, openapi31);
385385
}
386386
}

0 commit comments

Comments
 (0)