From 5a01bf013a93b75b193948859ca3655fafed3811 Mon Sep 17 00:00:00 2001 From: VLE2FE Date: Mon, 20 Apr 2020 16:13:49 +0200 Subject: [PATCH] api definition created --- oas.yaml | 1105 ++++++++++++++++++++++++++++++++++++++++++++++++++ oas.yml | 53 --- package.json | 2 +- src/index.ts | 2 +- 4 files changed, 1107 insertions(+), 55 deletions(-) create mode 100644 oas.yaml delete mode 100644 oas.yml diff --git a/oas.yaml b/oas.yaml new file mode 100644 index 0000000..3ab5a05 --- /dev/null +++ b/oas.yaml @@ -0,0 +1,1105 @@ +openapi: 3.0.2 + + +info: + title: Digital fingerprint of plastics - API + version: 1.0.0 + description: | + This API gives access to the project database.
+ Access is restricted. Authentication can be obtained with HTTP Basic Auth using username and password. Data access methods can also be accessed using an API key at the URL ending like ?key=xxx
+ There are a number of different user levels:
+ + + +servers: + - url: http://localhost:3000 + description: local server + - url: https://digital-fingerprint-of-plastics-api.apps.de1.bosch-iot-cloud.com/ + description: server on the BIC + + +security: + - ApiKey: [] + - BasicAuth: [] + + +tags: + - name: / + - name: /sample + - name: /material + - name: /condition + - name: /measurement + - name: /templates + - name: /model + - name: /user + + +paths: + /: + get: + summary: Root method + tags: + - / + security: [] + responses: + 200: + description: Server is working + content: + application/json: + schema: + properties: + message: + type: string + example: 'API server up and running!' + 500: + $ref: '#/components/responses/500' + + /samples: + get: + summary: TODO all samples in overview + description: 'levels: read, write, maintain, dev, admin' + tags: + - /sample + responses: + 200: + description: samples overview + content: + application/json: + schema: + $ref: '#/components/schemas/Samples' + 401: + $ref: '#/components/responses/401' + 500: + $ref: '#/components/responses/500' + /sample/{id}: + parameters: + - $ref: '#/components/parameters/Id' + get: + summary: TODO sample details + description: 'levels: read, write, maintain, dev, admin' + tags: + - /sample + responses: + 200: + description: samples details + content: + application/json: + schema: + $ref: '#/components/schemas/SampleDetail' + 400: + $ref: '#/components/responses/400' + 401: + $ref: '#/components/responses/401' + 404: + $ref: '#/components/responses/404' + 500: + $ref: '#/components/responses/500' + put: + summary: TODO add/change sample + description: 'levels: write, maintain, dev, admin' + tags: + - /sample + requestBody: + required: true + content: + application/json: + schema: + $ref: '#/components/schemas/Sample' + responses: + 200: + description: samples details + content: + application/json: + schema: + $ref: '#/components/schemas/SampleDetail' + 400: + $ref: '#/components/responses/400' + 401: + $ref: '#/components/responses/401' + 403: + $ref: '#/components/responses/403' + 404: + $ref: '#/components/responses/404' + 500: + $ref: '#/components/responses/500' + delete: + summary: TODO delete sample + description: 'levels: write, maintain, dev, admin' + tags: + - /sample + responses: + 200: + $ref: '#/components/responses/Ok' + 400: + $ref: '#/components/responses/400' + 401: + $ref: '#/components/responses/401' + 403: + $ref: '#/components/responses/403' + 404: + $ref: '#/components/responses/404' + 500: + $ref: '#/components/responses/500' + /sample/notes/fields: + get: + summary: TODO list all existing field names for custom notes fields + description: 'levels: write, maintain, dev, admin' + tags: + - /sample + responses: + 200: + description: field names and quantity of usage + content: + application/json: + schema: + properties: + name: + type: string + qty: + type: number + example: 20 + 401: + $ref: '#/components/responses/401' + 500: + $ref: '#/components/responses/500' + + /material/{id}: + parameters: + - $ref: '#/components/parameters/Id' + get: + summary: TODO get material details + description: 'levels: read, write, maintain, dev, admin' + tags: + - /material + responses: + 200: + description: created material + content: + application/json: + schema: + $ref: '#/components/schemas/Material' + 400: + $ref: '#/components/responses/400' + 401: + $ref: '#/components/responses/401' + 500: + $ref: '#/components/responses/500' + put: + summary: TODO add/change material + description: 'levels: write, maintain, dev, admin' + tags: + - /material + requestBody: + required: true + content: + application/json: + schema: + $ref: '#/components/schemas/Material' + responses: + 200: + description: material details + content: + application/json: + schema: + $ref: '#/components/schemas/Material' + 400: + $ref: '#/components/responses/400' + 401: + $ref: '#/components/responses/401' + 403: + $ref: '#/components/responses/403' + 500: + $ref: '#/components/responses/500' + delete: + summary: TODO delete material + description: 'levels: write, maintain, dev, admin' + tags: + - /material + responses: + 200: + $ref: '#/components/responses/Ok' + 400: + $ref: '#/components/responses/400' + 401: + $ref: '#/components/responses/401' + 403: + $ref: '#/components/responses/403' + 500: + $ref: '#/components/responses/500' + + /condition/{id}: + parameters: + - $ref: '#/components/parameters/Id' + get: + summary: TODO condition by id + description: 'levels: read, write, maintain, dev, admin' + tags: + - /condition + responses: + 200: + description: condition details + content: + application/json: + schema: + $ref: '#/components/schemas/Condition' + 400: + $ref: '#/components/responses/400' + 401: + $ref: '#/components/responses/401' + 404: + $ref: '#/components/responses/404' + 500: + $ref: '#/components/responses/500' + put: + summary: TODO add/change condition + description: 'levels: write, maintain, dev, admin' + tags: + - /condition + requestBody: + required: true + content: + application/json: + schema: + $ref: '#/components/schemas/Condition' + responses: + 200: + description: condition details + content: + application/json: + schema: + $ref: '#/components/schemas/Condition' + 400: + $ref: '#/components/responses/400' + 401: + $ref: '#/components/responses/401' + 403: + $ref: '#/components/responses/403' + 404: + $ref: '#/components/responses/404' + 500: + $ref: '#/components/responses/500' + delete: + summary: TODO delete condition + description: 'levels: write, maintain, dev, admin' + tags: + - /condition + responses: + 200: + $ref: '#/components/responses/Ok' + 400: + $ref: '#/components/responses/400' + 401: + $ref: '#/components/responses/401' + 403: + $ref: '#/components/responses/403' + 404: + $ref: '#/components/responses/404' + 500: + $ref: '#/components/responses/500' + + /measurement/{id}: + parameters: + - $ref: '#/components/parameters/Id' + get: + summary: TODO measurement values by id + description: 'levels: read, write, maintain, dev, admin' + tags: + - /measurement + responses: + 200: + description: measurement details + content: + application/json: + schema: + $ref: '#/components/schemas/Measurement' + 400: + $ref: '#/components/responses/400' + 401: + $ref: '#/components/responses/401' + 404: + $ref: '#/components/responses/404' + 500: + $ref: '#/components/responses/500' + put: + summary: TODO add/change measurement + description: 'levels: write, maintain, dev, admin' + tags: + - /measurement + requestBody: + required: true + content: + application/json: + schema: + $ref: '#/components/schemas/Measurement' + responses: + 200: + description: measurement details + content: + application/json: + schema: + $ref: '#/components/schemas/Measurement' + 400: + $ref: '#/components/responses/400' + 401: + $ref: '#/components/responses/401' + 403: + $ref: '#/components/responses/403' + 404: + $ref: '#/components/responses/404' + 500: + $ref: '#/components/responses/500' + delete: + summary: TODO delete measurement + description: 'levels: write, maintain, dev, admin' + tags: + - /measurement + responses: + 200: + $ref: '#/components/responses/Ok' + 400: + $ref: '#/components/responses/400' + 401: + $ref: '#/components/responses/401' + 403: + $ref: '#/components/responses/403' + 404: + $ref: '#/components/responses/404' + 500: + $ref: '#/components/responses/500' + + /template/treatments: + get: + summary: TODO all available treatment methods + description: 'levels: read, write, maintain, dev, admin' + tags: + - /templates + security: + - BasicAuth: [] + responses: + 200: + description: list of treatments + content: + application/json: + schema: + type: array + items: + $ref: '#/components/schemas/Template' + example: + name: heat aging + parameters: + - name: method + range: + - copper + 401: + $ref: '#/components/responses/401' + 500: + $ref: '#/components/responses/500' + /templates/treatment/{name}: + parameters: + - $ref: '#/components/parameters/Name' + get: + summary: TODO treatment method details + description: 'levels: read, write, maintain, admin' + tags: + - /templates + security: + - BasicAuth: [] + responses: + 200: + description: treatment details + content: + application/json: + schema: + allOf: + - $ref: '#/components/schemas/Template' + example: + name: heat aging + parameters: + - name: method + range: + - copper + 400: + $ref: '#/components/responses/400' + 401: + $ref: '#/components/responses/401' + 404: + $ref: '#/components/responses/404' + 500: + $ref: '#/components/responses/500' + put: + summary: TODO add/change treatment method + description: 'levels: maintain, admin' + tags: + - /templates + requestBody: + required: true + content: + application/json: + schema: + allOf: + - $ref: '#/components/schemas/Template' + example: + name: heat aging + parameters: + - name: method + range: + - copper + responses: + 200: + description: treatment details + content: + application/json: + schema: + allOf: + - $ref: '#/components/schemas/Template' + example: + name: heat aging + parameters: + - name: method + range: + - copper + 400: + $ref: '#/components/responses/400' + 401: + $ref: '#/components/responses/401' + 403: + $ref: '#/components/responses/403' + 404: + $ref: '#/components/responses/404' + 500: + $ref: '#/components/responses/500' + delete: + summary: TODO delete treatment method + description: 'levels: maintain, admin' + tags: + - /templates + responses: + 200: + $ref: '#/components/responses/200' + 400: + $ref: '#/components/responses/400' + 401: + $ref: '#/components/responses/401' + 403: + $ref: '#/components/responses/403' + 404: + $ref: '#/components/responses/404' + 500: + $ref: '#/components/responses/500' + /template/measurements: + get: + summary: TODO all available measurement methods + description: 'levels: read, write, maintain, dev, admin' + tags: + - /templates + security: + - BasicAuth: [] + responses: + 200: + description: list of measurement methods + content: + application/json: + schema: + type: array + items: + $ref: '#/components/schemas/Template' + example: + name: humidity + parameters: + - name: kf + range: + min: 0 + max: 2 + 401: + $ref: '#/components/responses/401' + 500: + $ref: '#/components/responses/500' + /templates/measurement/{name}: + parameters: + - $ref: '#/components/parameters/Name' + get: + summary: TODO measurement method details + description: 'levels: read, write, maintain, admin' + tags: + - /templates + security: + - BasicAuth: [] + responses: + 200: + description: measurement details + content: + application/json: + schema: + allOf: + - $ref: '#/components/schemas/Template' + example: + name: humidity + parameters: + - name: kf + range: + min: 0 + max: 2 + 400: + $ref: '#/components/responses/400' + 401: + $ref: '#/components/responses/401' + 404: + $ref: '#/components/responses/404' + 500: + $ref: '#/components/responses/500' + put: + summary: TODO add/change measurement method + description: 'levels: maintain, admin' + tags: + - /templates + requestBody: + required: true + content: + application/json: + schema: + allOf: + - $ref: '#/components/schemas/Template' + example: + name: humidity + parameters: + - name: kf + range: + min: 0 + max: 2 + responses: + 200: + description: measurement details + content: + application/json: + schema: + allOf: + - $ref: '#/components/schemas/Template' + example: + name: humidity + parameters: + - name: kf + range: + min: 0 + max: 2 + 400: + $ref: '#/components/responses/400' + 401: + $ref: '#/components/responses/401' + 403: + $ref: '#/components/responses/403' + 404: + $ref: '#/components/responses/404' + 500: + $ref: '#/components/responses/500' + delete: + summary: TODO delete measurement method + description: 'levels: maintain, admin' + tags: + - /templates + responses: + 200: + $ref: '#/components/responses/200' + 400: + $ref: '#/components/responses/400' + 401: + $ref: '#/components/responses/401' + 403: + $ref: '#/components/responses/403' + 404: + $ref: '#/components/responses/404' + 500: + $ref: '#/components/responses/500' + + + /model/{name}: + parameters: + - $ref: '#/components/parameters/Name' + get: + summary: TODO get model data by name + description: 'levels: dev, admin' + tags: + - /model + responses: + 200: + description: binary model data + content: + application/octet-stream: + schema: + type: string + format: binary + 401: + $ref: '#/components/responses/401' + 403: + $ref: '#/components/responses/403' + 404: + $ref: '#/components/responses/404' + 500: + $ref: '#/components/responses/500' + put: + summary: TODO add/replace model data by name + description: 'levels: dev, admin' + tags: + - /model + requestBody: + required: true + description: binary model data + content: + application/json: + schema: + type: string + format: binary + responses: + 200: + $ref: '#/components/responses/Ok' + 400: + $ref: '#/components/responses/400' + 401: + $ref: '#/components/responses/401' + 403: + $ref: '#/components/responses/403' + 404: + $ref: '#/components/responses/404' + 500: + $ref: '#/components/responses/500' + delete: + summary: TODO delete model data + description: 'levels: dev, admin' + tags: + - /model + responses: + 200: + $ref: '#/components/responses/Ok' + 400: + $ref: '#/components/responses/400' + 401: + $ref: '#/components/responses/401' + 403: + $ref: '#/components/responses/403' + 404: + $ref: '#/components/responses/404' + 500: + $ref: '#/components/responses/500' + + /users: + get: + summary: TODO lists all users + description: 'levels: admin' + tags: + - /user + security: + - BasicAuth: [] + responses: + 200: + description: user API key + content: + application/json: + schema: + type: array + items: + $ref: '#/components/schemas/User' + 401: + $ref: '#/components/responses/401' + 403: + $ref: '#/components/responses/403' + 500: + $ref: '#/components/responses/500' + /user/{name}: + parameters: + - $ref: '#/components/parameters/Name' + get: + summary: TODO list user details + description: 'levels: read, write, maintain, dev get their own information without a name property specified, level: admin can get any user using the name parameter' + tags: + - /user + security: + - BasicAuth: [] + responses: + 200: + description: user details + content: + application/json: + schema: + type: array + items: + $ref: '#/components/schemas/User' + 400: + $ref: '#/components/responses/400' + 401: + $ref: '#/components/responses/401' + 403: + $ref: '#/components/responses/403' + 404: + $ref: '#/components/responses/404' + 500: + $ref: '#/components/responses/500' + put: + summary: TODO change user details + description: 'levels: read, write, maintain, dev can change their own information (except level) without a name property specified, level: admin can change any user using the name parameter' + tags: + - /user + requestBody: + required: true + content: + application/json: + schema: + $ref: '#/components/schemas/User' + responses: + 200: + description: user details + content: + application/json: + schema: + type: array + items: + $ref: '#/components/schemas/User' + 400: + $ref: '#/components/responses/400' + 401: + $ref: '#/components/responses/401' + 403: + $ref: '#/components/responses/403' + 404: + $ref: '#/components/responses/404' + 500: + $ref: '#/components/responses/500' + delete: + summary: TODO delete user + description: 'levels: read, write, maintain, dev can delete their own account, level: admin can delete any user using the name parameter' + tags: + - /user + responses: + 200: + $ref: '#/components/responses/Ok' + 400: + $ref: '#/components/responses/400' + 401: + $ref: '#/components/responses/401' + 403: + $ref: '#/components/responses/403' + 404: + $ref: '#/components/responses/404' + 500: + $ref: '#/components/responses/500' + /user/key: + get: + summary: TODO get API key for the user + description: 'levels: read, write, maintain, dev, admin' + tags: + - /user + security: + - BasicAuth: [] + responses: + 200: + description: user details + content: + application/json: + schema: + $ref: '#/components/schemas/User' + 401: + $ref: '#/components/responses/401' + 500: + $ref: '#/components/responses/500' + /user/new: + post: + summary: TODO add new user + description: 'levels: admin' + tags: + - /user + security: + - BasicAuth: [] + requestBody: + required: true + content: + application/json: + schema: + $ref: '#/components/schemas/User' + responses: + 200: + description: user details + content: + application/json: + schema: + type: array + items: + $ref: '#/components/schemas/User' + 400: + $ref: '#/components/responses/400' + 401: + $ref: '#/components/responses/401' + 403: + $ref: '#/components/responses/403' + 500: + $ref: '#/components/responses/500' + /user/passreset: + post: + summary: TODO reset password and send mail to restore + tags: + - /user + security: [] + requestBody: + required: true + description: mail saved in user profile to provide authentication + content: + application/json: + schema: + $ref: '#/components/schemas/Email' + responses: + 200: + $ref: '#/components/responses/Ok' + 401: + $ref: '#/components/responses/401' + 500: + $ref: '#/components/responses/500' + +components: + schemas: + Id: + type: string + _Id: + properties: + _id: + allOf: + - $ref: '#/components/schemas/Id' + readOnly: true + Color: + properties: + color: + type: string + SampleProperties: + properties: + sample_number: + type: string + type: + type: string + batch: + type: string + validated: + type: boolean + + Samples: + allOf: + - $ref: '#/components/schemas/_Id' + - $ref: '#/components/schemas/Color' + - $ref: '#/components/schemas/SampleProperties' + properties: + material_id: + $ref: '#/components/schemas/Id' + note_id: + $ref: '#/components/schemas/Id' + user_id: + $ref: '#/components/schemas/Id' + Sample: + allOf: + - $ref: '#/components/schemas/_Id' + - $ref: '#/components/schemas/Color' + - $ref: '#/components/schemas/SampleProperties' + properties: + material: + $ref: '#/components/schemas/Material' + notes: + type: object + properties: + comments: + type: string + sample_references: + type: array + items: + $ref: '#/components/schemas/Id' + SampleDetail: + allOf: + - $ref: '#/components/schemas/_Id' + - $ref: '#/components/schemas/Color' + - $ref: '#/components/schemas/SampleProperties' + properties: + material: + $ref: '#/components/schemas/Material' + notes: + type: object + properties: + comments: + type: string + sample_references: + type: array + items: + $ref: '#/components/schemas/Id' + conditions: + type: array + items: + $ref: '#/components/schemas/Condition' + + Material: + allOf: + - $ref: '#/components/schemas/_Id' + properties: + material_numbers: + type: array + items: + type: object + allOf: + - $ref: '#/components/schemas/Color' + properties: + number: + type: number + material_group: + type: string + supplier: + type: string + material_name: + type: string + mineral: + type: number + glass_fiber: + type: number + carbon_fiber: + type: number + + Condition: + allOf: + - $ref: '#/components/schemas/_Id' + properties: + sample_id: + $ref: '#/components/schemas/Id' + parameters: + type: object + treatment_template: + $ref: '#/components/schemas/Id' + + Measurement: + allOf: + - $ref: '#/components/schemas/_Id' + properties: + condition_id: + $ref: '#/components/schemas/Id' + values: + type: object + measurement_template: + $ref: '#/components/schemas/Id' + + Template: + allOf: + - $ref: '#/components/schemas/_Id' + properties: + name: + type: string + parameters: + type: array + items: + type: object + properties: + name: + type: string + range: + type: object + + Email: + required: + - email + properties: + email: + type: string + example: john.doe@bosch.com + User: + allOf: + - $ref: '#/components/schemas/_Id' + - $ref: '#/components/schemas/Email' + properties: + name: + type: string + example: johndoe + levels: + type: array + items: + type: string + example: read + location: + type: string + example: Rng + device_name: + type: string + example: Alpha II + + + responses: + 400: + description: Bad request + content: + application/json: + schema: + properties: + status: + type: string + example: 'Bad request' + 401: + description: Unauthorized + content: + application/json: + schema: + properties: + status: + type: string + example: 'Unauthorized' + 403: + description: Forbidden + content: + application/json: + schema: + properties: + status: + type: string + example: 'Forbidden' + 404: + description: Not found + content: + application/json: + schema: + properties: + status: + type: string + example: 'Not found' + 500: + description: Internal server error + content: + application/json: + schema: + properties: + status: + type: string + example: 'Internal server error' + Ok: + description: request executed successfully + content: + application/json: + schema: + properties: + status: + type: string + example: OK + + parameters: + Id: + name: id + in: path + required: true + schema: + type: string + Name: + name: name + in: path + required: true + schema: + type: string + + securitySchemes: + BasicAuth: + type: http + scheme: basic + ApiKey: + type: apiKey + in: query + name: key \ No newline at end of file diff --git a/oas.yml b/oas.yml deleted file mode 100644 index 0129d82..0000000 --- a/oas.yml +++ /dev/null @@ -1,53 +0,0 @@ -openapi: 3.0.2 - - -info: - title: Digital fingerprint of plastics - API - version: 1.0.0 - description: Gives access to the project database - - -servers: - - url: http://localhost:3000 - description: local server - - url: https://digital-fingerprint-of-plastics-api.apps.de1.bosch-iot-cloud.com/ - description: server on the BIC - - -tags: - - name: / - - -paths: - /: - get: - summary: Root method - tags: - - / - responses: - 200: - description: Server is working - content: - application/json: - schema: - properties: - message: - type: string - example: 'API server up and running!' - 500: - $ref: '#/components/responses/500' - -components: - responses: - 500: - description: Internal server error - content: - application/json: - schema: - properties: - message: - type: string - example: 'Internal server error' - error: - type: boolean - example: true diff --git a/package.json b/package.json index 4a53c47..553a461 100644 --- a/package.json +++ b/package.json @@ -6,7 +6,7 @@ "scripts": { "test": "mocha dist/**/**.spec.js", "start": "tsc && node dist/index.js", - "dev": "nodemon -e ts --exec \"npm run start\"" + "dev": "nodemon -e ts,yaml --exec \"npm run start\"" }, "keywords": [], "author": "", diff --git a/src/index.ts b/src/index.ts index 6030518..8b1353e 100644 --- a/src/index.ts +++ b/src/index.ts @@ -44,7 +44,7 @@ app.use('/', require('./routes/root')); // Swagger UI app.use('/api', swagger.serve, swagger.setup( - yaml.load('./oas.yml'), + yaml.load('./oas.yaml'), { defaultModelsExpandDepth: -1, customCss: '.swagger-ui .topbar { display: none }'