How to use the @azure-tools/codegen.comment function in @azure-tools/codegen

To help you get started, we’ve selected a few @azure-tools/codegen examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github Azure / autorest.go / src / generator / protocol / models.ts View on Github external
function generateEnums(enums?: ChoiceSchema[]): string {
  let text = '';
  for (const enm of values(enums)) {
    if (HasDescription(enm.language.go!)) {
      text += `${comment(enm.language.go!.name, '// ')} - ${enm.language.go!.description}\n`;
    }
    text += `type ${enm.language.go!.name} ${enm.choiceType.language.go!.name}\n\n`;
    enm.choices.sort((a: ChoiceValue, b: ChoiceValue) => { return SortAscending(a.language.go!.name, b.language.go!.name); });
    const vals = new Array();
    text += 'const (\n'
    for (const val of values(enm.choices)) {
      if (HasDescription(val.language.go!)) {
        text += `\t${comment(val.language.go!.name, '// ')} - ${val.language.go!.description}\n`;
      }
      text += `\t${val.language.go!.name} ${enm.language.go!.name} = "${val.value}"\n`;
      vals.push(val.language.go!.name);
    }
    text += ")\n\n"
    text += `func ${enm.language.go!.possibleValuesFunc}() []${enm.language.go!.name} {\n`;
    text += `\treturn []${enm.language.go!.name}{${joinComma(vals, (item: string) => item)}}\n`;
    text += '}\n\n';
github Azure / autorest.go / src / generator / protocol / models.ts View on Github external
text(): string {
    let text = '';
    if (HasDescription(this.Language)) {
      text += `${comment(this.Language.description, '// ')}\n`;
    }
    text += `type ${this.Language.name} struct {\n`;
    for (const prop of values(this.Properties)) {
      if (HasDescription(prop.language.go!)) {
        text += `\t${comment(prop.language.go!.description, '// ')}\n`;
      }
      text += `\t${prop.language.go!.name} ${prop.schema.language.go!.name}\n`;
    }
    text += '}\n\n';
    if (this.Language.errorType) {
      text += `func new${this.Language.name}(resp *azcore.Response) error {\n`;
      text += `\terr := ${this.Language.name}{}\n`;
      text += `\tif err := resp.UnmarshalAsJSON(&err); err != nil {\n`;
      text += `\t\treturn err\n`;
      text += `\t}\n`;
      text += '\treturn err\n';
github Azure / autorest.go / src / generator / protocol / models.ts View on Github external
function generateEnums(enums?: ChoiceSchema[]): string {
  let text = '';
  for (const enm of values(enums)) {
    if (HasDescription(enm.language.go!)) {
      text += `${comment(enm.language.go!.name, '// ')} - ${enm.language.go!.description}\n`;
    }
    text += `type ${enm.language.go!.name} ${enm.choiceType.language.go!.name}\n\n`;
    enm.choices.sort((a: ChoiceValue, b: ChoiceValue) => { return SortAscending(a.language.go!.name, b.language.go!.name); });
    const vals = new Array();
    text += 'const (\n'
    for (const val of values(enm.choices)) {
      if (HasDescription(val.language.go!)) {
        text += `\t${comment(val.language.go!.name, '// ')} - ${val.language.go!.description}\n`;
      }
      text += `\t${val.language.go!.name} ${enm.language.go!.name} = "${val.value}"\n`;
      vals.push(val.language.go!.name);
    }
    text += ")\n\n"
    text += `func ${enm.language.go!.possibleValuesFunc}() []${enm.language.go!.name} {\n`;
    text += `\treturn []${enm.language.go!.name}{${joinComma(vals, (item: string) => item)}}\n`;
    text += '}\n\n';
  }
  return text;
}
github Azure / autorest.go / src / generator / enums.ts View on Github external
export async function generateEnums(session: Session): Promise {
  const enums = getEnums(session.model.schemas);
  if (enums.length === 0) {
    // no enums to generate
    return '';
  }
  let text = await contentPreamble(session);
  for (const enm of values(enums)) {
    if (enm.desc) {
      text += `${comment(enm.name, '/// ')} - ${enm.desc}\n`;
    }
    text += `public enum ${enm.name}: ${enm.type} {\n`;
    const vals = new Array();
    for (const val of values(enm.choices)) {
      if (hasDescription(val.language.go!)) {
        text += `\t${comment(val.language.go!.name, '// ')} - ${val.language.go!.description}\n`;
      }
      text += `\tcase ${val.language.go!.name} = "${val.value}"\n`;
      vals.push(val.language.go!.name);
    }
    // Add any enum funcs
    // text += `func ${enm.funcName}() []${enm.name} {\n`;
    // text += `\treturn []${enm.name}{\t\n`;
    // for (const val of values(vals)) {
    //   text += `\t\t${val},\n`;
    // }
github Azure / autorest.go / src / generator / enums.ts View on Github external
export async function generateEnums(session: Session): Promise {
  const enums = getEnums(session.model.schemas);
  if (enums.length === 0) {
    // no enums to generate
    return '';
  }
  let text = await contentPreamble(session);
  for (const enm of values(enums)) {
    if (enm.desc) {
      text += `${comment(enm.name, '/// ')} - ${enm.desc}\n`;
    }
    text += `public enum ${enm.name}: ${enm.type} {\n`;
    const vals = new Array();
    for (const val of values(enm.choices)) {
      if (hasDescription(val.language.go!)) {
        text += `\t${comment(val.language.go!.name, '// ')} - ${val.language.go!.description}\n`;
      }
      text += `\tcase ${val.language.go!.name} = "${val.value}"\n`;
      vals.push(val.language.go!.name);
    }
    // Add any enum funcs
    // text += `func ${enm.funcName}() []${enm.name} {\n`;
    // text += `\treturn []${enm.name}{\t\n`;
    // for (const val of values(vals)) {
    //   text += `\t\t${val},\n`;
    // }
    // text += '\t}\n';
    // text += '}\n\n';
    // text += `func (c ${enm.name}) ToPtr() *${enm.name} {\n`;
    // text += '\treturn &c\n';
    text += '}\n\n';
  }
github Azure / autorest.go / src / generator / convenience / models.ts View on Github external
};
        structs.push(entry);
      }
      if (op.responses) {
        const entry: EntryType = {
          name: op.responses[0].language.go!.name,
          desc: op.responses[0].language.go!.description,
        };
        structs.push(entry);
      }
    }
  }
  structs.sort((a: EntryType, b: EntryType) => { return SortAscending(a.name, b.name) });
  for (const struct of values(structs)) {
    if (struct.desc) {
      text += `${comment(struct.desc)}\n`;
    }
    text += `type ${struct.name} = azinternal.${struct.name}\n\n`;
  }
  return text;
}