From c10d1a154b1d18710c00f9d1b2a50a1254d79c3d Mon Sep 17 00:00:00 2001 From: jld3103 Date: Tue, 14 Mar 2023 12:19:56 +0100 Subject: [PATCH] dynamite: Support deprecated operations --- packages/dynamite/lib/src/models/operation.dart | 3 +++ packages/dynamite/lib/src/models/operation.g.dart | 13 ++++++++++++- packages/dynamite/lib/src/openapi_builder.dart | 3 +++ 3 files changed, 18 insertions(+), 1 deletion(-) diff --git a/packages/dynamite/lib/src/models/operation.dart b/packages/dynamite/lib/src/models/operation.dart index 6e9677de..cc5fa669 100644 --- a/packages/dynamite/lib/src/models/operation.dart +++ b/packages/dynamite/lib/src/models/operation.dart @@ -12,6 +12,7 @@ class Operation { this.operationId, this.summary, this.description, + this.deprecated, this.tags, this.parameters, this.requestBody, @@ -27,6 +28,8 @@ class Operation { final String? description; + final bool? deprecated; + final List? tags; final List? parameters; diff --git a/packages/dynamite/lib/src/models/operation.g.dart b/packages/dynamite/lib/src/models/operation.g.dart index 278779b4..7b1ad93b 100644 --- a/packages/dynamite/lib/src/models/operation.g.dart +++ b/packages/dynamite/lib/src/models/operation.g.dart @@ -9,12 +9,22 @@ part of 'operation.dart'; Operation _$OperationFromJson(Map json) { $checkKeys( json, - allowedKeys: const ['operationId', 'summary', 'description', 'tags', 'parameters', 'requestBody', 'responses'], + allowedKeys: const [ + 'operationId', + 'summary', + 'description', + 'deprecated', + 'tags', + 'parameters', + 'requestBody', + 'responses' + ], ); return Operation( operationId: json['operationId'] as String?, summary: json['summary'] as String?, description: json['description'] as String?, + deprecated: json['deprecated'] as bool?, tags: (json['tags'] as List?)?.map((e) => e as String).toList(), parameters: (json['parameters'] as List?)?.map((e) => Parameter.fromJson(e as Map)).toList(), @@ -37,6 +47,7 @@ Map _$OperationToJson(Operation instance) { writeNotNull('operationId', instance.operationId); writeNotNull('summary', instance.summary); writeNotNull('description', instance.description); + writeNotNull('deprecated', instance.deprecated); writeNotNull('tags', instance.tags); writeNotNull('parameters', instance.parameters?.map((e) => e.toJson()).toList()); writeNotNull('requestBody', instance.requestBody?.toJson()); diff --git a/packages/dynamite/lib/src/openapi_builder.dart b/packages/dynamite/lib/src/openapi_builder.dart index 1c605fff..1eb22a2e 100644 --- a/packages/dynamite/lib/src/openapi_builder.dart +++ b/packages/dynamite/lib/src/openapi_builder.dart @@ -583,6 +583,9 @@ class OpenAPIBuilder implements Builder { ], ..._descriptionToDocs(operation.description), ]); + if (operation.deprecated ?? false) { + b.annotations.add(refer('Deprecated').call([refer("''")])); + } final code = StringBuffer(''' var path = '$path';