Beispiel #1
0
        public MethodModel(PackageModel package, ResourceModel resource, string name, RestMethod restMethod)
        {
            Package         = package;
            Resource        = resource;
            Name            = name;
            PascalCasedName = name.ToClassName(package, resource.ClassName);
            ParentTyp       = resource?.Typ ?? package.ServiceTyp;
            RequestTyp      = Typ.Nested(ParentTyp, $"{PascalCasedName}Request");
            BodyTyp         = restMethod.Request is object?package.GetDataModelByReference(restMethod.Request.Ref__).GetTypForReference() : null;

            ResponseTyp = restMethod.Response is object?package.GetDataModelByReference(restMethod.Response.Ref__).GetTypForReference() : Typ.Of <string>();

            _restMethod = restMethod;
        }
Beispiel #2
0
        public EnumModel(PackageModel package, Typ parentTyp, string name, JsonSchema schema)
        {
            IList <string> values      = schema.Enum__;
            IList <string> description = schema.EnumDescriptions;

            Description = schema.Description;
            TypeName    = name.ToMemberName(addUnderscoresToEscape: false) + "Enum";
            // The exact value of the key doesn't particularly matter, so long as it's unique.
            // This should be fine.
            string enumStorageKey = $"{parentTyp.FullName}.{TypeName}";

            Members = schema.Enum__
                      .Zip(schema.EnumDescriptions ?? Enumerable.Repeat((string)null, schema.Enum__.Count), (text, description) => (text, description))
                      .ToReadOnlyList(pair => new EnumMemberModel(pair.text, pair.description, package.PackageEnumStorage.GetOrAddEnumValue(enumStorageKey, pair.text)));
        }
Beispiel #3
0
        public ParameterModel(PackageModel package, string name, JsonSchema schema, Typ parentTyp)
        {
            Name = name;
            CodeParameterName = name.ToLocalVariableName(package);

            // It's unclear why these properties don't get the "__" treatment, but apparently they don't.
            PropertyName = name.ToMemberName(addUnderscoresToEscape: false);
            Location     = schema.Location switch
            {
                "query" => RequestParameterType.Query,
                "path" => RequestParameterType.Path,
                _ => throw new InvalidOperationException($"Unhandled parameter location: '{_schema.Location}'")
            };
            EnumModel = schema.Enum__ is object?new EnumModel(name, schema) : null;
            _schema   = schema;
            Typ       = SchemaTypes.GetTypFromSchema(package, schema, name, currentTyp: parentTyp, inParameter: true);
        }
Beispiel #4
0
        public DataModel(PackageModel package, DataModel parent, string name, JsonSchema schema)
        {
            _schema = schema;
            Name    = name;
            Id      = schema.Id;
            Package = package;
            Parent  = parent;
            // TODO: Move this logic into Naming somehow, but noting that we *don't* escape keywords here. <sigh>
            string className = schema.Id is object && IsArray ? name + "Items" : name;

            className = className.ToUpperCamelCase(upperAfterDigit: null);
            if (className == parent?.Typ.Name)
            {
                className += "Schema";
            }
            Typ = parent is null?Typ.Manual(Package.PackageName + ".Data", className) : Typ.Nested(parent.Typ, className);

            // We may get a JsonSchema for an array as a nested model. Just use the properties from schema.Items for simplicity.
            Properties = GetProperties(schema).ToReadOnlyList(pair => new DataPropertyModel(this, pair.Key, pair.Value));
        }
Beispiel #5
0
 internal static string ToAnonymousModelClassName(this string name, PackageModel package, string containingClass, bool inAdditionalProperties)
 {
     // This is ugly, but when we've got an anonymous model that's also a dictionary, we end up with things round the
     // wrong way otherwise :( It's hard to fix the recursion to get this in the right order.
     name = inAdditionalProperties ? name[..^ 7] + "DataElement" : name + "Data";
Beispiel #6
0
 public MethodModel(PackageModel package, string name, RestMethod restMethod)
 {
     Package = package;
     Name    = name.ToUpperCamelCase();
 }