Skip to content

Commit 54f2201

Browse files
committed
added support for always run and updated example
1 parent d1e3ad0 commit 54f2201

File tree

18 files changed

+403
-107
lines changed

18 files changed

+403
-107
lines changed
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# See https://www.dartlang.org/tools/private-files.html
2+
3+
# Files and directories created by pub
4+
.buildlog
5+
.packages
6+
.project
7+
.pub/
8+
build/
9+
**/packages/
10+
11+
# Files created by dart2js
12+
# (Most Dart developers will use pub build to compile Dart, use/modify these
13+
# rules if you intend to use dart2js directly
14+
# Convention is to use extension '.dart.js' for Dart compiled to Javascript to
15+
# differentiate from explicit Javascript files)
16+
*.dart.js
17+
*.part.js
18+
*.js.deps
19+
*.js.map
20+
*.info.json
21+
22+
# Directory created by dartdoc
23+
doc/api/
24+
25+
# Don't commit pubspec lock file
26+
# (Library packages only! Remove pattern if developing an application package)
27+
pubspec.lock
28+
lib/
29+
doc/
30+
test/
31+
.openapi-generator
32+
.dart_tool
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# OpenAPI Generator Ignore
2+
# Generated by openapi-generator https://github.com/openapitools/openapi-generator
3+
4+
# Use this file to prevent files from being overwritten by the generator.
5+
# The patterns follow closely to .gitignore or .dockerignore.
6+
7+
# As an example, the C# client generator defines ApiClient.cs.
8+
# You can make changes and tell OpenAPI Generator to ignore just this file by uncommenting the following line:
9+
#ApiClient.cs
10+
11+
# You can match any string of characters against a directory, file or extension with a single asterisk (*):
12+
#foo/*/qux
13+
# The above matches foo/bar/qux and foo/baz/qux, but not foo/bar/baz/qux
14+
15+
# You can recursively match patterns against a directory, file or extension with a double asterisk (**):
16+
#foo/**/qux
17+
# This matches foo/bar/qux, foo/baz/qux, and foo/bar/baz/qux
18+
19+
# You can also negate patterns with an exclamation (!).
20+
# For example, you can ignore all files in a docs folder with the file extension .md:
21+
#docs/*.md
22+
# Then explicitly reverse the ignore rule for a single file:
23+
#!docs/README.md
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# https://docs.travis-ci.com/user/languages/dart/
2+
#
3+
language: dart
4+
dart:
5+
# Install a specific stable release
6+
- "1.24.3"
7+
install:
8+
- pub get
9+
10+
script:
11+
- pub run test

example/api/petstore_api/README.md

Lines changed: 130 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,130 @@
1+
# petstore_api
2+
This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters.
3+
4+
This Dart package is automatically generated by the [Open API Codegen](https://github.com/OpenAPITools/openapi-generator) project:
5+
6+
- API version: 1.0.0
7+
- Build package: org.openapitools.codegen.languages.DartJaguarClientCodegen
8+
9+
## Requirements
10+
11+
Dart 2 or later OR Flutter 0.7.0 or later.
12+
13+
Once your code is generated, you need to run the build_runner command to let Jaguar implement your API:
14+
15+
```sh
16+
flutter packages pub run build_runner build
17+
or
18+
pub run build_runner build
19+
```
20+
21+
## Installation & Usage
22+
23+
### Github
24+
If this Dart package is published to Github, please include the following in pubspec.yaml
25+
```
26+
name: petstore_api
27+
version: 1.0.0
28+
description: OpenAPI API client
29+
dependencies:
30+
petstore_api:
31+
git: https://github.com/GIT_USER_ID/GIT_REPO_ID.git
32+
version: 'any'
33+
```
34+
35+
### Local
36+
To use the package in your local drive, please include the following in pubspec.yaml
37+
```
38+
dependencies:
39+
petstore_api:
40+
path: /path/to/petstore_api
41+
```
42+
43+
## Tests
44+
45+
TODO
46+
47+
## Getting Started
48+
49+
Please follow the [installation procedure](#installation--usage) and then run the following:
50+
51+
```dart
52+
import 'package:petstore_api/api.dart';
53+
54+
// TODO Configure OAuth2 access token for authorization: petstore_auth
55+
//petstore_api.api.Configuration.accessToken = 'YOUR_ACCESS_TOKEN';
56+
57+
final jaguarApiGen = PetstoreApi();
58+
var api_instance = jaguarApiGen.getPetApi();
59+
var body = new Pet(); // Pet | Pet object that needs to be added to the store
60+
61+
try {
62+
api_instance.addPet(body);
63+
} catch (e) {
64+
print("Exception when calling PetApi->addPet: $e\n");
65+
}
66+
67+
```
68+
69+
## Documentation for API Endpoints
70+
71+
All URIs are relative to *http://petstore.swagger.io/v2*
72+
73+
Class | Method | HTTP request | Description
74+
------------ | ------------- | ------------- | -------------
75+
*PetApi* | [**addPet**](doc//PetApi.md#addpet) | **Post** /pet | Add a new pet to the store
76+
*PetApi* | [**deletePet**](doc//PetApi.md#deletepet) | **Delete** /pet/:petId | Deletes a pet
77+
*PetApi* | [**findPetsByStatus**](doc//PetApi.md#findpetsbystatus) | **Get** /pet/findByStatus | Finds Pets by status
78+
*PetApi* | [**findPetsByTags**](doc//PetApi.md#findpetsbytags) | **Get** /pet/findByTags | Finds Pets by tags
79+
*PetApi* | [**getPetById**](doc//PetApi.md#getpetbyid) | **Get** /pet/:petId | Find pet by ID
80+
*PetApi* | [**updatePet**](doc//PetApi.md#updatepet) | **Put** /pet | Update an existing pet
81+
*PetApi* | [**updatePetWithForm**](doc//PetApi.md#updatepetwithform) | **Post** /pet/:petId | Updates a pet in the store with form data
82+
*PetApi* | [**uploadFile**](doc//PetApi.md#uploadfile) | **Post** /pet/:petId/uploadImage | uploads an image
83+
*StoreApi* | [**deleteOrder**](doc//StoreApi.md#deleteorder) | **Delete** /store/order/:orderId | Delete purchase order by ID
84+
*StoreApi* | [**getInventory**](doc//StoreApi.md#getinventory) | **Get** /store/inventory | Returns pet inventories by status
85+
*StoreApi* | [**getOrderById**](doc//StoreApi.md#getorderbyid) | **Get** /store/order/:orderId | Find purchase order by ID
86+
*StoreApi* | [**placeOrder**](doc//StoreApi.md#placeorder) | **Post** /store/order | Place an order for a pet
87+
*UserApi* | [**createUser**](doc//UserApi.md#createuser) | **Post** /user | Create user
88+
*UserApi* | [**createUsersWithArrayInput**](doc//UserApi.md#createuserswitharrayinput) | **Post** /user/createWithArray | Creates list of users with given input array
89+
*UserApi* | [**createUsersWithListInput**](doc//UserApi.md#createuserswithlistinput) | **Post** /user/createWithList | Creates list of users with given input array
90+
*UserApi* | [**deleteUser**](doc//UserApi.md#deleteuser) | **Delete** /user/:username | Delete user
91+
*UserApi* | [**getUserByName**](doc//UserApi.md#getuserbyname) | **Get** /user/:username | Get user by user name
92+
*UserApi* | [**loginUser**](doc//UserApi.md#loginuser) | **Get** /user/login | Logs user into the system
93+
*UserApi* | [**logoutUser**](doc//UserApi.md#logoutuser) | **Get** /user/logout | Logs out current logged in user session
94+
*UserApi* | [**updateUser**](doc//UserApi.md#updateuser) | **Put** /user/:username | Updated user
95+
96+
97+
## Documentation For Models
98+
99+
- [ApiResponse](doc//ApiResponse.md)
100+
- [Category](doc//Category.md)
101+
- [Order](doc//Order.md)
102+
- [Pet](doc//Pet.md)
103+
- [Tag](doc//Tag.md)
104+
- [User](doc//User.md)
105+
106+
107+
## Documentation For Authorization
108+
109+
110+
## api_key
111+
112+
- **Type**: API key
113+
- **API key parameter name**: api_key
114+
- **Location**: HTTP header
115+
116+
## petstore_auth
117+
118+
- **Type**: OAuth
119+
- **Flow**: implicit
120+
- **Authorization URL**: http://petstore.swagger.io/api/oauth/dialog
121+
- **Scopes**:
122+
- **write:pets**: modify pets in your account
123+
- **read:pets**: read your pets
124+
125+
126+
## Author
127+
128+
129+
130+
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
analyzer:
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
#!/bin/sh
2+
# ref: https://help.github.com/articles/adding-an-existing-project-to-github-using-the-command-line/
3+
#
4+
# Usage example: /bin/sh ./git_push.sh wing328 openapi-pestore-perl "minor update" "gitlab.com"
5+
6+
git_user_id=$1
7+
git_repo_id=$2
8+
release_note=$3
9+
git_host=$4
10+
11+
if [ "$git_host" = "" ]; then
12+
git_host="github.com"
13+
echo "[INFO] No command line input provided. Set \$git_host to $git_host"
14+
fi
15+
16+
if [ "$git_user_id" = "" ]; then
17+
git_user_id="GIT_USER_ID"
18+
echo "[INFO] No command line input provided. Set \$git_user_id to $git_user_id"
19+
fi
20+
21+
if [ "$git_repo_id" = "" ]; then
22+
git_repo_id="GIT_REPO_ID"
23+
echo "[INFO] No command line input provided. Set \$git_repo_id to $git_repo_id"
24+
fi
25+
26+
if [ "$release_note" = "" ]; then
27+
release_note="Minor update"
28+
echo "[INFO] No command line input provided. Set \$release_note to $release_note"
29+
fi
30+
31+
# Initialize the local directory as a Git repository
32+
git init
33+
34+
# Adds the files in the local repository and stages them for commit.
35+
git add .
36+
37+
# Commits the tracked changes and prepares them to be pushed to a remote repository.
38+
git commit -m "$release_note"
39+
40+
# Sets the new remote
41+
git_remote=`git remote`
42+
if [ "$git_remote" = "" ]; then # git remote not defined
43+
44+
if [ "$GIT_TOKEN" = "" ]; then
45+
echo "[INFO] \$GIT_TOKEN (environment variable) is not set. Using the git credential in your environment."
46+
git remote add origin https://${git_host}/${git_user_id}/${git_repo_id}.git
47+
else
48+
git remote add origin https://${git_user_id}:${GIT_TOKEN}@${git_host}/${git_user_id}/${git_repo_id}.git
49+
fi
50+
51+
fi
52+
53+
git pull origin master
54+
55+
# Pushes (Forces) the changes in the local repository up to the remote repository
56+
echo "Git pushing to https://${git_host}/${git_user_id}/${git_repo_id}.git"
57+
git push origin master 2>&1 | grep -v 'To https'
58+
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: 38 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
import 'package:flutter/material.dart';
22

3+
import 'package:petstore_api/api.dart';
4+
import 'package:petstore_api/api/pet_api.dart';
5+
import 'package:petstore_api/api/store_api.dart';
6+
import 'package:provider/provider.dart';
37

48
void main() => runApp(MyApp());
59

@@ -23,7 +27,6 @@ class MyApp extends StatelessWidget {
2327
),
2428
home: MyHomePage(title: 'Flutter Demo Home Page'),
2529
);
26-
2730
}
2831
}
2932

@@ -48,6 +51,14 @@ class MyHomePage extends StatefulWidget {
4851
class _MyHomePageState extends State<MyHomePage> {
4952
int _counter = 0;
5053

54+
StoreApi _petApi = PetstoreApi().getStoreApi();
55+
56+
@override
57+
void initState() {
58+
// TODO: implement initState
59+
super.initState();
60+
}
61+
5162
void _incrementCounter() {
5263
setState(() {
5364
// This call to setState tells the Flutter framework that something has
@@ -73,35 +84,32 @@ class _MyHomePageState extends State<MyHomePage> {
7384
// the App.build method, and use it to set our appbar title.
7485
title: Text(widget.title),
7586
),
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-
),
87+
body: FutureBuilder<Map<String, int>>(
88+
builder: (context, snapshot) {
89+
if(snapshot.hasError){
90+
Center(
91+
child: Text(snapshot.error.toString()),
92+
);
93+
}
94+
if (!snapshot.hasData) {
95+
return Center(
96+
child: CircularProgressIndicator(),
97+
);
98+
}
99+
if (snapshot.hasData && snapshot.data.isEmpty) {
100+
return Center(
101+
child: Text('NO DATA'),
102+
);
103+
}
104+
var entries = snapshot.data.entries.toList();
105+
return ListView.separated(
106+
itemBuilder: (context, index) {
107+
return Text('${entries[0].key} : ${entries[index].value}');
108+
},
109+
separatorBuilder: (context, index) => Divider(),
110+
itemCount: snapshot.data.values.length);
111+
},
112+
future: _petApi.getInventory(),
105113
),
106114
floatingActionButton: FloatingActionButton(
107115
onPressed: _incrementCounter,

example/lib/openAPiConfig.dart renamed to example/lib/openapi_config.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,4 @@ import 'package:openapi_generator_annotations/openapi_generator_annotations.dart
88
inputSpecFile: 'spec/openapi-spec.yaml',
99
generatorName: 'dart-jaguar',
1010
outputDirectory: 'api/petstore_api')
11-
class OpenapiGeneratorCo extends OpenapiGeneratorConfig {}
11+
class OpenapiConfig extends OpenapiGeneratorConfig {}

example/pubspec.yaml

Lines changed: 4 additions & 2 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: ^0.0.2-dev
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.

0 commit comments

Comments
 (0)