createSchemaFromUrl static method
Create a schema from a URL.
This method is asyncronous to support automatic fetching of sub-JsonSchema
s for items,
properties, and sub-properties of the root schema.
Implementation
static Future<JsonSchema> createSchemaFromUrl(
String schemaUrl, {
SchemaVersion? schemaVersion,
}) async {
final uriWithFrag = Uri.parse(schemaUrl);
var uri = uriWithFrag.removeFragment();
if (schemaUrl.endsWith('#')) {
uri = uriWithFrag;
}
final client = Client();
final response =
await client.execute(request: Request(url: uri.toString()));
final parentSchema = await JsonSchema.createSchemaAsync(
response.body,
schemaVersion: schemaVersion,
fetchedFromUri: uri,
);
final schema =
JsonSchemaUtils.getSubMapFromFragment(parentSchema, uriWithFrag);
return schema;
}