public MethodDeclarationSyntax?Generate(ILocatedOpenApiElement <OpenApiResponse> response) { if (response.Element.Content == null) { return(null); } ILocatedOpenApiElement <OpenApiMediaType>?mediaType = MediaTypeSelector.Select(response); ILocatedOpenApiElement <OpenApiSchema>? schema = mediaType?.GetSchema(); if (schema == null) { return(null); } ITypeGenerator schemaGenerator = Context.SchemaGeneratorRegistry.Get(schema); TypeSyntax returnType = schemaGenerator.TypeName; return(MethodDeclaration( WellKnownTypes.System.Threading.Tasks.ValueTaskT.Name(returnType), GetBodyMethodName) .AddModifiers(Token(SyntaxKind.PublicKeyword), Token(SyntaxKind.AsyncKeyword)) .WithBody(Block(GenerateStatements(response, returnType)))); }
public IEnumerable <BaseMethodDeclarationSyntax> Generate(ILocatedOpenApiElement <OpenApiResponse> response, string className) { if (!response.IsRoot() && response.Element.Reference != null) { // Do not generator for responses within operations that are references to components, these will inherit // their get body method from the component base class yield break; } if (response.Element.Content == null) { yield break; } ILocatedOpenApiElement <OpenApiMediaType>?mediaType = MediaTypeSelector.Select(response); ILocatedOpenApiElement <OpenApiSchema>? schema = mediaType?.GetSchema(); if (schema == null) { yield break; } ITypeGenerator schemaGenerator = Context.TypeGeneratorRegistry.Get(schema); TypeSyntax returnType = schemaGenerator.TypeInfo.Name; yield return(MethodDeclaration( WellKnownTypes.System.Threading.Tasks.ValueTaskT.Name(returnType), GetBodyMethodName) .AddModifiers(Token(SyntaxKind.PublicKeyword), Token(SyntaxKind.AsyncKeyword)) .WithBody(Block(GenerateStatements(response, returnType)))); }
protected override void OnPreRender(EventArgs e) { base.OnPreRender(e); if (!BaseMapper.GetDataModel().MediaDetails.Any()) { var rootMediaType = MediaTypesMapper.GetByEnum(MediaTypeEnum.RootPage); if (rootMediaType != null) { MediaTypeSelector.SetMediaTypes(new List <MediaType>() { rootMediaType }); } } else { if (SelectedMedia != null) { MediaType mediaType = MediaTypesMapper.GetByID(MediaDetailsMapper.GetAtleastOneByMedia(SelectedMedia, CurrentLanguage).MediaTypeID); MediaTypeSelector.SetMediaTypes(mediaType.MediaTypes); } } }
protected void CopyFields_Click(object sender, EventArgs e) { var otherMediaType = MediaTypeSelector.GetSelectedMediaType(); foreach (var otherMediaTypeField in otherMediaType.Fields) { if (!mediaType.Fields.Any(i => i.FieldCode == otherMediaTypeField.FieldCode)) { var mediaTypeField = new MediaTypeField(); mediaTypeField.CopyFrom(otherMediaTypeField); mediaTypeField.DateCreated = mediaTypeField.DateLastModified = DateTime.Now; mediaType.Fields.Add(mediaTypeField); foreach (var mediaDetail in mediaType.MediaDetails) { var mediaDetailField = new MediaDetailField(); mediaDetailField.CopyFrom(mediaTypeField); if (string.IsNullOrEmpty(mediaDetailField.UsageExample)) { mediaDetailField.UsageExample = "{Field:" + mediaDetailField.FieldCode + "} OR {{Load:" + mediaDetail.MediaID + "}.Field:" + mediaDetailField.FieldCode + "}"; } mediaDetailField.UseMediaTypeFieldFrontEndLayout = true; mediaDetailField.UseMediaTypeFieldDescription = true; if (mediaDetailField.FrontEndSubmissions == null) { mediaDetailField.FrontEndSubmissions = ""; } if (mediaDetailField.FieldSettings == null) { mediaDetailField.FieldSettings = ""; } mediaDetailField.MediaTypeField = mediaTypeField; mediaDetailField.DateCreated = mediaDetailField.DateLastModified = DateTime.Now; mediaDetailField.OrderIndex = mediaDetail.Fields.Count; mediaDetail.Fields.Add(mediaDetailField); } } } var returnObj = MediaTypesMapper.Update(mediaType); if (!returnObj.IsError) { Bind(); } else { BasePage.DisplayErrorMessage("Error", returnObj.Error); } }
protected void Add_OnClick(object sender, EventArgs e) { MediaType addMediaType = MediaTypeSelector.GetSelectedMediaType(); if (MediaTypes.Where(i => i.ID == addMediaType.ID).Count() == 0) { MediaTypes.Add(addMediaType); } }
protected virtual IEnumerable <StatementSyntax> GenerateStatements( ILocatedOpenApiElement <OpenApiOperation> operation) { ILocatedOpenApiElement <OpenApiResponses> responseSet = operation.GetResponseSet(); ILocatedOpenApiElement <OpenApiResponse> primaryResponse = responseSet .GetResponses() .OrderBy(p => p.Key) .First(); ILocatedOpenApiElement <OpenApiMediaType>?mediaType = MediaTypeSelector.Select(primaryResponse); if (mediaType != null) { yield return(ExpressionStatement(InvocationExpression( SyntaxHelpers.MemberAccess(RequestMessageParameterName, "Headers", "Accept", "Add")) .AddArgumentListArguments( Argument(ObjectCreationExpression(WellKnownTypes.System.Net.Http.Headers.MediaTypeWithQualityHeaderValue.Name) .AddArgumentListArguments( Argument(SyntaxHelpers.StringLiteral(mediaType.Key))))))); } var propertyNameFormatter = NameFormatterSelector.GetFormatter(NameKind.Property); foreach (var headerParameter in operation.Element.Parameters.Where(p => p.In == ParameterLocation.Header)) { string propertyName = propertyNameFormatter.Format(headerParameter.Name); StatementSyntax statement = ExpressionStatement(InvocationExpression( SyntaxHelpers.MemberAccess(RequestMessageParameterName, "Headers", "Add")) .AddArgumentListArguments( Argument(SyntaxHelpers.StringLiteral(headerParameter.Name)), Argument(InvocationExpression(MemberAccessExpression(SyntaxKind.SimpleMemberAccessExpression, SerializationNamespace.HeaderSerializerInstance, IdentifierName("Serialize"))) .AddArgumentListArguments( Argument(IdentifierName(propertyName)), Argument(headerParameter.Explode ? LiteralExpression(SyntaxKind.TrueLiteralExpression) : LiteralExpression(SyntaxKind.FalseLiteralExpression)))))); if (!headerParameter.Required) { statement = MethodHelpers.IfNotNull( IdentifierName(propertyName), Block(statement)); } yield return(statement); } }
private (ITypeGenerator?schemaGenerator, bool isReference) GetSchemaGenerator() { ILocatedOpenApiElement <OpenApiMediaType>?mediaType = MediaTypeSelector.Select(Element); if (mediaType == null) { return(null, false); } ILocatedOpenApiElement <OpenApiSchema>?schemaElement = mediaType.GetSchema(); if (schemaElement == null) { return(null, false); } return(Context.SchemaGeneratorRegistry.Get(schemaElement), schemaElement.Element.Reference != null); }
public override IEnumerable <MemberDeclarationSyntax> Generate() { var classNameAndNamespace = (QualifiedNameSyntax)GetTypeName(); string className = classNameAndNamespace.Right.Identifier.Text; ClassDeclarationSyntax declaration = ClassDeclaration(className) .AddElementAnnotation(Element, Context.ElementRegistry) .AddModifiers(Token(SyntaxKind.PublicKeyword)) .AddBaseListTypes(SimpleBaseType(RequestsNamespace.OperationRequest)) .AddMembers(ConstructorDeclaration(className) .AddModifiers(Token(SyntaxKind.PublicKeyword)) .WithBody(Block())); declaration = AddParameterProperties(declaration, Element.GetParameters()); var requestBodyElement = Element.GetRequestBody(); if (requestBodyElement != null) { var schema = MediaTypeSelector.Select(requestBodyElement)?.GetSchema(); if (schema != null) { declaration = declaration.AddMembers( CreatePropertyDeclaration(requestBodyElement, className, schema, "Body")); } } declaration = declaration.AddMembers( BuildRequestMethodGenerator.Generate(Element), BuildUriMethodGenerator.Generate(Element), AddHeadersMethodGenerator.Generate(Element), BuildContentMethodGenerator.Generate(Element)); yield return(declaration); }
protected void CopyFields_Click(object sender, EventArgs e) { var otherMediaType = MediaTypeSelector.GetSelectedMediaType(); ImportNewFields(otherMediaType.Fields); }