Skip to content

Commit 4171115

Browse files
committed
# Conflicts: # openapi-generator/lib/src/openapi_generator_runner.dart # openapi-generator/test/builder_test.dart
2 parents 741f8d8 + 52e6821 commit 4171115

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+4468
-767
lines changed

.github/workflows/code_quality.yml

Lines changed: 34 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,32 @@ on:
1111
workflow_dispatch:
1212

1313
jobs:
14+
ci:
15+
name: Dart CI Checks
16+
runs-on: ubuntu-latest
17+
strategy:
18+
fail-fast: false
19+
matrix:
20+
work_dir: [ openapi-generator, openapi-generator-annotations ]
21+
defaults:
22+
run:
23+
working-directory: ${{ matrix.work_dir }}
24+
steps:
25+
- name: Checkout
26+
uses: actions/checkout@v3
27+
- name: Setup Dart
28+
uses: dart-lang/[email protected]
29+
with:
30+
sdk: stable
31+
- name: Install Dependencies
32+
run: dart pub get
33+
- name: Validate formatting
34+
run: dart format ./ --set-exit-if-changed
35+
- name: Run analyzer
36+
run: dart analyze --fatal-warnings
37+
- name: Run tests
38+
run: dart test
39+
1440
build:
1541
name: Build example project 🛠️
1642
runs-on: ubuntu-latest
@@ -33,20 +59,21 @@ jobs:
3359
- run: flutter pub run build_runner build --delete-conflicting-outputs
3460
- run: flutter build apk
3561

36-
# - name: Upload artifact (Client) ⬆️💻
37-
# uses: actions/[email protected]
38-
# with:
39-
# name: example
40-
# path: |
41-
# example/build/web
62+
# - name: Upload artifact (Client) ⬆️💻
63+
# uses: actions/[email protected]
64+
# with:
65+
# name: example
66+
# path: |
67+
# example/build/web
4268

4369
pr_context:
4470
name: Save PR context as artifact
4571
if: ${{ always() && !cancelled() && github.event_name == 'pull_request' }}
4672
runs-on: ubuntu-latest
4773
needs:
48-
# - dependency-review
74+
# - dependency-review
4975
- build
76+
- ci
5077

5178
steps:
5279
- name: Save PR context

README.md

Lines changed: 69 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,15 @@
44

55
This codebase houses the dart/flutter implementations of the openapi client sdk code generation libraries.
66

7+
## TOC
8+
9+
- [Introduction](#introduction)
10+
- [Usage](#usage)
11+
- [NextGen](#next-generation)
12+
- [Features & Bugs](#features-and-bugs)
13+
14+
## Introduction
15+
716
With this project, you can generate openapi client sdk libraries for your openapi specification right in your
817
flutter/dart projects. (see example)
918

@@ -17,37 +26,42 @@ This repo contains the following dart libraries
1726
| openapi-generator-annotations | Annotations for annotating dart class with instructions for generating openapi sdk [see here for usage](https://pub.dev/packages/openapi_generator_annotations) | [![pub package](https://img.shields.io/pub/v/openapi_generator_annotations.svg)](https://pub.dev/packages/openapi_generator) |
1827
| openapi-generator-cli | Cli code openapi sdk generator for dart [see here for usage](https://pub.dev/packages/openapi_generator_cli) | [![pub package](https://img.shields.io/pub/v/openapi_generator_cli.svg)](https://pub.dev/packages/openapi_generator_cli) |
1928

20-
21-
2229
## Usage
2330

24-
Include [openapi-generator-annotations](https://pub.dev/packages/openapi_generator_annotations) as a dependency in the dependencies section of your pubspec.yaml file :
31+
Include [openapi-generator-annotations](https://pub.dev/packages/openapi_generator_annotations) as a dependency in the
32+
dependencies section of your pubspec.yaml file :
2533

2634
```yaml
2735
dependencies:
2836
openapi_generator_annotations: ^[latest-version]
2937
```
30-
For testing out the beta features in openapi generator, use the beta branch like below. This is not recommended for production builds
38+
39+
For testing out the beta features in openapi generator, use the beta branch like below. This is not recommended for
40+
production builds
41+
3142
```yaml
3243
dependencies:
33-
openapi_generator_annotations:
44+
openapi_generator_annotations:
3445
git:
3546
url: https://github.com/gibahjoe/openapi-generator-dart.git
3647
ref: beta
3748
path: openapi-generator-annotations
3849
```
3950
40-
41-
Add [openapi-generator](https://pub.dev/packages/openapi_generator) in the dev dependencies section of your pubspec.yaml file:
51+
Add [openapi-generator](https://pub.dev/packages/openapi_generator) in the dev dependencies section of your pubspec.yaml
52+
file:
4253
4354
```yaml
4455
dev_dependencies:
4556
openapi_generator: ^[latest version]
4657
```
47-
For testing out the beta features in openapi generator, use the beta branch like below. This is not recommended for production builds
58+
59+
For testing out the beta features in openapi generator, use the beta branch like below. This is not recommended for
60+
production builds
61+
4862
```yaml
4963
dev_dependencies:
50-
openapi_generator:
64+
openapi_generator:
5165
git:
5266
url: https://github.com/gibahjoe/openapi-generator-dart.git
5367
ref: beta
@@ -66,17 +80,62 @@ Annotate a dart class with @Openapi() annotation
6680
class Example extends OpenapiGeneratorConfig {}
6781
```
6882

69-
Run
83+
Run
84+
7085
```shell
7186
dart run build_runner build --delete-conflicting-outputs
7287
```
88+
7389
or
90+
7491
```shell
7592
flutter pub run build_runner build --delete-conflicting-outputs
7693
```
94+
7795
to generate open api client sdk from spec file specified in annotation.
7896
The api sdk will be generated in the folder specified in the annotation. See examples for more details
7997

98+
## Next Generation
99+
100+
There is some new functionality slated to be added to the generator. This version will have the ability to:
101+
102+
- cache changes in the OAS spec
103+
- Rerun when there ares difference in the cached copy and current copy
104+
- Pull from a remote source and cache that.
105+
- **Note**: This means that your cache could be potentially stale. But in that case this flow will still pull the
106+
latest and run.
107+
- While this is a possible usage, if you are actively developing your spec it is preferred you provide a local copy.
108+
- Skip generation based off:
109+
- Flags
110+
- No difference between the cache and local
111+
- And all the functionality provided previously.
112+
113+
Your original workflow stay the same but there is a slight difference in the annotations.
114+
115+
New:
116+
117+
```dart
118+
@Openapi(
119+
additionalProperties:
120+
AdditionalProperties(pubName: 'petstore_api', pubAuthor: 'Johnny dep'),
121+
inputSpecFile: 'example/openapi-spec.yaml',
122+
generatorName: Generator.dart,
123+
outputDirectory: 'api/petstore_api',
124+
cachePath: 'some/preferred/directory/cache.json',
125+
useNextGen: true
126+
)
127+
class Example extends OpenapiGeneratorConfig {}
128+
```
129+
130+
**IMPORTANT** With the new changes comes 2 new annotation properties:
131+
132+
- useNextGen (boolean)
133+
- Default: `false`
134+
- cachePath (String)
135+
- Default: `.dart_tool/openapi-generator-cache.json`
136+
- Must be a path to a `json` file.
137+
- Can only be set when `useNextGen` is `true`
138+
80139
## Features and bugs
81140

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

example/.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,5 +44,5 @@ app.*.map.json
4444
/android/app/debug
4545
/android/app/profile
4646
/android/app/release
47-
api
47+
api/petstore_api/**
4848
!api/petstore_api/pubspec.yaml
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
name: petstore_api
2+
version: 1.0.0
3+
description: OpenAPI API client
4+
homepage: homepage
5+
6+
environment:
7+
sdk: '>=2.15.0 <3.0.0'
8+
9+
dependencies:
10+
dio: '^5.0.0'
11+
one_of: '>=1.5.0 <2.0.0'
12+
one_of_serializer: '>=1.5.0 <2.0.0'
13+
built_value: '>=8.4.0 <9.0.0'
14+
built_collection: '>=5.1.1 <6.0.0'
15+
16+
dev_dependencies:
17+
built_value_generator: '>=8.4.0 <9.0.0'
18+
build_runner: any
19+
test: ^1.16.0

example/lib/main.dart

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,15 @@ void main() {
66
}
77

88
@Openapi(
9-
additionalProperties:
10-
DioProperties(pubName: 'petstore_api', pubAuthor: 'Johnny dep..'),
11-
inputSpecFile: 'openapi-spec.yaml',
12-
typeMappings: {'Pet': 'ExamplePet'},
13-
generatorName: Generator.dio,
14-
runSourceGenOnOutput: true,
15-
alwaysRun: true,
16-
outputDirectory: 'api/petstore_api')
9+
additionalProperties:
10+
DioProperties(pubName: 'petstore_api', pubAuthor: 'Johnny dep..'),
11+
inputSpecFile: 'openapi-spec.yaml',
12+
typeMappings: {'Pet': 'ExamplePet'},
13+
generatorName: Generator.dio,
14+
runSourceGenOnOutput: true,
15+
alwaysRun: true,
16+
outputDirectory: 'api/petstore_api',
17+
)
1718
class MyApp extends StatelessWidget {
1819
const MyApp({Key? key}) : super(key: key);
1920

openapi-generator-annotations/analysis_options.yaml

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,3 @@
1-
# Defines a default set of lint rules enforced for
2-
# projects at Google. For details and rationale,
3-
# see https://github.com/dart-lang/pedantic#enabled-lints.
4-
include: package:pedantic/analysis_options.yaml
5-
61
# For lint rules and documentation, see http://dart-lang.github.io/linter/lints.
72
# Uncomment to specify additional rules.
83
# linter:

openapi-generator-annotations/example/example.dart

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,7 @@ import 'package:openapi_generator_annotations/openapi_generator_annotations.dart
55
AdditionalProperties(pubName: 'petstore_api', pubAuthor: 'Johnny dep'),
66
inputSpecFile: 'example/openapi-spec.yaml',
77
generatorName: Generator.dio,
8-
outputDirectory: 'api/petstore_api')
8+
outputDirectory: 'api/petstore_api',
9+
// useNextGen: true,
10+
cachePath: 'something')
911
class Example extends OpenapiGeneratorConfig {}

0 commit comments

Comments
 (0)