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

[DX-123] seprated db and api schemas #1701

Merged
merged 12 commits into from
May 8, 2023
Merged

[DX-123] seprated db and api schemas #1701

merged 12 commits into from
May 8, 2023

Conversation

suhailkakar
Copy link
Member

@suhailkakar suhailkakar commented Apr 26, 2023

What does this pull request do? Explain your changes. (required)

Separated database and API schemas. Instead of one schema, we now have two schemas, the api-schema.yaml is the schema for API references, and db-schema.yaml is similar to API schema except it has keys that open API doesn't validate but it is needed for db such as readOnly, table.

@victorges This PR is just for the separation of the schemas, I will open two other follow-up PRs for including other APIs that are missing here and another one for API references

Specific updates (required)

  • Separated database and API schemas

Does this pull request close any open issues?
Linear - DX 123

Checklist

  • I have read the CONTRIBUTING document.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have added tests to cover my changes.

@suhailkakar suhailkakar requested a review from a team as a code owner April 26, 2023 08:32
@vercel
Copy link

vercel bot commented Apr 26, 2023

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
livepeer-studio ✅ Ready (Inspect) Visit Preview 💬 Add feedback May 4, 2023 8:22am

@suhailkakar
Copy link
Member Author

I will take a look on why test are failing as well :)

@hjpotter92
Copy link
Member

hjpotter92 commented Apr 26, 2023

Does this pull request close any open issues?
Linear - DX 123

you can edit the title of your PR to start with [DX-123] and linear should automatically pick up correct reference.

@suhailkakar
Copy link
Member Author

Oh, that is cool! thanks @hjpotter92

@suhailkakar suhailkakar changed the title seprated db and api schemas [DX-123] seprated db and api schemas Apr 26, 2023
@linear
Copy link

linear bot commented Apr 26, 2023

DX-123 OpenAPI cleanup

Copy link
Member

@victorges victorges left a comment

Choose a reason for hiding this comment

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

LGTM!

Made comments about components/APIs that should not be in the public API reference (api-schema.yaml). Looks like there are a lot of comments but it's just flagging of some components that should be removed from the API reference (either moved to the internal schema or deleted completely)

table: webhook
properties:
id:
readOnly: true
Copy link
Member

Choose a reason for hiding this comment

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

readOnly is an OpenAPI field which changes the generated documentation (doesn't include the field in the request payloads, only responses). https://swagger.io/docs/specification/data-models/data-types/

Is this breaking the readme.io generation somehow? If that's the case, this is probably something to bring up with them as they are not following the OpenAPI spec.

sourceInfo:
properties:
width:
minValue: 1
Copy link
Member

Choose a reason for hiding this comment

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

Interesting, I though this was OpenAPI as well but their field is actually minimum and maximum. Maybe this never worked lol

packages/api/src/schema/db-schema.yaml Show resolved Hide resolved
Comment on lines 137 to 142
recordingStatus:
readonly: true
recordingUrl:
readonly: true
mp4Url:
readonly: true
Copy link
Member

Choose a reason for hiding this comment

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

typo

Suggested change
recordingStatus:
readonly: true
recordingUrl:
readonly: true
mp4Url:
readonly: true
recordingStatus:
readOnly: true
recordingUrl:
readOnly: true
mp4Url:
readOnly: true

(should be moved to api-schema anyway, like all other readOnlys)

- hevc
- vp8
- vp9
cdn-data-row:
Copy link
Member

Choose a reason for hiding this comment

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

This is an internal object type that should not be in api reference. We should move it to db-schema

application/json:
schema:
$ref: "#/components/schemas/error"
/user/token:
Copy link
Member

Choose a reason for hiding this comment

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

Same, let's remove this

application/json:
schema:
$ref: "#/components/schemas/error"
"/user/{id}":
Copy link
Member

Choose a reason for hiding this comment

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

Same, this. oneis internal. We can change it to /user/me though and re-document it as "retrieves own user object"

application/json:
schema:
$ref: "#/components/schemas/error"
/api-token:
Copy link
Member

Choose a reason for hiding this comment

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

Same, let's remove this. Users can only use our API with an API key, and API keys are not allowed to manage other API keys for security purposes.

application/json:
schema:
$ref: "#/components/schemas/error"
"/region/{region}":
Copy link
Member

Choose a reason for hiding this comment

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

Same, let's remove this

application/json:
schema:
$ref: "#/components/schemas/error"
/room:
Copy link
Member

Choose a reason for hiding this comment

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

Nice! Good to know you already rebased 🙏

@victorges
Copy link
Member

Hmm, it seems like the build is also failing. Is the merged schema coming out with the exact types as the original schema? Maybe one flow that you can follow is:

  • run yarn compile-schemas from master (from inside packages/api)
  • copy the generated schema.json file
  • change to your branch and run compile-schemas again
  • compare the generated schema.json with the one that came from master. Make sure only docs change

Copy link
Member

@victorges victorges left a comment

Choose a reason for hiding this comment

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

a couple documentation fixes

packages/api/src/schema/api-schema.yaml Show resolved Hide resolved
packages/api/src/schema/api-schema.yaml Show resolved Hide resolved
type: array
items:
$ref: "#/components/schemas/ffmpeg-profile"
error:
Copy link
Member

Choose a reason for hiding this comment

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

Ohhh interesting! We should use this schema for the error responses in the API declarations below. Will save a lot of repetitive declarations.

packages/api/src/schema/api-schema.yaml Show resolved Hide resolved
packages/api/src/schema/api-schema.yaml Show resolved Hide resolved
Comment on lines +1983 to +1986
properties:
$ref: "#/components/schemas/signing-key/properties"
privateKey:
type: string
Copy link
Member

Choose a reason for hiding this comment

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

So this is a little hack we've used in our schema: a $ref key that is not the only entry in the object, and then we add more keys to it. Make sure this works with readme.io!

packages/api/src/schema/api-schema.yaml Show resolved Hide resolved
packages/api/src/schema/api-schema.yaml Outdated Show resolved Hide resolved
suhailkakar and others added 6 commits April 28, 2023 22:41
Co-authored-by: Victor Elias <victor@livepeer.org>
Co-authored-by: Victor Elias <victor@livepeer.org>
Co-authored-by: Victor Elias <victor@livepeer.org>
Co-authored-by: Victor Elias <victor@livepeer.org>
Co-authored-by: Victor Elias <victor@livepeer.org>
Co-authored-by: Victor Elias <victor@livepeer.org>
Copy link
Member

@victorges victorges left a comment

Choose a reason for hiding this comment

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

Amazing! Only some smaller comments now. The only one that might involve some work is the readOnly, which might be easier to handle with a script instead of manually 🥴

packages/api/src/schema/db-schema.yaml Outdated Show resolved Hide resolved
Name of template to send to the users regarding the suspension.
enum:
- copyright
webhook:
Copy link
Member

@victorges victorges Apr 28, 2023

Choose a reason for hiding this comment

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

I think this one was forgotten here with the full spec and not only the fields diff. This can be mostly on the public API reference on ly, we only need the internal fields here (e.g. table and the event property).
Nevermind, realized it was including only the internal fields already (only got the readonly issue)

Friendly reminder that the readOnly ones should go back to API reference (not sure if you intended to include that in this update, just making sure). Confirmed that readme.io supposedly supports those: https://docs.readme.com/main/discuss/6137da73509c3500180719ed

Copy link
Member Author

Choose a reason for hiding this comment

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

Thanks! Just pushed the changes for readOnly fields going back to api-schema

packages/api/src/schema/db-schema.yaml Show resolved Hide resolved
packages/api/src/schema/db-schema.yaml Outdated Show resolved Hide resolved
packages/api/src/schema/api-schema.yaml Outdated Show resolved Hide resolved
type: object
description: User-defined webhook context
additionalProperties: true
paths:
Copy link
Member

Choose a reason for hiding this comment

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

Not looking from here down as you mentioned you're updating this section later

@victorges
Copy link
Member

victorges commented Apr 28, 2023

(need to fix tests/build)

Edit: did it for you 🎁

@adamsoffer
Copy link
Member

Looks great! Good to merge @suhailkakar?

@suhailkakar
Copy link
Member Author

Almost!, just pushing a final change :)

@adamsoffer
Copy link
Member

Almost!, just pushing a final change :)

great. feel free to merge afterwards

@suhailkakar
Copy link
Member Author

I believe it is now completed, @victorges can you please confirm?

Copy link
Member

@victorges victorges left a comment

Choose a reason for hiding this comment

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

Yes!

@suhailkakar suhailkakar merged commit 45cb66e into master May 8, 2023
12 checks passed
@suhailkakar suhailkakar deleted the api-reference branch May 8, 2023 18:19
@adamsoffer
Copy link
Member

@victorges heads up not sure if you're aware but looks like checks are failing after merging.

CleanShot 2023-05-08 at 17 09 14@2x

@victorges
Copy link
Member

Yeah that was fixed later on #1720. I think this branch wasn't rebased

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants