Skip to content

Commit

Permalink
feat(orchestrator): add OpenAPI support (#1123)
Browse files Browse the repository at this point in the history
* Add generate-model to common

Signed-off-by: Gloria Ciavarrini <[email protected]>

* Add openapi spec and /oveview definition

Signed-off-by: Gloria Ciavarrini <[email protected]>

* Add generated models

Signed-off-by: Gloria Ciavarrini <[email protected]>

* Export generated types

Signed-off-by: Gloria Ciavarrini <[email protected]>

* Create openAPIBackend

Signed-off-by: Gloria Ciavarrini <[email protected]>

* Let OpenaAPIBackend handle requests

Signed-off-by: Gloria Ciavarrini <[email protected]>

* Comment api validation code block

Due to the simultaneous use of both v1 and v2, validation is
temporarily disabled. Enabling it results in an "operation unknown" error.
This change ensures smooth operation until v1 is no longer needed.

Signed-off-by: Gloria Ciavarrini <[email protected]>

* Move generated models to auto-generated dir

Signed-off-by: Gloria Ciavarrini <[email protected]>

* Fix openapi.yaml header

Signed-off-by: Gloria Ciavarrini <[email protected]>

* Fix: change folder for exported types

Signed-off-by: Gloria Ciavarrini <[email protected]>

* Fix tsc

Signed-off-by: Gloria Ciavarrini <[email protected]>

* Add generated schema into dist-type dir

tsc doens't copy d.ts files.
Rename the generated schema to .ts and move it inside src

Signed-off-by: Gloria Ciavarrini <[email protected]>

* Script to include openapi spec at build-time.

The sh script derives from notification-plugin[1]

[1] https://github.com/janus-idp/backstage-plugins/blob/main/plugins/notifications-backend/scripts/openapi.sh

Signed-off-by: Gloria Ciavarrini <[email protected]>

* Add openapi script in common package.json

Signed-off-by: Gloria Ciavarrini <[email protected]>

* Update backend dist-dynamic

Signed-off-by: Gloria Ciavarrini <[email protected]>

* Generate openapidocument.ts

Using `yarn openapi` command

Signed-off-by: Gloria Ciavarrini <[email protected]>

* Export openapidocument.ts

Signed-off-by: Gloria Ciavarrini <[email protected]>

* Implementation of workflow overview endpoints in handlers.ts

Signed-off-by: Gloria Ciavarrini <[email protected]>

* Use openapidocument instead of relative path

Signed-off-by: Gloria Ciavarrini <[email protected]>

* Implement v2 getWorkflowsOverview

Signed-off-by: Gloria Ciavarrini <[email protected]>

* Fix: Functions should not have too many parameters

According to SonarCloud "Function 'setupInternalRoutes' has too
many parameters (8). Maximum allowed is 7"

Signed-off-by: Gloria Ciavarrini <[email protected]>

* Reorganize openapi files

- Rename openapidocument.ts to definition.ts
- Move it into autogenerated folder
- Moved openapi.yaml into src to create a valid dist-type

Signed-off-by: Gloria Ciavarrini <[email protected]>

* Split handlers into v1 and v2

Organize endpoint implementations based on the API versions
for improved maintainability and clarity

Signed-off-by: Gloria Ciavarrini <[email protected]>

* Refactor initialization of OpenAPIBackend

Signed-off-by: Gloria Ciavarrini <[email protected]>

* Remove handler definiion in OpenAPIBackend

Signed-off-by: Gloria Ciavarrini <[email protected]>

---------

Signed-off-by: Gloria Ciavarrini <[email protected]>
  • Loading branch information
gciavarrini authored Feb 15, 2024
1 parent db59c91 commit bd88e23
Show file tree
Hide file tree
Showing 13 changed files with 653 additions and 143 deletions.
1 change: 1 addition & 0 deletions plugins/orchestrator-backend/dist-dynamic/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@
"express-promise-router": "^4.1.1",
"fs-extra": "^10.1.0",
"json-schema": "^0.4.0",
"openapi-backend": "^5.10.5",
"openapi-types": "^12.1.3",
"winston": "^3.11.0",
"yn": "^5.0.0",
Expand Down
280 changes: 198 additions & 82 deletions plugins/orchestrator-backend/dist-dynamic/yarn.lock

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions plugins/orchestrator-backend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@
"express-promise-router": "^4.1.1",
"fs-extra": "^10.1.0",
"json-schema": "^0.4.0",
"openapi-backend": "^5.10.5",
"openapi-types": "^12.1.3",
"winston": "^3.11.0",
"yn": "^5.0.0"
Expand Down
19 changes: 19 additions & 0 deletions plugins/orchestrator-backend/src/service/api/v1.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { WorkflowOverviewListResult } from '@janus-idp/backstage-plugin-orchestrator-common';

import { SonataFlowService } from '../SonataFlowService';

export async function getWorkflowOverviewV1(
sonataFlowService: SonataFlowService,
): Promise<WorkflowOverviewListResult> {
const overviews = await sonataFlowService.fetchWorkflowOverviews();
if (!overviews) {
throw new Error("Couldn't fetch workflow overviews");
}
const result: WorkflowOverviewListResult = {
items: overviews,
limit: 0,
offset: 0,
totalCount: overviews?.length ?? 0,
};
return result;
}
19 changes: 19 additions & 0 deletions plugins/orchestrator-backend/src/service/api/v2.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { WorkflowOverviewListResultDTO } from '@janus-idp/backstage-plugin-orchestrator-common';

import { SonataFlowService } from '../SonataFlowService';
import { getWorkflowOverviewV1 } from './v1';

export async function getWorkflowOverviewV2(
sonataFlowService: SonataFlowService,
): Promise<WorkflowOverviewListResultDTO> {
const overviewsV1 = await getWorkflowOverviewV1(sonataFlowService);
const result: WorkflowOverviewListResultDTO = {
overviews: overviewsV1.items,
paginationInfo: {
limit: 0,
offset: 0,
totalCount: overviewsV1.items?.length ?? 0,
},
};
return result;
}
Loading

0 comments on commit bd88e23

Please sign in to comment.