Skip to content

Commit 7e92afc

Browse files
committed
Springdoc does not resolve property descriptions for arrays. Fixes #2003
1 parent 588a1a2 commit 7e92afc

File tree

5 files changed

+32
-103
lines changed

5 files changed

+32
-103
lines changed

springdoc-openapi-starter-common/src/main/java/org/springdoc/core/service/OpenAPIService.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@
5858
import io.swagger.v3.oas.models.info.Contact;
5959
import io.swagger.v3.oas.models.info.Info;
6060
import io.swagger.v3.oas.models.info.License;
61+
import io.swagger.v3.oas.models.media.ArraySchema;
6162
import io.swagger.v3.oas.models.media.Schema;
6263
import io.swagger.v3.oas.models.security.SecurityScheme;
6364
import io.swagger.v3.oas.models.servers.Server;
@@ -470,6 +471,9 @@ public Schema resolveProperties(Schema schema, Locale locale) {
470471
if (!CollectionUtils.isEmpty(properties)) {
471472
LinkedHashMap<String, Schema> resolvedSchemas = properties.entrySet().stream().map(es -> {
472473
es.setValue(resolveProperties(es.getValue(), locale));
474+
if(es.getValue() instanceof ArraySchema arraySchema){
475+
resolveProperties(arraySchema.getItems(), locale);
476+
}
473477
return es;
474478
}).collect(Collectors.toMap(Entry::getKey, Entry::getValue, (e1, e2) -> e2,
475479
LinkedHashMap::new));

springdoc-openapi-starter-common/src/main/java/org/springdoc/core/utils/PropertyResolverUtils.java

Lines changed: 0 additions & 101 deletions
Original file line numberDiff line numberDiff line change
@@ -24,29 +24,15 @@
2424

2525
package org.springdoc.core.utils;
2626

27-
import java.util.LinkedHashMap;
28-
import java.util.List;
2927
import java.util.Locale;
30-
import java.util.Map;
31-
import java.util.Map.Entry;
32-
import java.util.function.Consumer;
33-
import java.util.function.Supplier;
34-
import java.util.stream.Collectors;
3528

36-
import io.swagger.v3.oas.models.info.Contact;
37-
import io.swagger.v3.oas.models.info.Info;
38-
import io.swagger.v3.oas.models.info.License;
39-
import io.swagger.v3.oas.models.media.Schema;
40-
import io.swagger.v3.oas.models.servers.Server;
41-
import org.apache.commons.lang3.StringUtils;
4229
import org.slf4j.Logger;
4330
import org.slf4j.LoggerFactory;
4431
import org.springdoc.core.properties.SpringDocConfigProperties;
4532

4633
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
4734
import org.springframework.context.MessageSource;
4835
import org.springframework.context.NoSuchMessageException;
49-
import org.springframework.util.CollectionUtils;
5036

5137
/**
5238
* The type Property resolver utils.
@@ -115,93 +101,6 @@ public String resolve(String parameterProperty, Locale locale) {
115101
return result;
116102
}
117103

118-
/**
119-
* Resolve properties info.
120-
*
121-
* @param servers the servers
122-
* @param locale the locale
123-
* @return the servers
124-
*/
125-
public List<Server> resolveProperties(List<Server> servers, Locale locale) {
126-
servers.forEach(server -> {
127-
resolveProperty(server::getUrl, server::url, this, locale);
128-
resolveProperty(server::getDescription, server::description, this, locale);
129-
if (CollectionUtils.isEmpty(server.getVariables()))
130-
server.setVariables(null);
131-
});
132-
return servers;
133-
}
134-
135-
/**
136-
* Resolve properties info.
137-
*
138-
* @param info the info
139-
* @param locale the locale
140-
* @return the info
141-
*/
142-
public Info resolveProperties(Info info, Locale locale) {
143-
resolveProperty(info::getTitle, info::title, this, locale);
144-
resolveProperty(info::getDescription, info::description, this, locale);
145-
resolveProperty(info::getVersion, info::version, this, locale);
146-
resolveProperty(info::getTermsOfService, info::termsOfService, this, locale);
147-
148-
License license = info.getLicense();
149-
if (license != null) {
150-
resolveProperty(license::getName, license::name, this, locale);
151-
resolveProperty(license::getUrl, license::url, this, locale);
152-
}
153-
154-
Contact contact = info.getContact();
155-
if (contact != null) {
156-
resolveProperty(contact::getName, contact::name, this, locale);
157-
resolveProperty(contact::getEmail, contact::email, this, locale);
158-
resolveProperty(contact::getUrl, contact::url, this, locale);
159-
}
160-
return info;
161-
}
162-
163-
/**
164-
* Resolve properties schema.
165-
*
166-
* @param schema the schema
167-
* @param locale the locale
168-
* @return the schema
169-
*/
170-
@SuppressWarnings("unchecked")
171-
public Schema resolveProperties(Schema<?> schema, Locale locale) {
172-
resolveProperty(schema::getName, schema::name, this, locale);
173-
resolveProperty(schema::getTitle, schema::title, this, locale);
174-
resolveProperty(schema::getDescription, schema::description, this, locale);
175-
176-
Map<String, Schema> properties = schema.getProperties();
177-
if (!CollectionUtils.isEmpty(properties)) {
178-
LinkedHashMap<String, Schema> resolvedSchemas = properties.entrySet().stream().map(es -> {
179-
es.setValue(resolveProperties(es.getValue(), locale));
180-
return es;
181-
}).collect(Collectors.toMap(Entry::getKey, Entry::getValue, (e1, e2) -> e2,
182-
LinkedHashMap::new));
183-
schema.setProperties(resolvedSchemas);
184-
}
185-
186-
return schema;
187-
}
188-
189-
/**
190-
* Resolve property.
191-
*
192-
* @param getProperty the get property
193-
* @param setProperty the set property
194-
* @param propertyResolverUtils the property resolver utils
195-
* @param locale the locale
196-
*/
197-
private void resolveProperty(Supplier<String> getProperty, Consumer<String> setProperty,
198-
PropertyResolverUtils propertyResolverUtils, Locale locale) {
199-
String value = getProperty.get();
200-
if (StringUtils.isNotBlank(value)) {
201-
setProperty.accept(propertyResolverUtils.resolve(value, locale));
202-
}
203-
}
204-
205104
/**
206105
* Gets factory.
207106
*

springdoc-openapi-starter-webmvc-api/src/test/java/test/org/springdoc/api/v30/app164/SampleResponseClass.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,11 @@
2424

2525
package test.org.springdoc.api.v30.app164;
2626

27+
import java.util.List;
28+
29+
import io.swagger.v3.oas.annotations.media.ArraySchema;
30+
import io.swagger.v3.oas.annotations.media.Schema;
31+
2732
public class SampleResponseClass {
2833

2934
private String idAsFirstParameter;
@@ -34,6 +39,18 @@ public class SampleResponseClass {
3439

3540
private boolean booleanValueAsFourthParameter;
3641

42+
@ArraySchema( arraySchema = @Schema( description = "${blahDescription.value}" ),
43+
schema = @Schema( description = "${blahDescription.value}" ) )
44+
private List<String> listBlah;
45+
46+
public List<String> getListBlah() {
47+
return listBlah;
48+
}
49+
50+
public void setListBlah(List<String> listBlah) {
51+
this.listBlah = listBlah;
52+
}
53+
3754
public String getIdAsFirstParameter() {
3855
return idAsFirstParameter;
3956
}
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
spring.main.banner-mode=off
22
logging.level.root=OFF
3-
spring.main.lazy-initialization=true
3+
spring.main.lazy-initialization=true
4+
blahDescription.value=test

springdoc-openapi-starter-webmvc-api/src/test/resources/results/3.0.1/app164.json

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,17 @@
4848
},
4949
"booleanValueAsFourthParameter": {
5050
"type": "boolean"
51+
},
52+
"listBlah": {
53+
"type": "array",
54+
"description": "test",
55+
"items": {
56+
"type": "string",
57+
"description": "test"
58+
}
5159
}
5260
}
5361
}
5462
}
5563
}
56-
}
64+
}

0 commit comments

Comments
 (0)