Skip to content

Commit

Permalink
feat: add generate workflow from swagger or openai
Browse files Browse the repository at this point in the history
  • Loading branch information
jellydn committed Sep 23, 2023
1 parent ba0529b commit e8d9537
Show file tree
Hide file tree
Showing 6 changed files with 147 additions and 9 deletions.
5 changes: 2 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
<h1 align="center">StepCI Demo for Fastify API Testing 👋</h1>
<h1 align="center">StepCI Demo for E2E Testing 👋</h1>

## Overview

This repository provides a guide to set up continuous integration for a [Fastify API](https://fastify.dev/docs/latest/Reference/TypeScript/) using [Step CI](https://stepci.com/#get-started).
This repository provides a guide to set up continuous integration for a [Fastify](https://fastify.dev/docs/latest/Reference/TypeScript/) using [Step CI](https://stepci.com/#get-started).

## Prerequisites

- [Node.js LTS](https://nodejs.org/en/)
- [Bun](https://bun.sh/)

## Usage
Expand Down
14 changes: 8 additions & 6 deletions index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,14 @@ await server.register(swagger, {
swagger: {
info: {
title: "Test swagger",
description: "Testing the Fastify swagger API",
description: "This is the documentation of the API",
version: "0.1.0",
},
externalDocs: {
url: "https://swagger.io",
description: "Find more info here",
},
host: "localhost",
host: "localhost:3000",
schemes: ["http", "https"],
consumes: ["application/json"],
produces: ["application/json"],
Expand All @@ -43,6 +43,12 @@ await server.register(swaggerUI, {
staticCSP: true,
});

// Health check
server.get("/", async (_request, _reply) => {
return { ok: true };
});


// Declare a route
server.get<{
Querystring: { name: string };
Expand Down Expand Up @@ -74,10 +80,6 @@ server.get(
}
);

server.get("/", async (_request, _reply) => {
return { ok: true };
});

const start = async () => {
try {
await server.listen({ port: 3000 });
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"ci": "run-p --race test:*",
"test:server": "NODE_DEVELOPMENT=test tsx index.ts",
"test:e2e": "wait-on -l tcp:3000 && stepci run workflow.yml",
"test:generate": "stepci generate ./specs/openapi.yaml ./specs/generated.yaml",
"start": "tsx index.ts"
},
"dependencies": {
Expand Down
35 changes: 35 additions & 0 deletions specs/generated.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
version: "1.0"
name: Test swagger
config:
http:
baseURL: http://localhost:3000
tests:
default:
name: Default
steps:
- http:
url: /
method: GET
schema:
type: object
properties:
ok: bool
- http:
url: /hello
method: GET
check:
status: 200
schema:
type: object
description: Successful response with a JSON object
- http:
url: /ping
method: GET
check:
status: 200
schema:
type: object
properties:
pong:
type: string
components: {}
40 changes: 40 additions & 0 deletions specs/openapi.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
openapi: 3.0.1
info:
title: Test swagger
description: Testing the Fastify swagger API
version: 0.1.0
externalDocs:
description: Find more info here
url: https://swagger.io
servers:
- url: http://localhost:3000
paths:
/:
get:
responses:
200:
description: Default Response
content: {}
/hello:
get:
responses:
200:
description: Successful response with a JSON object
content:
application/json:
schema:
type: string
description: Successful response with a JSON object
/ping:
get:
responses:
200:
description: Default Response
content:
application/json:
schema:
type: object
properties:
pong:
type: string
components: {}
61 changes: 61 additions & 0 deletions specs/swagger.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
{
"swagger": "2.0",
"info": {
"title": "Test swagger",
"description": "Testing the Fastify swagger API",
"version": "0.1.0"
},
"definitions": {},
"paths": {
"/": {
"get": {
"responses": {
"200": {
"description": "Default Response"
}
}
}
},
"/hello": {
"get": {
"responses": {
"200": {
"description": "Default Response"
}
}
}
},
"/ping": {
"get": {
"responses": {
"200": {
"description": "Default Response",
"schema": {
"type": "object",
"properties": {
"pong": {
"type": "string"
}
}
}
}
}
}
}
},
"host": "localhost:3000",
"schemes": [
"http",
"https"
],
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"externalDocs": {
"url": "https://swagger.io",
"description": "Find more info here"
}
}

0 comments on commit e8d9537

Please sign in to comment.