Following this post : Get Data JSON in Flask
I was able to write a simple API where i post a json objet (a first name & last name & a generate ID) to insert it into a database.
After that, i want to use swagger/flasgger to model it. It's already working for the get or get_by_id, but impossible for the POST to work.
In my python code i have this :
from flask import Flask, jsonify, request
@app.route('/api/v1/list', methods=['POST'])
@swag_from('index_post.yml')
def add_entry():
request_json = request.get_json()
value1 = request_json.get('First_Name')
value2 = request_json.get('Last_Name')
if value1 is not None and value2 is not None:
cursor.execute("INSERT INTO person (first_name,last_name) VALUES
(%s,%s)", (value1, value2))
data = conn.commit()
return jsonify(data)
And in the YAML file, i have :
paths:
/api/v1/list:
post:
description: testpost
operationId: PostNewName
consumes:
- application/json
parameters:
- name: body
in: body
required: true
schema:
id : toto
required:
- first
- last
properties:
first:
type: string
description: Unique identifier representing a First Name
last:
type: string
description: Unique identifier representing a Last Name
responses:
200:
description: creation OK
But the parameters doesnt appear on the swagger html page. And i dont know what the issue is on this...
Thanks for your help.