Repository: Redocly/openapi-cli
Pull request #172 (2020-07-22 15:44:48)

chore: Update issue templates


Patch:
diff --git a/.github/ISSUE_TEMPLATE/bug_report.md b/.github/ISSUE_TEMPLATE/bug_report.md
new file mode 100644
index 00000000..63103a05
--- /dev/null
+++ b/.github/ISSUE_TEMPLATE/bug_report.md
@@ -0,0 +1,33 @@
+---
+name: Bug report
+about: Create a report to help us improve
+title: ''
+labels: bug
+assignees: ''
+
+---
+
+**Describe the bug**
+A clear and concise description of what the bug is.
+
+**To Reproduce**
+Steps to reproduce the behavior:
+1. Given this `.redocly.yaml` file
+2. And this OpenAPI file(s)
+3. Run this command with these arguments... `openapi ...`
+4. See error
+
+**Expected behavior**
+A clear and concise description of what you expected to happen.
+
+**Logs**
+If applicable, add logs to help explain your problem.
+
+**OpenAPI definition**
+If applicable, add an OpenAPI definition and `.redocly.yaml` configuration file that helps reproduce the problem.
+
+**Version(s)**
+What version are you using?
+
+**Additional context**
+Add any other context about the problem here.
diff --git a/.github/ISSUE_TEMPLATE/feature_request.md b/.github/ISSUE_TEMPLATE/feature_request.md
new file mode 100644
index 00000000..e301d68c
--- /dev/null
+++ b/.github/ISSUE_TEMPLATE/feature_request.md
@@ -0,0 +1,20 @@
+---
+name: Feature request
+about: Suggest an idea for this project
+title: ''
+labels: feature request
+assignees: ''
+
+---
+
+**Is your feature request related to a problem? Please describe.**
+A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]
+
+**Describe the solution you'd like**
+A clear and concise description of what you want to happen.
+
+**Describe alternatives you've considered**
+A clear and concise description of any alternative solutions or features you've considered.
+
+**Additional context**
+Add any other context or screenshots about the feature request here.
diff --git a/package-lock.json b/package-lock.json
index 5d88dfd4..0d9d3826 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -1,6 +1,6 @@
 {
   "name": "@redocly/openapi-cli",
-  "version": "1.0.0-beta.5",
+  "version": "1.0.0-beta.7",
   "lockfileVersion": 1,
   "requires": true,
   "dependencies": {
@@ -3120,9 +3120,9 @@
       }
     },
     "lodash": {
-      "version": "4.17.15",
-      "resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.15.tgz",
-      "integrity": "sha512-8xOcRHvCjnocdS5cpwXQXVzmmh5e5+saE2QGoeQmbKmRS6J3VQppPOIt0MnmE+4xlZoumy0GPG0D0MVIQbNA1A=="
+      "version": "4.17.19",
+      "resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.19.tgz",
+      "integrity": "sha512-JNvd8XER9GQX0v2qJgsaN/mzFCNA5BRe/j8JN9d+tWyGLSodKQHKFicdwNYzWwI3wjRnaKPsGj1XkBjx/F96DQ=="
     },
     "lodash.isequal": {
       "version": "4.5.0",
diff --git a/package.json b/package.json
index 7862aede..4eb1b537 100644
--- a/package.json
+++ b/package.json
@@ -1,6 +1,6 @@
 {
   "name": "@redocly/openapi-cli",
-  "version": "1.0.0-beta.5",
+  "version": "1.0.0-beta.7",
   "description": "",
   "main": "lib/index.js",
   "scripts": {
diff --git a/src/bundle.ts b/src/bundle.ts
index a12ca257..b60a7ed9 100644
--- a/src/bundle.ts
+++ b/src/bundle.ts
@@ -74,7 +74,7 @@ export async function bundleDocument(opts: {
       {
         severity: 'error',
         ruleId: 'bundler',
-        visitor: makeBundleVisitor(oasMajorVersion, dereference),
+        visitor: makeBundleVisitor(oasMajorVersion, dereference, document),
       },
       ...decorators,
     ],
@@ -143,7 +143,7 @@ function mapTypeToComponent(typeName: string, version: OasMajorVersion) {
 
 // function oas3Move
 
-function makeBundleVisitor(version: OasMajorVersion, dereference: boolean) {
+function makeBundleVisitor(version: OasMajorVersion, dereference: boolean, rootDocument: Document) {
   let components: Record<string, Record<string, any>>;
 
   const visitor: Oas3Visitor | Oas2Visitor = {
@@ -153,6 +153,12 @@ function makeBundleVisitor(version: OasMajorVersion, dereference: boolean) {
           reportUnresolvedRef(resolved, ctx.report, ctx.location);
           return;
         }
+        if (
+          resolved.location.source === rootDocument.source &&
+          resolved.location.source === ctx.location.source
+        ) {
+          return;
+        }
         const componentType = mapTypeToComponent(ctx.type.name, version);
         if (!componentType) {
           if (ctx.type.name === 'scalar') {
@@ -237,14 +243,14 @@ function makeBundleVisitor(version: OasMajorVersion, dereference: boolean) {
       return name;
 
     if (pointerBase) {
-      name = `${refBase}/${pointerBase}`;
+      name = `${refBase}_${pointerBase}`;
       if (!componentsGroup[name] || isEqual(componentsGroup[name], target.node)) return name;
     }
 
     const prevName = name;
     let serialId = 2;
     while (componentsGroup[name] && !isEqual(componentsGroup[name], target.node)) {
-      name = `${name}-${serialId}`;
+      name = `${prevName}-${serialId}`;
       serialId++;
     }
 
diff --git a/src/redocly/index.ts b/src/redocly/index.ts
index 41dbf8b1..171ec80d 100644
--- a/src/redocly/index.ts
+++ b/src/redocly/index.ts
@@ -48,7 +48,7 @@ export class RedoclyClient {
       process.stderr.write(
         `${yellow(
           'Warning:',
-        )} invalid Redoc.ly access token. Use "npx @redocly/openapi-cli registry:login" to provide your access token\n`,
+        )} invalid Redoc.ly access token. Use "npx @redocly/openapi-cli login" to provide your access token\n`,
       );
       return undefined;
     }
diff --git a/src/rules/common/path-not-include-query.ts b/src/rules/common/path-not-include-query.ts
index 463b940e..b8672733 100644
--- a/src/rules/common/path-not-include-query.ts
+++ b/src/rules/common/path-not-include-query.ts
@@ -3,13 +3,15 @@ import { UserContext } from '../../walk';
 
 export const PathNotIncludeQuery: Oas3Rule | Oas2Rule = () => {
   return {
-    PathItem(_operation: object, { report, key }: UserContext) {
-      if (key.toString().includes('?')) {
-        report({
-          message: `Don't put query string items in the path, they belong in parameters with \`in: query\`.`,
-          location: { reportOnKey: true },
-        });
-      }
-    },
+    PathMap: {
+      PathItem(_operation: object, { report, key }: UserContext) {
+        if (key.toString().includes('?')) {
+          report({
+            message: `Don't put query string items in the path, they belong in parameters with \`in: query\`.`,
+            location: { reportOnKey: true },
+          });
+        }
+      },
+    }
   };
 };
diff --git a/src/types/oas3.ts b/src/types/oas3.ts
index 7979230e..20f4f341 100644
--- a/src/types/oas3.ts
+++ b/src/types/oas3.ts
@@ -182,6 +182,11 @@ const Parameter: NodeType = {
   required: ['name', 'in'],
 };
 
+const Callback = {
+  properties: {},
+  additionalProperties: 'PathItem'
+}
+
 const Operation: NodeType = {
   properties: {
     tags: {
@@ -207,7 +212,7 @@ const Operation: NodeType = {
     deprecated: {
       type: 'boolean',
     },
-    callbacks: 'PathMap',
+    callbacks: mapOf('Callback'),
     'x-codeSamples': listOf('XCodeSample'),
     'x-code-samples': listOf('XCodeSample'), // deprecated
   },
@@ -536,6 +541,7 @@ export const Oas3Types: Record<string, NodeType> = {
   PathItem,
   Parameter,
   Operation,
+  Callback,
   RequestBody,
   MediaTypeMap,
   MediaType,
diff --git a/src/visitors.ts b/src/visitors.ts
index d8c051cd..2de53717 100644
--- a/src/visitors.ts
+++ b/src/visitors.ts
@@ -133,6 +133,7 @@ type Oas3FlatVisitor = {
   License?: VisitFunctionOrObject<Oas3License>;
   PathMap?: VisitFunctionOrObject<Record<string, Oas3PathItem>>;
   PathItem?: VisitFunctionOrObject<Oas3PathItem>;
+  Callback?: VisitFunctionOrObject<Record<string, Oas3PathItem>>;
   Parameter?: VisitFunctionOrObject<Oas3Parameter>;
   Operation?: VisitFunctionOrObject<Oas3Operation>;
   RequestBody?: VisitFunctionOrObject<Oas3RequestBody>;


Test patch:
diff --git a/src/__tests__/__snapshots__/bundle.test.ts.snap b/src/__tests__/__snapshots__/bundle.test.ts.snap
index 132a3107..19199b82 100644
--- a/src/__tests__/__snapshots__/bundle.test.ts.snap
+++ b/src/__tests__/__snapshots__/bundle.test.ts.snap
@@ -10,10 +10,14 @@ paths:
       parameters:
         - $ref: '#/components/parameters/param-a'
         - $ref: '#/components/parameters/param-b'
+        - name: test
     get:
       parameters:
         - $ref: '#/components/parameters/param-a'
         - $ref: '#/components/parameters/param-c'
+    post:
+      parameters:
+        - $ref: '#/paths/~1pet/put/parameters/2'
 components:
   parameters:
     param-a:
diff --git a/src/__tests__/fixtures/refs/openapi-with-external-refs.yaml b/src/__tests__/fixtures/refs/openapi-with-external-refs.yaml
index 1406fa7b..c0ab3f90 100644
--- a/src/__tests__/fixtures/refs/openapi-with-external-refs.yaml
+++ b/src/__tests__/fixtures/refs/openapi-with-external-refs.yaml
@@ -7,10 +7,14 @@ paths:
       parameters:
         - $ref: '#/components/parameters/param-a'
         - $ref: ./param-b.yaml
+        - name: test
     get:
       parameters:
         - $ref: '#/components/parameters/param-a'
         - $ref: ./param-c.yaml
+    post:
+      parameters:
+        - $ref: '#/paths/~1pet/put/parameters/2'
 components:
   parameters:
     param-a:
diff --git a/src/rules/oas3/__tests__/spec/callbacks.test.ts b/src/rules/oas3/__tests__/spec/callbacks.test.ts
new file mode 100644
index 00000000..65fdea67
--- /dev/null
+++ b/src/rules/oas3/__tests__/spec/callbacks.test.ts
@@ -0,0 +1,41 @@
+import { outdent } from 'outdent';
+import { validateDoc } from './utils';
+
+it('should not fail on valid callbacks object', async () => {
+  const source = outdent`
+    openapi: 3.0.2
+    info:
+      title: Test
+      version: '1.0'
+
+    servers:
+      - url: http://google.com
+
+    paths:
+      '/ping':
+        summary: test
+        get:
+          callbacks:
+            test:
+              'http://notificationServer.com?transactionId={$request.body#/id}&email={$request.body#/email}':
+                post:
+                  requestBody:
+                    description: Callback payload
+                    content:
+                      'application/json':
+                        schema:
+                          $ref: '#/components/schemas/SomePayload'
+                  responses:
+                    '200':
+                      description: webhook successfully processed and no retries will be performed
+          responses:
+            '200':
+              description: example description
+  `;
+
+  expect(
+    await validateDoc(source, {
+      spec: 'error',
+    }),
+  ).toMatchInlineSnapshot(`Array []`);
+});