Skip to content

Commit 7cda1cf

Browse files
committed
Merge branch 'mine-master' into refactor-testing
2 parents 973bc55 + 9970634 commit 7cda1cf

31 files changed

+815
-120
lines changed

.github/workflows/code_quality.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ on:
88
pull_request:
99
paths-ignore:
1010
- '**/*.md'
11+
workflow_call:
1112
workflow_dispatch:
1213

1314
jobs:
@@ -24,6 +25,9 @@ jobs:
2425
steps:
2526
- name: Checkout
2627
uses: actions/checkout@v3
28+
- name: Start Docker compose containers
29+
if: ${{ matrix.work_dir == 'openapi-generator' }}
30+
run: docker-compose -f "docker-compose.yaml" up -d --build
2731
- name: Setup Dart
2832
uses: dart-lang/setup-dart@v1.5.0
2933
with:
@@ -47,6 +51,9 @@ jobs:
4751
verbose: true
4852
flags: ${{ matrix.work_dir }}
4953
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
54+
- name: Stop Docker Container
55+
if: ${{ matrix.work_dir == 'openapi-generator' && always() }}
56+
run: docker-compose -f "docker-compose.yaml" down
5057

5158
build:
5259
name: Build example project 🛠️

.github/workflows/release.yml

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,14 @@ on:
55
types:
66
- released
77
- prereleased
8+
workflow_dispatch:
89

910
jobs:
11+
test:
12+
uses: gibahjoe/openapi-generator-dart/.github/workflows/code_quality.yml@master
1013
publish-cli:
11-
1214
runs-on: ubuntu-latest
13-
needs: [Dart CI Checks, Build example project 🛠️]
14-
15+
needs: [test]
1516
steps:
1617
- name: Checkout
1718
uses: actions/checkout@v1
@@ -23,12 +24,9 @@ jobs:
2324
flutter_package: true
2425
skip_test: true
2526
dry_run: false
26-
2727
publish-annotation:
28-
2928
runs-on: ubuntu-latest
30-
needs: [Dart CI Checks, Build example project 🛠️]
31-
29+
needs: [test]
3230
steps:
3331
- name: Checkout
3432
uses: actions/checkout@v1
@@ -40,9 +38,7 @@ jobs:
4038
flutter_package: true
4139
skip_test: true
4240
dry_run: false
43-
4441
publish-generator:
45-
4642
runs-on: ubuntu-latest
4743
needs: [publish-annotation, publish-cli]
4844
steps:

.release-please-manifest.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"openapi-generator": "4.12.1",
3-
"openapi-generator-annotations": "4.12.0",
4-
"openapi-generator-cli": "4.12.0"
2+
"openapi-generator": "4.13.0",
3+
"openapi-generator-annotations": "4.13.0",
4+
"openapi-generator-cli": "4.13.0"
55
}

CONTRIBUTING.md

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# How to become a contributor
2+
3+
## Before submitting an issue
4+
5+
- Search the [open issue](https://github.com/gibahjoe/openapi-generator-dart/issues)
6+
and [closed issue](https://github.com/openapitools/openapi-generator/issues?q=is%3Aissue+is%3Aclosed) to ensure no one
7+
else has reported something similar before.
8+
- File an [issue ticket](https://github.com/gibahjoe/openapi-generator-dart/issues/new) by providing all the required
9+
information. Failure to provide enough detail may result in slow response from the community.
10+
- You can also make a suggestion or ask a question by opening an "issue".
11+
12+
## Contributing A Patch
13+
14+
1. Submit an issue describing your proposed change to the repo in question.
15+
1. The repo owner will respond to your issue promptly.
16+
1. If your proposed change is accepted, fork the desired repo, develop and test your code changes.
17+
1. Ensure that your code adheres to the existing style in the code to which
18+
you are contributing.
19+
1. Ensure that your code has an appropriate set of tests which all pass.
20+
1. **Title your pull request as well as all your commits
21+
following [Conventional Commits](https://www.conventionalcommits.org/) styling.**
22+
1. Submit a pull request.
23+
24+
# Note
25+
26+
It is important that all your commits as well as your PR follow
27+
the [Conventional Commits](https://www.conventionalcommits.org/) styling.

README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,11 @@ class Example extends OpenapiGeneratorConfig {}
138138
- Must be a path to a `json` file.
139139
- Can only be set when `useNextGen` is `true`
140140

141+
## Contributing
142+
143+
All contributions are welcome. Please ensure to read through our [contributing guidelines](Contributing.md) before
144+
sending your PRs.
145+
141146
## Features and bugs
142147

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

example/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,3 +46,4 @@ app.*.map.json
4646
/android/app/release
4747
api/petstore_api/**
4848
!api/petstore_api/pubspec.yaml
49+
cache.json

openapi-generator-annotations/CHANGELOG.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,18 @@
1+
## [4.13.0](https://github.com/gibahjoe/openapi-generator-dart/compare/v4.12.0...v4.13.0) (2023-09-02)
2+
3+
4+
### Features
5+
6+
* Add headers options for requests (nextGen only) ([bc4a170](https://github.com/gibahjoe/openapi-generator-dart/commit/bc4a170be1c011ca3e2843cf05a92a39965bcc29))
7+
* Bumped versions to match ([506689c](https://github.com/gibahjoe/openapi-generator-dart/commit/506689c960491962c56cbb4418fc86dafc1a4c2e))
8+
9+
10+
### Bug Fixes
11+
12+
* move to delegate, add tests, revert version requirement ([6a32542](https://github.com/gibahjoe/openapi-generator-dart/commit/6a32542cc7e09558db837d0313c4029951dc48ba))
13+
* remove duplicate run test, fix failing tests ([677a318](https://github.com/gibahjoe/openapi-generator-dart/commit/677a3189d4f694c999d3ea1cf0075543649e40c1))
14+
* repair the docker run command, update the type_methods to expand out the remote delegate ([c00b334](https://github.com/gibahjoe/openapi-generator-dart/commit/c00b3345d934e2f1508ba1129a3a769f86a85017))
15+
116
## 4.12.0
217

318
- Added spec diff tracking. This means you Openapi generator now tracks changes to your spec and only regenerates the

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

Lines changed: 185 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
import 'dart:convert';
2+
import 'dart:io';
3+
4+
import 'package:crypto/crypto.dart';
5+
import 'package:meta/meta.dart';
6+
17
/// Config base class
28
/// Your annotated class must extend this config class
39
@Deprecated(
@@ -23,8 +29,22 @@ class Openapi {
2329
/// relative path or url to spec file
2430
///
2531
/// -i
32+
@Deprecated('To be removed in the next major')
2633
final String inputSpecFile;
2734

35+
/// Provides the access information to the input spec file.
36+
///
37+
/// For use with useNextGen.
38+
///
39+
/// The next generation of the OAS spec file information. Allows for local and
40+
/// remote spec files.
41+
///
42+
/// This version of the spec file configuration allows for custom authorization
43+
/// to be applied to the fetch request when the spec file is in a remote
44+
/// location. There is also special handling for when the spec file lives within
45+
/// AWS.
46+
final InputSpec? inputSpec;
47+
2848
/// folder containing the template files
2949
///
3050
/// You can read more about templating here
@@ -133,6 +153,7 @@ class Openapi {
133153
this.overwriteExistingFiles,
134154
this.skipSpecValidation = false,
135155
required this.inputSpecFile,
156+
this.inputSpec,
136157
this.templateDirectory,
137158
required this.generatorName,
138159
this.outputDirectory,
@@ -152,6 +173,170 @@ class Openapi {
152173
});
153174
}
154175

176+
/// Provides the input spec file to be used.
177+
///
178+
/// Provides the location of the input spec file to be used by the generator.
179+
/// Includes the option to use the default json or yaml paths.
180+
class InputSpec {
181+
final String path;
182+
final bool defaultYaml;
183+
final bool useYml;
184+
185+
const InputSpec({String? path, this.defaultYaml = true, this.useYml = false})
186+
: path = path ??
187+
'openapi.${defaultYaml ? 'y${useYml ? '' : 'a'}ml' : 'json'}';
188+
189+
const InputSpec.empty() : this();
190+
191+
const InputSpec.emptyJson() : this(defaultYaml: false);
192+
const InputSpec.emptyYml() : this(useYml: true);
193+
194+
Map<String, dynamic> toJsonMap() => {
195+
'path': path,
196+
'defaultYaml': defaultYaml,
197+
'useYml': useYml,
198+
};
199+
200+
InputSpec.fromMap(Map<String, dynamic> map)
201+
: this(
202+
path: map['path'],
203+
defaultYaml: map['defaultYaml'] == 'true' ? true : false,
204+
useYml: map['useYml'] == 'true' ? true : false,
205+
);
206+
}
207+
208+
/// Provides the location for the remote specification.
209+
///
210+
/// Provides basic support for fetching remote specification files hidden behind
211+
/// an authenticated endpoint.
212+
///
213+
/// By default when no [url] is provided a default [Uri.http] to
214+
/// localhost:8080/ is used.
215+
///
216+
/// This contains authentication information for fetching the OAS spec ONLY. This
217+
/// does not apply security to the entry points defined in the OAS spec.
218+
class RemoteSpec extends InputSpec {
219+
final RemoteSpecHeaderDelegate headerDelegate;
220+
221+
const RemoteSpec({
222+
required String path,
223+
this.headerDelegate = const RemoteSpecHeaderDelegate(),
224+
}) : super(path: path);
225+
226+
const RemoteSpec.empty() : this(path: 'http://localhost:8080/');
227+
228+
Uri get url => Uri.parse(path);
229+
230+
RemoteSpec.fromMap(Map<String, dynamic> map)
231+
: headerDelegate =
232+
map['headerDelegate'] ?? const RemoteSpecHeaderDelegate(),
233+
super.fromMap(map);
234+
}
235+
236+
/// Default [RemoteSpecHeaderDelegate] used when retrieving a remote OAS spec.
237+
class RemoteSpecHeaderDelegate {
238+
const RemoteSpecHeaderDelegate();
239+
240+
Map<String, String>? header() => null;
241+
242+
RemoteSpecHeaderDelegate.fromMap(Map<String, dynamic> map) : this();
243+
}
244+
245+
/// Indicates whether or not the spec file live within AWS.
246+
///
247+
/// Since AWS handles the authentication header differently, we need to inform
248+
/// the builder to include the alternate auth header.
249+
///
250+
/// This currently only supports AWS Object GET.
251+
///
252+
/// This contains authentication information for fetching the OAS spec ONLY. This
253+
/// does not apply security to the entry points defined in the OAS spec.
254+
///
255+
/// This delegate makes the assumption that the AWS credentials to be used are
256+
/// provided by the environment and are not empty.
257+
class AWSRemoteSpecHeaderDelegate extends RemoteSpecHeaderDelegate {
258+
/// The [bucket] where the OAS spec is stored within AWS.
259+
final String bucket;
260+
final String? accessKeyId;
261+
final String? secretAccessKey;
262+
263+
const AWSRemoteSpecHeaderDelegate({
264+
required this.bucket,
265+
this.secretAccessKey = null,
266+
this.accessKeyId = null,
267+
}) : super();
268+
269+
AWSRemoteSpecHeaderDelegate.fromMap(Map<String, dynamic> map)
270+
: bucket = map['bucket'],
271+
accessKeyId = map['accessKeyId'],
272+
secretAccessKey = map['secretAccessKey'],
273+
super.fromMap(map);
274+
275+
/// Generates the [header] map used within the GET request.
276+
///
277+
/// Assumes that the user's auth AWS credentials
278+
@override
279+
Map<String, String>? header({
280+
String? path,
281+
}) {
282+
if (!(path != null && path.isNotEmpty)) {
283+
throw new AssertionError('The path to the OAS spec should be provided');
284+
}
285+
286+
// Use the provided credentials to the constructor, if any, otherwise
287+
// fallback to the environment values or throw.
288+
final accessKey = accessKeyId ?? Platform.environment['AWS_ACCESS_KEY_ID'];
289+
final secretKey =
290+
secretAccessKey ?? Platform.environment['AWS_SECRET_ACCESS_KEY'];
291+
if ((accessKey == null || accessKey.isEmpty) ||
292+
(secretKey == null || secretKey.isEmpty)) {
293+
throw new AssertionError(
294+
'AWS_SECRET_KEY_ID & AWS_SECRET_ACCESS_KEY should be defined and not empty or they should be provided in the delegate constructor.');
295+
}
296+
297+
final now = DateTime.now();
298+
299+
return {
300+
'Authorization': authHeaderContent(
301+
now: now,
302+
bucket: bucket,
303+
path: path,
304+
accessKeyId: accessKey,
305+
secretAccessKey: secretKey,
306+
),
307+
'x-amz-date': now.toIso8601String(),
308+
};
309+
}
310+
311+
/// The [Authentication] header content.
312+
///
313+
/// This builds the Authorization header content format used by AWS.
314+
@visibleForTesting
315+
String authHeaderContent({
316+
required DateTime now,
317+
required String bucket,
318+
required String path,
319+
required String accessKeyId,
320+
required String secretAccessKey,
321+
}) {
322+
// https://docs.aws.amazon.com/AmazonS3/latest/userguide/RESTAuthentication.html#RESTAuthenticationExamples
323+
String toSign = [
324+
'GET',
325+
'',
326+
'',
327+
now.toIso8601String(),
328+
'/$bucket/$path',
329+
].join('\n');
330+
331+
final utf8AKey = utf8.encode(secretAccessKey);
332+
final utf8ToSign = utf8.encode(toSign);
333+
334+
final signature =
335+
base64Encode(Hmac(sha1, utf8AKey).convert(utf8ToSign).bytes);
336+
return 'AWS $accessKeyId:$signature';
337+
}
338+
}
339+
155340
class AdditionalProperties {
156341
/// toggles whether unicode identifiers are allowed in names or not, default is false
157342
final bool? allowUnicodeIdentifiers;

openapi-generator-annotations/pubspec.yaml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,16 @@
11
name: openapi_generator_annotations
22
description: Annotation package for openapi_generator https://pub.dev/packages/openapi_generator.
3-
version: 4.12.0
3+
version: 4.13.0
44
homepage: https://github.com/gibahjoe/openapi-generator-dart
55

66

77
environment:
88
sdk: '>=2.12.0 <3.0.0'
99

10+
dependencies:
11+
crypto: '>=3.0.0 <4.0.0'
12+
meta: '>=1.3.0 <2.0.0'
13+
1014
dev_dependencies:
1115
test:
1216
source_gen_test:

0 commit comments

Comments
 (0)