-
Notifications
You must be signed in to change notification settings - Fork 935
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Enable jsonschema support in debug page for annotated too #5253
base: main
Are you sure you want to change the base?
Changes from all commits
10d5da5
e6df943
5d0d9d5
d8af561
d871ee8
65d1278
8c7b3bd
b41f945
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -130,6 +130,7 @@ private ObjectNode generate(MethodInfo methodInfo) { | |||||
methodFields = ImmutableList.of(); | ||||||
} else { | ||||||
methodFields = structInfo.fields(); | ||||||
root.put("useParamaterAsRoot", true); | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
} | ||||||
visited.put(signature, currentPath); | ||||||
} else { | ||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -98,6 +98,27 @@ public MethodInfo(String serviceName, String name, | |
); | ||
} | ||
|
||
/** | ||
* Creates a new instance. | ||
*/ | ||
public MethodInfo(String serviceName, String name, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I have added yet more craziness to this file. Hopefully not for this PR, but probably need to get a builder in |
||
TypeSignature returnTypeSignature, | ||
Iterable<FieldInfo> parameters, | ||
boolean useParameterAsRoot, | ||
Iterable<TypeSignature> exceptionTypeSignatures, | ||
Iterable<EndpointInfo> endpoints, | ||
Iterable<HttpHeaders> exampleHeaders, | ||
Iterable<String> exampleRequests, | ||
Iterable<String> examplePaths, | ||
Iterable<String> exampleQueries, | ||
HttpMethod httpMethod, | ||
DescriptionInfo descriptionInfo) { | ||
this(name, returnTypeSignature, parameters, useParameterAsRoot, | ||
exceptionTypeSignatures, endpoints, exampleHeaders, | ||
exampleRequests, examplePaths, exampleQueries, httpMethod, descriptionInfo, | ||
createId(serviceName, name, 0, httpMethod)); | ||
} | ||
|
||
/** | ||
* Creates a new instance. | ||
*/ | ||
|
@@ -112,11 +133,12 @@ public MethodInfo(String serviceName, String name, | |
Iterable<String> examplePaths, | ||
Iterable<String> exampleQueries, | ||
HttpMethod httpMethod, | ||
DescriptionInfo descriptionInfo) { | ||
DescriptionInfo descriptionInfo, | ||
int overloadId) { | ||
this(name, returnTypeSignature, parameters, useParameterAsRoot, | ||
exceptionTypeSignatures, endpoints, exampleHeaders, | ||
exampleRequests, examplePaths, exampleQueries, httpMethod, descriptionInfo, | ||
createId(serviceName, name, 0, httpMethod)); | ||
createId(serviceName, name, overloadId, httpMethod)); | ||
} | ||
|
||
MethodInfo(String name, TypeSignature returnTypeSignature, | ||
|
@@ -130,7 +152,6 @@ public MethodInfo(String serviceName, String name, | |
|
||
this.returnTypeSignature = requireNonNull(returnTypeSignature, "returnTypeSignature"); | ||
this.parameters = ImmutableList.copyOf(requireNonNull(parameters, "parameters")); | ||
assert !useParameterAsRoot || this.parameters.size() == 1; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I could tweak the assertion to look for a single root parameter but it seemed like overkill There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Note: the following is also a valid method that has multiple resolvers, but uses headers/query params instead of the body to fill the bean. Since the last non-param/query will be used, in the worst case it is possible that wrong autocomplete/recommendations are done. @Post("/bean2")
public HttpResponse bean2(@RequestObject JsonRequest jsonRequest, CompositeBean compositeBean1) {
return HttpResponse.of("world");
} Having said this, I'm not sure if there is a non-trivial way to intelligently find the parameter that should be used as the body. |
||
this.useParameterAsRoot = useParameterAsRoot; | ||
|
||
this.exceptionTypeSignatures = | ||
|
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -55,12 +55,11 @@ const RequestBody: React.FunctionComponent<Props> = ({ | |||||
}) => { | ||||||
const monacoEditor = useMonaco(); | ||||||
|
||||||
const supportsJsonSchema = | ||||||
const forceJsonSchema = | ||||||
serviceType === ServiceType.GRPC || serviceType === ServiceType.THRIFT; | ||||||
useMemo(() => { | ||||||
if (supportsJsonSchema) { | ||||||
const schema = jsonSchemas.find((s: any) => s.$id === method.id) || {}; | ||||||
|
||||||
const hasJsonSchema = useMemo(() => { | ||||||
const schema = jsonSchemas.find((s: any) => s.$id === method.id); | ||||||
if (schema && (schema.useParamaterAsRoot || forceJsonSchema)) { | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
monacoEditor?.languages.json.jsonDefaults.setDiagnosticsOptions({ | ||||||
validate: true, | ||||||
schemas: [ | ||||||
|
@@ -71,12 +70,13 @@ const RequestBody: React.FunctionComponent<Props> = ({ | |||||
}, | ||||||
], | ||||||
}); | ||||||
} else { | ||||||
monacoEditor?.languages.json.jsonDefaults.setDiagnosticsOptions({ | ||||||
validate: false, | ||||||
}); | ||||||
return true; | ||||||
} | ||||||
}, [monacoEditor, jsonSchemas, method.id, supportsJsonSchema]); | ||||||
monacoEditor?.languages.json.jsonDefaults.setDiagnosticsOptions({ | ||||||
validate: false, | ||||||
}); | ||||||
return false; | ||||||
}, [monacoEditor, jsonSchemas, method.id, forceJsonSchema]); | ||||||
|
||||||
return ( | ||||||
<> | ||||||
|
@@ -109,7 +109,7 @@ const RequestBody: React.FunctionComponent<Props> = ({ | |||||
<Typography variant="body2" paragraph /> | ||||||
<Editor | ||||||
height="30vh" | ||||||
language={supportsJsonSchema ? 'json' : undefined} | ||||||
language={hasJsonSchema ? 'json' : undefined} | ||||||
theme="vs-light" | ||||||
options={{ | ||||||
minimap: { enabled: false }, | ||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.