Skip to content

Conversation

jeremystretch
Copy link
Member

Closes: #20203

  • Add a static record of the OpenAPI schema at contrib/openapi.json
  • Introduce the verify-openapi.sh script to generate the OpenAPI schema & compare it to the static record
  • Add a pre-commit rule to run the OpenAPI verification check
  • Update the release documentation to include updating contrib/openapi.json

@jeremystretch jeremystretch requested review from a team and arthanson and removed request for a team September 2, 2025 18:15
- id: openapi-check
name: "Validate OpenAPI schema"
description: "Check for any unexpected changes to the OpenAPI schema"
files: api/.*\.py$
Copy link
Member Author

Choose a reason for hiding this comment

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

Lazy regex to avoid triggering the rule unless it's likely that a modification to the REST API was made.

Update the static OpenAPI schema definition at `contrib/openapi.json` with the management command below. If the schema file is up-to-date, only the NetBox version will be changed.

```nohighlight
./manage.py spectacular --format openapi-json > ../contrib/openapi.json
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think that should be ./manage.py spectacular --format openapi-json > contrib/openapi.json the ../ before contrib causes an error.

Copy link
Member Author

Choose a reason for hiding this comment

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

The command assumes you're in the path where manage.py exists; contrib/ is one up from that.

@arthanson arthanson merged commit 8a1db81 into main Sep 4, 2025
10 checks passed
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.

Add pre-commit check for changes to OpenAPI schema
2 participants