Skip to content

Commit

Permalink
[jsonschema2adoc] enable to use items.ref when there is no id for arr…
Browse files Browse the repository at this point in the history
…ay level
  • Loading branch information
rmannibucau committed May 20, 2023
1 parent 7850eef commit 2617748
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import java.util.function.Predicate;

import static java.util.Objects.requireNonNull;
import static java.util.Optional.empty;
import static java.util.Optional.ofNullable;

public class JsonSchema2AdocGenerator implements Runnable {
Expand Down Expand Up @@ -89,7 +90,12 @@ protected ForceEmptyMetaJsonSchema2Adoc(final String levelPrefix, final Schema r
@Override
public void prepare(final Schema in) {
if (in.getTitle() == null) {
in.setTitle(ofNullable(in.getId()).orElse("Model"));
in.setTitle(ofNullable(in.getId())
.or(() -> in.getType() == Schema.SchemaType.array && in.getItems() != null ?
ofNullable(in.getItems().getRef())
.map(it -> it.replace("#/schemas/", "")) :
empty())
.orElse("Model"));
}
if (in.getDescription() == null) {
in.setDescription("");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,10 +76,10 @@ void run(@TempDir final Path work) throws IOException {
"|===\n" +
"\n" +
"[#io.yupiik.test.MyObject]\n" +
"== Model\n" +
"== io.yupiik.test.MyObject\n" +
"\n" +
"[cols=\"2,2m,1,5\", options=\"header\"]\n" +
".Model\n" +
".io.yupiik.test.MyObject\n" +
"|===\n" +
"|Name|JSON Name|Type|Description\n" +
"|name|name|string|-\n" +
Expand Down

0 comments on commit 2617748

Please sign in to comment.