Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generate for spec changes #96

Merged
merged 20 commits into from
Aug 19, 2023
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
39a7aa1
Provide Yaml and Json version of test spec
Nexushunter Aug 8, 2023
d317ed9
Refactor spec loading, comment out the dependency on the flutter sdk,…
Nexushunter Aug 9, 2023
49a96e2
Provide support for nested lists, reorganize some tests
Nexushunter Aug 9, 2023
a17d7bb
Provide support for nested lists, reorganize some tests, refine some …
Nexushunter Aug 9, 2023
0f833d7
(WIP) Large refactor to get things moving in a nicer way. Adds ~80 te…
Nexushunter Aug 11, 2023
985de8b
(WIP) FMT, fix up remaining tests for Generator Arguments. TODO: Twea…
Nexushunter Aug 13, 2023
b2f03f2
(WIP) Address failing original tests. Add tests for NextGen path.
Nexushunter Aug 13, 2023
a619f4d
All tests passing
Nexushunter Aug 13, 2023
763f115
Add more tests for the annotations library
Nexushunter Aug 13, 2023
f7d5737
Add example builder annotation tests
Nexushunter Aug 13, 2023
4e1898d
Fix the dart ci not being run in the working dirs
Nexushunter Aug 17, 2023
0df70e1
doc: Add next gen documentation to readme
Nexushunter Aug 17, 2023
90a1b90
fix: Tweak the processing of the builder to handle how process.run re…
Nexushunter Aug 17, 2023
37f862c
fix: fix gitignore, readd api/petstore_api/pubspec
Nexushunter Aug 17, 2023
4643a0c
fix: fix tests now that the generator is running correctly
Nexushunter Aug 18, 2023
5003ea1
fix: use bool.tryParse instead of casting
Nexushunter Aug 18, 2023
c229767
fix: Use API within SDK bounds (will change in future release), fix t…
Nexushunter Aug 18, 2023
12c138a
fix: Last few tweaks
Nexushunter Aug 18, 2023
523f169
fix: Add work around to be able to always be able to regenerate when …
Nexushunter Aug 19, 2023
8d59613
fix: Use Dart 2 API
Nexushunter Aug 19, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion openapi-generator-annotations/example/example.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,8 @@ import 'package:openapi_generator_annotations/openapi_generator_annotations.dart
AdditionalProperties(pubName: 'petstore_api', pubAuthor: 'Johnny dep'),
inputSpecFile: 'example/openapi-spec.yaml',
generatorName: Generator.dio,
outputDirectory: 'api/petstore_api')
outputDirectory: 'api/petstore_api',
// useNextGen: true,
cachePath: 'something'
)
class Example extends OpenapiGeneratorConfig {}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added new config options, added deprecations

Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ class Openapi {
/// --reserved-words-mappings
final Map<String, String>? reservedWordsMappings;


/// Tells openapi-generator to always run during the build process
/// if set to false (the default), openapi-generator will skip processing if the [outputDirectory] already exists
final bool? alwaysRun;
Expand Down Expand Up @@ -94,8 +95,19 @@ class Openapi {
/// e.g {'inline_object_2': 'SomethingMapped'}
final Map<String, String>? inlineSchemaNameMappings;

/// Use the next generation of the generator.
///
/// Default: false
final bool useNextGen;
Nexushunter marked this conversation as resolved.
Show resolved Hide resolved

/// The path where to store the cached copy of the specification.
///
/// For use with [useNextGen].
final String? cachePath;

const Openapi(
{this.additionalProperties,
@deprecated
this.overwriteExistingFiles,
this.skipSpecValidation = false,
required this.inputSpecFile,
Expand All @@ -110,7 +122,10 @@ class Openapi {
this.apiPackage,
this.fetchDependencies = true,
this.runSourceGenOnOutput = true,
this.alwaysRun = false});
@deprecated
this.alwaysRun = false,
this.cachePath,
this.useNextGen = false,}): assert(cachePath != null && !useNextGen, 'useNextGen should be set when providing cachePath');
}

class AdditionalProperties {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
import 'package:openapi_generator_annotations/src/openapi_generator_annotations_base.dart';
import 'package:test/test.dart';

void main() {
group('A group of tests', () {
// Awesome awesome;
//
// setUp(() {
// awesome = Awesome();
// });
//
// test('First Test', () {
// expect(awesome.isAwesome, isTrue);
// });
group('OpenApi', () {
group('NextGen', (){

test('Sets cachePath',(){
final api =Openapi(inputSpecFile: '', generatorName: Generator.dart, cachePath: 'somePath');
expect(api.cachePath, 'somePath');
});
test('Sets useNextGenFlag',(){
final api =Openapi(inputSpecFile: '', generatorName: Generator.dart, useNextGen: true);
expect(api.useNextGen, isTrue);
});
});
});
}
3 changes: 3 additions & 0 deletions openapi-generator/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -166,3 +166,6 @@ Temporary Items
.apdisk
.idea/
example/.dart_tool

# Generated test output
test/specs/test-cached.json
9 changes: 4 additions & 5 deletions openapi-generator/example/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,16 +27,15 @@ dependency_overrides:
path: ../../openapi-generator-cli

dependencies:
flutter:
sdk: flutter
# flutter:
# sdk: flutter
openapi_generator_annotations: ^4.10.0
cupertino_icons: ^1.0.2

dev_dependencies:
flutter_test:
sdk: flutter
# flutter_test:
# sdk: flutter
build_runner:
openapi_generator_annotations: ^4.10.0
openapi_generator: ^4.10.0


Expand Down
44 changes: 44 additions & 0 deletions openapi-generator/lib/src/determine_flutter_project_status.dart
gibahjoe marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import 'dart:async';
import 'dart:io';

import 'package:openapi_generator_annotations/openapi_generator_annotations.dart';
import 'package:yaml/yaml.dart';

/// Determines whether a project has a dependency on the Flutter sdk.
///
/// If a wrapper annotation is provided that is not null or [Wrapper.none] and
/// is one of [Wrapper.flutterw] or [Wrapper.fvm] it is safe to assume the project
/// requires the Flutter sdk.
///
/// As a fallback we check the pubspec at the root of the current directory, which
/// will be where the build_runner command will have been called from, and check
/// the Pubspec's dependency list for the 'flutter' key.
///
/// Note: This has support for providing a custom path to a pubspec but there isn't
/// any current implementation to receive it via the generator itself.
FutureOr<bool> checkPubspecAndWrapperForFlutterSupport(
{Wrapper? wrapper = Wrapper.none, String? providedPubspecPath}) async {
if ([Wrapper.flutterw, Wrapper.fvm].contains(wrapper)) {
return true;
} else {
// Use the path provided or default the directory the command was called from.
final pubspecPath = providedPubspecPath ??
'${Directory.current.path}${Platform.pathSeparator}pubspec.yaml';

final pubspecFile = File(pubspecPath);

if (!pubspecFile.existsSync()) {
return Future.error('Pubspec doesn\'t exist at path: $pubspecPath');
}

final contents = await pubspecFile.readAsString();
if (contents.isEmpty) {
return Future.error('Invalid pubspec.yaml');
}

final pubspec = loadYaml(contents) as YamlMap;

return pubspec.containsKey('dependencies') &&
(pubspec.nodes['dependencies'] as YamlMap).containsKey('flutter');
}
}
37 changes: 37 additions & 0 deletions openapi-generator/lib/src/extensions/type_methods.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import 'dart:mirrors';

import 'package:analyzer/dart/ast/ast.dart';
import 'package:analyzer/dart/constant/value.dart';
import 'package:analyzer/dart/element/type.dart';
import 'package:source_gen/source_gen.dart' show ConstantReader, TypeChecker;

Expand Down Expand Up @@ -71,3 +73,38 @@ extension TypeMethods on ConstantReader {
return values[enumIndex];
}
}

extension ReadProperty on ConstantReader {
T readPropertyOrDefault<T>(String name, T defaultValue) {
final v = peek(name);
if (v == null) {
return defaultValue;
}

// TODO: This may be way too naive
if (defaultValue is Map<String, DartObject>) {
return v.revive().namedArguments as T;
}

switch (T) {
case Map:
return v.mapValue as T;
case bool:
return v.boolValue as T;
case int:
return v.intValue as T;
case List:
return v.listValue as T;
case double:
return v.doubleValue as T;
case String:
return v.stringValue as T;
case Set:
return v.setValue as T;
case Literal:
return v.literalValue as T;
default:
return defaultValue;
}
}
}
Loading