question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Generate schema descriptions from XML docstrings

See original GitHub issue

Is your feature request related to a problem? Please describe. Currently the only way to provide descriptions to the GraphQL schema built using Hot Chocolate is through fluent APIs such as overriding the ObjectType<T>.Configure(IObjectTypeDescriptor<T>) method.

Describe the solution you’d like I would like the XML docstrings that are part of my codebase to automatically generate descriptions in the generated GraphQL API. This will reduce the amount of effort required to properly document both my API and the C# code I write. As an example, given the following C# code

/// <summary>
/// Represents a character in the game.
/// </summary>
public class Character
{
    /// <summary>
    /// The name of the character.
    /// </summary>
    public string Name { get; set; }
}

then querying the API’s for the Character type would present the following.

// GraphQL query
query {
  __type(name: "Character") {
    name,
    description,
    fields {
      name,
      description
    }
  }
}

// Response
{
  "data": {
    "__type": {
      "name": "Character",
      "description": "Represents a character in the game."
      "fields": [
        {
          "name": "name",
          "description": "The name of the character."
        }
      ]
    }
  }
}

The XML docstrings could serve as the default description for any types or queries, then be overridden by the fluent APIs.

Describe alternatives you’ve considered

  • The primary method of accomplishing this is to write duplicate documentation between XML docstrings and and the fluent APIs, leaving the possibility for inaccurate or mismatching documentation.
  • I was able to build some extension methods that use NJsonSchema to pull in property, class, and method XML doc summaries. Although it’s possible to build the functionalities independently, it would be nice for this type of functionality to be supported out of the box.
    • One barrier I’ve encountered is adding descriptions for arguments to methods. If I only include a description then a HotChocolate.SchemaException is thrown due to a null value for the typeReference parameter. This can be overcome by manually including some kind of type mapping. I’m still exploring Hot Chocolate, so perhaps there is already a service/tool that can handle mapping default type mappings to IInputTypes?

Additional context Other open source projects use XML documentation to generate API documentation for Swagger documents. Example projects include NSwag and Swashbuckle.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:14 (14 by maintainers)

github_iconTop GitHub Comments

1reaction
michaelstaibcommented, May 16, 2019

I have created a documentation task so that we do not forget about it #753

1reaction
michaelstaibcommented, May 16, 2019

@willwolfram18 have you joined out slack channel?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Generate schema descriptions from XML docstrings #715
The primary method of accomplishing this is to write duplicate documentation between XML docstrings and and the fluent APIs, leaving the ...
Read more >
document APIs using /// comments
Learn about documentation comments. You can create documentation for your code by including XML elements in special comment fields.
Read more >
Generating Documentation for an XML Schema
To generate documentation for an XML Schema document, select XML Schema Documentation from the Tools > Generate Documentation menu or from the Generate...
Read more >
XML Documentation - C# in a Nutshell [Book]
XML Documentation C# offers three different styles of source-code ... a common next step is to run the XML through XSLT, generating HTML...
Read more >
Command Line - xsData 21.11 documentation
Commands: generate* Generate code from xml schemas, webservice definitions and... download Download a schema or a definition locally with all its...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found