Skip to content

Commit

Permalink
feat: extend Arazzo types
Browse files Browse the repository at this point in the history
  • Loading branch information
DmitryAnansky committed Jul 4, 2024
1 parent 2fde553 commit c9e47b8
Show file tree
Hide file tree
Showing 30 changed files with 340 additions and 71 deletions.
32 changes: 32 additions & 0 deletions __tests__/bundle/bundle-arazzo-valid-test-description/museum.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
arazzo: 1.0.0
info:
title: Redocly Museum API Tickets
description: >-
A part of imaginary, but delightful Museum API for interacting with museum services
and information. Built with love by Redocly.
version: 1.0.0

sourceDescriptions:
- name: museum-api
type: openapi
url: museum-api.yaml

workflows:
- workflowId: get-museum-tickets
description: >-
This workflow demonstrates how to buy tickets for the museum.
parameters:
- $ref: './parameter.yaml'
steps:
- stepId: buy-tickets
description: >-
Buy museum tickets resolving request details with buyMuseumTickets operationId from museum-api.yaml description.
operationId: buyMuseumTickets
requestBody:
$ref: './request-body.yaml#/requestBody'
successCriteria:
- condition: $statusCode == 201
outputs:
ticketId: $response.body.ticketId
outputs:
ticketId: $steps.buy-tickets.outputs.ticketId
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
in: header
name: Authorization
value: Basic Og==
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
requestBody:
payload:
ticketType: general
ticketDate: 2023-09-07
email: [email protected]
40 changes: 40 additions & 0 deletions __tests__/lint/arazzo-type-extensions-with-plugin/museum.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
arazzo: 1.0.0
info:
title: Redocly Museum API Tickets
description: >-
A part of imaginary, but delightful Museum API for interacting with museum services
and information. Built with love by Redocly.
version: 1.0.0
wrong-key: wrong-value
metadata:
lifecycle: production
owner-team: Engineering/Integrations
sourceDescriptions:
- name: museum-api
type: openapi
url: museum-api.yaml

workflows:
- workflowId: get-museum-tickets
description: >-
This workflow demonstrates how to buy tickets for the museum.
parameters:
- in: header
name: Authorization
value: Basic Og==
steps:
- stepId: buy-tickets
description: >-
Buy museum tickets resolving request details with buyMuseumTickets operationId from museum-api.yaml description.
operationId: buyMuseumTickets
requestBody:
payload:
ticketType: general
ticketDate: 2023-09-07
email: [email protected]
successCriteria:
- condition: $statusCode == 201
outputs:
ticketId: $response.body.ticketId
outputs:
ticketId: $steps.buy-tickets.outputs.ticketId
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
const XMetaData = {
properties: {
lifecycle: { type: 'string', enum: ['development', 'staging', 'production'] },
'owner-team': { type: 'string' },
},
required: ['lifecycle'],
};

module.exports = {
id: 'type-extension',
typeExtension: {
arazzo(types) {
newTypes = {
...types,
XMetaData: XMetaData,
'Root.info': {
...types['Root.info'],
properties: {
...types['Root.info'].properties,
metadata: 'XMetaData',
},
},
};

return newTypes;
},
},
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
plugins:
- plugins/type-extention.js

arazzoRules:
spec: error
32 changes: 16 additions & 16 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion packages/cli/src/utils/miscellaneous.ts
Original file line number Diff line number Diff line change
Expand Up @@ -526,7 +526,9 @@ export function checkIfRulesetExist(rules: typeof StyleguideConfig.prototype.rul
const ruleset = {
...rules.oas2,
...rules.oas3_0,
...rules.oas3_0,
...rules.oas3_1,
...rules.async2,
...rules.arazzo,
};

if (isEmptyObject(ruleset)) {
Expand Down
1 change: 1 addition & 0 deletions packages/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
"@types/node": "^20.11.5",
"@types/node-fetch": "^2.5.7",
"@types/pluralize": "^0.0.29",
"json-schema-to-ts": "^3.1.0",
"typescript": "^5.2.2"
}
}
13 changes: 13 additions & 0 deletions packages/core/src/bundle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,15 @@ export function mapTypeToComponent(typeName: string, version: SpecMajorVersion)
default:
return null;
}
case SpecMajorVersion.Arazzo:
switch (typeName) {
case 'Root.x-parameters_items':
case 'Root.workflows_items.parameters_items':
case 'Root.workflows_items.steps_items.parameters_items':
return 'parameters';
default:
return null;
}
}
}

Expand Down Expand Up @@ -367,6 +376,10 @@ function makeBundleVisitor(
components = root.components = root.components || {};
} else if (version === SpecMajorVersion.OAS2) {
components = root;
} else if (version === SpecMajorVersion.Async2) {
components = root.components = root.components || {};
} else if (version === SpecMajorVersion.Arazzo) {
components = root.components = root.components || {};
}
},
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,21 @@

exports[`resolveConfig should ignore minimal from the root and read local file 1`] = `
{
"arazzoDecorators": {},
"arazzoPreprocessors": {},
"arazzoRules": {
"spec": "error",
},
"async2Decorators": {},
"async2Preprocessors": {},
"async2Rules": {
"channels-kebab-case": "off",
"info-contact": "off",
"no-channel-trailing-slash": "off",
"operation-operationId": "warn",
"spec": "error",
"tag-description": "warn",
"tags-alphabetical": "off",
},
"decorators": {},
"doNotResolveExamples": undefined,
Expand Down Expand Up @@ -109,11 +119,21 @@ exports[`resolveConfig should ignore minimal from the root and read local file 1

exports[`resolveStyleguideConfig should resolve extends with local file config which contains path to nested config 1`] = `
{
"arazzoDecorators": {},
"arazzoPreprocessors": {},
"arazzoRules": {
"spec": "error",
},
"async2Decorators": {},
"async2Preprocessors": {},
"async2Rules": {
"channels-kebab-case": "off",
"info-contact": "off",
"no-channel-trailing-slash": "off",
"operation-operationId": "warn",
"spec": "error",
"tag-description": "warn",
"tags-alphabetical": "off",
},
"decorators": {},
"doNotResolveExamples": undefined,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,7 @@ StyleguideConfig {
"_usedVersions": Set {},
"configFile": undefined,
"decorators": {
"arazzo": {
"oas2": {},
"oas3_0": {},
"oas3_1": {},
},
"arazzo": {},
"async2": {
"oas2": {},
"oas3_0": {},
Expand Down Expand Up @@ -49,11 +45,7 @@ StyleguideConfig {
"pluginPaths": [],
"plugins": [],
"preprocessors": {
"arazzo": {
"oas2": {},
"oas3_0": {},
"oas3_1": {},
},
"arazzo": {},
"async2": {
"oas2": {},
"oas3_0": {},
Expand Down Expand Up @@ -117,20 +109,7 @@ StyleguideConfig {
},
"recommendedFallback": false,
"rules": {
"arazzo": {
"oas2": {
"no-empty-servers": "error",
"operation-summary": "error",
},
"oas3_0": {
"no-empty-servers": "error",
"operation-summary": "error",
},
"oas3_1": {
"no-empty-servers": "error",
"operation-summary": "error",
},
},
"arazzo": {},
"async2": {
"oas2": {
"no-empty-servers": "error",
Expand Down
9 changes: 2 additions & 7 deletions packages/core/src/config/__tests__/config.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -144,9 +144,7 @@ describe('getMergedConfig', () => {
},
"recommendedFallback": false,
"rules": {
"arazzo": {
"operation-summary": "warn",
},
"arazzo": {},
"async2": {
"operation-summary": "warn",
},
Expand Down Expand Up @@ -256,10 +254,7 @@ describe('getMergedConfig', () => {
},
"recommendedFallback": false,
"rules": {
"arazzo": {
"no-empty-servers": "error",
"operation-summary": "error",
},
"arazzo": {},
"async2": {
"no-empty-servers": "error",
"operation-summary": "error",
Expand Down
6 changes: 6 additions & 0 deletions packages/core/src/config/all.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,9 +106,15 @@ const all: PluginStyleguideConfig<'built-in'> = {
'array-parameter-serialization': 'error',
},
async2Rules: {
spec: 'error',
'info-contact': 'error',
'operation-operationId': 'error',
'tag-description': 'error',
'tags-alphabetical': 'error',
'channels-kebab-case': 'error',
'no-channel-trailing-slash': 'error',
},
arazzoRules: { spec: 'error' },
};

export default all;
Loading

0 comments on commit c9e47b8

Please sign in to comment.