Skip to content
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

Improve Swagger typings for getAll #622

Merged
merged 2 commits into from
Sep 10, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,6 @@ private void BuildJSON() {
try {
initSwagger();
addPaths();
addDefaultDefinitions();
// addSubclassOperations(); //FIXME uncomment after fixing the method
}
catch (Exception e) {
Expand Down Expand Up @@ -253,7 +252,7 @@ private boolean testOperationImplemented(OperationEnum operation, DelegatingReso
if (method == null) {
return false;
} else {
method.invoke(resourceHandler, new RequestContext());
method.invoke(resourceHandler, RestConstants.SWAGGER_IMPOSSIBLE_UNIQUE_ID, new RequestContext());
}

break;
Expand Down Expand Up @@ -1069,7 +1068,10 @@ private Operation createOperation(DelegatingResourceHandler<?> resourceHandler,

operation.setSummary("Fetch all non-retired");
operation.setOperationId("getAll" + getOperationTitle(resourceHandler, true));
operation.addResponse("200", response200.schema(new RefProperty("#/definitions/FetchAll")));
operation.addResponse("200",
response200.schema(new ArrayProperty(
new RefProperty(getSchemaRef(resourceName, resourceParentName, OperationEnum.get)))));
Comment on lines +1071 to +1073
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not deeply familiar with Swagger. Could you leave a comment with a brief description of how this changes things? Is it replacing the definition of the return value with something that matches the GET request?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Currently, the getAll operation on a resouce is not properly typed in swagger. It returns a generic type called FetchAll, which has no typing information of the actual array being returned. (For example, getAll on patients should return PatientGet[]). This change should fix that.

Here's the typing for getAll on Patient currently:
image


operation.setParameters(buildPagingParameters());
operation.parameter(v);
if (((BaseDelegatingResource<?>) resourceHandler).hasTypesDefined()) {
Expand Down
Loading