private string GetClassName() { INameFormatter formatter = Context.NameFormatterSelector.GetFormatter(NameKind.Class); if (Element.IsRoot()) { // We're in the components section return(formatter.Format(Response.Reference.Id + "Response")); } else { // We're in an operation OpenApiOperation operation = Element.Parents() .OfType <LocatedOpenApiElement <OpenApiOperation> >() .First() .Element; string responseCode = Enum.TryParse <HttpStatusCode>(Element.Key, out var statusCode) ? HttpResponseCodeNameProvider.GetName(statusCode) : Element.Key; return(formatter.Format($"{operation.OperationId}{responseCode}Response")); } }
protected virtual EnumMemberDeclarationSyntax?CreateEnumMember( ILocatedOpenApiElement <OpenApiSchema> schemaElement, IOpenApiAny value, INameFormatter nameFormatter, NamingContext namingContext) { if (value.AnyType != AnyType.Primitive) { return(null); } var primitive = (IOpenApiPrimitive)value; if (primitive.PrimitiveType != PrimitiveType.String) { return(null); } var stringPrimitive = (OpenApiPrimitive <string>)primitive; string memberName = namingContext.RegisterName(nameFormatter.Format(stringPrimitive.Value)); return(SyntaxFactory.EnumMemberDeclaration(memberName) .AddAttributeLists(SyntaxFactory.AttributeList().AddAttributes( CreateEnumMemberAttribute(stringPrimitive.Value)))); }
protected override YardarmTypeInfo GetTypeInfo() { INameFormatter formatter = Context.NameFormatterSelector.GetFormatter(NameKind.Class); NameSyntax ns = Context.NamespaceProvider.GetNamespace(Element); return(new YardarmTypeInfo(QualifiedName(ns, IdentifierName(formatter.Format(Operation.OperationId + "Request"))))); }
public override QualifiedNameSyntax GetChildName <TChild>(ILocatedOpenApiElement <TChild> child, NameKind nameKind) { QualifiedNameSyntax?name = Parent?.GetChildName(Element, nameKind); INameFormatter formatter = Context.NameFormatterSelector.GetFormatter(nameKind); if (name == null) { // At the components root, use the schema namespace return(QualifiedName( Context.NamespaceProvider.GetNamespace(Element), IdentifierName(formatter.Format(Element.Key + "-Item")))); } return(name.WithRight(IdentifierName( formatter.Format(name.Right.Identifier.ValueText + "-Item")))); }
private string GetClassName() { INameFormatter formatter = Context.NameFormatterSelector.GetFormatter(NameKind.Class); OpenApiOperation operation = Element.Parents().OfType <LocatedOpenApiElement <OpenApiOperation> >().First().Element; return(formatter.Format($"{operation.OperationId}UnknownResponse")); }
protected override YardarmTypeInfo GetTypeInfo() { INameFormatter formatter = Context.NameFormatterSelector.GetFormatter(NameKind.Class); NameSyntax ns = Context.NamespaceProvider.GetNamespace(RequestTypeGenerator.Element); TypeSyntax name = QualifiedName(ns, IdentifierName(formatter.Format($"{RequestTypeGenerator.Element.Element.OperationId}-HttpContent-Request"))); return(new YardarmTypeInfo(name)); }
protected virtual TypeSyntax GetTypeName() { ILocatedOpenApiElement <OpenApiMediaType>?mediaType = MediaTypeSelector.Select(RequestBodyElement); if (mediaType == null) { throw new InvalidOperationException("No valid media type for this request"); } ILocatedOpenApiElement <OpenApiSchema>?schemaElement = mediaType.GetSchema(); if (schemaElement != null && (schemaElement.Element.Type != "object" || schemaElement.Element.Reference != null)) { return(Context.SchemaGeneratorRegistry.Get(schemaElement).TypeName); } INameFormatter formatter = Context.NameFormatterSelector.GetFormatter(NameKind.Class); NameSyntax ns = Context.NamespaceProvider.GetNamespace(RequestBodyElement); if (RequestBody.Reference != null) { // We're in the components section return(SyntaxFactory.QualifiedName(ns, SyntaxFactory.IdentifierName(formatter.Format(RequestBody.Reference.Id + "RequestBody")))); } else { // We're in an operation var operation = RequestBodyElement.Parents().OfType <LocatedOpenApiElement <OpenApiOperation> >().First().Element; return(SyntaxFactory.QualifiedName(ns, SyntaxFactory.IdentifierName(formatter.Format(operation.OperationId + "RequestBody")))); } }
public override QualifiedNameSyntax GetChildName <TChild>(ILocatedOpenApiElement <TChild> child, NameKind nameKind) { QualifiedNameSyntax?name = Parent?.GetChildName(Element, nameKind); INameFormatter formatter = Context.NameFormatterSelector.GetFormatter(nameKind); if (name == null) { // At the components root, use the responses namespace return(QualifiedName( GetNamespace(), IdentifierName(formatter.Format(Element.Key)))); } return(name); }
public override QualifiedNameSyntax GetChildName <TChild>(ILocatedOpenApiElement <TChild> child, NameKind nameKind) { QualifiedNameSyntax?name = Parent?.GetChildName(Element, nameKind); INameFormatter formatter = Context.NameFormatterSelector.GetFormatter(nameKind); if (name == null) { // At the components root, use the parameters namespace. In this case, use the key on the components // dictionary and not the parameter name, since multiple component parameters may have the same name. return(QualifiedName( GetNamespace(), IdentifierName(formatter.Format(Element.Key)))); } return(name); }
protected override YardarmTypeInfo GetTypeInfo() { SerializerDescriptor?serializerDescriptor = SerializerSelector.Select(Element)?.Descriptor; if (serializerDescriptor == null) { throw new InvalidOperationException($"No serializer configured for {Element}."); } INameFormatter formatter = Context.NameFormatterSelector.GetFormatter(NameKind.Class); NameSyntax ns = Context.NamespaceProvider.GetNamespace(RequestTypeGenerator.Element); TypeSyntax name = QualifiedName(ns, IdentifierName(formatter.Format($"{RequestTypeGenerator.Element.Element.OperationId}-{serializerDescriptor.NameSegment}-Request"))); return(new YardarmTypeInfo(name)); }
public string Format(string value) { if (string.IsNullOrEmpty(value)) { return(value); } if (value.Length == 1) { return(value.ToUpper()); } var camelCase = _camelCase.Format(value); var pascalCase = camelCase[0].ToString().ToUpper() + camelCase.Substring(1); return(pascalCase); }
public virtual string GetFieldName(string rosIdentifier) { return(_fieldNameFormatter.Format(rosIdentifier)); }
public virtual string GetConstantName(string rosIdentifier) { return(_constantNameFormatter.Format(rosIdentifier)); }