diff --git a/.github/workflows/docs.yml b/.github/workflows/docs.yml new file mode 100644 index 0000000..8177753 --- /dev/null +++ b/.github/workflows/docs.yml @@ -0,0 +1,48 @@ +# This is a basic workflow to help you get started with Actions + +name: CI - Build API and deploy API spec + +# Controls when the workflow will run +on: + # Triggers the workflow on push or pull request events but only for the "main" branch + push: + branches: [ "main" ] + + # Allows you to run this workflow manually from the Actions tab + workflow_dispatch: + +# A workflow run is made up of one or more jobs that can run sequentially or in parallel +jobs: + # This workflow contains a single job called "build" + build: + # The type of runner that the job will run on + runs-on: ubuntu-latest + + # Steps represent a sequence of tasks that will be executed as part of the job + steps: + # Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it + - uses: actions/checkout@v4 + + # Runs a single command using the runners shell + - name: Run a one-line script + run: echo Hello, world! + + # Set up Node.js + - name: Setup Node.js + uses: actions/setup-node@v4 + with: + node-version: 20 + + # Install Redocly CLI + - name: Install Redocly CLI + run: npm install -g @redocly/cli + + # Lint OpenAPI spec + - name: Lint OpenAPI Spec + run: redocly lint api-specs/api-v1.yaml + + # Build docs + - name: Build Docs + run: | + redocly build-docs api-specs/api-v1.yaml --output docs/index.html + diff --git a/.redocly.lint-ignore.yaml b/.redocly.lint-ignore.yaml new file mode 100644 index 0000000..fe75c4c --- /dev/null +++ b/.redocly.lint-ignore.yaml @@ -0,0 +1,25 @@ +# This file instructs Redocly's linter to ignore the rules contained for specific parts of your API. +# See https://redocly.com/docs/cli/ for more information. +api-specs/api-v1.yaml: + info-license: + - '#/info' + no-server-example.com: + - '#/servers/0/url' + operation-operationId: + - '#/paths/products/get/operationId' + - '#/paths/products/post/operationId' + - '#/paths/products~1productId/get/operationId' + - '#/paths/products~1productId/put/operationId' + - '#/paths/products~1productId/delete/operationId' + operation-4xx-response: + - '#/paths/products/get/responses' + - '#/paths/products/post/responses' + - '#/paths/products~1productId/get/responses' + - '#/paths/products~1productId/put/responses' + - '#/paths/products~1productId/delete/responses' + security-defined: + - '#/paths/products/get' + - '#/paths/products/post' + - '#/paths/products~1productId/get' + - '#/paths/products~1productId/put' + - '#/paths/products~1productId/delete' diff --git a/README.md b/README.md index 24429eb..201a5b5 100644 --- a/README.md +++ b/README.md @@ -1 +1,22 @@ -# create-cicd-automation \ No newline at end of file +# Open API Spec and CI/CD to Redocly + +## Introduction + +This repository demonstrates the use of an OpenAPI specification and the deployment of an API using GitHub Actions. Special thanks to Ćukasz Michta for his "CI/CD for Technical Writers with OpenAPI and Redocly" tutorial, which served as the foundation for this project. I adapted and refined the API to align with my use case. + +## What is Redocly + +Redocly is a platform designed to streamline and enhance the process of creating, managing, and publishing API documentation. Redocly helps generate interactive and visually appealing API documentation from OpenAPI specifications. It transforms raw API definitions into developer-friendly documentation. + +**The OpenAPI YAML API** + +> api-specs/api-v1.yaml + +*Sample view of the Products API* + +[Products API](docs/API-screen.png) + + + + + diff --git a/api-specs/api-v1.yaml b/api-specs/api-v1.yaml index b743259..102c8e5 100644 --- a/api-specs/api-v1.yaml +++ b/api-specs/api-v1.yaml @@ -62,7 +62,7 @@ paths: description: Internal Server Error /products/{productId}: get: - summary: Get product by ID + summary: Get product by ID. security: - ApiKeyAuth: [] parameters: @@ -81,7 +81,7 @@ paths: 500: description: Internal Server Error put: - summary: Update product + summary: Update product. security: - ApiKeyAuth: [] parameters: @@ -180,4 +180,4 @@ components: securitySchemes: ApiKeyAuth: type: http - scheme: basic \ No newline at end of file + scheme: basic diff --git a/api-specs/v2/api-majors.yaml b/api-specs/v2/api-majors.yaml new file mode 100644 index 0000000..8016602 --- /dev/null +++ b/api-specs/v2/api-majors.yaml @@ -0,0 +1,68 @@ +openapi: 3.0.1 +info: + title: CMC Majors + version: v1 +paths: + /popularity: + get: + summary: Get popularity by major + responses: + '200': + description: OK + headers: + x-amzn-requestid: + schema: + description: ID of the Amazon request + type: string + content: + application/json: + schema: + type: object + properties: + class: + type: string + breakdown: + type: array + items: + type: object + properties: + major: + type: string + count: + type: integer + parameters: + - name: class + in: query + required: true + schema: + type: string + example: "2025" + /majors: + post: + summary: Add a major + requestBody: + content: + application/json: + $ref: '#/components/schemas/major' + responses: + '200': + description: OK + content: + application/json: + $ref: '#/components/schemas/major' + security: + - admin: [] +components: + schemas: + major: + type: object + properties: + major: + type: string + examples: + - APIs + securitySchemes: + admin: + type: http + scheme: bearer + bearerFormat: JWT \ No newline at end of file diff --git a/docs/API-screen.png b/docs/API-screen.png new file mode 100644 index 0000000..2b55d93 Binary files /dev/null and b/docs/API-screen.png differ diff --git a/docs/index.html b/docs/index.html index 2e86238..a1758a5 100644 --- a/docs/index.html +++ b/docs/index.html @@ -1,6 +1,5 @@ -