Browse Source

refactor(dynamite): refactor models structure

Signed-off-by: Nikolas Rimikis <leptopoda@users.noreply.github.com>
pull/846/head
Nikolas Rimikis 1 year ago
parent
commit
4248e3909c
No known key found for this signature in database
GPG Key ID: 85ED1DE9786A4FF2
  1. 41
      packages/dynamite/dynamite/lib/src/builder/client.dart
  2. 16
      packages/dynamite/dynamite/lib/src/builder/header_serializer.dart
  3. 13
      packages/dynamite/dynamite/lib/src/builder/ofs_builder.dart
  4. 9
      packages/dynamite/dynamite/lib/src/builder/resolve_enum.dart
  5. 9
      packages/dynamite/dynamite/lib/src/builder/resolve_interface.dart
  6. 9
      packages/dynamite/dynamite/lib/src/builder/resolve_object.dart
  7. 9
      packages/dynamite/dynamite/lib/src/builder/resolve_type.dart
  8. 2
      packages/dynamite/dynamite/lib/src/builder/state.dart
  9. 2
      packages/dynamite/dynamite/lib/src/helpers/built_value.dart
  10. 7
      packages/dynamite/dynamite/lib/src/helpers/dynamite.dart
  11. 2
      packages/dynamite/dynamite/lib/src/helpers/type_result.dart
  12. 70
      packages/dynamite/dynamite/lib/src/models/openapi.dart
  13. 2
      packages/dynamite/dynamite/lib/src/models/openapi.g.dart
  14. 4
      packages/dynamite/dynamite/lib/src/models/openapi/components.dart
  15. 0
      packages/dynamite/dynamite/lib/src/models/openapi/components.g.dart
  16. 0
      packages/dynamite/dynamite/lib/src/models/openapi/discriminator.dart
  17. 0
      packages/dynamite/dynamite/lib/src/models/openapi/discriminator.g.dart
  18. 2
      packages/dynamite/dynamite/lib/src/models/openapi/header.dart
  19. 0
      packages/dynamite/dynamite/lib/src/models/openapi/header.g.dart
  20. 2
      packages/dynamite/dynamite/lib/src/models/openapi/info.dart
  21. 0
      packages/dynamite/dynamite/lib/src/models/openapi/info.g.dart
  22. 0
      packages/dynamite/dynamite/lib/src/models/openapi/license.dart
  23. 0
      packages/dynamite/dynamite/lib/src/models/openapi/license.g.dart
  24. 2
      packages/dynamite/dynamite/lib/src/models/openapi/media_type.dart
  25. 0
      packages/dynamite/dynamite/lib/src/models/openapi/media_type.g.dart
  26. 10
      packages/dynamite/dynamite/lib/src/models/openapi/open_api.dart
  27. 0
      packages/dynamite/dynamite/lib/src/models/openapi/open_api.g.dart
  28. 8
      packages/dynamite/dynamite/lib/src/models/openapi/operation.dart
  29. 0
      packages/dynamite/dynamite/lib/src/models/openapi/operation.g.dart
  30. 2
      packages/dynamite/dynamite/lib/src/models/openapi/parameter.dart
  31. 0
      packages/dynamite/dynamite/lib/src/models/openapi/parameter.g.dart
  32. 4
      packages/dynamite/dynamite/lib/src/models/openapi/path_item.dart
  33. 0
      packages/dynamite/dynamite/lib/src/models/openapi/path_item.g.dart
  34. 2
      packages/dynamite/dynamite/lib/src/models/openapi/request_body.dart
  35. 0
      packages/dynamite/dynamite/lib/src/models/openapi/request_body.g.dart
  36. 4
      packages/dynamite/dynamite/lib/src/models/openapi/response.dart
  37. 0
      packages/dynamite/dynamite/lib/src/models/openapi/response.g.dart
  38. 2
      packages/dynamite/dynamite/lib/src/models/openapi/schema.dart
  39. 0
      packages/dynamite/dynamite/lib/src/models/openapi/schema.g.dart
  40. 0
      packages/dynamite/dynamite/lib/src/models/openapi/security_scheme.dart
  41. 0
      packages/dynamite/dynamite/lib/src/models/openapi/security_scheme.g.dart
  42. 2
      packages/dynamite/dynamite/lib/src/models/openapi/server.dart
  43. 0
      packages/dynamite/dynamite/lib/src/models/openapi/server.g.dart
  44. 0
      packages/dynamite/dynamite/lib/src/models/openapi/server_variable.dart
  45. 0
      packages/dynamite/dynamite/lib/src/models/openapi/server_variable.g.dart
  46. 0
      packages/dynamite/dynamite/lib/src/models/openapi/tag.dart
  47. 0
      packages/dynamite/dynamite/lib/src/models/openapi/tag.g.dart
  48. 52
      packages/dynamite/dynamite/lib/src/models/serializers.dart
  49. 1
      packages/dynamite/dynamite/lib/src/models/type_result.dart
  50. 0
      packages/dynamite/dynamite/lib/src/models/type_result/base.dart
  51. 0
      packages/dynamite/dynamite/lib/src/models/type_result/enum.dart
  52. 0
      packages/dynamite/dynamite/lib/src/models/type_result/list.dart
  53. 0
      packages/dynamite/dynamite/lib/src/models/type_result/map.dart
  54. 0
      packages/dynamite/dynamite/lib/src/models/type_result/object.dart
  55. 0
      packages/dynamite/dynamite/lib/src/models/type_result/type_result.dart
  56. 11
      packages/dynamite/dynamite/lib/src/openapi_builder.dart
  57. 2
      packages/dynamite/dynamite/test/type_result_test.dart

41
packages/dynamite/dynamite/lib/src/builder/client.dart

@ -7,11 +7,8 @@ import 'package:dynamite/src/builder/state.dart';
import 'package:dynamite/src/helpers/dart_helpers.dart';
import 'package:dynamite/src/helpers/dynamite.dart';
import 'package:dynamite/src/helpers/type_result.dart';
import 'package:dynamite/src/models/open_api.dart';
import 'package:dynamite/src/models/path_item.dart';
import 'package:dynamite/src/models/response.dart';
import 'package:dynamite/src/models/schema.dart';
import 'package:dynamite/src/type_result/type_result.dart';
import 'package:dynamite/src/models/openapi.dart' as openapi;
import 'package:dynamite/src/models/type_result.dart';
List<Class> generateDynamiteOverrides(final State state) => [
Class(
@ -111,7 +108,7 @@ return ${state.classPrefix}ApiException(
];
Iterable<Class> generateClients(
final OpenAPI spec,
final openapi.OpenAPI spec,
final State state,
) sync* {
yield* generateDynamiteOverrides(state);
@ -125,7 +122,7 @@ Iterable<Class> generateClients(
}
Class buildRootClient(
final OpenAPI spec,
final openapi.OpenAPI spec,
final State state,
final List<String> tags,
) =>
@ -224,7 +221,7 @@ super(
);
Class buildClient(
final OpenAPI spec,
final openapi.OpenAPI spec,
final State state,
final List<String> tags,
final String tag,
@ -272,7 +269,7 @@ Class buildClient(
);
Iterable<Method> buildTags(
final OpenAPI spec,
final openapi.OpenAPI spec,
final State state,
final List<String> tags,
final String? tag,
@ -299,7 +296,7 @@ Iterable<Method> buildTags(
b.annotations.add(refer('Deprecated').call([refer("''")]));
}
var responses = <Response, List<int>>{};
var responses = <openapi.Response, List<int>>{};
if (operation.responses != null) {
for (final responseEntry in operation.responses!.entries) {
final statusCode = int.parse(responseEntry.key);
@ -530,7 +527,7 @@ final _response = await ${isRootClient ? 'this' : '_rootClient'}.doRequest(
spec,
state,
identifier,
Schema(
openapi.Schema(
(final b) => b
..properties.replace(
response.headers!.map(
@ -625,8 +622,8 @@ final _response = await ${isRootClient ? 'this' : '_rootClient'}.doRequest(
}
}
Map<String, PathItem> generatePaths(final OpenAPI spec, final String? tag) {
final paths = <String, PathItem>{};
Map<String, openapi.PathItem> generatePaths(final openapi.OpenAPI spec, final String? tag) {
final paths = <String, openapi.PathItem>{};
if (spec.paths != null) {
for (final path in spec.paths!.entries) {
@ -637,21 +634,21 @@ Map<String, PathItem> generatePaths(final OpenAPI spec, final String? tag) {
paths[path.key] ??= path.value;
paths[path.key]!.rebuild((final b) {
switch (operationEntry.key) {
case PathItemOperation.get:
case openapi.PathItemOperation.get:
b.get.replace(operation);
case PathItemOperation.put:
case openapi.PathItemOperation.put:
b.put.replace(operation);
case PathItemOperation.post:
case openapi.PathItemOperation.post:
b.post.replace(operation);
case PathItemOperation.delete:
case openapi.PathItemOperation.delete:
b.delete.replace(operation);
case PathItemOperation.options:
case openapi.PathItemOperation.options:
b.options.replace(operation);
case PathItemOperation.head:
case openapi.PathItemOperation.head:
b.head.replace(operation);
case PathItemOperation.patch:
case openapi.PathItemOperation.patch:
b.patch.replace(operation);
case PathItemOperation.trace:
case openapi.PathItemOperation.trace:
b.trace.replace(operation);
}
});
@ -663,7 +660,7 @@ Map<String, PathItem> generatePaths(final OpenAPI spec, final String? tag) {
return paths;
}
List<String> generateTags(final OpenAPI spec) {
List<String> generateTags(final openapi.OpenAPI spec) {
final tags = <String>[];
if (spec.paths != null) {

16
packages/dynamite/dynamite/lib/src/builder/header_serializer.dart

@ -3,11 +3,15 @@ import 'package:dynamite/src/builder/resolve_type.dart';
import 'package:dynamite/src/builder/state.dart';
import 'package:dynamite/src/helpers/dart_helpers.dart';
import 'package:dynamite/src/helpers/dynamite.dart';
import 'package:dynamite/src/models/open_api.dart';
import 'package:dynamite/src/models/schema.dart';
import 'package:dynamite/src/type_result/type_result.dart';
import 'package:dynamite/src/models/openapi.dart' as openapi;
import 'package:dynamite/src/models/type_result.dart';
Spec buildHeaderSerializer(final State state, final String identifier, final OpenAPI spec, final Schema schema) =>
Spec buildHeaderSerializer(
final State state,
final String identifier,
final openapi.OpenAPI spec,
final openapi.Schema schema,
) =>
Class(
(final b) => b
..name = '_\$${state.classPrefix}${identifier}Serializer'
@ -107,8 +111,8 @@ return result.build();
Iterable<String> deserializeProperty(
final State state,
final String identifier,
final OpenAPI spec,
final Schema schema,
final openapi.OpenAPI spec,
final openapi.Schema schema,
) sync* {
for (final property in schema.properties!.entries) {
final propertyName = property.key;

13
packages/dynamite/dynamite/lib/src/builder/ofs_builder.dart

@ -5,15 +5,14 @@ import 'package:dynamite/src/builder/resolve_type.dart';
import 'package:dynamite/src/builder/state.dart';
import 'package:dynamite/src/helpers/built_value.dart';
import 'package:dynamite/src/helpers/dart_helpers.dart';
import 'package:dynamite/src/models/open_api.dart';
import 'package:dynamite/src/models/schema.dart';
import 'package:dynamite/src/type_result/type_result.dart';
import 'package:dynamite/src/models/openapi.dart' as openapi;
import 'package:dynamite/src/models/type_result.dart';
TypeResult resolveAllOf(
final OpenAPI spec,
final openapi.OpenAPI spec,
final State state,
final String identifier,
final Schema schema, {
final openapi.Schema schema, {
final bool nullable = false,
}) {
final result = TypeResultObject(
@ -65,10 +64,10 @@ TypeResult resolveAllOf(
}
TypeResult resolveOfs(
final OpenAPI spec,
final openapi.OpenAPI spec,
final State state,
final String identifier,
final Schema schema, {
final openapi.Schema schema, {
final bool nullable = false,
}) {
if (schema.allOf != null) {

9
packages/dynamite/dynamite/lib/src/builder/resolve_enum.dart

@ -4,15 +4,14 @@ import 'package:dynamite/src/builder/state.dart';
import 'package:dynamite/src/helpers/built_value.dart';
import 'package:dynamite/src/helpers/dart_helpers.dart';
import 'package:dynamite/src/helpers/type_result.dart';
import 'package:dynamite/src/models/open_api.dart';
import 'package:dynamite/src/models/schema.dart';
import 'package:dynamite/src/type_result/type_result.dart';
import 'package:dynamite/src/models/openapi.dart' as openapi;
import 'package:dynamite/src/models/type_result.dart';
TypeResult resolveEnum(
final OpenAPI spec,
final openapi.OpenAPI spec,
final State state,
final String identifier,
final Schema schema,
final openapi.Schema schema,
final TypeResult subResult, {
final bool nullable = false,
}) {

9
packages/dynamite/dynamite/lib/src/builder/resolve_interface.dart

@ -4,15 +4,14 @@ import 'package:dynamite/src/builder/state.dart';
import 'package:dynamite/src/helpers/built_value.dart';
import 'package:dynamite/src/helpers/dart_helpers.dart';
import 'package:dynamite/src/helpers/dynamite.dart';
import 'package:dynamite/src/models/open_api.dart';
import 'package:dynamite/src/models/schema.dart';
import 'package:dynamite/src/type_result/type_result.dart';
import 'package:dynamite/src/models/openapi.dart' as openapi;
import 'package:dynamite/src/models/type_result.dart';
TypeResultObject resolveInterface(
final OpenAPI spec,
final openapi.OpenAPI spec,
final State state,
final String identifier,
final Schema schema,
final openapi.Schema schema,
) {
final result = TypeResultObject(
'${state.classPrefix}$identifier',

9
packages/dynamite/dynamite/lib/src/builder/resolve_object.dart

@ -5,15 +5,14 @@ import 'package:dynamite/src/builder/state.dart';
import 'package:dynamite/src/helpers/built_value.dart';
import 'package:dynamite/src/helpers/dart_helpers.dart';
import 'package:dynamite/src/helpers/type_result.dart';
import 'package:dynamite/src/models/open_api.dart';
import 'package:dynamite/src/models/schema.dart';
import 'package:dynamite/src/type_result/type_result.dart';
import 'package:dynamite/src/models/openapi.dart' as openapi;
import 'package:dynamite/src/models/type_result.dart';
TypeResultObject resolveObject(
final OpenAPI spec,
final openapi.OpenAPI spec,
final State state,
final String identifier,
final Schema schema, {
final openapi.Schema schema, {
final bool nullable = false,
final bool isHeader = false,
}) {

9
packages/dynamite/dynamite/lib/src/builder/resolve_type.dart

@ -2,15 +2,14 @@ import 'package:dynamite/src/builder/ofs_builder.dart';
import 'package:dynamite/src/builder/resolve_enum.dart';
import 'package:dynamite/src/builder/resolve_object.dart';
import 'package:dynamite/src/builder/state.dart';
import 'package:dynamite/src/models/open_api.dart';
import 'package:dynamite/src/models/schema.dart';
import 'package:dynamite/src/type_result/type_result.dart';
import 'package:dynamite/src/models/openapi.dart' as openapi;
import 'package:dynamite/src/models/type_result.dart';
TypeResult resolveType(
final OpenAPI spec,
final openapi.OpenAPI spec,
final State state,
final String identifier,
final Schema schema, {
final openapi.Schema schema, {
final bool ignoreEnum = false,
final bool nullable = false,
}) {

2
packages/dynamite/dynamite/lib/src/builder/state.dart

@ -1,6 +1,6 @@
import 'package:code_builder/code_builder.dart';
import 'package:dynamite/src/helpers/dart_helpers.dart';
import 'package:dynamite/src/type_result/type_result.dart';
import 'package:dynamite/src/models/type_result.dart';
class State {
State(final String prefix)

2
packages/dynamite/dynamite/lib/src/helpers/built_value.dart

@ -1,7 +1,7 @@
import 'package:built_collection/built_collection.dart';
import 'package:code_builder/code_builder.dart';
import 'package:dynamite/src/helpers/dart_helpers.dart';
import 'package:dynamite/src/type_result/type_result.dart';
import 'package:dynamite/src/models/type_result.dart';
const interfaceSuffix = 'Interface';

7
packages/dynamite/dynamite/lib/src/helpers/dynamite.dart

@ -1,8 +1,7 @@
// ignore_for_file: avoid_positional_boolean_parameters
import 'package:dynamite/src/helpers/dart_helpers.dart';
import 'package:dynamite/src/models/parameter.dart';
import 'package:dynamite/src/models/schema.dart';
import 'package:dynamite/src/models/openapi.dart' as openapi;
String filterMethodName(final String operationId, final String tag) {
final expandedTag = tag.split('/').toList();
@ -20,7 +19,7 @@ String clientName(final String tag) => '${toDartName(tag, uppercaseFirstCharacte
bool isDartParameterNullable(
final bool? required,
final Schema? schema,
final openapi.Schema? schema,
) =>
(!(required ?? false) && schema?.$default == null) || (schema?.nullable ?? false);
@ -30,7 +29,7 @@ bool isRequired(
) =>
(required ?? false) && default_ == null;
int sortRequiredParameters(final Parameter a, final Parameter b) {
int sortRequiredParameters(final openapi.Parameter a, final openapi.Parameter b) {
if (a.isDartRequired != b.isDartRequired) {
if (a.isDartRequired && !b.isDartRequired) {
return -1;

2
packages/dynamite/dynamite/lib/src/helpers/type_result.dart

@ -1,5 +1,5 @@
import 'package:dynamite/src/helpers/dart_helpers.dart';
import 'package:dynamite/src/type_result/type_result.dart';
import 'package:dynamite/src/models/type_result.dart';
String valueToEscapedValue(final TypeResult result, final String value) {
if (result is TypeResultBase && result.name == 'String') {

70
packages/dynamite/dynamite/lib/src/models/openapi.dart

@ -0,0 +1,70 @@
import 'package:built_collection/built_collection.dart';
import 'package:built_value/serializer.dart';
import 'package:built_value/standard_json_plugin.dart';
import 'package:dynamite/src/models/openapi/components.dart';
import 'package:dynamite/src/models/openapi/discriminator.dart';
import 'package:dynamite/src/models/openapi/header.dart';
import 'package:dynamite/src/models/openapi/info.dart';
import 'package:dynamite/src/models/openapi/license.dart';
import 'package:dynamite/src/models/openapi/media_type.dart';
import 'package:dynamite/src/models/openapi/open_api.dart';
import 'package:dynamite/src/models/openapi/operation.dart';
import 'package:dynamite/src/models/openapi/parameter.dart';
import 'package:dynamite/src/models/openapi/path_item.dart';
import 'package:dynamite/src/models/openapi/request_body.dart';
import 'package:dynamite/src/models/openapi/response.dart';
import 'package:dynamite/src/models/openapi/schema.dart';
import 'package:dynamite/src/models/openapi/security_scheme.dart';
import 'package:dynamite/src/models/openapi/server.dart';
import 'package:dynamite/src/models/openapi/server_variable.dart';
import 'package:dynamite/src/models/openapi/tag.dart';
export 'openapi/components.dart';
export 'openapi/discriminator.dart';
export 'openapi/header.dart';
export 'openapi/info.dart';
export 'openapi/license.dart';
export 'openapi/media_type.dart';
export 'openapi/open_api.dart';
export 'openapi/operation.dart';
export 'openapi/parameter.dart';
export 'openapi/path_item.dart';
export 'openapi/request_body.dart';
export 'openapi/response.dart';
export 'openapi/schema.dart';
export 'openapi/security_scheme.dart';
export 'openapi/server.dart';
export 'openapi/server_variable.dart';
export 'openapi/tag.dart';
part 'openapi.g.dart';
@SerializersFor([
Components,
Discriminator,
Header,
Info,
License,
MediaType,
OpenAPI,
Operation,
Parameter,
PathItem,
RequestBody,
Response,
Schema,
SecurityScheme,
Server,
ServerVariable,
Tag,
])
final Serializers serializers = (_$serializers.toBuilder()
..addBuilderFactory(
const FullType(BuiltMap, [
FullType(String),
FullType(BuiltList, [FullType(String)]),
]),
MapBuilder<String, BuiltList<String>>.new,
)
..addPlugin(StandardJsonPlugin()))
.build();

2
packages/dynamite/dynamite/lib/src/models/serializers.g.dart → packages/dynamite/dynamite/lib/src/models/openapi.g.dart

@ -1,6 +1,6 @@
// GENERATED CODE - DO NOT MODIFY BY HAND
part of 'serializers.dart';
part of 'openapi.dart';
// **************************************************************************
// BuiltValueGenerator

4
packages/dynamite/dynamite/lib/src/models/components.dart → packages/dynamite/dynamite/lib/src/models/openapi/components.dart

@ -1,8 +1,8 @@
import 'package:built_collection/built_collection.dart';
import 'package:built_value/built_value.dart';
import 'package:built_value/serializer.dart';
import 'package:dynamite/src/models/schema.dart';
import 'package:dynamite/src/models/security_scheme.dart';
import 'package:dynamite/src/models/openapi/schema.dart';
import 'package:dynamite/src/models/openapi/security_scheme.dart';
part 'components.g.dart';

0
packages/dynamite/dynamite/lib/src/models/components.g.dart → packages/dynamite/dynamite/lib/src/models/openapi/components.g.dart

0
packages/dynamite/dynamite/lib/src/models/discriminator.dart → packages/dynamite/dynamite/lib/src/models/openapi/discriminator.dart

0
packages/dynamite/dynamite/lib/src/models/discriminator.g.dart → packages/dynamite/dynamite/lib/src/models/openapi/discriminator.g.dart

2
packages/dynamite/dynamite/lib/src/models/header.dart → packages/dynamite/dynamite/lib/src/models/openapi/header.dart

@ -1,6 +1,6 @@
import 'package:built_value/built_value.dart';
import 'package:built_value/serializer.dart';
import 'package:dynamite/src/models/schema.dart';
import 'package:dynamite/src/models/openapi/schema.dart';
part 'header.g.dart';

0
packages/dynamite/dynamite/lib/src/models/header.g.dart → packages/dynamite/dynamite/lib/src/models/openapi/header.g.dart

2
packages/dynamite/dynamite/lib/src/models/info.dart → packages/dynamite/dynamite/lib/src/models/openapi/info.dart

@ -1,6 +1,6 @@
import 'package:built_value/built_value.dart';
import 'package:built_value/serializer.dart';
import 'package:dynamite/src/models/license.dart';
import 'package:dynamite/src/models/openapi/license.dart';
part 'info.g.dart';

0
packages/dynamite/dynamite/lib/src/models/info.g.dart → packages/dynamite/dynamite/lib/src/models/openapi/info.g.dart

0
packages/dynamite/dynamite/lib/src/models/license.dart → packages/dynamite/dynamite/lib/src/models/openapi/license.dart

0
packages/dynamite/dynamite/lib/src/models/license.g.dart → packages/dynamite/dynamite/lib/src/models/openapi/license.g.dart

2
packages/dynamite/dynamite/lib/src/models/media_type.dart → packages/dynamite/dynamite/lib/src/models/openapi/media_type.dart

@ -1,6 +1,6 @@
import 'package:built_value/built_value.dart';
import 'package:built_value/serializer.dart';
import 'package:dynamite/src/models/schema.dart';
import 'package:dynamite/src/models/openapi/schema.dart';
part 'media_type.g.dart';

0
packages/dynamite/dynamite/lib/src/models/media_type.g.dart → packages/dynamite/dynamite/lib/src/models/openapi/media_type.g.dart

10
packages/dynamite/dynamite/lib/src/models/open_api.dart → packages/dynamite/dynamite/lib/src/models/openapi/open_api.dart

@ -1,11 +1,11 @@
import 'package:built_collection/built_collection.dart';
import 'package:built_value/built_value.dart';
import 'package:built_value/serializer.dart';
import 'package:dynamite/src/models/components.dart';
import 'package:dynamite/src/models/info.dart';
import 'package:dynamite/src/models/path_item.dart';
import 'package:dynamite/src/models/server.dart';
import 'package:dynamite/src/models/tag.dart';
import 'package:dynamite/src/models/openapi/components.dart';
import 'package:dynamite/src/models/openapi/info.dart';
import 'package:dynamite/src/models/openapi/path_item.dart';
import 'package:dynamite/src/models/openapi/server.dart';
import 'package:dynamite/src/models/openapi/tag.dart';
part 'open_api.g.dart';

0
packages/dynamite/dynamite/lib/src/models/open_api.g.dart → packages/dynamite/dynamite/lib/src/models/openapi/open_api.g.dart

8
packages/dynamite/dynamite/lib/src/models/operation.dart → packages/dynamite/dynamite/lib/src/models/openapi/operation.dart

@ -2,9 +2,9 @@ import 'package:built_collection/built_collection.dart';
import 'package:built_value/built_value.dart';
import 'package:built_value/serializer.dart';
import 'package:dynamite/src/helpers/docs.dart';
import 'package:dynamite/src/models/parameter.dart';
import 'package:dynamite/src/models/request_body.dart';
import 'package:dynamite/src/models/response.dart';
import 'package:dynamite/src/models/openapi/parameter.dart';
import 'package:dynamite/src/models/openapi/request_body.dart';
import 'package:dynamite/src/models/openapi/response.dart';
part 'operation.g.dart';
@ -38,7 +38,7 @@ abstract class Operation implements Built<Operation, OperationBuilder> {
Iterable<String> get formattedDescription sync* {
yield* descriptionToDocs(summary);
if (summary != null && description != null) {
if (summary != null && summary!.isNotEmpty && description != null && description!.isNotEmpty) {
yield docsSeparator;
}

0
packages/dynamite/dynamite/lib/src/models/operation.g.dart → packages/dynamite/dynamite/lib/src/models/openapi/operation.g.dart

2
packages/dynamite/dynamite/lib/src/models/parameter.dart → packages/dynamite/dynamite/lib/src/models/openapi/parameter.dart

@ -1,7 +1,7 @@
import 'package:built_value/built_value.dart';
import 'package:built_value/serializer.dart';
import 'package:dynamite/src/helpers/dynamite.dart';
import 'package:dynamite/src/models/schema.dart';
import 'package:dynamite/src/models/openapi/schema.dart';
part 'parameter.g.dart';

0
packages/dynamite/dynamite/lib/src/models/parameter.g.dart → packages/dynamite/dynamite/lib/src/models/openapi/parameter.g.dart

4
packages/dynamite/dynamite/lib/src/models/path_item.dart → packages/dynamite/dynamite/lib/src/models/openapi/path_item.dart

@ -1,8 +1,8 @@
import 'package:built_collection/built_collection.dart';
import 'package:built_value/built_value.dart';
import 'package:built_value/serializer.dart';
import 'package:dynamite/src/models/operation.dart';
import 'package:dynamite/src/models/parameter.dart';
import 'package:dynamite/src/models/openapi/operation.dart';
import 'package:dynamite/src/models/openapi/parameter.dart';
part 'path_item.g.dart';

0
packages/dynamite/dynamite/lib/src/models/path_item.g.dart → packages/dynamite/dynamite/lib/src/models/openapi/path_item.g.dart

2
packages/dynamite/dynamite/lib/src/models/request_body.dart → packages/dynamite/dynamite/lib/src/models/openapi/request_body.dart

@ -1,7 +1,7 @@
import 'package:built_collection/built_collection.dart';
import 'package:built_value/built_value.dart';
import 'package:built_value/serializer.dart';
import 'package:dynamite/src/models/media_type.dart';
import 'package:dynamite/src/models/openapi/media_type.dart';
part 'request_body.g.dart';

0
packages/dynamite/dynamite/lib/src/models/request_body.g.dart → packages/dynamite/dynamite/lib/src/models/openapi/request_body.g.dart

4
packages/dynamite/dynamite/lib/src/models/response.dart → packages/dynamite/dynamite/lib/src/models/openapi/response.dart

@ -1,8 +1,8 @@
import 'package:built_collection/built_collection.dart';
import 'package:built_value/built_value.dart';
import 'package:built_value/serializer.dart';
import 'package:dynamite/src/models/header.dart';
import 'package:dynamite/src/models/media_type.dart';
import 'package:dynamite/src/models/openapi/header.dart';
import 'package:dynamite/src/models/openapi/media_type.dart';
part 'response.g.dart';

0
packages/dynamite/dynamite/lib/src/models/response.g.dart → packages/dynamite/dynamite/lib/src/models/openapi/response.g.dart

2
packages/dynamite/dynamite/lib/src/models/schema.dart → packages/dynamite/dynamite/lib/src/models/openapi/schema.dart

@ -3,7 +3,7 @@ import 'package:built_value/built_value.dart';
import 'package:built_value/json_object.dart';
import 'package:built_value/serializer.dart';
import 'package:dynamite/src/helpers/docs.dart';
import 'package:dynamite/src/models/discriminator.dart';
import 'package:dynamite/src/models/openapi/discriminator.dart';
part 'schema.g.dart';

0
packages/dynamite/dynamite/lib/src/models/schema.g.dart → packages/dynamite/dynamite/lib/src/models/openapi/schema.g.dart

0
packages/dynamite/dynamite/lib/src/models/security_scheme.dart → packages/dynamite/dynamite/lib/src/models/openapi/security_scheme.dart

0
packages/dynamite/dynamite/lib/src/models/security_scheme.g.dart → packages/dynamite/dynamite/lib/src/models/openapi/security_scheme.g.dart

2
packages/dynamite/dynamite/lib/src/models/server.dart → packages/dynamite/dynamite/lib/src/models/openapi/server.dart

@ -1,7 +1,7 @@
import 'package:built_collection/built_collection.dart';
import 'package:built_value/built_value.dart';
import 'package:built_value/serializer.dart';
import 'package:dynamite/src/models/server_variable.dart';
import 'package:dynamite/src/models/openapi/server_variable.dart';
part 'server.g.dart';

0
packages/dynamite/dynamite/lib/src/models/server.g.dart → packages/dynamite/dynamite/lib/src/models/openapi/server.g.dart

0
packages/dynamite/dynamite/lib/src/models/server_variable.dart → packages/dynamite/dynamite/lib/src/models/openapi/server_variable.dart

0
packages/dynamite/dynamite/lib/src/models/server_variable.g.dart → packages/dynamite/dynamite/lib/src/models/openapi/server_variable.g.dart

0
packages/dynamite/dynamite/lib/src/models/tag.dart → packages/dynamite/dynamite/lib/src/models/openapi/tag.dart

0
packages/dynamite/dynamite/lib/src/models/tag.g.dart → packages/dynamite/dynamite/lib/src/models/openapi/tag.g.dart

52
packages/dynamite/dynamite/lib/src/models/serializers.dart

@ -1,52 +0,0 @@
import 'package:built_collection/built_collection.dart';
import 'package:built_value/serializer.dart';
import 'package:built_value/standard_json_plugin.dart';
import 'package:dynamite/src/models/components.dart';
import 'package:dynamite/src/models/discriminator.dart';
import 'package:dynamite/src/models/header.dart';
import 'package:dynamite/src/models/info.dart';
import 'package:dynamite/src/models/license.dart';
import 'package:dynamite/src/models/media_type.dart';
import 'package:dynamite/src/models/open_api.dart';
import 'package:dynamite/src/models/operation.dart';
import 'package:dynamite/src/models/parameter.dart';
import 'package:dynamite/src/models/path_item.dart';
import 'package:dynamite/src/models/request_body.dart';
import 'package:dynamite/src/models/response.dart';
import 'package:dynamite/src/models/schema.dart';
import 'package:dynamite/src/models/security_scheme.dart';
import 'package:dynamite/src/models/server.dart';
import 'package:dynamite/src/models/server_variable.dart';
import 'package:dynamite/src/models/tag.dart';
part 'serializers.g.dart';
@SerializersFor([
Components,
Discriminator,
Header,
Info,
License,
MediaType,
OpenAPI,
Operation,
Parameter,
PathItem,
RequestBody,
Response,
Schema,
SecurityScheme,
Server,
ServerVariable,
Tag,
])
final Serializers serializers = (_$serializers.toBuilder()
..addBuilderFactory(
const FullType(BuiltMap, [
FullType(String),
FullType(BuiltList, [FullType(String)]),
]),
MapBuilder<String, BuiltList<String>>.new,
)
..addPlugin(StandardJsonPlugin()))
.build();

1
packages/dynamite/dynamite/lib/src/models/type_result.dart

@ -0,0 +1 @@
export 'type_result/type_result.dart';

0
packages/dynamite/dynamite/lib/src/type_result/base.dart → packages/dynamite/dynamite/lib/src/models/type_result/base.dart

0
packages/dynamite/dynamite/lib/src/type_result/enum.dart → packages/dynamite/dynamite/lib/src/models/type_result/enum.dart

0
packages/dynamite/dynamite/lib/src/type_result/list.dart → packages/dynamite/dynamite/lib/src/models/type_result/list.dart

0
packages/dynamite/dynamite/lib/src/type_result/map.dart → packages/dynamite/dynamite/lib/src/models/type_result/map.dart

0
packages/dynamite/dynamite/lib/src/type_result/object.dart → packages/dynamite/dynamite/lib/src/models/type_result/object.dart

0
packages/dynamite/dynamite/lib/src/type_result/type_result.dart → packages/dynamite/dynamite/lib/src/models/type_result/type_result.dart

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

@ -11,9 +11,8 @@ import 'package:dynamite/src/builder/resolve_type.dart';
import 'package:dynamite/src/builder/serializer.dart';
import 'package:dynamite/src/builder/state.dart';
import 'package:dynamite/src/helpers/dart_helpers.dart';
import 'package:dynamite/src/models/open_api.dart';
import 'package:dynamite/src/models/serializers.dart';
import 'package:dynamite/src/type_result/type_result.dart';
import 'package:dynamite/src/models/openapi.dart' as openapi;
import 'package:dynamite/src/models/type_result.dart';
class OpenAPIBuilder implements Builder {
@override
@ -34,13 +33,13 @@ class OpenAPIBuilder implements Builder {
);
final spec = switch (inputId.extension) {
'.json' => serializers.deserializeWith(
OpenAPI.serializer,
'.json' => openapi.serializers.deserializeWith(
openapi.OpenAPI.serializer,
json.decode(await buildStep.readAsString(inputId)),
)!,
'.yaml' => checkedYamlDecode(
await buildStep.readAsString(inputId),
(final m) => serializers.deserializeWith(OpenAPI.serializer, m)!,
(final m) => openapi.serializers.deserializeWith(openapi.OpenAPI.serializer, m)!,
),
_ => throw StateError('Openapi specs can only be yaml or json.'),
};

2
packages/dynamite/dynamite/test/type_result_test.dart

@ -1,4 +1,4 @@
import 'package:dynamite/src/type_result/type_result.dart';
import 'package:dynamite/src/models/type_result.dart';
import 'package:test/test.dart';
void main() {

Loading…
Cancel
Save