toJson method

Map<String, dynamic> toJson()

Implementation

Map<String, dynamic> toJson() {
  final _responses = <String, SwaggerResponse>{};
  for (final e in responses) {
    _responses.putIfAbsent(e.statusCode, () => e);
  }

  return {
    method.toLowerCase(): {
      'tags': [
        tag,
      ],
      if (summary != null) 'summary': summary,
      if (description != null) 'description': description,
      'responses': includeResponse
          ? _responses
          : {
              'default': {
                'description': 'API response',
                'content': {
                  'application/json': {
                    'schema': {
                      'type': 'string',
                    },
                  }
                }
              }
            },
      if (requestBody != null)
        'requestBody': {
          'content': requestBody,
        },
      if (queryParams != null) 'parameters': queryParams,
      if (headers.isNotEmpty) 'security': headers,
    }
  };
}