Skip to content

Commit 65681b6

Browse files
committed
chore: updating node types for oas 3.0
1 parent 6a4914c commit 65681b6

2 files changed

Lines changed: 121 additions & 33 deletions

File tree

packages/core/src/types/index.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,11 +60,15 @@ export function listOf(
6060
};
6161
}
6262

63-
export function mapOf(typeName: string) {
63+
export function mapOf(
64+
typeName: string,
65+
opts: { description?: string; documentationLink?: string } = {}
66+
) {
6467
return {
6568
name: `${typeName}Map`,
6669
properties: {},
6770
additionalProperties: () => typeName,
71+
...opts,
6872
};
6973
}
7074

packages/core/src/types/oas3.ts

Lines changed: 116 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -19,17 +19,20 @@ const Root: NodeType = {
1919
},
2020
required: ['openapi', 'paths', 'info'],
2121
extensionsPrefix: 'x-',
22+
documentationLink: 'https://redocly.com/learn/openapi/openapi-visual-reference/openapi#openapi',
23+
description:
24+
'REQUIRED. This string MUST be the semantic version number of the OpenAPI Specification version that the OpenAPI document uses. The openapi field SHOULD be used by tooling specifications and clients to interpret the OpenAPI document. This is not related to the API info.version string.',
2225
};
2326

2427
const Tag: NodeType = {
2528
properties: {
2629
name: {
2730
type: 'string',
28-
description: `The name of the tag.`,
31+
description: 'REQUIRED. The name of the tag.',
2932
},
3033
description: {
3134
type: 'string',
32-
description: `A short description for the tag. CommonMark syntax MAY be used for rich text representation.`,
35+
description: 'A description for the tag.',
3336
},
3437
externalDocs: 'ExternalDocs',
3538
'x-traitTag': { type: 'boolean' },
@@ -54,59 +57,98 @@ const ExternalDocs: NodeType = {
5457
description: {
5558
type: 'string',
5659
description:
57-
'A description of the target documentation. CommonMark syntax MAY be used for rich text representation.',
60+
'A description of the target documentation. Used as the link anchor text in Redocly. If not provided, the url is used as the link anchor text.',
5861
},
5962
url: {
6063
type: 'string',
61-
description:
62-
'REQUIRED. The URL for the target documentation. This MUST be in the format of a URL.',
64+
description: 'REQUIRED. The URL for the target documentation.',
6365
},
6466
},
6567
required: ['url'],
6668
extensionsPrefix: 'x-',
6769
description: 'Additional external documentation for this operation.',
70+
documentationLink: 'https://redocly.com/learn/openapi/openapi-visual-reference/external-docs',
6871
};
6972

7073
const Server: NodeType = {
7174
properties: {
72-
url: { type: 'string' },
73-
description: { type: 'string' },
75+
url: {
76+
type: 'string',
77+
description:
78+
'REQUIRED. A URL to the target host. This URL supports Server Variables and MAY be relative, to indicate that the host location is relative to the location where the OpenAPI document is being served. Variable substitutions are made when a variable is named in { curly braces }.',
79+
},
80+
description: {
81+
type: 'string',
82+
description: 'An optional string describing the host designated by the URL.',
83+
},
7484
variables: 'ServerVariablesMap',
7585
},
7686
required: ['url'],
7787
extensionsPrefix: 'x-',
88+
description: 'A server object to be used by the target operation.',
7889
};
7990

8091
const ServerVariable: NodeType = {
8192
properties: {
8293
enum: {
8394
type: 'array',
8495
items: { type: 'string' },
96+
description:
97+
'An enumeration of string values to be used if the substitution options are from a limited set. The array MUST NOT be empty. If defined, the array MUST contain the default value.',
98+
},
99+
default: {
100+
type: 'string',
101+
description: `REQUIRED. The default value to use for substitution, which SHALL be sent if an alternate value is not supplied. Note this behavior is different than the Schema Object's treatment of default values, because in those cases parameter values are optional. If the enum is defined, the value MUST exist in the enum's values.`,
102+
},
103+
description: {
104+
type: 'string',
105+
description: 'An optional description for the server variable.',
85106
},
86-
default: { type: 'string' },
87-
description: { type: 'string' },
88107
},
89108
required: ['default'],
90109
extensionsPrefix: 'x-',
110+
documentationLink:
111+
'https://redocly.com/learn/openapi/openapi-visual-reference/server-variables#server-variables',
112+
description:
113+
'Server variables are used when you need to make a substitution into the server URL such as when the subdomain is unique per tenant.',
91114
};
92115

93116
const SecurityRequirement: NodeType = {
94117
properties: {},
95118
additionalProperties: { type: 'array', items: { type: 'string' } },
119+
documentationLink: 'https://redocly.com/learn/openapi/openapi-visual-reference/security',
120+
description:
121+
'A declaration of which security mechanisms can be used across the API. The list of values includes alternative security requirement objects that can be used. Only one of the security requirement objects need to be satisfied to authorize a request. Individual operations can override this definition. To make security optional, an empty security requirement ({}) can be included in the array.',
96122
};
97123

98124
const Info: NodeType = {
99125
properties: {
100-
title: { type: 'string' },
101-
version: { type: 'string' },
102-
description: { type: 'string' },
103-
termsOfService: { type: 'string' },
126+
title: {
127+
type: 'string',
128+
description: 'REQUIRED. The title of the API.',
129+
},
130+
version: {
131+
type: 'string',
132+
description:
133+
'REQUIRED. The version of the OpenAPI document (which is distinct from the OpenAPI Specification version or the API implementation version).',
134+
},
135+
description: {
136+
type: 'string',
137+
description: 'RECOMMENDED. A description of the API (Markdown may be used).',
138+
},
139+
termsOfService: {
140+
type: 'string',
141+
description: 'A URL to the Terms of Service for the API.',
142+
},
104143
contact: 'Contact',
105144
license: 'License',
106145
'x-logo': 'Logo',
107146
},
108147
required: ['title', 'version'],
109148
extensionsPrefix: 'x-',
149+
description:
150+
'REQUIRED. Provides metadata about the API. The metadata MAY be used by tooling as required.',
151+
documentationLink: 'https://redocly.com/learn/openapi/openapi-visual-reference/info#info',
110152
};
111153

112154
const Logo: NodeType = {
@@ -116,32 +158,57 @@ const Logo: NodeType = {
116158
backgroundColor: { type: 'string' },
117159
href: { type: 'string' },
118160
},
161+
documentationLink:
162+
'https://redocly.com/docs-legacy/api-reference-docs/specification-extensions/x-logo#x-logo',
163+
description:
164+
'A commonly used specification extension containing the information about the API logo.',
119165
};
120166

121167
const Contact: NodeType = {
122168
properties: {
123-
name: { type: 'string' },
124-
url: { type: 'string' },
125-
email: { type: 'string' },
169+
name: {
170+
type: 'string',
171+
description: 'The identifying name of the contact person or organization.',
172+
},
173+
url: {
174+
type: 'string',
175+
description: 'The URL pointing to the contact information.',
176+
},
177+
email: {
178+
type: 'string',
179+
description: 'The email address of the contact person or organization.',
180+
},
126181
},
127182
extensionsPrefix: 'x-',
183+
documentationLink: 'https://redocly.com/learn/openapi/openapi-visual-reference/contact',
184+
description: 'The contact information for the exposed API.',
128185
};
129186

130187
const License: NodeType = {
131188
properties: {
132-
name: { type: 'string' },
133-
url: { type: 'string' },
189+
name: {
190+
type: 'string',
191+
description: 'REQUIRED. The license name used for the API.',
192+
},
193+
url: {
194+
type: 'string',
195+
description: 'The URL pointing to the contact information.',
196+
},
134197
},
135198
required: ['name'],
136199
extensionsPrefix: 'x-',
200+
documentationLink: 'https://redocly.com/learn/openapi/openapi-visual-reference/license#license',
201+
description: 'The license information for the exposed API.',
137202
};
138203

139204
const Paths: NodeType = {
140205
properties: {},
141206
additionalProperties: (_value: any, key: string) =>
142207
key.startsWith('/') ? 'PathItem' : undefined,
143-
description: 'The available paths and operations for the API.',
144-
documentationLink: 'https://redocly.com/learn/openapi/openapi-visual-reference/paths',
208+
description:
209+
'The Paths Object is a map of a paths to the path item object. A path starts with a /.',
210+
documentationLink:
211+
'https://redocly.com/learn/openapi/openapi-visual-reference/paths#paths-object',
145212
};
146213

147214
const WebhooksMap: NodeType = {
@@ -166,7 +233,7 @@ const PathItem: NodeType = {
166233
description: {
167234
type: 'string',
168235
description:
169-
'An optional, string description, intended to apply to all operations in this path. CommonMark syntax MAY be used for rich text representation.',
236+
'An optional, string description, intended to apply to all operations in this path.',
170237
},
171238

172239
get: 'Operation',
@@ -198,8 +265,7 @@ const Parameter: NodeType = {
198265
},
199266
description: {
200267
type: 'string',
201-
description:
202-
'A brief description of the parameter. This could contain examples of use. CommonMark syntax MAY be used for rich text representation.',
268+
description: 'A brief description of the parameter. This could contain examples of use.',
203269
},
204270
required: {
205271
type: 'boolean',
@@ -250,7 +316,6 @@ const Operation: NodeType = {
250316
items: { type: 'string' },
251317
description:
252318
'A list of tags for API documentation control. Tags can be used for logical grouping of operations by resources or any other qualifier.',
253-
documentationLink: 'https://redocly.com/learn/openapi/openapi-visual-reference/operation',
254319
},
255320
summary: {
256321
type: 'string',
@@ -260,8 +325,7 @@ const Operation: NodeType = {
260325
},
261326
description: {
262327
type: 'string',
263-
description:
264-
'A verbose explanation of the operation behavior. CommonMark syntax MAY be used for rich text representation.',
328+
description: 'A verbose explanation of the operation behavior.',
265329
documentationLink:
266330
'https://redocly.com/learn/openapi/openapi-visual-reference/operation#description',
267331
},
@@ -300,14 +364,21 @@ const XCodeSample: NodeType = {
300364

301365
const RequestBody: NodeType = {
302366
properties: {
303-
description: { type: 'string' },
304-
required: { type: 'boolean' },
367+
description: {
368+
type: 'string',
369+
description: 'A brief description of the request body. This could contain examples of use.',
370+
},
371+
required: {
372+
type: 'boolean',
373+
description: 'Determines if the request body is required in the request. Defaults to false.',
374+
},
305375
content: 'MediaTypesMap',
306376
},
307377
required: ['content'],
308378
extensionsPrefix: 'x-',
379+
documentationLink: 'https://redocly.com/learn/openapi/openapi-visual-reference/request-body',
309380
description:
310-
'The request body applicable for this operation. The requestBody is fully supported in HTTP methods where the HTTP 1.1 specification [RFC7231] Section 4.3.1 has explicitly defined semantics for request bodies. In other cases where the HTTP spec is vague (such as GET, HEAD and DELETE), requestBody is permitted but does not have well-defined semantics and SHOULD be avoided if possible.',
381+
'The request body is defined inside of operations (including paths and webhooks). The request body can also be defined inside of the named requestBodies object in components.',
311382
};
312383

313384
const MediaTypesMap: NodeType = {
@@ -323,6 +394,8 @@ const MediaType: NodeType = {
323394
encoding: 'EncodingMap',
324395
},
325396
extensionsPrefix: 'x-',
397+
description: 'The Media Type Object is one of the important building blocks of OpenAPI.',
398+
documentationLink: 'https://redocly.com/learn/openapi/openapi-visual-reference/media-type',
326399
};
327400

328401
const Example: NodeType = {
@@ -333,6 +406,9 @@ const Example: NodeType = {
333406
externalValue: { type: 'string' },
334407
},
335408
extensionsPrefix: 'x-',
409+
description:
410+
'Example of the media type. The example object SHOULD be in the correct format as specified by the media type. The example field is mutually exclusive of the examples field. Furthermore, if referencing a schema which contains an example, the example value SHALL override the example provided by the schema.',
411+
documentationLink: 'https://redocly.com/learn/openapi/openapi-visual-reference/example',
336412
};
337413

338414
const Encoding: NodeType = {
@@ -461,6 +537,8 @@ const Schema: NodeType = {
461537
'x-explicitMappingOnly': { type: 'boolean' },
462538
},
463539
extensionsPrefix: 'x-',
540+
description: 'The schema defining the content of the request, response, or parameter.',
541+
documentationLink: 'https://redocly.com/learn/openapi/openapi-visual-reference/schemas',
464542
};
465543

466544
const Xml: NodeType = {
@@ -626,15 +704,21 @@ export const Oas3Types = {
626704
Root,
627705
Tag,
628706
TagList: listOf('Tag', {
629-
description: `A list of tags used by the document with additional metadata.`,
707+
documentationLink: 'https://redocly.com/learn/openapi/openapi-visual-reference/tags',
708+
description: `A list of tags used by the document with additional metadata. The order of the tags can be used to reflect on their order by the parsing tools. Not all tags that are used by the Operation Object must be declared. The tags that are not declared MAY be organized randomly or based on the tools' logic. Each tag name in the list MUST be unique.`,
630709
}),
631710
TagGroups: listOf('TagGroup'),
632711
TagGroup,
633712
ExternalDocs,
634713
Server,
635-
ServerList: listOf('Server'),
714+
ServerList: listOf('Server', {
715+
description: 'A list of servers available to the API.',
716+
documentationLink: 'https://redocly.com/learn/openapi/openapi-visual-reference/servers#servers',
717+
}),
636718
ServerVariable,
637-
ServerVariablesMap: mapOf('ServerVariable'),
719+
ServerVariablesMap: mapOf('ServerVariable', {
720+
description: `A map between a variable name and its value. The value is used for substitution in the server's URL template.`,
721+
}),
638722
SecurityRequirement,
639723
SecurityRequirementList: listOf('SecurityRequirement'),
640724
Info,

0 commit comments

Comments
 (0)