Skip to content

Commit 81ef4c6

Browse files
authored
Merge pull request #2 from gibahjoe/feature/always-run
Feature/always run
2 parents d1e3ad0 + 2ea7b27 commit 81ef4c6

38 files changed

+1301
-153
lines changed

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
## 1.0.0
22

3-
- Initial version, created by Stagehand
3+
- Initial version

LICENSE

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
Copyright 2020 Joseph Gibah
2+
3+
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following
4+
conditions are met:
5+
6+
1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
7+
8+
2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer
9+
in the documentation and/or other materials provided with the distribution.
10+
11+
3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived
12+
from this software without specific prior written permission.
13+
14+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,
15+
BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
16+
IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
17+
OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
18+
OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
19+
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
20+
POSSIBILITY OF SUCH DAMAGE.

example/.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,3 +188,5 @@ fabric.properties
188188

189189
# Android studio 3.1+ serialized cache file
190190
.idea/caches/build_file_checksums.ser
191+
!/api/petstore_api/pubspec.yaml
192+
api/
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
name: petstore_api
2+
version: 1.0.0
3+
description: OpenAPI API client
4+
environment:
5+
sdk: ">=2.0.0 <3.0.0"
6+
dependencies:
7+
jaguar_retrofit: ^2.8.8
8+
jaguar_serializer: ^2.2.12
9+
dev_dependencies:
10+
jaguar_retrofit_gen: ^2.8.10
11+
jaguar_serializer_cli: ^2.2.8
12+
build_runner: ^1.6.5

example/lib/main.dart

Lines changed: 36 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import 'package:flutter/material.dart';
2-
2+
import 'package:petstore_api/api.dart';
3+
import 'package:petstore_api/api/store_api.dart';
34

45
void main() => runApp(MyApp());
56

@@ -23,7 +24,6 @@ class MyApp extends StatelessWidget {
2324
),
2425
home: MyHomePage(title: 'Flutter Demo Home Page'),
2526
);
26-
2727
}
2828
}
2929

@@ -48,6 +48,14 @@ class MyHomePage extends StatefulWidget {
4848
class _MyHomePageState extends State<MyHomePage> {
4949
int _counter = 0;
5050

51+
StoreApi _petApi = PetstoreApi().getStoreApi();
52+
53+
@override
54+
void initState() {
55+
// TODO: implement initState
56+
super.initState();
57+
}
58+
5159
void _incrementCounter() {
5260
setState(() {
5361
// This call to setState tells the Flutter framework that something has
@@ -73,35 +81,32 @@ class _MyHomePageState extends State<MyHomePage> {
7381
// the App.build method, and use it to set our appbar title.
7482
title: Text(widget.title),
7583
),
76-
body: Center(
77-
// Center is a layout widget. It takes a single child and positions it
78-
// in the middle of the parent.
79-
child: Column(
80-
// Column is also a layout widget. It takes a list of children and
81-
// arranges them vertically. By default, it sizes itself to fit its
82-
// children horizontally, and tries to be as tall as its parent.
83-
//
84-
// Invoke "debug painting" (press "p" in the console, choose the
85-
// "Toggle Debug Paint" action from the Flutter Inspector in Android
86-
// Studio, or the "Toggle Debug Paint" command in Visual Studio Code)
87-
// to see the wireframe for each widget.
88-
//
89-
// Column has various properties to control how it sizes itself and
90-
// how it positions its children. Here we use mainAxisAlignment to
91-
// center the children vertically; the main axis here is the vertical
92-
// axis because Columns are vertical (the cross axis would be
93-
// horizontal).
94-
mainAxisAlignment: MainAxisAlignment.center,
95-
children: <Widget>[
96-
Text(
97-
'You have pushed the button this many times:',
98-
),
99-
Text(
100-
'$_counter',
101-
style: Theme.of(context).textTheme.display1,
102-
),
103-
],
104-
),
84+
body: FutureBuilder<Map<String, int>>(
85+
builder: (context, snapshot) {
86+
if(snapshot.hasError){
87+
Center(
88+
child: Text(snapshot.error.toString()),
89+
);
90+
}
91+
if (!snapshot.hasData) {
92+
return Center(
93+
child: CircularProgressIndicator(),
94+
);
95+
}
96+
if (snapshot.hasData && snapshot.data.isEmpty) {
97+
return Center(
98+
child: Text('NO DATA'),
99+
);
100+
}
101+
var entries = snapshot.data.entries.toList();
102+
return ListView.separated(
103+
itemBuilder: (context, index) {
104+
return Text('${entries[0].key} : ${entries[index].value}');
105+
},
106+
separatorBuilder: (context, index) => Divider(),
107+
itemCount: snapshot.data.values.length);
108+
},
109+
future: _petApi.getInventory(),
105110
),
106111
floatingActionButton: FloatingActionButton(
107112
onPressed: _incrementCounter,

example/lib/openapi_config.dart

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import 'package:openapi_generator_annotations/openapi_generator_annotations.dart';
2+
3+
@Openapi(
4+
additionalProperties:
5+
AdditionalProperties(pubName: 'petstore_api', pubAuthor: 'Johnny depp'),
6+
inputSpecFile: 'spec/openapi-spec.yaml',
7+
generatorName: 'dart-jaguar',
8+
outputDirectory: 'api/petstore_api')
9+
class OpenapiConfig extends OpenapiGeneratorConfig {
10+
}

example/pubspec.yaml

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,10 @@ environment:
1919
dependencies:
2020
flutter:
2121
sdk: flutter
22-
openapi_generator_annotations:
23-
path: ../openapi-generator-annotations
22+
openapi_generator_annotations: ^1.0.2
23+
petstore_api:
24+
path: api/petstore_api
25+
provider: ^4.0.4
2426

2527

2628
# The following adds the Cupertino Icons font to your application.
@@ -31,8 +33,7 @@ dev_dependencies:
3133
flutter_test:
3234
sdk: flutter
3335
build_runner: ^1.7.4
34-
openapi_generator:
35-
path: ../openapi-generator
36+
openapi_generator: ^0.1.2
3637

3738

3839
# For information on the generic Dart part of this file, see the

openapi-generator-annotations/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## 1.0.2
2+
3+
- Updated documentation
4+
15
## 0.0.2-dev
26

37
- Changed version to dev since this package is still in active development

openapi-generator-annotations/README.md

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,27 @@
11
Annotation library for dart/flutter implementation of openapi client code generation.
2+
To be used together with [openapi-generator](https://pub.dev/packages/openapi_generator)
23

3-
Created from templates made available by Stagehand under a BSD-style
4-
[license](https://github.com/dart-lang/stagehand/blob/master/LICENSE).
4+
[license](https://github.com/gibahjoe/openapi-generator-dart/blob/master/openapi-generator-annotations/LICENSE).
55

66
## Usage
77

8-
A simple usage example:
8+
Include [openapi-generator-annotations](https://pub.dev/packages/openapi_generator_annotations) as a dependency in the dependencies section of your pubspec.yaml file :
9+
10+
```yaml
11+
dependencies:
12+
openapi_generator_annotations: ^1.0.0
13+
```
14+
15+
16+
Add [openapi-generator](https://pub.dev/packages/openapi_generator) in the dev dependencies section of your pubspec.yaml file:
17+
18+
```yaml
19+
dev_dependencies:
20+
openapi_generator: ^0.0.2-beta
21+
```
22+
23+
24+
Annotate a dart class with @Openapi() annotation
925
1026
```dart
1127
@Openapi(
@@ -17,6 +33,13 @@ A simple usage example:
1733
class Example extends OpenapiGeneratorConfig {}
1834
```
1935

36+
Run command below to generate open api client sdk from spec file specified in annotation.
37+
```cmd
38+
flutter pub run build_runner build --delete-conflicting-outputs
39+
```
40+
41+
The api sdk will be generated in the folder specified in the annotation. See examples for more details
42+
2043
## Features and bugs
2144

2245
Please file feature requests and bugs at the [issue tracker][tracker].

openapi-generator-annotations/lib/src/openapi_generator_annotations_base.dart

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,26 +4,32 @@ abstract class OpenapiGeneratorConfig {}
44

55
class Openapi {
66
/// Additional properties to pass to tge compiler (CSV)
7+
///
78
/// --additional-properties
89
final AdditionalProperties additionalProperties;
910

1011
/// relative path or url to spec file
12+
///
1113
/// -i
1214
final String inputSpecFile;
1315

14-
/// Generator to use (see list command for list)
16+
/// Generator to use (dart|dart-jaguar|dart-dio)
17+
///
1518
/// -g, --generator-name
1619
final String generatorName;
1720

1821
/// Where to write the generated files (current dir by default)
22+
///
1923
/// -o, --output
2024
final String outputDirectory;
2125

2226
/// Specifies if the existing files should be overwritten during the generation
27+
///
2328
/// -s, --skip-overwrite
2429
final bool overwriteExistingFiles;
2530

2631
/// Skips the default behavior of validating an input specification.
32+
///
2733
/// --skip-validate-spec
2834
final bool skipValidateSpec;
2935

@@ -91,8 +97,4 @@ class AdditionalProperties {
9197
this.sortModelPropertiesByRequiredFlag = true,
9298
this.sortParamsByRequiredFlag = true,
9399
this.sourceFolder});
94-
95-
String _append(String base, String str) {
96-
return '$base,$str';
97-
}
98100
}

0 commit comments

Comments
 (0)