swagger_parser_core 1.0.1
swagger_parser_core: ^1.0.1 copied to clipboard
Typed Swagger and OpenAPI models with JSON/YAML parsing, validation, and reference resolution for swagger_parser.
example/swagger_parser_core_example.dart
import 'dart:convert';
import 'package:swagger_parser_core/swagger_parser_core.dart';
void main() {
const source = SchemaSource.yaml('''
swagger: '2.0'
info:
title: Pets
version: '1'
paths:
/pets:
get:
responses:
'200':
description: Pets
schema:
type: array
items:
type: string
''');
final document = const OpenApiParser().parse(source) as SwaggerV2Document;
final ValidationReport report = const OpenApiValidator().validate(document);
if (report.hasErrors) {
throw StateError('The schema has validation errors.');
}
// ignore: avoid_print
print(const JsonEncoder.withIndent(' ').convert(document.toJson()));
}