public AWSQueryValidator(IDictionary<string, string> paramters, object request, ServiceModel serviceModel, Operation operation) { this.Parameters = paramters; this.Request = request; this.Model = serviceModel; this.Operation = operation; }
/// <summary> /// Constructs on operation from a service model, operation name, and the json model /// </summary> /// <param name="model">The model of the service the operation belongs to</param> /// <param name="name">The name of the operation</param> /// <param name="data">The json data from the model file</param> public Operation(ServiceModel model, string name, JsonData data) : base(model, data) { this.model = model; this.name = name; this.data = data; }
/// <summary> /// Creates a shape with a reference to the model it's a part of, its name, and the json data of the shape pulled from the model. /// Shapes are used to model structures and member types. If they are a structure the shape /// defines what members it has and what shape those members are. It also defines which of those /// members are required. If it is not a structure then it is used to specify the type of the member and its properties. /// </summary> /// <param name="model">The model that contains the shape</param> /// <param name="name">The name of the shape</param> /// <param name="data">The json object of the shape, pulled form the model json</param> public Shape(ServiceModel model, string name, JsonData data) : base(model, data) { this._name = ServiceModel.CapitalizeFirstChar(name); var nameOverride = this.model.Customizations.GetOverrideShapeName(this._name); if (nameOverride != null) this._name = nameOverride; }
public Member(ServiceModel model, Shape owningShape, string name, string defaultMarshallName, JsonData data, CustomizationsModel.PropertyModifier propertyModifier) : base(model, data) { this.OwningShape = owningShape; _name = name; _defaultMarshallName = defaultMarshallName; this.PropertyModifier = propertyModifier; this.PropertyInjector = null; }
private void SanityGenerateForAllsOperations(ServiceModel serviceModel) { foreach (var operation in serviceModel.Operations) { try { Generate(serviceModel, operation.Name); } catch (Exception e) { throw new Exception("Failed to generate for operation " + operation, e); } } }
public static void Validate(string operation, object request, IRequest marshalledRequest, ServiceModel serviceModel) { switch (serviceModel.Type) { //case ServiceType.Json: // break; //case ServiceType.Query: // break; case ServiceType.Rest_Xml: new RestXmlValidator(operation, request, marshalledRequest, serviceModel).Validate(); break; case ServiceType.Rest_Json: case ServiceType.Json: new RestJsonValidator(operation, request, marshalledRequest, serviceModel).Validate(); break; default: throw new InvalidOperationException(); } }
/// <summary> /// Checks if the shape is referred directly by another shape /// </summary> /// <param name="shapeName">Name of the shape to look for references of</param> /// <param name="serviceModel">The ServiceModel containing information about the shapes of the service</param> /// <returns>If the shape is a member of a structure or is a list or map</returns> private static bool IsShapeReferred(string shapeName, ServiceModel serviceModel) { foreach (var shape in serviceModel.Shapes) { if (shape.IsStructure) { foreach (var member in shape.Members) { if (member.Shape.Name == shapeName) { return true; } } } else if (shape.IsList && shape.ListShape.Name == shapeName) { return true; } else if (shape.IsMap && (shape.ValueShape.Name == shapeName || shape.KeyShape.Name == shapeName)) { return true; } } return false; }
/// <summary> /// Creates an operation input through the BaseModel /// </summary> /// <param name="model">The model of the service</param> /// <param name="data">The model as a jsonData object</param> public OperationInput(ServiceModel model, JsonData data) : base(model, data) { }
/// <summary> /// Creates an enumeration that can model parts of the enumeration for the service /// </summary> /// <param name="model">The service model that is using the enumartion</param> /// <param name="name">The name of the enumeration</param> /// <param name="data">The json data for the enumartion object</param> public Enumeration(ServiceModel model, string name, JsonData data) { this.model = model; this._name = ServiceModel.CapitalizeFirstChar(name); this._data = data; }
protected BaseModel(ServiceModel model, JsonData data) { this.model = model; this.data = data; }
/// <summary> /// Determines the type of the member based on customizations, if it isn't custom then it pulls /// from the full json model to get the shape of this member /// </summary> /// <param name="extendedData">The json data from the parent shape model</param> /// <param name="treatEnumsAsString">If true all any found enum type will be returned as a string</param> /// <returns></returns> private string DetermineType(JsonData extendedData, bool treatEnumsAsString) { JsonData typeNode = null; // Check to see if customizations is overriding - first by simple type remap // and then via more extensive customization. If we are handed a collection // shape to begin with, this check is whether the collection shape, not the // collected type, is remapped. /*var remapAsShapeName = this.model.Customizations.GetSubstituteShapeName(this.Shape.Name); * if (remapAsShapeName != null) * { * var remappedShape = this.model.FindShape(remapAsShapeName); * if (remappedShape == null) * throw new Exception(string.Format("Found shape remap from {0} to {1} but no such shape in model!", * this.Shape.Name, remapAsShapeName)); * if (remappedShape.IsStructure) * return remapAsShapeName; * * switch (remappedShape.Type) * { * case "boolean": * return "bool"; * case "integer": * return "int"; * case "timestamp": * return "DateTime"; * default: * return remappedShape.Type; * } * }*/ var overrideType = this.model.Customizations.OverrideDataType(OwningShape.Name, this._name); if (overrideType != null) { this._newType = overrideType.DataType; return(overrideType.DataType); } var extendsNode = extendedData[ServiceModel.ShapeKey]; if (extendsNode == null) { throw new Exception("Missing extends for member " + this._name); } JsonData memberShape = null; // if this shape is a collection, has the collected type been remapped? var emitAsShapeName = this.model.Customizations.GetSubstituteShapeName(extendsNode.ToString()); var renameShape = this.model.Customizations.GetOverrideShapeName(extendsNode.ToString()); if (emitAsShapeName == null) { memberShape = this.model.DocumentRoot[ServiceModel.ShapesKey][extendsNode.ToString()]; typeNode = memberShape[Shape.TypeKey]; } else { // we only handle remap to one level at present memberShape = this.model.DocumentRoot[ServiceModel.ShapesKey][emitAsShapeName]; typeNode = memberShape[Shape.TypeKey]; } if (typeNode == null) { throw new Exception("Type is missing for shape " + extendsNode.ToString()); } switch (typeNode.ToString()) { case "string": if (!treatEnumsAsString && memberShape["enum"] != null) { return(ServiceModel.CapitalizeFirstChar(renameShape ?? extendsNode.ToString())); } return("string"); case "blob": if (this.IsStreaming) { return("Stream"); } return("MemoryStream"); case "boolean": return("bool"); case "double": return("double"); case "float": return("float"); case "integer": return("int"); case "long": return("long"); case "timestamp": return("DateTime"); case "structure": return(emitAsShapeName ?? renameShape ?? extendsNode.ToString()); case "map": var keyType = DetermineType(memberShape["key"], true); var valueType = DetermineType(memberShape["value"], true); return(string.Format("Dictionary<{0}, {1}>", keyType, valueType)); case "list": var listType = DetermineType(memberShape["member"], true); return(string.Format("List<{0}>", listType)); case "decimal": throw new Exception(UnhandledTypeDecimalErrorMessage); default: throw new Exception("Unknown type " + typeNode.ToString()); } }
/// <summary> /// Creates an enumeration that can model parts of the enumeration for the service /// </summary> /// <param name="model">The service model that is using the enumartion</param> /// <param name="name">The name of the enumeration</param> /// <param name="data">The json data for the enumartion object</param> public Enumeration(ServiceModel model, string name, JsonData data) { this.model = model; _modelName = name; _data = data; var overrideName = model.Customizations.GetOverrideShapeName(_modelName); _outputName = !string.IsNullOrEmpty(overrideName) ? ServiceModel.CapitalizeFirstChar(overrideName) : ServiceModel.CapitalizeFirstChar(_modelName); }
public JsonSampleGenerator(ServiceModel model, Shape rootStructure) { this._model = model; this._rootStructure = rootStructure; }
/// <summary> /// Creates a model that represents an exception in the service processed in the response /// </summary> /// <param name="data">The json data that contains information about the exception found in the model</param> /// <param name="name">The name of the exception</param> /// <param name="documentation">The documentation for the exception found in the service model json</param> /// <param name="structure">The shape that represents the exception</param> public ExceptionShape(ServiceModel model, string name, JsonData data) : base(model, name, data) { }
public Example(ServiceModel model, string operationName, JsonData data) : base(model, data) { this.OperationName = operationName; }
public XmlSampleGenerator(ServiceModel model, Operation operation) { this._model = model; this._operation = operation; }
/// <summary> /// Creates a shape with a reference to the model it's a part of, its name, and the json data of the shape pulled from the model. /// Shapes are used to model structures and member types. If they are a structure the shape /// defines what members it has and what shape those members are. It also defines which of those /// members are required. If it is not a structure then it is used to specify the type of the member and its properties. /// </summary> /// <param name="model">The model that contains the shape</param> /// <param name="name">The name of the shape</param> /// <param name="data">The json object of the shape, pulled form the model json</param> public Shape(ServiceModel model, string name, JsonData data) : base(model, data) { this._name = ServiceModel.CapitalizeFirstChar(name); }
string Generate(ServiceModel model, string operationName) { var operation = model.Operations.First(x => x.Name == operationName); var generator = new XmlSampleGenerator(model, operation); return generator.Execute(); }
void Generate(ServiceModel model, string operationName, out string requestJson, out string responseJson) { var operation = model.Operations.First(x => x.Name == operationName); JsonSampleGenerator generator = new JsonSampleGenerator(model, operation.RequestStructure); requestJson = generator.Execute(); generator = new JsonSampleGenerator(model, operation.ResponseStructure); responseJson = generator.Execute(); }