Skip to content

Commit 3dba5e6

Browse files
committed
SpringDocUI doest add Javadoc into swagger from abstract class. FIXES #2744
1 parent 286cb0d commit 3dba5e6

File tree

9 files changed

+408
-82
lines changed

9 files changed

+408
-82
lines changed

Diff for: springdoc-openapi-starter-common/src/main/java/org/springdoc/core/configuration/SpringDocJavadocConfiguration.java

+3
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@
3838
import org.springframework.context.annotation.Bean;
3939
import org.springframework.context.annotation.Configuration;
4040
import org.springframework.context.annotation.Lazy;
41+
import org.springframework.core.Ordered;
42+
import org.springframework.core.annotation.Order;
4143

4244
/**
4345
* The type Spring doc security configuration.
@@ -73,6 +75,7 @@ SpringDocJavadocProvider springDocJavadocProvider() {
7375
@Bean
7476
@ConditionalOnMissingBean
7577
@Lazy(false)
78+
@Order(Ordered.HIGHEST_PRECEDENCE)
7679
JavadocPropertyCustomizer javadocPropertyCustomizer(JavadocProvider javadocProvider, ObjectMapperProvider objectMapperProvider) {
7780
return new JavadocPropertyCustomizer(javadocProvider, objectMapperProvider);
7881
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package test.org.springdoc.api.app174;
2+
3+
import org.springframework.web.bind.annotation.PostMapping;
4+
import org.springframework.web.bind.annotation.RestController;
5+
6+
/**
7+
* The Example Controller
8+
*/
9+
@RestController
10+
public class ExampleController {
11+
12+
@PostMapping
13+
public Test post(){
14+
return null;
15+
}
16+
17+
}
18+
19+
20+
21+
22+
23+
24+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
package test.org.springdoc.api.app174;
2+
3+
import com.fasterxml.jackson.annotation.JsonSubTypes;
4+
import com.fasterxml.jackson.annotation.JsonTypeInfo;
5+
6+
/**
7+
* The type Question.
8+
*
9+
* @author bnasslahsen base class for all questions in test with polymorphism
10+
*/
11+
@JsonTypeInfo(
12+
use = JsonTypeInfo.Id.NAME,
13+
property = "type")
14+
@JsonSubTypes({
15+
@JsonSubTypes.Type(value = TestQuestion.class, name = "test"),
16+
@JsonSubTypes.Type(value = TextQuestion.class, name = "text")
17+
})
18+
public abstract class Question {
19+
private final String question;
20+
private final String type;
21+
22+
public Question(String question, String type) {
23+
this.question = question;
24+
this.type = type;
25+
}
26+
27+
public String getQuestion() {
28+
return question;
29+
}
30+
31+
public String getType() {
32+
return type;
33+
}
34+
35+
@Override
36+
public String toString() {
37+
return "Question{" +
38+
"question='" + question + '\'' +
39+
", type='" + type + '\'' +
40+
'}';
41+
}
42+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package test.org.springdoc.api.app174;
2+
3+
import test.org.springdoc.api.AbstractSpringDocTest;
4+
5+
import org.springframework.boot.autoconfigure.SpringBootApplication;
6+
7+
/**
8+
* The type Spring doc app 174 test.
9+
*/
10+
public class SpringDocApp174Test extends AbstractSpringDocTest {
11+
12+
/**
13+
* The type Spring doc test app.
14+
*/
15+
@SpringBootApplication
16+
static class SpringDocTestApp {
17+
}
18+
19+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
package test.org.springdoc.api.app174;
2+
3+
import java.io.Serializable;
4+
import java.util.List;
5+
6+
/**
7+
* The type Test.
8+
*
9+
* @author bnasslahsen
10+
*/
11+
12+
public class Test implements Serializable {
13+
14+
private static final long serialVersionUID = 1L; // Recommended for Serializable classes
15+
16+
private List<Question> questions;
17+
18+
// No-argument constructor
19+
public Test() {
20+
}
21+
22+
// Constructor with arguments
23+
public Test(List<Question> questions) {
24+
this.questions = questions;
25+
}
26+
27+
// Getter method for 'questions'
28+
public List<Question> getQuestions() {
29+
return questions;
30+
}
31+
32+
// Setter method for 'questions'
33+
public void setQuestions(List<Question> questions) {
34+
this.questions = questions;
35+
}
36+
37+
// Optionally, you can override toString, hashCode, equals, etc.
38+
@Override
39+
public String toString() {
40+
return "Test{" +
41+
"questions=" + questions +
42+
'}';
43+
}
44+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
package test.org.springdoc.api.app174;
2+
3+
import java.util.List;
4+
5+
/**
6+
* The type Test question.
7+
*
8+
* @author bnasslahsen test question
9+
*/
10+
public class TestQuestion extends Question {
11+
/**
12+
* list of variants
13+
*/
14+
private final List<String> variants;
15+
/**
16+
* correct answer
17+
*/
18+
private final int answer;
19+
20+
public TestQuestion(String question, String type, List<String> variants, int answer) {
21+
super(question, type);
22+
this.variants = variants;
23+
this.answer = answer;
24+
}
25+
26+
public List<String> getVariants() {
27+
return variants;
28+
}
29+
30+
public int getAnswer() {
31+
return answer;
32+
}
33+
34+
@Override
35+
public String toString() {
36+
return "TestQuestion{" +
37+
"question='" + getQuestion() + '\'' +
38+
", variants=" + variants +
39+
", answer=" + answer +
40+
'}';
41+
}
42+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
package test.org.springdoc.api.app174;
2+
3+
/**
4+
* The type Text question.
5+
*
6+
* @author bnasslahsen
7+
*/
8+
public class TextQuestion extends Question {
9+
private final String answer;
10+
11+
public TextQuestion(String question, String type, String answer) {
12+
super(question, type);
13+
this.answer = answer;
14+
}
15+
16+
public String getAnswer() {
17+
return answer;
18+
}
19+
20+
@Override
21+
public String toString() {
22+
return "TextQuestion{" +
23+
"question='" + getQuestion() + '\'' +
24+
", type='" + getType() + '\'' +
25+
", answer='" + answer + '\'' +
26+
'}';
27+
}
28+
}

0 commit comments

Comments
 (0)