-
Notifications
You must be signed in to change notification settings - Fork 213
fix(schema): OpenAPI 3.1 bump + schema fixes #1025
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
Open
tdabasinskas
wants to merge
7
commits into
github-community-projects:main-enterprise
Choose a base branch
from
datolabs-io:fix/schema-nullable-rewrite
base: main-enterprise
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
5bf4c92
fix(schema): remove nullable keywords from generated schemas
tdabasinskas 2df2433
fix(schema): update branch protection null handling in tests
tdabasinskas 37c16c9
fix(schema): improve spec resolver URL matching precision
tdabasinskas 08cda34
fix(schema): correct ruleset schema references for repo scope
tdabasinskas 968ae90
fix(schema): expand branch protection empty value handling
tdabasinskas acb1b74
fix(schema): add explicit utf8 encoding to test file reads
tdabasinskas b7b3d9b
fix(schema): make test assertions order-independent
tdabasinskas File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,76 @@ | ||
| /* eslint-disable no-undef */ | ||
|
|
||
| const fs = require('fs') | ||
| const path = require('path') | ||
|
|
||
| // The generated schemas declare JSON Schema draft 2020-12, where OpenAPI 3.0's | ||
| // `nullable` keyword does not exist. The build consumes GitHub's OpenAPI 3.1 | ||
| // description, which models null-ability as `type: [X, 'null']` unions instead, | ||
| // so no `nullable` keyword may survive in the output. | ||
| describe('dereferenced schemas', () => { | ||
| const files = ['settings.json', 'suborgs.json', 'repos.json'] | ||
|
|
||
| files.forEach(file => { | ||
| describe(file, () => { | ||
| const schema = JSON.parse(fs.readFileSync(path.join(__dirname, '../../schema/dereferenced', file), 'utf8')) | ||
|
|
||
| it('contains no OpenAPI `nullable` keywords', () => { | ||
| const found = [] | ||
| const walk = (node, at) => { | ||
| if (Array.isArray(node)) { | ||
| node.forEach((v, i) => walk(v, `${at}/${i}`)) | ||
| } else if (node && typeof node === 'object') { | ||
| if ('nullable' in node) { | ||
| found.push(at) | ||
| } | ||
| Object.entries(node).forEach(([k, v]) => walk(v, `${at}/${k}`)) | ||
| } | ||
| } | ||
| walk(schema, '') | ||
| expect(found).toEqual([]) | ||
| }) | ||
| }) | ||
| }) | ||
|
|
||
| it('allows null for required-but-nullable branch protection fields', () => { | ||
| const schema = JSON.parse(fs.readFileSync(path.join(__dirname, '../../schema/dereferenced/settings.json'), 'utf8')) | ||
| const protection = schema.properties.branches.items.properties.protection | ||
| const protectionObject = protection.anyOf.find(variant => variant.type === 'object') | ||
| expect(protectionObject.properties.required_status_checks.type).toContain('null') | ||
| expect(protectionObject.properties.enforce_admins.type).toContain('null') | ||
| expect(protectionObject.properties.restrictions.type).toContain('null') | ||
| }) | ||
|
|
||
| // Suborg and repo override files feed the rulesets plugin at repo scope | ||
| // (childPluginsList in lib/settings.js), so their schemas validate rulesets | ||
| // against the repo-level API shape, not the org-level one. | ||
| it('validates per-repo rulesets in the suborg and repo schemas', () => { | ||
| ;['suborgs.json', 'repos.json'].forEach(file => { | ||
| const schema = JSON.parse(fs.readFileSync(path.join(__dirname, '../../schema/dereferenced', file), 'utf8')) | ||
| const ruleset = schema.properties.rulesets.items | ||
| // `required` is an unordered set in JSON Schema | ||
| expect(ruleset.required).toHaveLength(2) | ||
| expect(ruleset.required).toEqual(expect.arrayContaining(['name', 'enforcement'])) | ||
| // org-only condition targeting must not leak into the repo-level shape | ||
| expect(JSON.stringify(ruleset.properties.conditions)).not.toContain('repository_name') | ||
| const actorTypes = ruleset.properties.bypass_actors.items.properties.actor_type.enum | ||
| expect(actorTypes).toContain('User') | ||
| }) | ||
| }) | ||
|
|
||
| // An empty `protection` value is safe-settings' own delete-branch-protection | ||
| // semantic (see isEmpty in lib/plugins/branches.js, and the plugin tests for | ||
| // null/{}/[]/false); the GitHub API's PUT body it is validated against does | ||
| // not model that, so the schema allows the empty values explicitly. | ||
| it('allows the empty protection values that delete branch protection', () => { | ||
| files.forEach(file => { | ||
| const schema = JSON.parse(fs.readFileSync(path.join(__dirname, '../../schema/dereferenced', file), 'utf8')) | ||
| const protection = schema.properties.branches.items.properties.protection | ||
| // enum ordering is not semantically meaningful, so assert membership | ||
| const emptyVariant = protection.anyOf.find(variant => Array.isArray(variant.enum)) | ||
| expect(emptyVariant).toBeDefined() | ||
| expect(emptyVariant.enum).toHaveLength(4) | ||
| expect(emptyVariant.enum).toEqual(expect.arrayContaining([null, {}, [], false])) | ||
| }) | ||
| }) | ||
| }) |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.