Skip to content

Commit

Permalink
chore: implement JSON Schema to NodeType adapter (Redocly#1401)
Browse files Browse the repository at this point in the history
  • Loading branch information
tatomyr authored Feb 16, 2024
1 parent d01b16f commit fc21cfd
Show file tree
Hide file tree
Showing 25 changed files with 2,849 additions and 223 deletions.
1 change: 1 addition & 0 deletions __tests__/commands.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ describe('E2E', () => {
{ dirName: 'invalid-config-format-json', option: 'warn', format: 'json' },
{ dirName: 'config-with-refs', option: 'warn' },
{ dirName: 'config-with-refs-extended', option: 'error' },
{ dirName: 'config-structure', option: 'error' },
];

const validOpenapiFile = join(__dirname, 'lint-config/__fixtures__/valid-openapi.yaml');
Expand Down
264 changes: 264 additions & 0 deletions __tests__/lint-config/config-structure/.redocly.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,264 @@
licenseKey: 123 # Must be a string

apis:
without-root:
foo: Not expected!
output: file.json
with-wrong-root:
root: 456 # Must be a string
with-theme:
root: ./openapi.yaml
theme:
openapi: wrong, must be an object
not-expected: Must fail

seo:
keywords: 789 # Must be an array

redirects:
some-redirect:
t1o: Wrong name, should be 'two'
type: wrong type, must be a number

rbac:
'team-b.md':
TeamB: read
team-c.md:
TeamC: read
/blog/*:
anonymous: none
authenticated: read
/blogpost/:
TeamD: none
'**/*.md':
TeamA: none
authenticated: none
'*': read
'blog/april-2022.md':
TeamA: none
TeamC: read
test.md:
TeamC: none
TeamB: none
authenticated: none
'*': read
test/**:
TeamB: read
TeamC: read
authenticated: read
anonymous: read
additional-property:
something: 123 # Must be a string
content:
'**':
additionalProp: 456 # Must be a stirng
foo:
additionalProp2: 789 # Must be a stirng

responseHeaders:
some-header: wrong, must be an array
some-header2:
- wrong, must be an object
- unexpected-property: Should fail
# name: Must be reported as a missing required prop
value: 123 # Must be a string

ssoOnPrem:
oidc:
title: 456 # Must be a string
type: OIDC
configurationUrl: http://localhost/oidc/.well-known/openid-configuration
clientId: '{{ process.env.public }}'
clientSecret: '{{ process.env.secret }}'
teamsClaimName: https://test.com
scopes:
- openid
audience:
- default
authorizationRequestCustomParams:
login_hint: 789 # Must be a string
prompt: login
configuration:
token_endpoint: 123 # Must be a string
# authorization_endpoint: Must be reported as a missing required prop
additional-propery: Must be allowed
defaultTeams:
- 456 # Must be a string

sso-config-schema-without-configurationUrl:
type: OIDC
# clientId: Must be reported as a missing required prop
# configurationUrl: Must be reported as a missing required prop
clientSecret: '{{ process.env.secret }}'

basic:
type: BASIC
credentials:
- teams:
- 789 # Must be a string
- correct
# username: Must be reported as a missing required prop

sso:
- WRONG # Does not match allowed options

developerOnboarding:
wrong: A not allowed field
adapters:
- should be object
- type: 123 # Must be a string
- type: APIGEE_X
# organizationName: Must be reported as a missing required prop
auth:
type: OAUTH2
# tokenEndpoint: Must be reported as a missing required prop
clientId: 456 # Must be a string
clientSecret: '{{ process.env.secret }}'
not-expected: Must fail
- type: APIGEE_X
organizationName: Test
auth:
type: SERVICE_ACCOUNT
# serviceAccountPrivateKey: Must be reported as a missing required prop
serviceAccountEmail: 789 # Must be a string

i18n:
defaultLocale: en-US
locales:
- code: 123 # Must be a string
name: English
- code: es-ES
name: Spanish

metadata:
test: anything

not-listed-filed: Must be reported as not expected

env:
some-env:
mockServer:
off: must be boolean
not-expected: Must fail
apis:
no-root:
# root: Must be defined
rules: {}
wrong-root:
root: 789 # Must be a string

referenced-env:
$ref: ./env.yaml

theme:
breadcrumbs:
hide: false
prefixItems:
- label: Home
page: '/'
imports:
- '@redocly/test-theme'

logo:
srcSet: './images/redocly-black-logo.svg light, ./images/redocly-brand-logo.svg dark'
altText: Test
link: /
asyncapi:
hideInfo: false
expandSchemas:
root: true
elements: true
navbar:
items:
- label: Markdown
page: /markdown/

search:
shortcuts:
- ctrl+f
- cmd+k
- /
suggestedPages:
- label: TSX page
page: tsx.page.tsx
- page: /my-catalog/

footer:
copyrightText: Copyright © Test 2019-2020.
items:
- group: Legal
items:
- label: Terms of Use
href: 'https://test.com/' # Not expected

markdown:
lastUpdatedBlock:
format: 'long'
editPage:
baseUrl: https://test.com
graphql:
pagination: section
menu:
{
initialLoadState: 'default',
requireExactGroups: false,
groups:
[
{
name: 'GraphQL custom group',
directives: { includeByName: ['cacheControl', 'typeDirective'] },
},
],
otherItemsGroupName: 'Other',
}
sidebar:
separatorLine: true
linePosition: top
catalog:
main:
title: API Catalog
description: 'This is a description of the API Catalog'
slug: /my-catalog/
filters:
- title: Domain
property: domain
missingCategoryName: Other
- title: API Category
property: category
missingCategoryName: Other
groupByFirstFilter: false
items:
- directory: ./
flatten: true
includeByMetadata:
type: [openapi]
scorecard:
ignoreNonCompliant: true
levels:
- name: Baseline
extends:
- minimal
- name: Silver
extends:
- recommended
rules:
info-description: off

- name: Gold
rules:
rule/path-item-get-required:
severity: warn
subject:
type: PathItem
message: Every path item must have a GET operation.
assertions:
required:
- get

operation-4xx-response: warn
targets:
- where:
metadata:
l0: Distribution
publishDateRange: 2021-01-01T00:00:00Z/2022-01-01
minimumLevel: Silver
3 changes: 3 additions & 0 deletions __tests__/lint-config/config-structure/env.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
ignore:
- 123 # Must be an string
- correct
Loading

0 comments on commit fc21cfd

Please sign in to comment.