Skip to content

Commit 9e51816

Browse files
author
Matheus Cruz
committed
Add documentation
1 parent 84ea10a commit 9e51816

File tree

5 files changed

+88
-20
lines changed

5 files changed

+88
-20
lines changed
Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,37 @@
11
package io.quarkiverse.openapi.moqu;
22

3+
import io.quarkiverse.openapi.moqu.model.RequestResponsePair;
4+
35
import java.util.ArrayList;
46
import java.util.Collections;
57
import java.util.List;
68
import java.util.Objects;
79

8-
import io.quarkiverse.openapi.moqu.model.RequestResponsePair;
9-
import io.quarkiverse.openapi.moqu.model.Request;
10-
import io.quarkiverse.openapi.moqu.model.Response;
11-
1210
/**
13-
* Moqu represents all {@link Request} and {@link Response}
14-
* pair list.
11+
* Represents a collection of request-response pairs, providing methods to access
12+
* these pairs in an immutable list.
1513
*/
1614
public class Moqu {
1715

1816
private List<RequestResponsePair> requestResponsePairs = new ArrayList<>();
1917

18+
/**
19+
* Constructs a {@code Moqu} instance with the provided list of request-response pairs.
20+
*
21+
* @param requestResponsePairs the list of {@link RequestResponsePair} objects to initialize
22+
* the collection. Must not be {@code null}.
23+
* @throws NullPointerException if {@code requestResponsePairs} is null.
24+
*/
2025
public Moqu(List<RequestResponsePair> requestResponsePairs) {
2126
this.requestResponsePairs = Objects.requireNonNull(requestResponsePairs);
2227
}
2328

29+
/**
30+
* Returns an unmodifiable list of request-response pairs.
31+
*
32+
* @return an immutable list of {@link RequestResponsePair}.
33+
*/
2434
public List<RequestResponsePair> getRequestResponsePairs() {
2535
return Collections.unmodifiableList(requestResponsePairs);
2636
}
27-
}
37+
}
Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,17 @@
11
package io.quarkiverse.openapi.moqu;
22

33
/**
4-
* {@link MoquImporter} aims to convert an specification {@link Moqu} model.
4+
* {@link MoquImporter} aims to convert a specification into a {@link Moqu} model.
5+
* It provides a method to parse the content, typically from an OpenAPI specification,
6+
* and generate a corresponding {@link Moqu} instance.
57
*/
68
public interface MoquImporter {
79

810
/**
9-
* @param content OpenAPI content
10-
* @return A new {@link Moqu} instance
11+
* Parses the provided OpenAPI content and generates a new {@link Moqu} instance.
12+
*
13+
* @param content the OpenAPI content as a string, which will be parsed into a {@link Moqu} model.
14+
* @return a new {@link Moqu} instance based on the provided content.
1115
*/
1216
Moqu parse(String content);
13-
}
17+
}

moqu/core/src/main/java/io/quarkiverse/openapi/moqu/MoquMapper.java

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,18 @@
22

33
import java.util.List;
44

5+
/**
6+
* A generic interface for mapping a {@link Moqu} instance to a list of objects of type {@code T}.
7+
*
8+
* @param <T> the type of objects to which the {@link Moqu} instance will be mapped.
9+
*/
510
public interface MoquMapper<T> {
611

7-
List<T> map(Moqu mock);
8-
}
12+
/**
13+
* Maps the given {@link Moqu} instance to a list of objects of type {@code T}.
14+
*
15+
* @param moqu the {@link Moqu} instance to be mapped.
16+
* @return a list of mapped objects of type {@code T}.
17+
*/
18+
List<T> map(Moqu moqu);
19+
}
Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,43 @@
11
package io.quarkiverse.openapi.moqu;
22

3+
/**
4+
* Enum representing the type of a parameter in an HTTP request, indicating its location.
5+
* The parameter can be part of the path, query string, or headers.
6+
*/
37
public enum ParameterType {
8+
9+
/**
10+
* Indicates that the parameter is part of the URL path.
11+
*/
412
PATH("path"),
13+
14+
/**
15+
* Indicates that the parameter is part of the query string.
16+
*/
517
QUERY("query"),
18+
19+
/**
20+
* Indicates that the parameter is part of the HTTP headers.
21+
*/
622
HEADER("header");
723

824
private final String value;
925

26+
/**
27+
* Constructs a {@code ParameterType} with the given string value representing the parameter location.
28+
*
29+
* @param value the string value corresponding to the parameter type.
30+
*/
1031
ParameterType(String value) {
1132
this.value = value;
1233
}
1334

35+
/**
36+
* Returns the string value associated with this {@code ParameterType}.
37+
*
38+
* @return the string representation of the parameter type.
39+
*/
1440
public String value() {
1541
return this.value;
1642
}
17-
}
43+
}

moqu/core/src/main/java/io/quarkiverse/openapi/moqu/SchemaReader.java

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,31 @@
11
package io.quarkiverse.openapi.moqu;
22

3-
import static io.swagger.v3.parser.util.SchemaTypeUtil.OBJECT_TYPE;
3+
import com.fasterxml.jackson.core.JsonProcessingException;
4+
import io.quarkiverse.openapi.moqu.marshall.ObjectMapperFactory;
5+
import io.swagger.v3.oas.models.media.Schema;
46

57
import java.util.HashMap;
68
import java.util.Map;
79
import java.util.Optional;
810

9-
import com.fasterxml.jackson.core.JsonProcessingException;
10-
11-
import io.quarkiverse.openapi.moqu.marshall.ObjectMapperFactory;
12-
import io.swagger.v3.oas.models.media.Schema;
11+
import static io.swagger.v3.parser.util.SchemaTypeUtil.OBJECT_TYPE;
1312

13+
/**
14+
* Utility class for reading schema examples and converting them into JSON representations.
15+
* This class provides methods to extract example data from a given schema and serialize it
16+
* into JSON format.
17+
*/
1418
public class SchemaReader {
1519

1620
static String EMPTY_JSON_OBJECT = "{}";
1721

22+
/**
23+
* Reads the example object from the provided schema and converts it to a JSON string.
24+
*
25+
* @param schema the schema from which to extract the example object.
26+
* @return a JSON string representation of the example object, or an empty JSON object
27+
* if an error occurs during processing.
28+
*/
1829
static String readObjectExample(Schema<?> schema) {
1930
try {
2031
Map<String, Object> map = mapObjectExample(schema);
@@ -24,6 +35,12 @@ static String readObjectExample(Schema<?> schema) {
2435
}
2536
}
2637

38+
/**
39+
* Recursively maps the properties of the provided schema to a map.
40+
*
41+
* @param schema the schema from which to map properties.
42+
* @return a map representing the example properties of the schema.
43+
*/
2744
private static Map<String, Object> mapObjectExample(Schema<?> schema) {
2845
Map<String, Object> currentRoot = new HashMap<>();
2946

@@ -43,4 +60,4 @@ private static Map<String, Object> mapObjectExample(Schema<?> schema) {
4360

4461
return currentRoot;
4562
}
46-
}
63+
}

0 commit comments

Comments
 (0)