Skip to content

Commit f6275e2

Browse files
authored
docs(orchestrator): add OpenAPI doc (janus-idp#1441)
* docs(orchestrator): add OpenAPI doc Expands the documentation to include detailed information on leveraging OpenAPI within the plugin. It covers topics such as integrating OpenAPI, adding new endpoints, and generating documentation and code using OpenAPI. Signed-off-by: Gloria Ciavarrini <[email protected]> * docs(orchestrator): clarify v2 usage Signed-off-by: Gloria Ciavarrini <[email protected]> --------- Signed-off-by: Gloria Ciavarrini <[email protected]>
1 parent f8fc349 commit f6275e2

File tree

1 file changed

+92
-0
lines changed

1 file changed

+92
-0
lines changed

plugins/orchestrator/README.md

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,3 +219,95 @@ The Orchestrator plugin enhances the Backstage with the execution of developer s
219219
1. Open your Backstage application.
220220
1. Click the **Orchestrator** tab from the left-side panel to navigate to the **Orchestrator** main page.
221221
1. Inside the **Orchestrator** main page, you can see the list of workflow definitions that are available in your Backstage application.
222+
223+
## OpenAPI
224+
225+
The plugin provides OpenAPI `v2` endpoints definition to facilitate communication between the frontend and backend. This approach minimizes the data that needs to be sent to the frontend, provides flexibility and avoids dependencies on changes in the [CNCF serverless specification](https://github.com/serverlessworkflow/specification/blob/main/specification.md). It also allows for a seamless transition if there's a need to replace the backend implementation.
226+
227+
In addition, by leveraging on OpenAPI spec, it is possible to generate clients and create CI steps.
228+
229+
OpenAPI specification [file](https://github.com/janus-idp/backstage-plugins/blob/main/plugins/orchestrator-common/src/openapi/openapi.yaml) is available in [orchestrator-common](https://github.com/janus-idp/backstage-plugins/blob/main/plugins/orchestrator-common).
230+
231+
> **NOTE:**\
232+
> While the OpenAPI specification is available in the Orchestrator plugin, the UI currently does not rely on this spec. \
233+
> We plan to incorporate v2 endpoints into the UI in the near future.
234+
235+
### orchestrator-common
236+
237+
The typescript schema is generated in [auto-generated](https://github.com/janus-idp/backstage-plugins/blob/main/plugins/orchestrator-common/src/auto-generated/api/models/schema.ts) folder from openapi.yaml specification file.
238+
239+
### orchestrator-backend
240+
241+
The orchestrator backend can use the generated schema to validate the HTTP requests and responses.
242+
243+
> NOTE: Temporary the validation has been disabled. It will be enabled when the orchestrator frontend will switch to the use of v2 endpoints only.
244+
245+
#### Development instruction
246+
247+
Checkout the backstage-plugin
248+
249+
`git clone [email protected]:janus-idp/backstage-plugins.git`
250+
251+
If you need to change the OpenAPI spec, edit the [openapi.yaml](https://github.com/janus-idp/backstage-plugins/blob/main/plugins/orchestrator-common/src/openapi/openapi.yaml) according to your needs and then execute from the project root folder:
252+
253+
`yarn --cwd plugins/orchestrator-common openapi`
254+
255+
This command updates the [auto-generated files](https://github.com/janus-idp/backstage-plugins/blob/main/plugins/orchestrator-common/src/auto-generated/api/) and the [auto-generated docs](https://github.com/janus-idp/backstage-plugins/tree/main/plugins/orchestrator-common/src/auto-generated/docs).
256+
257+
> NOTE: Do not manually edit auto-generated files
258+
259+
If you add a new component in the spec, then you need to export the generated typescript object [here](https://github.com/janus-idp/backstage-plugins/blob/main/plugins/orchestrator-common/src/openapi/types.ts). For example, if you define
260+
261+
```yaml
262+
components:
263+
schemas:
264+
Person:
265+
type: object
266+
properties:
267+
name:
268+
type: string
269+
surname:
270+
type: string
271+
```
272+
273+
then
274+
275+
```typescript
276+
export type Person = components['schemas']['Person'];
277+
```
278+
279+
When defining a new endpoint, you have to define the `operationId`.
280+
That `id` is the one that you can use to implement the endpoint logic.
281+
282+
For example, let's assume you add
283+
284+
```yaml
285+
paths:
286+
/names:
287+
get:
288+
operationId: getNames
289+
description: Get a list of names
290+
responses:
291+
'200':
292+
description: Success
293+
content:
294+
application/json:
295+
schema:
296+
type: array
297+
items:
298+
$ref: '#/components/schemas/Person'
299+
```
300+
301+
Then you can implement the endpoint in [router.ts](https://github.com/janus-idp/backstage-plugins/blob/main/plugins/orchestrator-backend/src/service/router.ts) referring the operationId `getNames`:
302+
303+
```typescript
304+
api.register('getNames', async (_c, _req, res: express.Response, next) => {
305+
// YOUR LOGIC HERE
306+
const result: Person[] = [
307+
{ name: 'John', surname: 'Snow' },
308+
{ name: 'John', surname: 'Black' },
309+
];
310+
311+
res.status(200).json(result);
312+
});
313+
```

0 commit comments

Comments
 (0)