@redocly/openapi-core 1.14.0 → 1.16.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (43) hide show
  1. package/CHANGELOG.md +16 -0
  2. package/lib/bundle.js +2 -2
  3. package/lib/config/config.d.ts +0 -6
  4. package/lib/config/config.js +1 -19
  5. package/lib/config/load.js +2 -2
  6. package/lib/decorators/common/registry-dependencies.js +2 -2
  7. package/lib/index.d.ts +3 -2
  8. package/lib/index.js +17 -2
  9. package/lib/redocly/domains.d.ts +14 -0
  10. package/lib/redocly/domains.js +41 -0
  11. package/lib/redocly/index.d.ts +1 -2
  12. package/lib/redocly/index.js +14 -24
  13. package/lib/redocly/registry-api.d.ts +2 -2
  14. package/lib/redocly/registry-api.js +9 -9
  15. package/lib/rules/common/no-invalid-parameter-examples.js +1 -1
  16. package/lib/rules/common/no-invalid-schema-examples.js +1 -1
  17. package/lib/rules/oas3/no-invalid-media-type-examples.js +1 -1
  18. package/lib/types/redocly-yaml.d.ts +0 -1
  19. package/lib/types/redocly-yaml.js +3 -7
  20. package/lib/utils.d.ts +2 -0
  21. package/lib/utils.js +7 -1
  22. package/package.json +5 -3
  23. package/src/__tests__/lint.test.ts +15 -36
  24. package/src/bundle.ts +1 -1
  25. package/src/config/__tests__/load.test.ts +13 -13
  26. package/src/config/config.ts +1 -23
  27. package/src/config/load.ts +2 -1
  28. package/src/decorators/common/registry-dependencies.ts +1 -1
  29. package/src/index.ts +4 -1
  30. package/src/redocly/__tests__/domains.test.ts +52 -0
  31. package/src/redocly/__tests__/redocly-client.test.ts +5 -3
  32. package/src/redocly/domains.ts +48 -0
  33. package/src/redocly/index.ts +14 -24
  34. package/src/redocly/registry-api.ts +25 -31
  35. package/src/rules/common/__tests__/no-invalid-parameter-examples.test.ts +53 -0
  36. package/src/rules/common/__tests__/no-invalid-schema-examples.test.ts +51 -0
  37. package/src/rules/common/no-invalid-parameter-examples.ts +1 -1
  38. package/src/rules/common/no-invalid-schema-examples.ts +1 -1
  39. package/src/rules/oas3/__tests__/no-invalid-media-type-examples.test.ts +52 -0
  40. package/src/rules/oas3/no-invalid-media-type-examples.ts +1 -1
  41. package/src/types/redocly-yaml.ts +3 -13
  42. package/src/utils.ts +7 -1
  43. package/tsconfig.tsbuildinfo +1 -1
@@ -0,0 +1,51 @@
1
+ import { outdent } from 'outdent';
2
+ import { lintDocument } from '../../../lint';
3
+ import { parseYamlToDocument, replaceSourceWithRef, makeConfig } from '../../../../__tests__/utils';
4
+ import { BaseResolver } from '../../../resolve';
5
+
6
+ describe('no-invalid-schema-examples', () => {
7
+ it('should report on invalid falsy example', async () => {
8
+ const document = parseYamlToDocument(
9
+ outdent`
10
+ openapi: 3.1.0
11
+ components:
12
+ schemas:
13
+ Car:
14
+ type: object
15
+ properties:
16
+ color:
17
+ type: string
18
+ example: 0
19
+ `,
20
+ 'foobar.yaml'
21
+ );
22
+
23
+ const results = await lintDocument({
24
+ externalRefResolver: new BaseResolver(),
25
+ document,
26
+ config: await makeConfig({ 'no-invalid-schema-examples': 'error' }),
27
+ });
28
+
29
+ expect(replaceSourceWithRef(results)).toMatchInlineSnapshot(`
30
+ [
31
+ {
32
+ "from": {
33
+ "pointer": "#/components/schemas/Car/properties/color",
34
+ "source": "foobar.yaml",
35
+ },
36
+ "location": [
37
+ {
38
+ "pointer": "#/components/schemas/Car/properties/color/example",
39
+ "reportOnKey": false,
40
+ "source": "foobar.yaml",
41
+ },
42
+ ],
43
+ "message": "Example value must conform to the schema: type must be string.",
44
+ "ruleId": "no-invalid-schema-examples",
45
+ "severity": "error",
46
+ "suggest": [],
47
+ },
48
+ ]
49
+ `);
50
+ });
51
+ });
@@ -7,7 +7,7 @@ export const NoInvalidParameterExamples: any = (opts: any) => {
7
7
  return {
8
8
  Parameter: {
9
9
  leave(parameter: Oas3Parameter, ctx: UserContext) {
10
- if (parameter.example) {
10
+ if (parameter.example !== undefined) {
11
11
  validateExample(
12
12
  parameter.example,
13
13
  parameter.schema!,
@@ -18,7 +18,7 @@ export const NoInvalidSchemaExamples: any = (opts: any) => {
18
18
  );
19
19
  }
20
20
  }
21
- if (schema.example) {
21
+ if (schema.example !== undefined) {
22
22
  validateExample(schema.example, schema, ctx.location.child('example'), ctx, true);
23
23
  }
24
24
  },
@@ -137,6 +137,58 @@ describe('no-invalid-media-type-examples', () => {
137
137
  `);
138
138
  });
139
139
 
140
+ it('should report on invalid example with a falsy value', async () => {
141
+ const document = parseYamlToDocument(
142
+ outdent`
143
+ openapi: 3.1.0
144
+ paths:
145
+ /test:
146
+ get:
147
+ responses:
148
+ '200':
149
+ content:
150
+ application/json:
151
+ schema:
152
+ type: string
153
+ example: false
154
+ `,
155
+ 'foobar.yaml'
156
+ );
157
+
158
+ const results = await lintDocument({
159
+ externalRefResolver: new BaseResolver(),
160
+ document,
161
+ config: await makeConfig({
162
+ 'no-invalid-media-type-examples': {
163
+ severity: 'error',
164
+ allowAdditionalProperties: false,
165
+ },
166
+ }),
167
+ });
168
+
169
+ expect(replaceSourceWithRef(results)).toMatchInlineSnapshot(`
170
+ [
171
+ {
172
+ "from": {
173
+ "pointer": "#/paths/~1test/get/responses/200/content/application~1json",
174
+ "source": "foobar.yaml",
175
+ },
176
+ "location": [
177
+ {
178
+ "pointer": "#/paths/~1test/get/responses/200/content/application~1json/example",
179
+ "reportOnKey": false,
180
+ "source": "foobar.yaml",
181
+ },
182
+ ],
183
+ "message": "Example value must conform to the schema: type must be string.",
184
+ "ruleId": "no-invalid-media-type-examples",
185
+ "severity": "error",
186
+ "suggest": [],
187
+ },
188
+ ]
189
+ `);
190
+ });
191
+
140
192
  it('should not report on valid example with allowAdditionalProperties', async () => {
141
193
  const document = parseYamlToDocument(
142
194
  outdent`
@@ -12,7 +12,7 @@ export const ValidContentExamples: Oas3Rule = (opts) => {
12
12
  leave(mediaType, ctx: UserContext) {
13
13
  const { location, resolve } = ctx;
14
14
  if (!mediaType.schema) return;
15
- if (mediaType.example) {
15
+ if (mediaType.example !== undefined) {
16
16
  resolveAndValidateExample(mediaType.example, location.child('example'));
17
17
  } else if (mediaType.examples) {
18
18
  for (const exampleName of Object.keys(mediaType.examples)) {
@@ -256,7 +256,6 @@ const createConfigRoot = (nodeTypes: Record<string, NodeType>): NodeType => ({
256
256
  ...nodeTypes.rootRedoclyConfigSchema.properties,
257
257
  ...ConfigStyleguide.properties,
258
258
  apis: 'ConfigApis', // Override apis with internal format
259
- theme: 'ConfigRootTheme', // Override theme with internal format
260
259
  'features.openapi': 'ConfigReferenceDocs', // deprecated
261
260
  'features.mockServer': 'ConfigMockServer', // deprecated
262
261
  organization: { type: 'string' },
@@ -315,14 +314,6 @@ const ConfigHTTP: NodeType = {
315
314
  },
316
315
  };
317
316
 
318
- const createConfigRootTheme = (nodeTypes: Record<string, NodeType>): NodeType => ({
319
- ...nodeTypes['rootRedoclyConfigSchema.theme'],
320
- properties: {
321
- ...nodeTypes['rootRedoclyConfigSchema.theme']?.properties,
322
- openapi: 'ConfigReferenceDocs', // Override theme.openapi with internal format
323
- },
324
- });
325
-
326
317
  const Rules: NodeType = {
327
318
  properties: {},
328
319
  additionalProperties: (value: unknown, key: string) => {
@@ -932,10 +923,10 @@ const GenerateCodeSamples: NodeType = {
932
923
  required: ['languages'],
933
924
  };
934
925
 
926
+ // TODO: deprecated
935
927
  const ConfigReferenceDocs: NodeType = {
936
- // TODO: partially invalid @Viacheslav
937
928
  properties: {
938
- theme: 'ConfigTheme', // TODO: deprecated @Viacheslav
929
+ theme: 'ConfigTheme',
939
930
  corsProxyUrl: { type: 'string' },
940
931
  ctrlFHijack: { type: 'boolean' },
941
932
  defaultSampleLanguage: { type: 'string' },
@@ -1072,9 +1063,8 @@ export const createConfigTypes = (extraSchemas: JSONSchema) => {
1072
1063
 
1073
1064
  return {
1074
1065
  ...CoreConfigTypes,
1075
- ConfigRoot: createConfigRoot(nodeTypes),
1066
+ ConfigRoot: createConfigRoot(nodeTypes), // This is the REAL config root type
1076
1067
  ConfigApisProperties: createConfigApisProperties(nodeTypes),
1077
- ConfigRootTheme: createConfigRootTheme(nodeTypes),
1078
1068
  ...nodeTypes,
1079
1069
  };
1080
1070
  };
package/src/utils.ts CHANGED
@@ -5,9 +5,10 @@ import fetch from 'node-fetch';
5
5
  import * as pluralize from 'pluralize';
6
6
  import { parseYaml } from './js-yaml';
7
7
  import { UserContext } from './walk';
8
- import { HttpResolveConfig } from './config';
9
8
  import { env } from './env';
10
9
  import { logger, colorize } from './logger';
10
+ import { HttpResolveConfig } from './config';
11
+ import { HttpsProxyAgent } from 'https-proxy-agent';
11
12
 
12
13
  export { parseYaml, stringifyYaml } from './js-yaml';
13
14
 
@@ -278,3 +279,8 @@ export async function pause(ms: number): Promise<void> {
278
279
  function getUpdatedFieldName(updatedField: string, updatedObject?: string) {
279
280
  return `${typeof updatedObject !== 'undefined' ? `${updatedObject}.` : ''}${updatedField}`;
280
281
  }
282
+
283
+ export function getProxyAgent() {
284
+ const proxy = process.env.HTTPS_PROXY || process.env.HTTP_PROXY;
285
+ return proxy ? new HttpsProxyAgent(proxy) : undefined;
286
+ }