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

chore(backend): update OpenAPI specs #799

Merged
merged 7 commits into from
Dec 12, 2022
Merged

chore(backend): update OpenAPI specs #799

merged 7 commits into from
Dec 12, 2022

Conversation

wilsonianb
Copy link
Contributor

@wilsonianb wilsonianb commented Nov 29, 2022

Changes proposed in this pull request

Context

Checklist

  • Related issues linked using fixes #number
  • Tests added/updated
  • Documentation added
  • Make sure that all checks pass

@github-actions github-actions bot added pkg: backend Changes in the backend package. type: ci Changes to the CI type: documentation type: source Changes business logic type: tests Testing related labels Nov 29, 2022
@wilsonianb wilsonianb marked this pull request as ready for review November 29, 2022 18:29
njlie
njlie previously approved these changes Nov 29, 2022
Copy link
Member

@sabineschaller sabineschaller left a comment

Choose a reason for hiding this comment

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

I'm confused, why are we fetching the specs now instead of updating URLs in env files?

@wilsonianb
Copy link
Contributor Author

Here's the previous two related pr's:

The Rafiki specific specs use the shared Open Payments schemas file
https://github.com/interledger/rafiki/tree/main/packages/auth/src/openapi
https://github.com/interledger/open-payments/blob/main/openapi/schemas.yaml

So it is fetched instead of updating the $ref urls in the local files, and to support local dev using modified (pending changes to) specs/schemas:

I suggested also fetching the relevant Open Payments spec(s)

Comment on lines 12 to 13
curl -o "$OUTDIR/resource-server.yaml" https://raw.githubusercontent.com/interledger/open-payments/b363d33038fe789e5388f04f80ddd06a4fa97093/openapi/resource-server.yaml
curl -o "$OUTDIR/schemas.yaml" https://raw.githubusercontent.com/interledger/open-payments/b363d33038fe789e5388f04f80ddd06a4fa97093/openapi/schemas.yaml
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we also update the open-payments commit version in this PR

or would it make sense to export these from open-payments? so we can be sure both are using the same spec? This does seem vaguely familiar though... have we discussed this before?

Copy link
Contributor

Choose a reason for hiding this comment

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

We could even do it for both of backend and auth projects since open-payments contains both, which would eliminate the need for the packages/backend/src/openapi/auth-server.yaml dependency

Copy link
Contributor Author

@wilsonianb wilsonianb Dec 7, 2022

Choose a reason for hiding this comment

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

would it make sense to export these from open-payments?

I'm favor of defining the (default) commit in a single place.
It seems like that could happen while still allowing subsequent local tinkering of the specs
#684 (comment)

which would eliminate the need for the packages/backend/src/openapi/auth-server.yaml dependency

Did you mean resource-server.yaml?

Comment on lines 113 to 118
const authServerSpec = await createOpenAPI(
path.resolve(__dirname, './openapi/auth-server.yaml')
)
const resourceServerSpec = await createOpenAPI(
path.resolve(__dirname, './openapi/resource-server.yaml')
)
Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link
Contributor Author

@wilsonianb wilsonianb Dec 7, 2022

Choose a reason for hiding this comment

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

As is, we get something like

    ResolverError: Error opening file "/home/brandon/rafiki/packages/auth/src/openapi/auth-server.yaml"

      at ReadFileContext.callback (node_modules/.pnpm/@[email protected]/node_modules/@apidevtools/json-schema-ref-parser/lib/resolvers/file.js:52:20)

Are you thinking of having it mention the command to fetch the schemas?

Copy link
Contributor

@mkurapov mkurapov Dec 8, 2022

Choose a reason for hiding this comment

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

Yes, that's what I was thinking, something along the lines of "Could not find Open API schema files. Did you run <command> ?"

Copy link
Contributor Author

Choose a reason for hiding this comment

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

As long we remember not to change the command 😅

README.md Outdated
Comment on lines 85 to 86
pnpm --filter auth fetch-schemas
pnpm --filter backend fetch-schemas
Copy link
Contributor

Choose a reason for hiding this comment

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

can we add a root level command?
"localenv:fetch-op-schemas": "pnpm --filter auth --filter backend fetch-schemas" , and then include it as part of the local env setup readme?

https://interledgerfoundation.slack.com/archives/C0302LMKBT7/p1670414356297499?thread_ts=1670407497.730339&cid=C0302LMKBT7

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I was thinking that devs would run through this environment setup before doing local env, but I guess that's not entirely necessary.
https://github.com/interledger/rafiki#environment-setup
Should we split out installing node & pnpm and fetching schemas into a separate prerequisite section?

I also noticed that as is it shouldn't work to have tests before fetch schemas.

Restructure local development / localenv instructions.
@github-actions github-actions bot added type: localenv Local playground pkg: auth Changes in the GNAP auth package. pkg: open-payments labels Dec 7, 2022
mkurapov
mkurapov previously approved these changes Dec 9, 2022
Copy link
Contributor

@mkurapov mkurapov left a comment

Choose a reason for hiding this comment

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

Once the specs stabilize it would be good to have them be defined in a singular place, even like with the exported commit hash as you suggested - I am a bit worried about specs diverging accidentally

idpSpec
container.singleton('openApi', async (deps: IocContract<AppServices>) => {
try {
const authServerSpec = await createOpenAPI(
Copy link
Contributor

Choose a reason for hiding this comment

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

what do you think of openPaymentsAuthServerSpec? Likewise with openPaymentsResourceServerSpec in the backend?

Trying to see if there is a better way of distinguishing the several different spec we have

Copy link
Contributor Author

@wilsonianb wilsonianb Dec 9, 2022

Choose a reason for hiding this comment

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

This one here is actually authServerSpec (from https://github.com/interledger/rafiki/blob/main/packages/auth/src/openapi/resource-server.yaml)
I think openPaymentsAuthServerSpec would be https://github.com/interledger/open-payments/blob/main/openapi/schemas.yaml

What if we just called the first one introspection/tokenIntrospection for both the file name (make it consistent in both auth and backend) and the variable name?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm gonna change https://github.com/interledger/rafiki/blob/main/packages/auth/src/openapi/resource-server.yaml to token-introspection.yaml with

Suggested change
const authServerSpec = await createOpenAPI(
const tokenIntrospectionSpec = await createOpenAPI(

and not

Suggested change
const authServerSpec = await createOpenAPI(
const tokenIntroSPECtion = await createOpenAPI(

and keep the other file and variable names as is.

Copy link
Contributor

Choose a reason for hiding this comment

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

The tokenIntrospectionSpec change makes sense, but it should be replacingresourceServerSpec variable (the one that contains the introspection route), right?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ha, yeah. I was thinking these comments were for packages/backend/src/index.ts 🙃

@wilsonianb wilsonianb requested a review from mkurapov December 9, 2022 17:37
@wilsonianb wilsonianb merged commit 107e48f into main Dec 12, 2022
@wilsonianb wilsonianb deleted the bw-backend-openapi branch December 12, 2022 21:07
@huijing huijing added the type: documentation (archived) Improvements or additions to documentation label Oct 30, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pkg: auth Changes in the GNAP auth package. pkg: backend Changes in the backend package. type: ci Changes to the CI type: documentation (archived) Improvements or additions to documentation type: localenv Local playground type: source Changes business logic type: tests Testing related
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Update backend OpenAPI specs
5 participants