gibahjoe / openapi-generator-dart

Openapi Generator for Dart/Flutter
BSD 3-Clause "New" or "Revised" License
128 stars 34 forks source link

Code not updating when API changes #33

Closed mikthemonster closed 3 years ago

mikthemonster commented 3 years ago

Hi.

I have successfully created flutter/dart client code for my .net core API based on my "API.yaml" file (open API 3.0.0).

When I change my API and supply a new API.yaml file with the updated API my code is NOT re-generated. How can I trigger a re-generation?

This is the command I run in my flutter project and the output: PS C:\Dokumenter\MyFirstFlutterApp\myfirstapp> flutter pub run build_runner build --delete-conflicting-outputs [INFO] Generating build script... [INFO] Generating build script completed, took 478ms

[INFO] Initializing inputs [INFO] Reading cached asset graph... [INFO] Reading cached asset graph completed, took 91ms

[INFO] Checking for updates since last build... [INFO] Checking for updates since last build completed, took 641ms

[INFO] Running build... [INFO] Running build completed, took 492ms

[INFO] Caching finalized dependency graph... [INFO] Caching finalized dependency graph completed, took 61ms

[INFO] Succeeded after 565ms with 0 outputs (1 actions)

gibahjoe commented 3 years ago

Build runner will only trigger builds on files that have changed since the last time it has run.

In other to get around this, you will have to change something in the file where your annotation is.

What I do is just add a full stop to the pubAuthor property in additionalProperties then try again.

mikthemonster commented 3 years ago

Build runner will only trigger builds on files that have changed since the last time it has run.

In other to get around this, you will have to change something in the file where your annotation is.

What I do is just add a full stop to the pubAuthor property in additionalProperties then try again.

Thaks, it is working now :-)

I ended up adding two "flags" (alwaysRun and overwriteExistingFiles) in the configuration and then then the code is generated when I do as you described. My openapi configuration looks like this:

@Openapi( alwaysRun: true, overwriteExistingFiles: true, additionalProperties: AdditionalProperties(pubName: 'petstore_api', pubAuthor: 'Johnny dep2'), inputSpecFile: 'lib/example/API.yaml', generatorName: Generator.DART, outputDirectory: 'lib/example/OutFolder') class Example extends OpenapiGeneratorConfig {} .

Strainy commented 1 year ago

This is annoying. But to get around it in a more automated fashion, I've written a wrapper script that updates a commented timestamp in the configuration file every time I need to regenerate the client code:

#!/usr/bin/env bash
set -ue

OPENAPI_GENERATOR_FILE=lib/data/network/openapi_generator.dart
LAST_BUILT_TS=$(date -u +"%Y-%m-%dT%H:%M:%SZ")

# Annoyingly, we need to alter the openapi_generator.dart file in order to trigger client code generation
# so we're just going to write a comment with the current timestamp at the top of the file on each build
sed -i '' 's/.*Last generated timestamp.*/\/\/ Last generated timestamp: '''$LAST_BUILT_TS'''/' $OPENAPI_GENERATOR_FILE

script -q /dev/null dart run build_runner build --delete-conflicting-outputs