function convertScalar2CMDSchemaBase()

in src/typespec-aaz/src/convertor.ts [1092:1256]


function convertScalar2CMDSchemaBase(context: AAZSchemaEmitterContext, scalar: Scalar): CMDSchemaBase | undefined {
  const isStd = context.program.checker.isStdType(scalar);
  const encodeData = getEncode(context.program, scalar);
  let schema;
  if (isStd) {
    switch (scalar.name) {
      case "bytes":
        schema = {
          type: "byte",
        } as CMDByteSchemaBase;
        break;
      case "numeric":
        schema = {
          type: "integer",
        } as CMDIntegerSchemaBase;
        break;
      case "integer":
        schema = {
          type: "integer",
        } as CMDIntegerSchemaBase;
        break;
      case "int8":
        // TODO: add format for int8
        schema = {
          type: "integer",
        } as CMDIntegerSchemaBase;
        break;
      case "int16":
        // TODO: add format for int16
        schema = {
          type: "integer",
        } as CMDIntegerSchemaBase;
        break;
      case "int32":
        schema = {
          type: "integer32",
        } as CMDInteger32SchemaBase;
        break;
      case "int64":
        schema = {
          type: "integer64",
        } as CMDInteger64SchemaBase;
        break;
      case "safeint":
        schema = {
          type: "integer64",
        } as CMDInteger64SchemaBase;
        break;
      case "uint8":
        // TODO: add format for uint8
        schema = {
          type: "integer",
        } as CMDIntegerSchemaBase;
        break;
      case "uint16":
        // TODO: add format for uint16
        schema = {
          type: "integer",
        } as CMDIntegerSchemaBase;
        break;
      case "uint32":
        // TODO: add format for uint32
        schema = {
          type: "integer",
        } as CMDIntegerSchemaBase;
        break;
      case "uint64":
        // TODO: add format for uint64
        schema = {
          type: "integer",
        } as CMDIntegerSchemaBase;
        break;
      case "float":
        schema = {
          type: "float",
        } as CMDFloatSchemaBase;
        break;
      case "float32":
        schema = {
          type: "float32",
        } as CMDFloat32SchemaBase;
        break;
      case "float64":
        schema = {
          type: "float64",
        } as CMDFloat64SchemaBase;
        break;
      case "decimal":
        schema = {
          type: "float64",
        } as CMDFloat64SchemaBase;
        break;
      case "decimal128":
        // TODO: add format for decimal128
        schema = {
          type: "float",
        } as CMDFloatSchemaBase;
        break;
      case "string":
        schema = {
          type: "string",
        } as CMDStringSchemaBase;
        break;
      case "url":
        schema = {
          type: "string",
        } as CMDStringSchemaBase;
        break;
      case "plainDate":
        schema = {
          type: "date",
        };
        break;
      case "plainTime":
        schema = {
          type: "time",
        };
        break;
      case "utcDateTime":
      case "offsetDateTime":
        switch (encodeData?.encoding) {
          case "rfc3339":
            schema = { type: "dateTime" };
            break;
          case "unixTimestamp":
            // TODO: add "unixtime" support
            schema = { type: "dateTime" };
            break;
          case "rfc7231":
            // TODO: add "date-time-rfc7231" support
            schema = { type: "dateTime" };
            break;
          default:
            if (encodeData !== undefined) {
              schema = convertScalar2CMDSchemaBase(context, encodeData.type);
            }
            schema ??= { type: "dateTime" };
        }
        break;
      case "duration":
        switch (encodeData?.encoding) {
          case "ISO8601":
            schema = { type: "duration" };
            break;
          case "seconds":
            // TODO: add "seconds" support
            schema = { type: "duration" };
            break;
          default:
            if (encodeData !== undefined) {
              schema = convertScalar2CMDSchemaBase(context, encodeData.type);
            }
            schema ??= { type: "duration" };
        }
        break;
      case "boolean":
        schema = { type: "boolean" };
        break;
    }
  } else if (scalar.baseScalar) {
    schema = convertScalar2CMDSchemaBase(context, scalar.baseScalar);
  }

  return schema;
}