This Flutter application shows an example of Flutter working with OpenAPIv2 generated code for the petstore example API.
The project should work without any required configuration. Press the floating action button to make requests to the API and observe results in the console.
To build your own code:
- Navigate to the root of your project.
- Make sure you have a config file, like
flutter.config.json
, set up, so you are building code for the flutter environment. - Use openapi-generator-cli (see ‘DownloadJAR’ section) to run the following command. Switch out the path to the jar, input swagger.json and output folder to suit your environment and needs.
java -jar /path/to/openapi-generator-cli.jar generate -i http://petstore.swagger.io/v2/swagger.json -l dart -c flutter.config.json -o your-api
- Update your main project’s
pubspec.yaml
to include the library
swagger:
path: ./petstore-api
- Access the API using the import:
import 'package:swagger/api.dart';