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

feat(ocm): add openApi schema and OpenApiRouter #2050

Merged
merged 12 commits into from
Aug 28, 2024

Conversation

dzemanov
Copy link
Member

@dzemanov dzemanov commented Aug 13, 2024

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:
    ocm-1
    ocm-2
    (When openapi.yaml specifies endpoint /example that requires name query param.)
  • Validation and verification tooling
    For example when calling /example endpoint 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)
...

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:

RHIDP-3570

@dzemanov dzemanov requested review from a team as code owners August 13, 2024 17:31
@dzemanov dzemanov changed the title feat(ocm): Add openapi schema and openapi router feat(ocm): add openApi schema and OpenApiRouter Aug 13, 2024
Copy link
Member

@PatAKnight PatAKnight left a comment

Choose a reason for hiding this comment

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

Tested and everything works!

One suggestion and one question for you.

plugins/ocm-backend/scripts/openapi-doc.sh Outdated Show resolved Hide resolved
plugins/ocm-backend/src/schema/openapi.yaml Outdated Show resolved Hide resolved
@dzemanov
Copy link
Member Author

dzemanov commented Aug 22, 2024

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

@dzemanov dzemanov force-pushed the ocm-openapi branch 2 times, most recently from 3b4e8a0 to 0ec0873 Compare August 27, 2024 17:59
Copy link
Member

@PatAKnight PatAKnight left a comment

Choose a reason for hiding this comment

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

/lgtm

@openshift-ci openshift-ci bot removed the lgtm label Aug 28, 2024
Copy link
Member

@PatAKnight PatAKnight left a comment

Choose a reason for hiding this comment

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

Looks good, might need to pull in the latest changes to get the CI to pass

Copy link

Copy link
Member

@PatAKnight PatAKnight left a comment

Choose a reason for hiding this comment

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

/lgtm

@openshift-ci openshift-ci bot added the lgtm label Aug 28, 2024
@openshift-merge-bot openshift-merge-bot bot merged commit 384434d into janus-idp:main Aug 28, 2024
10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants