diff --git a/__tests__/commands/openapi/__snapshots__/index.test.ts.snap b/__tests__/commands/openapi/__snapshots__/index.test.ts.snap new file mode 100644 index 00000000..25754f2b --- /dev/null +++ b/__tests__/commands/openapi/__snapshots__/index.test.ts.snap @@ -0,0 +1,1083 @@ +// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html + +exports[`rdme openapi > GHA onboarding E2E tests > should create GHA workflow (--create flag enabled with ignored id opt) 1`] = ` +" +Your GitHub Actions workflow file has been created! ✨ + +Almost done! Just a couple more steps: +1. Push your newly created file (.github/workflows/openapi-file-create-flag-id-opt.yml) to GitHub 🚀 +2. Create a GitHub secret called README_API_KEY and populate the value with your ReadMe API key (••••••••••••I_KEY) 🔑 + +🔐 Check out GitHub's docs for more info on creating encrypted secrets (https://docs.github.com/actions/security-guides/encrypted-secrets#creating-encrypted-secrets-for-a-repository) + +🦉 If you have any more questions, feel free to drop us a line! support@readme.io +" +`; + +exports[`rdme openapi > GHA onboarding E2E tests > should create GHA workflow (--create flag enabled with ignored id opt) 2`] = ` +"# This GitHub Actions workflow was auto-generated by the \`rdme\` cli on 2022-01-01T00:00:00.000Z +# You can view our full documentation here: https://docs.readme.com/docs/rdme +name: ReadMe GitHub Action 🦉 + +on: + push: + branches: + # This workflow will run every time you push code to the following branch: \`openapi-branch-create-flag-id-opt\` + # Check out GitHub's docs for more info on configuring this: + # https://docs.github.com/actions/using-workflows/events-that-trigger-workflows + - openapi-branch-create-flag-id-opt + +jobs: + rdme-openapi: + runs-on: ubuntu-latest + steps: + - name: Check out repo 📚 + uses: actions/checkout@v4 + + - name: Run \`openapi\` command 🚀 + uses: readmeio/rdme@v7 + with: + rdme: openapi ./__tests__/__fixtures__/ref-oas/petstore.json --key=\${{ secrets.README_API_KEY }} --version=1.0.0 --create +" +`; + +exports[`rdme openapi > GHA onboarding E2E tests > should create GHA workflow (--create flag enabled) 1`] = ` +" +Your GitHub Actions workflow file has been created! ✨ + +Almost done! Just a couple more steps: +1. Push your newly created file (.github/workflows/openapi-file-create-flag.yml) to GitHub 🚀 +2. Create a GitHub secret called README_API_KEY and populate the value with your ReadMe API key (••••••••••••I_KEY) 🔑 + +🔐 Check out GitHub's docs for more info on creating encrypted secrets (https://docs.github.com/actions/security-guides/encrypted-secrets#creating-encrypted-secrets-for-a-repository) + +🦉 If you have any more questions, feel free to drop us a line! support@readme.io +" +`; + +exports[`rdme openapi > GHA onboarding E2E tests > should create GHA workflow (--create flag enabled) 2`] = ` +"# This GitHub Actions workflow was auto-generated by the \`rdme\` cli on 2022-01-01T00:00:00.000Z +# You can view our full documentation here: https://docs.readme.com/docs/rdme +name: ReadMe GitHub Action 🦉 + +on: + push: + branches: + # This workflow will run every time you push code to the following branch: \`openapi-branch-create-flag\` + # Check out GitHub's docs for more info on configuring this: + # https://docs.github.com/actions/using-workflows/events-that-trigger-workflows + - openapi-branch-create-flag + +jobs: + rdme-openapi: + runs-on: ubuntu-latest + steps: + - name: Check out repo 📚 + uses: actions/checkout@v4 + + - name: Run \`openapi\` command 🚀 + uses: readmeio/rdme@v7 + with: + rdme: openapi ./__tests__/__fixtures__/ref-oas/petstore.json --key=\${{ secrets.README_API_KEY }} --version=1.0.1 --create +" +`; + +exports[`rdme openapi > GHA onboarding E2E tests > should create GHA workflow (--github flag enabled) 1`] = ` +" +Your GitHub Actions workflow file has been created! ✨ + +Almost done! Just a couple more steps: +1. Push your newly created file (.github/workflows/openapi-file-github-flag.yml) to GitHub 🚀 +2. Create a GitHub secret called README_API_KEY and populate the value with your ReadMe API key (••••••••••••I_KEY) 🔑 + +🔐 Check out GitHub's docs for more info on creating encrypted secrets (https://docs.github.com/actions/security-guides/encrypted-secrets#creating-encrypted-secrets-for-a-repository) + +🦉 If you have any more questions, feel free to drop us a line! support@readme.io +" +`; + +exports[`rdme openapi > GHA onboarding E2E tests > should create GHA workflow (--github flag enabled) 2`] = ` +"# This GitHub Actions workflow was auto-generated by the \`rdme\` cli on 2022-01-01T00:00:00.000Z +# You can view our full documentation here: https://docs.readme.com/docs/rdme +name: ReadMe GitHub Action 🦉 + +on: + push: + branches: + # This workflow will run every time you push code to the following branch: \`openapi-branch-github-flag\` + # Check out GitHub's docs for more info on configuring this: + # https://docs.github.com/actions/using-workflows/events-that-trigger-workflows + - openapi-branch-github-flag + +jobs: + rdme-openapi: + runs-on: ubuntu-latest + steps: + - name: Check out repo 📚 + uses: actions/checkout@v4 + + - name: Run \`openapi\` command 🚀 + uses: readmeio/rdme@v7 + with: + rdme: openapi ./__tests__/__fixtures__/ref-oas/petstore.json --key=\${{ secrets.README_API_KEY }} --id=1 +" +`; + +exports[`rdme openapi > GHA onboarding E2E tests > should create GHA workflow (--update flag enabled) 1`] = ` +" +Your GitHub Actions workflow file has been created! ✨ + +Almost done! Just a couple more steps: +1. Push your newly created file (.github/workflows/openapi-file-update-flag.yml) to GitHub 🚀 +2. Create a GitHub secret called README_API_KEY and populate the value with your ReadMe API key (••••••••••••I_KEY) 🔑 + +🔐 Check out GitHub's docs for more info on creating encrypted secrets (https://docs.github.com/actions/security-guides/encrypted-secrets#creating-encrypted-secrets-for-a-repository) + +🦉 If you have any more questions, feel free to drop us a line! support@readme.io +" +`; + +exports[`rdme openapi > GHA onboarding E2E tests > should create GHA workflow (--update flag enabled) 2`] = ` +"# This GitHub Actions workflow was auto-generated by the \`rdme\` cli on 2022-01-01T00:00:00.000Z +# You can view our full documentation here: https://docs.readme.com/docs/rdme +name: ReadMe GitHub Action 🦉 + +on: + push: + branches: + # This workflow will run every time you push code to the following branch: \`openapi-branch-update-flag\` + # Check out GitHub's docs for more info on configuring this: + # https://docs.github.com/actions/using-workflows/events-that-trigger-workflows + - openapi-branch-update-flag + +jobs: + rdme-openapi: + runs-on: ubuntu-latest + steps: + - name: Check out repo 📚 + uses: actions/checkout@v4 + + - name: Run \`openapi\` command 🚀 + uses: readmeio/rdme@v7 + with: + rdme: openapi ./__tests__/__fixtures__/ref-oas/petstore.json --key=\${{ secrets.README_API_KEY }} --id=1 +" +`; + +exports[`rdme openapi > GHA onboarding E2E tests > should create GHA workflow (create spec) 1`] = ` +" +Your GitHub Actions workflow file has been created! ✨ + +Almost done! Just a couple more steps: +1. Push your newly created file (.github/workflows/openapi-file.yml) to GitHub 🚀 +2. Create a GitHub secret called README_API_KEY and populate the value with your ReadMe API key (••••••••••••I_KEY) 🔑 + +🔐 Check out GitHub's docs for more info on creating encrypted secrets (https://docs.github.com/actions/security-guides/encrypted-secrets#creating-encrypted-secrets-for-a-repository) + +🦉 If you have any more questions, feel free to drop us a line! support@readme.io +" +`; + +exports[`rdme openapi > GHA onboarding E2E tests > should create GHA workflow (create spec) 2`] = ` +"# This GitHub Actions workflow was auto-generated by the \`rdme\` cli on 2022-01-01T00:00:00.000Z +# You can view our full documentation here: https://docs.readme.com/docs/rdme +name: ReadMe GitHub Action 🦉 + +on: + push: + branches: + # This workflow will run every time you push code to the following branch: \`openapi-branch\` + # Check out GitHub's docs for more info on configuring this: + # https://docs.github.com/actions/using-workflows/events-that-trigger-workflows + - openapi-branch + +jobs: + rdme-openapi: + runs-on: ubuntu-latest + steps: + - name: Check out repo 📚 + uses: actions/checkout@v4 + + - name: Run \`openapi\` command 🚀 + uses: readmeio/rdme@v7 + with: + rdme: openapi ./__tests__/__fixtures__/ref-oas/petstore.json --key=\${{ secrets.README_API_KEY }} --id=1 +" +`; + +exports[`rdme openapi > GHA onboarding E2E tests > should create GHA workflow (including workingDirectory) 1`] = ` +" +Your GitHub Actions workflow file has been created! ✨ + +Almost done! Just a couple more steps: +1. Push your newly created file (.github/workflows/openapi-file-workingdirectory.yml) to GitHub 🚀 +2. Create a GitHub secret called README_API_KEY and populate the value with your ReadMe API key (••••••••••••I_KEY) 🔑 + +🔐 Check out GitHub's docs for more info on creating encrypted secrets (https://docs.github.com/actions/security-guides/encrypted-secrets#creating-encrypted-secrets-for-a-repository) + +🦉 If you have any more questions, feel free to drop us a line! support@readme.io +" +`; + +exports[`rdme openapi > GHA onboarding E2E tests > should create GHA workflow (including workingDirectory) 2`] = ` +"# This GitHub Actions workflow was auto-generated by the \`rdme\` cli on 2022-01-01T00:00:00.000Z +# You can view our full documentation here: https://docs.readme.com/docs/rdme +name: ReadMe GitHub Action 🦉 + +on: + push: + branches: + # This workflow will run every time you push code to the following branch: \`openapi-branch-workingdirectory\` + # Check out GitHub's docs for more info on configuring this: + # https://docs.github.com/actions/using-workflows/events-that-trigger-workflows + - openapi-branch-workingdirectory + +jobs: + rdme-openapi: + runs-on: ubuntu-latest + steps: + - name: Check out repo 📚 + uses: actions/checkout@v4 + + - name: Run \`openapi\` command 🚀 + uses: readmeio/rdme@v7 + with: + rdme: openapi petstore.json --key=\${{ secrets.README_API_KEY }} --id=1 --workingDirectory=./__tests__/__fixtures__/relative-ref-oas +" +`; + +exports[`rdme openapi > GHA onboarding E2E tests > should create GHA workflow (update spec via prompt) 1`] = ` +" +Your GitHub Actions workflow file has been created! ✨ + +Almost done! Just a couple more steps: +1. Push your newly created file (.github/workflows/openapi-file-update-prompt.yml) to GitHub 🚀 +2. Create a GitHub secret called README_API_KEY and populate the value with your ReadMe API key (••••••••••••I_KEY) 🔑 + +🔐 Check out GitHub's docs for more info on creating encrypted secrets (https://docs.github.com/actions/security-guides/encrypted-secrets#creating-encrypted-secrets-for-a-repository) + +🦉 If you have any more questions, feel free to drop us a line! support@readme.io +" +`; + +exports[`rdme openapi > GHA onboarding E2E tests > should create GHA workflow (update spec via prompt) 2`] = ` +"# This GitHub Actions workflow was auto-generated by the \`rdme\` cli on 2022-01-01T00:00:00.000Z +# You can view our full documentation here: https://docs.readme.com/docs/rdme +name: ReadMe GitHub Action 🦉 + +on: + push: + branches: + # This workflow will run every time you push code to the following branch: \`openapi-branch-update-prompt\` + # Check out GitHub's docs for more info on configuring this: + # https://docs.github.com/actions/using-workflows/events-that-trigger-workflows + - openapi-branch-update-prompt + +jobs: + rdme-openapi: + runs-on: ubuntu-latest + steps: + - name: Check out repo 📚 + uses: actions/checkout@v4 + + - name: Run \`openapi\` command 🚀 + uses: readmeio/rdme@v7 + with: + rdme: openapi ./__tests__/__fixtures__/ref-oas/petstore.json --key=\${{ secrets.README_API_KEY }} --id=spec2 +" +`; + +exports[`rdme openapi > error handling > should throw an error if an invalid OpenAPI 3.0 definition is supplied 1`] = `[MissingPointerError: Token "Error" does not exist.]`; + +exports[`rdme openapi > error handling > should throw an error if an invalid OpenAPI 3.1 definition is supplied 1`] = ` +[SyntaxError: OpenAPI schema validation failed. + +REQUIRED must have required property 'name' + + 24 | "components": { + 25 | "securitySchemes": { +> 26 | "tlsAuth": { + | ^ ☹️ name is missing here! + 27 | "type": "mutualTLS" + 28 | } + 29 | }] +`; + +exports[`rdme openapi > error handling > should throw an error if an invalid ref is supplied 1`] = `[MissingPointerError: Token "Petty" does not exist.]`; + +exports[`rdme openapi > updates / resyncs > should use specified working directory and upload the expected content 1`] = ` +{ + "components": { + "securitySchemes": { + "api_key": { + "in": "header", + "name": "api_key", + "type": "apiKey", + }, + "petstore_auth": { + "flows": { + "implicit": { + "authorizationUrl": "http://petstore.swagger.io/oauth/dialog", + "scopes": { + "read:pets": "read your pets", + "write:pets": "modify pets in your account", + }, + }, + }, + "type": "oauth2", + }, + }, + }, + "info": { + "title": "Example petstore to demo our handling of relative external $ref pointers", + "version": "1.0.0", + }, + "openapi": "3.0.0", + "paths": { + "/pet": { + "post": { + "description": "", + "operationId": "addPet", + "requestBody": { + "$ref": "#/paths/~1pet/put/requestBody", + }, + "responses": { + "405": { + "description": "Invalid input", + }, + }, + "security": [ + { + "petstore_auth": [ + "write:pets", + "read:pets", + ], + }, + ], + "summary": "Add a new pet to the store", + "tags": [ + "pet", + ], + }, + "put": { + "description": "", + "operationId": "updatePet", + "requestBody": { + "content": { + "application/json": { + "schema": { + "$ref": "#/paths/~1pet~1%7BpetId%7D/get/responses/200/content/application~1xml/schema", + }, + }, + "application/xml": { + "schema": { + "$ref": "#/paths/~1pet~1%7BpetId%7D/get/responses/200/content/application~1xml/schema", + }, + }, + }, + "description": "Pet object that needs to be added to the store", + "required": true, + }, + "responses": { + "400": { + "description": "Invalid ID supplied", + }, + "404": { + "description": "Pet not found", + }, + "405": { + "description": "Validation exception", + }, + }, + "security": [ + { + "petstore_auth": [ + "write:pets", + "read:pets", + ], + }, + ], + "summary": "Update an existing pet", + "tags": [ + "pet", + ], + }, + }, + "/pet/{petId}": { + "get": { + "description": "Returns a single pet", + "operationId": "getPetById", + "parameters": [ + { + "description": "ID of pet to return", + "in": "path", + "name": "petId", + "required": true, + "schema": { + "format": "int64", + "type": "integer", + }, + }, + ], + "responses": { + "200": { + "content": { + "application/json": { + "schema": { + "$ref": "#/paths/~1pet~1%7BpetId%7D/get/responses/200/content/application~1xml/schema", + }, + }, + "application/xml": { + "schema": { + "properties": { + "category": { + "properties": { + "id": { + "format": "int64", + "type": "integer", + }, + "name": { + "type": "string", + }, + }, + "type": "object", + "xml": { + "name": "Category", + }, + }, + "id": { + "default": 40, + "example": 25, + "format": "int64", + "type": "integer", + }, + "name": { + "example": "doggie", + "type": "string", + }, + "photoUrls": { + "items": { + "example": "https://example.com/photo.png", + "type": "string", + }, + "type": "array", + "xml": { + "name": "photoUrl", + "wrapped": true, + }, + }, + "status": { + "description": "pet status in the store", + "enum": [ + "available", + "pending", + "sold", + ], + "type": "string", + }, + "tags": { + "items": { + "properties": { + "id": { + "format": "int64", + "type": "integer", + }, + "name": { + "type": "string", + }, + }, + "type": "object", + "xml": { + "name": "Tag", + }, + }, + "type": "array", + "xml": { + "name": "tag", + "wrapped": true, + }, + }, + }, + "required": [ + "name", + "photoUrls", + ], + "type": "object", + "xml": { + "name": "Pet", + }, + }, + }, + }, + "description": "successful operation", + }, + "400": { + "description": "Invalid ID supplied", + }, + "404": { + "description": "Pet not found", + }, + "default": { + "description": "successful response", + }, + }, + "security": [ + { + "api_key": [], + }, + ], + "summary": "Find pet by ID", + "tags": [ + "pet", + ], + }, + }, + "/user": { + "post": { + "description": "This can only be done by the logged in user.", + "operationId": "createUser", + "requestBody": { + "content": { + "application/json": { + "schema": { + "properties": { + "email": { + "type": "string", + }, + "firstName": { + "type": "string", + }, + "id": { + "format": "int64", + "type": "integer", + }, + "lastName": { + "type": "string", + }, + "password": { + "type": "string", + }, + "phone": { + "type": "string", + }, + "userStatus": { + "description": "User Status", + "format": "int32", + "type": "integer", + }, + "username": { + "type": "string", + }, + }, + "type": "object", + "xml": { + "name": "User", + }, + }, + }, + }, + "description": "Created user object", + "required": true, + }, + "responses": { + "default": { + "description": "successful operation", + }, + }, + "summary": "Create user", + "tags": [ + "user", + ], + }, + }, + }, + "servers": [ + { + "url": "http://petstore.swagger.io/v2", + }, + ], +} +`; + +exports[`rdme openapi > upload > should bundle and upload the expected content 1`] = ` +{ + "components": { + "securitySchemes": { + "api_key": { + "in": "header", + "name": "api_key", + "type": "apiKey", + }, + "petstore_auth": { + "flows": { + "implicit": { + "authorizationUrl": "http://petstore.swagger.io/oauth/dialog", + "scopes": { + "read:pets": "read your pets", + "write:pets": "modify pets in your account", + }, + }, + }, + "type": "oauth2", + }, + }, + }, + "info": { + "title": "Example petstore to demo our handling of external $ref pointers", + "version": "1.0.0", + }, + "openapi": "3.0.0", + "paths": { + "/pet": { + "post": { + "description": "", + "operationId": "addPet", + "requestBody": { + "$ref": "#/paths/~1pet/put/requestBody", + }, + "responses": { + "405": { + "description": "Invalid input", + }, + }, + "security": [ + { + "petstore_auth": [ + "write:pets", + "read:pets", + ], + }, + ], + "summary": "Add a new pet to the store", + "tags": [ + "pet", + ], + }, + "put": { + "description": "", + "operationId": "updatePet", + "requestBody": { + "content": { + "application/json": { + "schema": { + "$ref": "#/paths/~1pet~1%7BpetId%7D/get/responses/200/content/application~1xml/schema", + }, + }, + "application/xml": { + "schema": { + "$ref": "#/paths/~1pet~1%7BpetId%7D/get/responses/200/content/application~1xml/schema", + }, + }, + }, + "description": "Pet object that needs to be added to the store", + "required": true, + }, + "responses": { + "400": { + "description": "Invalid ID supplied", + }, + "404": { + "description": "Pet not found", + }, + "405": { + "description": "Validation exception", + }, + }, + "security": [ + { + "petstore_auth": [ + "write:pets", + "read:pets", + ], + }, + ], + "summary": "Update an existing pet", + "tags": [ + "pet", + ], + }, + }, + "/pet/{petId}": { + "get": { + "description": "Returns a single pet", + "operationId": "getPetById", + "parameters": [ + { + "description": "ID of pet to return", + "in": "path", + "name": "petId", + "required": true, + "schema": { + "format": "int64", + "type": "integer", + }, + }, + ], + "responses": { + "200": { + "content": { + "application/json": { + "schema": { + "$ref": "#/paths/~1pet~1%7BpetId%7D/get/responses/200/content/application~1xml/schema", + }, + }, + "application/xml": { + "schema": { + "properties": { + "category": { + "properties": { + "id": { + "format": "int64", + "type": "integer", + }, + "name": { + "type": "string", + }, + }, + "type": "object", + "xml": { + "name": "Category", + }, + }, + "id": { + "default": 40, + "example": 25, + "format": "int64", + "type": "integer", + }, + "name": { + "example": "doggie", + "type": "string", + }, + "photoUrls": { + "items": { + "example": "https://example.com/photo.png", + "type": "string", + }, + "type": "array", + "xml": { + "name": "photoUrl", + "wrapped": true, + }, + }, + "status": { + "description": "pet status in the store", + "enum": [ + "available", + "pending", + "sold", + ], + "type": "string", + }, + "tags": { + "items": { + "properties": { + "id": { + "format": "int64", + "type": "integer", + }, + "name": { + "type": "string", + }, + }, + "type": "object", + "xml": { + "name": "Tag", + }, + }, + "type": "array", + "xml": { + "name": "tag", + "wrapped": true, + }, + }, + }, + "required": [ + "name", + "photoUrls", + ], + "type": "object", + "xml": { + "name": "Pet", + }, + }, + }, + }, + "description": "successful operation", + }, + "400": { + "description": "Invalid ID supplied", + }, + "404": { + "description": "Pet not found", + }, + "default": { + "description": "successful response", + }, + }, + "security": [ + { + "api_key": [], + }, + ], + "summary": "Find pet by ID", + "tags": [ + "pet", + ], + }, + }, + }, + "servers": [ + { + "url": "http://petstore.swagger.io/v2", + }, + ], +} +`; + +exports[`rdme openapi > upload > should update title, bundle and upload the expected content 1`] = ` +{ + "components": { + "securitySchemes": { + "api_key": { + "in": "header", + "name": "api_key", + "type": "apiKey", + }, + "petstore_auth": { + "flows": { + "implicit": { + "authorizationUrl": "http://petstore.swagger.io/oauth/dialog", + "scopes": { + "read:pets": "read your pets", + "write:pets": "modify pets in your account", + }, + }, + }, + "type": "oauth2", + }, + }, + }, + "info": { + "title": "some alternative title", + "version": "1.0.0", + }, + "openapi": "3.0.0", + "paths": { + "/pet": { + "post": { + "description": "", + "operationId": "addPet", + "requestBody": { + "$ref": "#/paths/~1pet/put/requestBody", + }, + "responses": { + "405": { + "description": "Invalid input", + }, + }, + "security": [ + { + "petstore_auth": [ + "write:pets", + "read:pets", + ], + }, + ], + "summary": "Add a new pet to the store", + "tags": [ + "pet", + ], + }, + "put": { + "description": "", + "operationId": "updatePet", + "requestBody": { + "content": { + "application/json": { + "schema": { + "$ref": "#/paths/~1pet~1%7BpetId%7D/get/responses/200/content/application~1xml/schema", + }, + }, + "application/xml": { + "schema": { + "$ref": "#/paths/~1pet~1%7BpetId%7D/get/responses/200/content/application~1xml/schema", + }, + }, + }, + "description": "Pet object that needs to be added to the store", + "required": true, + }, + "responses": { + "400": { + "description": "Invalid ID supplied", + }, + "404": { + "description": "Pet not found", + }, + "405": { + "description": "Validation exception", + }, + }, + "security": [ + { + "petstore_auth": [ + "write:pets", + "read:pets", + ], + }, + ], + "summary": "Update an existing pet", + "tags": [ + "pet", + ], + }, + }, + "/pet/{petId}": { + "get": { + "description": "Returns a single pet", + "operationId": "getPetById", + "parameters": [ + { + "description": "ID of pet to return", + "in": "path", + "name": "petId", + "required": true, + "schema": { + "format": "int64", + "type": "integer", + }, + }, + ], + "responses": { + "200": { + "content": { + "application/json": { + "schema": { + "$ref": "#/paths/~1pet~1%7BpetId%7D/get/responses/200/content/application~1xml/schema", + }, + }, + "application/xml": { + "schema": { + "properties": { + "category": { + "properties": { + "id": { + "format": "int64", + "type": "integer", + }, + "name": { + "type": "string", + }, + }, + "type": "object", + "xml": { + "name": "Category", + }, + }, + "id": { + "default": 40, + "example": 25, + "format": "int64", + "type": "integer", + }, + "name": { + "example": "doggie", + "type": "string", + }, + "photoUrls": { + "items": { + "example": "https://example.com/photo.png", + "type": "string", + }, + "type": "array", + "xml": { + "name": "photoUrl", + "wrapped": true, + }, + }, + "status": { + "description": "pet status in the store", + "enum": [ + "available", + "pending", + "sold", + ], + "type": "string", + }, + "tags": { + "items": { + "properties": { + "id": { + "format": "int64", + "type": "integer", + }, + "name": { + "type": "string", + }, + }, + "type": "object", + "xml": { + "name": "Tag", + }, + }, + "type": "array", + "xml": { + "name": "tag", + "wrapped": true, + }, + }, + }, + "required": [ + "name", + "photoUrls", + ], + "type": "object", + "xml": { + "name": "Pet", + }, + }, + }, + }, + "description": "successful operation", + }, + "400": { + "description": "Invalid ID supplied", + }, + "404": { + "description": "Pet not found", + }, + "default": { + "description": "successful response", + }, + }, + "security": [ + { + "api_key": [], + }, + ], + "summary": "Find pet by ID", + "tags": [ + "pet", + ], + }, + }, + }, + "servers": [ + { + "url": "http://petstore.swagger.io/v2", + }, + ], +} +`; + +exports[`rdme openapi > upload > should upload the expected content and return raw output 1`] = ` +"{ + "commandType": "create", + "docs": "https://dash.readme.com/project/example-project/1.0.1/refs/ex", + "id": 1, + "specPath": "./__tests__/__fixtures__/ref-oas/petstore.json", + "specType": "OpenAPI", + "version": "1.0.0" +}" +`; diff --git a/src/lib/prepareOas.ts b/src/lib/prepareOas.ts index 6cae7f26..7c385d53 100644 --- a/src/lib/prepareOas.ts +++ b/src/lib/prepareOas.ts @@ -37,7 +37,7 @@ function truthy(value: T): value is Truthy { return !!value; } -type OpenAPIAction = CommandIdForTopic<'openapi'>; +type OpenAPIAction = CommandIdForTopic<'openapi'> | 'upload'; const capitalizeSpecType = (type: string) => type === 'openapi' ? 'OpenAPI' : type.charAt(0).toUpperCase() + type.slice(1); @@ -81,7 +81,7 @@ export default async function prepareOas( const fileFindingSpinner = ora({ text: 'Looking for API definitions...', ...oraOptions() }).start(); - const action: OpenAPIAction = command.replace('openapi ', '') as OpenAPIAction; + const action: OpenAPIAction = command === 'openapi' ? 'upload' : (command.replace('openapi ', '') as OpenAPIAction); const jsonAndYamlFiles = readdirRecursive('.', true).filter( file =>