Browse Source

feat(dynamite): support yaml specs

Signed-off-by: Nikolas Rimikis <leptopoda@users.noreply.github.com>
pull/766/head
Nikolas Rimikis 1 year ago
parent
commit
a9a2504d6f
No known key found for this signature in database
GPG Key ID: 85ED1DE9786A4FF2
  1. 13
      packages/dynamite/dynamite/lib/src/openapi_builder.dart
  2. 1
      packages/dynamite/dynamite/pubspec.yaml

13
packages/dynamite/dynamite/lib/src/openapi_builder.dart

@ -2,6 +2,7 @@ import 'dart:convert';
import 'package:build/build.dart';
import 'package:built_collection/built_collection.dart';
import 'package:checked_yaml/checked_yaml.dart';
import 'package:code_builder/code_builder.dart';
import 'package:dart_style/dart_style.dart';
import 'package:dynamite/src/builder/client.dart';
@ -18,6 +19,7 @@ class OpenAPIBuilder implements Builder {
@override
final buildExtensions = const {
'.openapi.json': ['.openapi.dart'],
'.openapi.yaml': ['.openapi.dart'],
};
@override
@ -31,10 +33,17 @@ class OpenAPIBuilder implements Builder {
useNullSafetySyntax: true,
);
final spec = serializers.deserializeWith(
final spec = switch (inputId.extension) {
'json' => serializers.deserializeWith(
OpenAPI.serializer,
json.decode(await buildStep.readAsString(inputId)),
)!;
)!,
'yaml' => checkedYamlDecode(
await buildStep.readAsString(inputId),
(final m) => serializers.deserializeWith(OpenAPI.serializer, m)!,
),
_ => throw StateError('Openapi specs can only be yaml or json.'),
};
final supportedVersions = ['3.0.3', '3.1.0'];
if (!supportedVersions.contains(spec.version)) {

1
packages/dynamite/dynamite/pubspec.yaml

@ -8,6 +8,7 @@ dependencies:
build: ^2.4.1
built_collection: ^5.1.1
built_value: ^8.6.2
checked_yaml: ^2.0.3
code_builder: ^4.6.0
collection: ^1.17.2
dart_style: ^2.3.2

Loading…
Cancel
Save