Skip to content

Commit

Permalink
Fix openpai generation bug when api has only one exception
Browse files Browse the repository at this point in the history
  • Loading branch information
babyfish-ct committed Jan 9, 2024
1 parent 9571cf2 commit ab36bab
Show file tree
Hide file tree
Showing 7 changed files with 60 additions and 4 deletions.
2 changes: 1 addition & 1 deletion project/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
allprojects {
group = "org.babyfish.jimmer"
version = "0.8.76"
version = "0.8.77"
}
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ private void generateResponses(Operation operation, YmlWriter writer) {
writer.object("application/json", () -> {
writer.object("schema", () -> {
if (exceptionTypes.size() == 1) {
generateType(operation.getReturnType(), writer);
generateType(exceptionTypes.get(0), writer);
} else {
writer.list("oneOf", () -> {
for (ObjectType exceptionType : exceptionTypes) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -942,8 +942,29 @@ public void testTreeService() {
" application/json:\n" +
" schema:\n" +
" $ref: '#/components/schemas/Tree_String'\n" +
" 500:\n" +
" description: ERROR\n" +
" content:\n" +
" application/json:\n" +
" schema:\n" +
" $ref: '#/components/schemas/DepthTooBigException'\n" +
"components:\n" +
" schemas:\n" +
" DepthTooBigException:\n" +
" type: object\n" +
" properties:\n" +
" family:\n" +
" type: string\n" +
" enum: [DEFAULT]\n" +
" code:\n" +
" type: string\n" +
" enum: [DEPTH_TOO_BIG]\n" +
" maxDepth:\n" +
" type: integer\n" +
" format: int32\n" +
" currentDepth:\n" +
" type: integer\n" +
" format: int32\n" +
" SimpleTreeNodeView:\n" +
" type: object\n" +
" description: The tree node input defined by DTO language\n" +
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package org.babyfish.jimmer.client.java.service;

import org.babyfish.jimmer.error.CodeBasedException;
import org.babyfish.jimmer.internal.ClientException;

@ClientException(code = "DEPTH_TOO_BIG")
public class DepthTooBigException extends CodeBasedException {

private final int maxDepth;

private final int currentDepth;

public DepthTooBigException(int maxDepth, int currentDepth) {
this.maxDepth = maxDepth;
this.currentDepth = currentDepth;
}

public int getMaxDepth() {
return maxDepth;
}

public int getCurrentDepth() {
return currentDepth;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ Tree<Integer> getNumberTree(
Tree<String> getStringTree(
@RequestParam Integer depth,
@RequestParam Integer breadth
);
) throws DepthTooBigException;

/**
* Create query recursive tree roots by optional node name.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,11 @@ public void testApiErrors() {
" family: 'SAVE_COMMAND', \n" +
" code: 'UNSTRUCTURED_ASSOCIATION', \n" +
" exportedPath: ExportedSavePath\n" +
" } | {\n" +
" family: 'DEFAULT', \n" +
" code: 'DEPTH_TOO_BIG', \n" +
" maxDepth: number, \n" +
" currentDepth: number\n" +
" };\n" +
"export type ApiErrors = {\n" +
" 'bookService': {\n" +
Expand Down Expand Up @@ -243,6 +248,11 @@ public void testApiErrors() {
" })\n" +
" }, \n" +
" 'treeService': {\n" +
" 'getStringTree': AllErrors & ({\n" +
" family: 'DEFAULT', \n" +
" code: 'DEPTH_TOO_BIG', \n" +
" readonly [key:string]: any\n" +
" })\n" +
" }\n" +
"};\n",
writer.toString()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
public class JimmerVersion {

public static final JimmerVersion CURRENT =
new JimmerVersion(0, 8, 76);
new JimmerVersion(0, 8, 77);

private final int major;

Expand Down

0 comments on commit ab36bab

Please sign in to comment.