class ApiDocuments {
static Future<ApiDoc> onePerson() async {
return ApiDoc(
post: ApiDoc(
response: {
'200': [
ApiResponse<int>('timestamp_start', def: 0),
ApiResponse<bool>('success', def: true),
ApiResponse<Map<String, String>>(
'data',
def: PersonCollectionFree.formPerson.fields.map((k, v) {
return MapEntry(k, v.defaultValue?.call());
}),
),
],
'404': r_404,
},
description: "Update one person by id.",
parameters: [
ApiParameter<String>(
'id',
isRequired: true,
paramIn: ParamIn.path,
),
ApiParameter<String>(
'name',
isRequired: false,
paramIn: ParamIn.header,
),
ApiParameter<int>(
'age',
isRequired: false,
paramIn: ParamIn.header,
),
ApiParameter<double>(
'height',
isRequired: false,
paramIn: ParamIn.header,
),
ApiParameter<String>(
'email',
isRequired: true,
paramIn: ParamIn.header,
),
ApiParameter<String>(
'married',
isRequired: false,
paramIn: ParamIn.header,
def: false,
),
],
),
get: ApiDoc(
response: {
'200': [
ApiResponse<int>('timestamp_start', def: 0),
ApiResponse<Map<String, String>>(
'data',
def: PersonCollectionFree.formPerson.fields.map((k, v) {
return MapEntry(k, v.defaultValue?.call());
}),
),
],
'404': r_404,
},
description: "Get one person by id.",
parameters: [
ApiParameter<String>('id', isRequired: true, paramIn: ParamIn.path),
],
),
delete: ApiDoc(
response: {
'200': [
ApiResponse<int>('timestamp_start', def: 0),
ApiResponse<bool>('success', def: true),
],
'404': r_404,
},
description: "Delete one person by id.",
parameters: [
ApiParameter<String>('id', isRequired: true, paramIn: ParamIn.path),
],
),
);
}
}
/// Adding ApiDoc to Routes for example
FinchRoute(
key: 'root.person.show',
path: 'api/person/{id}',
extraPath: ['example/person/{id}'],
index: homeController.onePerson,
methods: Methods.GET_POST,
apiDoc: ApiDocuments.onePerson,
),