mirror of
https://github.com/strapi/strapi.git
synced 2025-12-26 22:54:31 +00:00
Add open api spec and script to serve it
Signed-off-by: Alexandre Bodin <bodin.alex@gmail.com>
This commit is contained in:
parent
07e7cfc0bd
commit
487b872210
@ -72,7 +72,8 @@
|
||||
"test:unit": "jest --verbose",
|
||||
"test:e2e": "FORCE_COLOR=true jest --config jest.config.e2e.js --runInBand --verbose --forceExit --detectOpenHandles",
|
||||
"test:generate-app": "node test/createTestApp.js",
|
||||
"test:start-app": "node test/startTestApp.js"
|
||||
"test:start-app": "node test/startTestApp.js",
|
||||
"doc:api": "node scripts/serve-package-oas.js"
|
||||
},
|
||||
"author": {
|
||||
"email": "hi@strapi.io",
|
||||
|
||||
376
packages/strapi-plugin-content-manager/oas.yml
Normal file
376
packages/strapi-plugin-content-manager/oas.yml
Normal file
@ -0,0 +1,376 @@
|
||||
openapi: 3.0.2
|
||||
info:
|
||||
version: 1.0.0
|
||||
title: Strapi Content Manager API
|
||||
description: This is nice
|
||||
servers:
|
||||
- url: http://localhost:1337
|
||||
description: Local server
|
||||
externalDocs:
|
||||
url: https://strapi.io/documentation
|
||||
description: Strapi documentation
|
||||
paths:
|
||||
/admin/login:
|
||||
post:
|
||||
summary: Login admin
|
||||
requestBody:
|
||||
required: true
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
type: object
|
||||
required:
|
||||
- email
|
||||
- password
|
||||
properties:
|
||||
email:
|
||||
type: string
|
||||
format: email
|
||||
password:
|
||||
type: string
|
||||
|
||||
responses:
|
||||
200:
|
||||
description: Logged in
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
type: object
|
||||
properties:
|
||||
data:
|
||||
type: object
|
||||
properties:
|
||||
user:
|
||||
type: object
|
||||
token:
|
||||
type: string
|
||||
/content-manager/content-types:
|
||||
get:
|
||||
tags:
|
||||
- ContentTypes
|
||||
description: List content types
|
||||
parameters:
|
||||
- in: query
|
||||
name: kind
|
||||
schema:
|
||||
$ref: '#/components/parameters/kind'
|
||||
description: The number of items to skip before starting to collect the result set
|
||||
responses:
|
||||
200:
|
||||
description: A list of content types
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
type: object
|
||||
properties:
|
||||
data:
|
||||
type: array
|
||||
items:
|
||||
$ref: '#/components/schemas/contentType'
|
||||
examples:
|
||||
one:
|
||||
value:
|
||||
data:
|
||||
- $ref: '#/components/examples/restaurant'
|
||||
- $ref: '#/components/examples/category'
|
||||
|
||||
/content-manager/content-types/{uid}/configuration:
|
||||
get:
|
||||
tags:
|
||||
- ContentTypes
|
||||
description: Get content type configuration
|
||||
parameters:
|
||||
- in: path
|
||||
name: uid
|
||||
schema:
|
||||
type: string
|
||||
required: true
|
||||
description: Content Type uid
|
||||
responses:
|
||||
200:
|
||||
description: A content type configuration with its components configuration
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
type: object
|
||||
properties:
|
||||
data:
|
||||
type: object
|
||||
properties:
|
||||
contentType:
|
||||
$ref: '#/components/schemas/configuration'
|
||||
components:
|
||||
type: object
|
||||
additionalProperties:
|
||||
$ref: '#/components/schemas/component-configuration'
|
||||
put:
|
||||
tags:
|
||||
- ContentTypes
|
||||
description: Edit content type configuration
|
||||
parameters:
|
||||
- in: path
|
||||
name: uid
|
||||
schema:
|
||||
type: string
|
||||
required: true
|
||||
description: Content Type uid
|
||||
responses:
|
||||
200:
|
||||
description: A content type configuration
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
type: object
|
||||
properties:
|
||||
data:
|
||||
$ref: '#/components/schemas/configuration'
|
||||
|
||||
/content-manager/components:
|
||||
get:
|
||||
tags:
|
||||
- Components
|
||||
description: List components
|
||||
responses:
|
||||
200:
|
||||
description: A list of components
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
type: object
|
||||
properties:
|
||||
data:
|
||||
type: array
|
||||
items:
|
||||
$ref: '#/components/schemas/component'
|
||||
|
||||
/content-manager/components/{uid}/configuration:
|
||||
get:
|
||||
tags:
|
||||
- Components
|
||||
description: Get content type configuration
|
||||
parameters:
|
||||
- in: path
|
||||
name: uid
|
||||
schema:
|
||||
type: string
|
||||
required: true
|
||||
description: Component uid
|
||||
responses:
|
||||
200:
|
||||
description: A component configuration with its components configuration
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
type: object
|
||||
properties:
|
||||
data:
|
||||
type: object
|
||||
properties:
|
||||
component:
|
||||
$ref: '#/components/schemas/component-configuration'
|
||||
components:
|
||||
type: object
|
||||
additionalProperties:
|
||||
$ref: '#/components/schemas/component-configuration'
|
||||
put:
|
||||
tags:
|
||||
- Components
|
||||
description: Edit component configuration
|
||||
parameters:
|
||||
- in: path
|
||||
name: uid
|
||||
schema:
|
||||
type: string
|
||||
required: true
|
||||
description: Component uid
|
||||
responses:
|
||||
200:
|
||||
description: A component configuration with its components configuration
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
type: object
|
||||
properties:
|
||||
data:
|
||||
$ref: '#/components/schemas/component-configuration'
|
||||
|
||||
components:
|
||||
schemas:
|
||||
contentType:
|
||||
type: object
|
||||
properties:
|
||||
uid:
|
||||
type: string
|
||||
description: Model uid
|
||||
kind:
|
||||
$ref: '#/components/parameters/kind'
|
||||
isDisplayed:
|
||||
type: boolean
|
||||
apiID:
|
||||
type: string
|
||||
description: Model key based on filename
|
||||
info:
|
||||
type: object
|
||||
properties:
|
||||
name:
|
||||
type: string
|
||||
description: User defined name
|
||||
label:
|
||||
type: string
|
||||
description: Computed label with pluralization
|
||||
description:
|
||||
type: string
|
||||
description: Content type description
|
||||
|
||||
options:
|
||||
type: object
|
||||
properties:
|
||||
increments:
|
||||
type: boolean
|
||||
timestamps:
|
||||
type: array
|
||||
uniqueItems: true
|
||||
minItems: 2
|
||||
maxItems: 2
|
||||
items:
|
||||
type: string
|
||||
hasDraftAndPublish:
|
||||
type: boolean
|
||||
attributes:
|
||||
type: object
|
||||
additionalProperties:
|
||||
oneOf:
|
||||
- $ref: '#/components/schemas/scalarAttribute'
|
||||
- $ref: '#/components/schemas/relationalAttribute'
|
||||
|
||||
component:
|
||||
allOf:
|
||||
- type: object
|
||||
properties:
|
||||
category:
|
||||
type: string
|
||||
description: Component category
|
||||
|
||||
- $ref: '#/components/schemas/contentType'
|
||||
|
||||
scalarAttribute:
|
||||
type: object
|
||||
properties:
|
||||
type:
|
||||
type: string
|
||||
required:
|
||||
type: boolean
|
||||
|
||||
relationalAttribute:
|
||||
type: object
|
||||
properties:
|
||||
type:
|
||||
type: string
|
||||
|
||||
targetModel:
|
||||
type: string
|
||||
relationType:
|
||||
type: string
|
||||
enum:
|
||||
- oneWay
|
||||
- manyWay
|
||||
- oneToOne
|
||||
- oneToMany
|
||||
- manyToOne
|
||||
- manyToMany
|
||||
|
||||
configuration:
|
||||
type: object
|
||||
properties:
|
||||
uid:
|
||||
type: string
|
||||
settings:
|
||||
type: object
|
||||
properties:
|
||||
searchable:
|
||||
type: boolean
|
||||
bulkable:
|
||||
type: boolean
|
||||
filterable:
|
||||
type: boolean
|
||||
pageSize:
|
||||
type: integer
|
||||
mainField:
|
||||
type: string
|
||||
defaultSortBy:
|
||||
type: string
|
||||
defaultSortOrder:
|
||||
type: string
|
||||
metadatas:
|
||||
type: object
|
||||
layouts:
|
||||
type: object
|
||||
properties:
|
||||
list:
|
||||
type: array
|
||||
items:
|
||||
type: string
|
||||
editRelations:
|
||||
type: array
|
||||
items:
|
||||
type: string
|
||||
edit:
|
||||
type: array
|
||||
items:
|
||||
type: array
|
||||
items:
|
||||
type: object
|
||||
properties:
|
||||
name: string
|
||||
size: integer
|
||||
|
||||
component-configuration:
|
||||
allOf:
|
||||
- type: object
|
||||
properties:
|
||||
isComponent:
|
||||
type: boolean
|
||||
- $ref: '#/components/schemas/configuration'
|
||||
|
||||
examples:
|
||||
restaurant:
|
||||
uid: application::restaurant.restaurant
|
||||
apiID: restaurant
|
||||
kind: collectionType
|
||||
isDisplayed: true
|
||||
info:
|
||||
name: Restaurant
|
||||
label: Restaurants
|
||||
description: My restaurant Model
|
||||
options:
|
||||
hasDraftAndPublish: false
|
||||
timestamps: ['created_at', 'updated_at']
|
||||
attributes:
|
||||
title:
|
||||
type: string
|
||||
required: true
|
||||
slug:
|
||||
type: uid
|
||||
required: true
|
||||
targetField: title
|
||||
categories:
|
||||
type: relation
|
||||
relationTarget: application::category.category
|
||||
relationType: manyWay
|
||||
category:
|
||||
uid: application::category.category
|
||||
|
||||
parameters:
|
||||
kind:
|
||||
type: string
|
||||
enum:
|
||||
- singleType
|
||||
- collectionType
|
||||
|
||||
securitySchemes:
|
||||
bearerAuth:
|
||||
type: http
|
||||
scheme: bearer
|
||||
|
||||
security:
|
||||
- bearerAuth: []
|
||||
83
scripts/serve-package-oas.js
Normal file
83
scripts/serve-package-oas.js
Normal file
@ -0,0 +1,83 @@
|
||||
/* eslint-disable */
|
||||
'use strict';
|
||||
|
||||
const getPort = require('get-port');
|
||||
|
||||
const path = require('path');
|
||||
const fse = require('fs-extra');
|
||||
const koa = require('koa');
|
||||
const koaStatic = require('koa-static');
|
||||
|
||||
const args = process.argv.slice(2);
|
||||
|
||||
if (!args[0]) {
|
||||
console.error('Missing required parameter <package-name>');
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
async function run() {
|
||||
const app = new koa();
|
||||
|
||||
const openAPISpecPath = path.join(__dirname, '../packages', args[0], 'oas.yml');
|
||||
|
||||
if (!(await fse.pathExists(openAPISpecPath))) {
|
||||
throw new Error(`No OAS configuration found at ${openAPISpecPath}`);
|
||||
}
|
||||
|
||||
app.use(ctx => {
|
||||
if (ctx.path === '/spec.yml') {
|
||||
ctx.body = fse.createReadStream(openAPISpecPath);
|
||||
return;
|
||||
}
|
||||
|
||||
ctx.body = indexPage;
|
||||
});
|
||||
|
||||
const port = await getPort({ port: 1339 });
|
||||
|
||||
app.listen(port, () => {
|
||||
console.log(`Server available at http://localhost:${port}`);
|
||||
});
|
||||
}
|
||||
|
||||
run().catch(error => {
|
||||
console.log('Unexpected Error:', error);
|
||||
process.exit(1);
|
||||
});
|
||||
|
||||
const indexPage = `
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<link
|
||||
href="https://fonts.googleapis.com/css?family=Nunito"
|
||||
rel="stylesheet"
|
||||
/>
|
||||
<script
|
||||
type="module"
|
||||
src="https://unpkg.com/rapidoc/dist/rapidoc-min.js"
|
||||
></script>
|
||||
</head>
|
||||
<body>
|
||||
<rapi-doc
|
||||
spec-url="/spec.yml"
|
||||
allow-server-selection="false"
|
||||
show-header="false"
|
||||
regular-font="Nunito"
|
||||
bg-color="#2B303B"
|
||||
text-color="#dee3ec"
|
||||
nav-bg-color=""
|
||||
nav-text-color=""
|
||||
nav-hover-bg-color=""
|
||||
nav-hover-text-color=""
|
||||
nav-accent-color=""
|
||||
primary-color=""
|
||||
theme="dark"
|
||||
render-style="focused"
|
||||
schema-style="table"
|
||||
>
|
||||
</rapi-doc>
|
||||
</body>
|
||||
</html>
|
||||
`;
|
||||
Loading…
x
Reference in New Issue
Block a user