Skip to content

Commit

Permalink
feat: generate openapi files
Browse files Browse the repository at this point in the history
  • Loading branch information
solufa committed Aug 15, 2024
1 parent 0b50852 commit c64f422
Show file tree
Hide file tree
Showing 205 changed files with 49,149 additions and 398 deletions.
15 changes: 15 additions & 0 deletions aspida.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
module.exports = [
{ input: 'samples/swagger' },
{ input: 'samples/simple', openapi: { outputFile: 'samples/simple-openapi.json' } },
{ input: 'samples/strapi' },
{ input: 'samples/freee' },
{ input: 'samples/openapi' },
{ input: 'samples/externals' },
{ input: 'samples/nullable-object' },
{ input: 'samples/array-one-of' },
{ input: 'samples/request-bodies' },
{ input: 'samples/responses' },
{ input: 'samples/path' },
{ input: 'samples/headers' },
{ input: 'samples/allOf-required' },
];
723 changes: 330 additions & 393 deletions package-lock.json

Large diffs are not rendered by default.

7 changes: 2 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"main": "dist/index.js",
"bin": "bin/index.js",
"scripts": {
"dev": "npm run build && node samples/rimraf.js && node bin/index.js",
"dev": "npm run build && node bin/index.js",
"build": "npm run rimraf && tsc",
"rimraf": "node -e \"require('fs').existsSync('dist') && require('fs').rmSync('dist', { recursive: true })\"",
"lint": "eslint . && prettier --check \"./**/*.ts\"",
Expand All @@ -31,14 +31,11 @@
"swagger"
],
"dependencies": {
"@apidevtools/swagger-parser": "^10.1.0",
"aspida": "^1.14.0",
"js-yaml": "^4.1.0",
"openapi-types": "^12.1.3",
"swagger2openapi": "^7.0.8"
"typescript-json-schema": "^0.64.0"
},
"devDependencies": {
"@types/js-yaml": "^4.0.9",
"@types/minimist": "^1.2.5",
"eslint": "^9.9.0",
"eslint-config-flat-gitignore": "^0.1.8",
Expand Down
45 changes: 45 additions & 0 deletions samples/allOf-required.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
{
"openapi": "3.1.0",
"info": {
"title": "aspida to OpenAPI",
"version": "v0.0"
},
"servers": [
{
"url": "/api"
}
],
"paths": {
"samples/allOf-required/path": {
"get": {
"tags": [
"path"
],
"parameters": [],
"responses": {
"200": {
"content": {
"application/json": {
"schema": {
"description": "取得成功",
"type": "object",
"properties": {
"req_property": {
"description": "required property in response",
"type": "string"
},
"unreq_property": {
"description": "unrequired property in response",
"type": "string"
}
}
}
}
}
}
}
}
}
},
"components": {}
}
9 changes: 9 additions & 0 deletions samples/allOf-required/@types/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
/* eslint-disable */
export type ResponseSchema = BaseSchema

export type BaseSchema = {
/** required property in response */
req_property?: string | undefined;
/** unrequired property in response */
unreq_property?: string | undefined;
}
11 changes: 11 additions & 0 deletions samples/allOf-required/path/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/* eslint-disable */
import type { DefineMethods } from 'aspida';
import type * as Types from '../@types';

export type Methods = DefineMethods<{
get: {
status: 200;
/** 取得成功 */
resBody: Types.ResponseSchema;
};
}>;
78 changes: 78 additions & 0 deletions samples/array-one-of.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
{
"openapi": "3.1.0",
"info": {
"title": "aspida to OpenAPI",
"version": "v0.0"
},
"servers": [
{
"url": "/api"
}
],
"paths": {
"samples/array-one-of/user": {
"get": {
"tags": [
"user"
],
"parameters": [],
"responses": {
"200": {
"content": {
"application/json": {
"schema": {
"description": "sample",
"type": "object",
"properties": {
"user": {
"anyOf": [
{
"type": "object",
"properties": {
"id": {
"type": "string"
},
"roles": {
"type": "array",
"items": {
"anyOf": [
{
"type": "object",
"properties": {
"name": {
"type": "string"
}
}
},
{
"type": "object",
"properties": {
"name": {
"type": "string"
},
"authority": {
"type": "string"
}
}
}
]
}
}
}
},
{
"type": "null"
}
]
}
}
}
}
}
}
}
}
}
},
"components": {}
}
14 changes: 14 additions & 0 deletions samples/array-one-of/@types/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/* eslint-disable */
export type User = {
id?: string | undefined;
roles?: (RoleA | RoleB)[] | undefined;
}

export type RoleA = {
name?: string | undefined;
}

export type RoleB = {
name?: string | undefined;
authority?: string | undefined;
}
14 changes: 14 additions & 0 deletions samples/array-one-of/user/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/* eslint-disable */
import type { DefineMethods } from 'aspida';
import type * as Types from '../@types';

export type Methods = DefineMethods<{
get: {
status: 200;

/** sample */
resBody: {
user?: Types.User | null | undefined;
};
};
}>;
Loading

0 comments on commit c64f422

Please sign in to comment.