async function getResourceInfo()

in generator/cmd/listresources.ts [48:69]


async function getResourceInfo(schemaRef: string) {
  const schemaUri = schemaRef.split('#')[0];
  const relativeRef = schemaRef.split('#')[1].substring(1);

  let schema = await readSchema(schemaUri);

  for (const pathElement of relativeRef.split('/')) {
    schema = schema[pathElement];
  }

  if (!schema?.properties?.type?.enum || !schema?.properties?.apiVersion?.enum) {
    throw new Error(`Unable to find expected properties for ${schemaRef}`)
  }

  const resourceTypes: string[] = schema['properties']['type']['enum'];
  const apiVersions: string[] = schema['properties']['apiVersion']['enum'];

  return resourceTypes.map(type => apiVersions.map(apiVersion => ({
    apiVersion,
    type,
  }))).reduce((a, b) => a.concat(b), []);
}