Skip to content

Commit 493125c

Browse files
committed
NPE when customizing group's open-api without specifying any schema. Fixes #2960
1 parent aeb5f51 commit 493125c

File tree

4 files changed

+35
-23
lines changed

4 files changed

+35
-23
lines changed

springdoc-openapi-starter-common/src/main/java/org/springdoc/core/customizers/SpecPropertiesCustomizer.java

+16-16
Original file line numberDiff line numberDiff line change
@@ -221,25 +221,25 @@ private void customizeComponents(OpenAPI openApi, Components componentsPropertie
221221
else {
222222
Map<String, Schema> schemaMap = components.getSchemas();
223223
schemaMap.forEach((key, schema) -> {
224-
Schema schemaProperties = componentsProperties.getSchemas().get(key);
225-
if (schemaProperties != null) {
226-
resolveString(schema::setDescription, schemaProperties::getDescription);
227-
Map<String, Schema> properties = schema.getProperties();
228-
if (CollectionUtils.isEmpty(properties)) {
229-
return;
230-
}
231-
properties.forEach((propKey, propSchema) -> {
232-
Schema propSchemaProperties = (Schema) schemaProperties.getProperties().get(propKey);
233-
if (propSchemaProperties != null) {
234-
resolveString(propSchema::description, propSchemaProperties::getDescription);
235-
resolveString(propSchema::title, propSchemaProperties::getTitle);
236-
resolveString(propSchema::example, propSchemaProperties::getExample);
224+
if(!CollectionUtils.isEmpty(componentsProperties.getSchemas())) {
225+
Schema schemaProperties = componentsProperties.getSchemas().get(key);
226+
if (schemaProperties != null) {
227+
resolveString(schema::setDescription, schemaProperties::getDescription);
228+
Map<String, Schema> properties = schema.getProperties();
229+
if (CollectionUtils.isEmpty(properties)) {
230+
return;
237231
}
238-
});
232+
properties.forEach((propKey, propSchema) -> {
233+
Schema propSchemaProperties = (Schema) schemaProperties.getProperties().get(propKey);
234+
if (propSchemaProperties != null) {
235+
resolveString(propSchema::description, propSchemaProperties::getDescription);
236+
resolveString(propSchema::title, propSchemaProperties::getTitle);
237+
resolveString(propSchema::example, propSchemaProperties::getExample);
238+
}
239+
});
240+
}
239241
}
240242
});
241-
242-
243243
Map<String, SecurityScheme> securitySchemeMap = components.getSecuritySchemes();
244244
if (CollectionUtils.isEmpty(securitySchemeMap)) {
245245
components.setSecuritySchemes(componentsProperties.getSecuritySchemes());

springdoc-openapi-starter-webmvc-api/src/test/resources/application-217.yml

+5-7
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,11 @@ springdoc:
1717
- url: "https://demo.example.com"
1818
description: "demo Server"
1919
components:
20-
schemas:
21-
PersonDTO:
22-
description: Description for PersonDTO component
23-
properties:
24-
name:
25-
description: Description for 'name' property
26-
example: Example value for 'name' property
20+
security-schemes:
21+
auth:
22+
type: http
23+
scheme: bearer
24+
bearer-format: JWT
2725
- group: user
2826
display-name: User Interfaces
2927
packages-to-scan:

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

+7
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,13 @@
5050
},
5151
"description": "Description for PersonDTO component"
5252
}
53+
},
54+
"securitySchemes": {
55+
"auth": {
56+
"type": "http",
57+
"scheme": "bearer",
58+
"bearerFormat": "JWT"
59+
}
5360
}
5461
}
5562
}

springdoc-openapi-starter-webmvc-api/src/test/resources/results/3.1.0/app217-1.json

+7
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,13 @@
5050
}
5151
}
5252
}
53+
},
54+
"securitySchemes": {
55+
"auth": {
56+
"type": "http",
57+
"scheme": "bearer",
58+
"bearerFormat": "JWT"
59+
}
5360
}
5461
}
5562
}

0 commit comments

Comments
 (0)