feat(ocm): add openApi schema and OpenApiRouter
Description:
Introduces openapi schema for ocm-backend.
Introduces autogeneration of openapi documentation via yarn build:api-docs
Introduces openapi-utils dependency that adds:
- A typed express router
Some examples:
(When
openapi.yamlspecifies endpoint /example that requires name query param.) - Validation and verification tooling
For example when calling
/exampleendpoint without name:
curl -X GET http://localhost:7007/api/ocm/hello ─╯
{"error":{"name":"InputError","message":"request/query must have required property 'name'","stack":"InputError:
...
2024-08-13T14:48:35.814Z backstage error Request failed with status 400 request/query must have required property 'name' type=errorHandler cause=undefined name=InputError stack=InputError: request/query must have required property 'name'
at /home/dzemanov/Projects/janus/backstage-plugins/node_modules/@backstage/backend-openapi-utils/dist/index.cjs.js:23:10
at handleReturn (/home/dzemanov/Projects/janus/backstage-plugins/node_modules/express-promise-router/lib/express-promise-router.js:24:23)
...
-
option to autogenerate client code like Apis via:
yarn backstage-repo-tools package schema openapi generate client --client-package <directory>For ocm, this command could be run when inside ocm-backend folder:yarn backstage-repo-tools package schema openapi generate client --client-package plugins/ocm-common -
this could be used to generate catalog entities with swagger openapi docs (haven't tried this one yet) https://www.npmjs.com/package/@backstage/plugin-catalog-backend-module-backstage-openapi
The openapi.generated.ts needs to be regenerated when openapi schema changes via running:
yarn build:api-server .
"@backstage/repo-tools"` must be installed in root workspace for it to run.
Reference: https://backstage.io/docs/openapi/01-getting-started/
Fixes:
One thing I would mention is that I didn't add security to openapi.yaml schema because that way openApiRouter checks that requests contain it and for dev development it was giving Error: Authorization header required.
Update: fixed
Quality Gate passed
Issues
0 New issues
0 Accepted issues
Measures
0 Security Hotspots
0.0% Coverage on New Code
0.0% Duplication on New Code