Skip to content

Commit c16cd27

Browse files
committed
chore: cleaned up tests, updated docs and prepared for final release
1 parent d5555dd commit c16cd27

File tree

6 files changed

+72
-64
lines changed

6 files changed

+72
-64
lines changed

.github/workflows/release.yml

Lines changed: 7 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -15,22 +15,10 @@ jobs:
1515
runs-on: ubuntu-latest
1616
needs: [test]
1717
steps:
18-
- name: Checkout
19-
uses: actions/checkout@v3
20-
21-
- name: Setup Dart
22-
uses: dart-lang/setup-dart@v1
23-
24-
- name: Install Melos
25-
run: dart pub global activate melos
26-
27-
- name: Authenticate with Pub
28-
run: echo "${{ secrets.PUB_CREDENTIAL_JSON }}" > ~/.pub-cache/credentials.json
29-
30-
- name: Bootstrap Melos
31-
run: melos bootstrap
32-
33-
- name: Version and Publish
34-
run: |
35-
melos version --yes
36-
melos publish --no-dry-run --yes
18+
- uses: actions/checkout@v4
19+
- uses: dart-lang/setup-dart@v1
20+
- uses: bluefireteam/melos-action@v3
21+
- name: Authenticate with Pub
22+
run: echo "${{ secrets.PUB_CREDENTIAL_JSON }}" > ~/.pub-cache/credentials.json
23+
- name: Publish
24+
run: melos publish --no-dry-run --yes

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

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -143,15 +143,14 @@ class Openapi {
143143
/// Defaults to [false].
144144
final bool forceAlwaysRun;
145145

146-
/// Skips execution if the OpenAPI specification file is older than the output folder.
146+
/// Skips execution if the OpenAPI specification file is different from a cached copy.
147147
///
148148
/// For remote specifications, the file will be downloaded and cached locally.
149149
/// The cache is then compared to the remote file to detect any changes.
150150
///
151-
/// **Default behavior:**
152-
/// - If [inputSpec] is a [RemoteSpec], this is set to `true`, meaning execution will be skipped if no changes are detected.
153-
/// - For all other cases, this is set to `false`.
154-
151+
/// If set to false, a cached copy of the OpenAPI specification file is not kept.
152+
///
153+
/// Defaults to [true].
155154
final bool skipIfSpecIsUnchanged;
156155

157156
const Openapi({
@@ -175,8 +174,8 @@ class Openapi {
175174
this.projectPubspecPath,
176175
this.debugLogging = false,
177176
this.forceAlwaysRun = true,
178-
bool? skipIfSpecIsUnchanged,
179-
}) : skipIfSpecIsUnchanged = skipIfSpecIsUnchanged ?? inputSpec is RemoteSpec;
177+
this.skipIfSpecIsUnchanged = true,
178+
});
180179

181180
@override
182181
String toString() {

openapi-generator-annotations/pubspec.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ environment:
88
sdk: '>=2.12.0 <4.0.0'
99

1010
dependencies:
11+
crypto: '>=3.0.6 <=4.0.0'
12+
meta: '>=1.16.0 <=2.0.0'
1113

1214
dev_dependencies:
1315
test:

openapi-generator-annotations/test/openapi_generator_annotations_test.dart

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ void main() {
1313
generatorName: Generator.dart,
1414
);
1515
expect(props.additionalProperties, isNull);
16-
expect(props.skipSpecValidation, false);
16+
expect(props.skipSpecValidation, isFalse);
1717
expect(props.inputSpec.path, InputSpec.json().path);
1818
expect(props.templateDirectory, isNull);
1919
expect(props.generatorName, Generator.dart);
@@ -23,12 +23,13 @@ void main() {
2323
expect(props.reservedWordsMappings, isNull);
2424
expect(props.inlineSchemaNameMappings, isNull);
2525
expect(props.apiPackage, isNull);
26-
expect(props.fetchDependencies, true);
27-
expect(props.runSourceGenOnOutput, true);
26+
expect(props.fetchDependencies, isTrue);
27+
expect(props.runSourceGenOnOutput, isTrue);
2828
expect(props.cachePath, isNull);
2929
expect(props.projectPubspecPath, isNull);
3030
expect(props.debugLogging, isFalse);
3131
expect(props.nameMappings, isNull);
32+
expect(props.skipIfSpecIsUnchanged, isTrue);
3233
});
3334
group('NextGen', () {
3435
test('Sets cachePath', () {

openapi-generator/README.md

Lines changed: 49 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ To be used together with [openapi-generator-annotations](https://pub.dev/package
1111

1212
1. **Java**: You must have java installed on your system for this library to work. if you are a developer, chances aare
1313
you already. Walking you through how to install Java is beyond the scope of this project.
14-
2. **Internet**: _duh!!!_ Just to download the openapi jar initially. Once it is cached, you are good to go.
14+
2. **Internet Connection**: _duh!!!_ Just to download the openapi jar initially. Once it is cached, you are good to go.
1515

1616
## Usage
1717

@@ -31,16 +31,20 @@ dev_dependencies:
3131
openapi_generator: ^latest
3232
```
3333
34-
Annotate a dart class with @Openapi() annotation
34+
Annotate any dart class with @Openapi() annotation
3535
3636
```dart
3737
@Openapi(
38-
additionalProperties:
39-
AdditionalProperties(pubName: 'petstore_api', pubAuthor: 'Johnny dep'),
40-
inputSpecFile: 'example/openapi-spec.yaml',
41-
generatorName: Generator.dart,
42-
outputDirectory: 'api/petstore_api')
43-
class Example extends OpenapiGeneratorConfig {}
38+
additionalProperties:
39+
DioProperties(pubName: 'petstore_api', pubAuthor: 'Johnny dep..'),
40+
inputSpec:
41+
RemoteSpec(path: 'https://petstore3.swagger.io/api/v3/openapi.json'),
42+
typeMappings: {'Pet': 'ExamplePet'},
43+
generatorName: Generator.dio,
44+
runSourceGenOnOutput: true,
45+
outputDirectory: 'api/petstore_api',
46+
)
47+
class Example {}
4448
```
4549

4650
Run command below to generate open api client sdk from spec file specified in annotation.
@@ -51,40 +55,52 @@ flutter pub run build_runner build --delete-conflicting-outputs
5155

5256
The api sdk will be generated in the folder specified in the annotation. See examples for more details
5357

54-
## Next Generation
55-
56-
As of version 5.0 of this library, there is some new functionality that has been added to the generator. This version
58+
As of version 6.0 of this library, there is some new functionality that has been added to the generator. This version
5759
will have the ability to:
5860

59-
- cache changes in the openapi spec
60-
- Rerun when there ares difference in the cached copy and current copy
61-
- Pull from a remote source and cache that.
62-
- **Note**: This means that your cache could be potentially stale. But in that case this flow will still pull the
63-
latest and run.
64-
- While this is a possible usage, if you are actively developing your spec it is preferred you provide a local copy.
65-
- Skip generation based off:
66-
- Flags
67-
- No difference between the cache and local
68-
- And all the functionality provided previously.
61+
- `skipIfSpecUnchanged`: Set to `false` if you want the library to generate the client SDK each time, even without
62+
changes in the OpenAPI spec. Defaults to `true`.
63+
- `forceAlwaysRun` (**Breaking Change**): Forces `build_runner` to detect changes by marking the annotated file. May
64+
cause merge conflicts in team environments, so it defaults to `false`.
6965

70-
Your original workflow stay the same but there is a slight difference in the annotations.
66+
## Usage (pre 5.0.0 versions)
7167

72-
New:
68+
Include [openapi-generator-annotations](https://pub.dev/packages/openapi_generator_annotations) as a dependency in the
69+
dependencies section of your pubspec.yaml file :
70+
71+
```yaml
72+
dependencies:
73+
openapi_generator_annotations: ^latest
74+
```
75+
76+
Add [openapi-generator](https://pub.dev/packages/openapi_generator) in the dev dependencies section of your pubspec.yaml
77+
file:
78+
79+
```yaml
80+
dev_dependencies:
81+
openapi_generator: ^latest
82+
```
83+
84+
Annotate any dart class with @Openapi() annotation
7385
7486
```dart
7587
@Openapi(
76-
additionalProperties:
77-
DioProperties(pubName: 'petstore_api', pubAuthor: 'Johnny dep..'),
78-
inputSpec:
79-
RemoteSpec(path: 'https://petstore3.swagger.io/api/v3/openapi.json'),
80-
typeMappings: {'Pet': 'ExamplePet'},
81-
generatorName: Generator.dio,
82-
runSourceGenOnOutput: true,
83-
outputDirectory: 'api/petstore_api',
84-
)
85-
class Example {}
88+
additionalProperties:
89+
AdditionalProperties(pubName: 'petstore_api', pubAuthor: 'Johnny dep'),
90+
inputSpecFile: 'example/openapi-spec.yaml',
91+
generatorName: Generator.dart,
92+
outputDirectory: 'api/petstore_api')
93+
class Example extends OpenapiGeneratorConfig {}
94+
```
95+
96+
Run command below to generate open api client sdk from spec file specified in annotation.
97+
98+
```cmd
99+
flutter pub run build_runner build --delete-conflicting-outputs
86100
```
87101

102+
The api sdk will be generated in the folder specified in the annotation. See examples for more details
103+
88104
## Known Issues
89105

90106
### Dependency issues/conflicts

openapi-generator/pubspec.yaml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,11 @@ dependencies:
1010
build: '>=1.0.0 <=3.0.0'
1111
source_gen: '>=1.0.0 <=2.0.0'
1212
path: '>=1.0.0 <=2.0.0'
13-
openapi_generator_annotations: '5.0.2'
13+
openapi_generator_annotations: ^6.0.0
1414
analyzer: '>=2.0.0 <7.0.0'
15-
openapi_generator_cli: '>5.0.2 <7.0.0'
15+
openapi_generator_cli: ^6.0.0
16+
crypto: '>=3.0.6 <=4.0.0'
17+
meta: '>=1.16.0 <=2.0.0'
1618
yaml: ^3.1.2
1719
http: '>=0.13.1 <=2.0.0'
1820
logging: '>=1.0.0 <=2.0.0'

0 commit comments

Comments
 (0)