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

Commit the API schema to the repository #5865

Merged
merged 2 commits into from
Mar 17, 2023

Conversation

SpecLad
Copy link
Contributor

@SpecLad SpecLad commented Mar 15, 2023

Instead of generating the schema during the SDK build, store it in the repository. Add a CI check that verifies that the schema matches the server.

Motivation and context

This has the following benefits:

  • It becomes easy to see if and how a pull request affects the API (syntactically, at least). Since the schema is generated dynamically by drf-spectacular, it's not always obvious what effects a code change will have on the declared API. By requiring PRs to explicitly change the schema, we enable such changes to be reviewed directly.

  • It removes one step from the SDK generation procedure, making it easier for people to contribute. The schema generation step was, IMO, the most annoying (because you have to build the server) and the most error-prone (because it's easy to use the wrong version of the server).

There's also a drawback: there's now one more step to change the API, updating the schema. I think this is acceptable, because if you changed the API, then to test your modifications you probably started the new version of the server, so you can just get the schema from there. To make it easier, make the CI provide the expected version of the schema, the diff from the current version, and the command to regenerate the schema locally.

How has this been tested?

Mainly by running the CI. I added artificial problems to the PR to make sure the schema verification works, and also to make sure that the unit test failure reporting still works after my changes.

Checklist

  • I submit my changes into the develop branch
  • [ ] I have added a description of my changes into the CHANGELOG file I don't think this is changelog-worthy, because all changes are developer-facing.
  • I have updated the documentation accordingly
  • I have added tests to cover my changes
  • [ ] I have linked related issues (see GitHub docs)
  • [ ] I have increased versions of npm packages if it is necessary
    (cvat-canvas,
    cvat-core,
    cvat-data and
    cvat-ui)

License

  • I submit my code changes under the same MIT License that covers the project.
    Feel free to contact the maintainers if that's a concern.

@SpecLad
Copy link
Contributor Author

SpecLad commented Mar 15, 2023

/check

@github-actions
Copy link
Contributor

github-actions bot commented Mar 15, 2023

❌ Some checks failed
📄 See logs here

@SpecLad SpecLad force-pushed the schema-in-repo branch 6 times, most recently from c6af455 to 796d369 Compare March 16, 2023 12:15
@SpecLad SpecLad marked this pull request as ready for review March 16, 2023 12:27
@SpecLad SpecLad requested review from zhiltsov-max and removed request for nmanovic and azhavoro March 16, 2023 12:28
@@ -19,55 +19,29 @@ the repository. To get the full package, one need to generate missing package fi

## How to generate package code

1. Obtain the server API schema
1. Install generator dependencies:
Copy link
Contributor

Choose a reason for hiding this comment

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

Where can I see steps on how to generate the schema manually (except .github/*.yml files)?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

For what purpose?

Copy link
Contributor

Choose a reason for hiding this comment

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

I broke the schema. Should I generate a new one?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

In this case, the CI check prints the command you need to run. There's also a VS code launch configuration that does it.

Copy link
Contributor

Choose a reason for hiding this comment

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

OK

Copy link
Contributor

@Marishka17 Marishka17 Mar 19, 2023

Choose a reason for hiding this comment

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

In this case, the CI check prints the command you need to run.

There is one problem: The schema may not be generated correctly If we have an outdated image.

There's also a VS code launch configuration that does it.

In this case, for some reason some fields in the schema lose their min/max limitations.

Copy link
Contributor

Choose a reason for hiding this comment

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

Agree, I've also faced this difference in the generated schema.

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 have found the cause for this discrepancy; it's because in the Docker image, the production configuration is selected, which uses a different database. I'll submit a fix to the VS code configuration.

SpecLad added 2 commits March 16, 2023 20:44
Instead of generating the schema during the SDK build, store it in the
repository. Add a CI check that verifies that the schema matches the server.

This has the following benefits:

* It becomes easy to see if and how a pull request affects the API
  (syntactically, at least). Since the schema is generated dynamically by
  drf-spectacular, it's not always obvious what effects a code change will
  have on the declared API. By requiring PRs to explicitly change the
  schema, we enable such changes to be reviewed directly.

* It removes one step from the SDK generation procedure, making it easier for
  people to contribute. The schema generation step was, IMO, the most
  annoying (because you have to build the server) and the most error-prone
  (because it's easy to use the wrong version of the server).

There's also a drawback: there's now one more step to change the API,
updating the schema. I think this is acceptable, because if you changed the API,
then to test your modifications you probably started the new version of the server,
so you can just get the schema from there. To make it easier, make the CI provide
the expected version of the schema, the diff from the current version, and the command
to regenerate the schema locally.
@nmanovic nmanovic merged commit 3e4fb8d into cvat-ai:develop Mar 17, 2023
mikhail-treskin pushed a commit to retailnext/cvat that referenced this pull request Jul 1, 2023
@SpecLad SpecLad deleted the schema-in-repo branch July 20, 2023 10:10
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.

4 participants