OpenAPI Integration with DocC "Proposal"

@sofiaromorales, Having attempted to generate basic documentation for conversion documentation, I am seeking guidance on the next steps to take. I have recently updated the GitHub repository.

docc convert symbolgraph.json --output-path docs

I’ve completed this step and now I’m wondering if I should try integrating it into the OpenAPI Generator. I’ve seen the basic structure in the documentation, and I need to integrate it with Swift-DocC.

Could you please review my updated proposal so that I can identify and address any potential issues?

Process request, please don't use bold (or caps lock), messages; it can come off somewhat disrespectful.

We'll be going over all proposals with mentors. When able to we try to provide extra feedback but please don't be pushy about it. Thank you!

1 Like

Apologies if I made any errors. Actually, I'm 20 years old, and this is the first time I'm applying for any open source program or even an internship, so I’m getting used to what to do or not. I wanted to ensure that I can continue working on the project as proof of concept. So far, I have successfully saved the symbolgraph.json file and executed the docC convert command. Here’s the code on GitHub, So that if I'm doing anything wrong, I can address the issue with feedback.

Also I have overlooked bold text as I have written it down in my reminders app to ask for a proposal review. I have simply copied and pasted the text from there.

Sorry for that. @ktoso

Will we be using AsyncHTTPClient Transport for Swift OpenAPI Generator to integrate the tool within the openapi generator? Also, since I’m hosting a documentation on an HTTP server and docC already has an implementation, do I need to write separate code for that, or can I use that implementation, as you mentioned earlier?

Hi Ayush. What's the benefit of using AsyncHTTPClient Transport?

I was browsing through the documentation and Introduction for OpenAPI Generator, as it was mentioned as a stretch goal. I noticed that OpenAPI Generator already has existing transport implementations. Which is using HTTP LIBRARY INTERFACE in the protocols ClientTransport and ServerTransport.

Existing Transfort Implementation

[Swift.org - Introducing Swift OpenAPI Generator]

I’m looking into how Open API operations map to Swift functions based on the transport. This will aid my tool in generating matching SymbolGraph symbols.

SymbolGraph might not directly show if a function is async, but we can add SymbolKit’s isAsync flag for HTTP operations.

AsyncHTTPClient Transport can handles many HTTP requests at once without waiting, using asynchronous, nonblocking operations. as it ensures the generated code and DocC documentation reflect these fast, async API calls for Swift developers.

In SymbolGraph, the signature field can include the async keyword. This way, DocC can handle async functions.

But I'm aware that asynchronous HTTP is a runtime concern and will have no major effect on documentation.

I'm just trying to understand how things are set up between OpenAPI and docC so it will help me better understand the workflow of code, if we go towards server implementation.

Currently, I have two dependencies that will map OpenAPI with Symbolgraph.

I’ve made some revisions to the proposal and added more explanations to make it clearer. Would you like me to explain the technical details in more detail? I’ve reviewed the documentation and even tried to implement some of the project components. Please share any other suggestions you have for improving the proposal, I’d love to hear them!

ThankYou.

1 Like

That's awesome that you've worked on a PoC! :star_struck:

Could you provide more details on how the mapping will work between the OpenAPI structure (the information, paths, and operations) and the SymbolKit symbol kinds? Are you planning to create new symbol types, or do the existing ones in SymbolKit already cover everything you need?

Also, do you have a working example of a REST API documented with DocC that people can check out?

Just a friendly reminder, the proposal needs to be submitted via the GSoC website, and the deadline is April 8 at 18:00 UTC.

1 Like

Hi @sofiaromorales, thank you for the feedback!

In the initial phase of hosting, I’ve set up the project at https://ayushshrivastv.github.io/OpenAPI-integration-with-DocC/ with a landing page linking to the documentation.

For the mapping process, the API root (info) maps to swift.module, schemas to swift.struct, properties to swift.property, operations (GET /users) to swift.func, parameters to swift.var, and responses to swift.enum. Currently, I believe SymbolKit’s existing kinds cover everything, so we won’t need any new types.

Code GitHub - ayushshrivastv/OpenAPI-integration-with-DocC: OpenAPI Integration with Swift-DocC: Automated API Documentation Generation

I’m curious to know if this approach is what you had in mind or if there’s anything I might be missing. I just want to make sure I’m on the right track!

Also, do you think I should expand on the mapping details further in the proposal before I submit the final draft by tomorrow.

1 Like

I’ve submitted two pull requests to address the issues

  1. Added a Validation that checks all OperationIds valid
    Added a Validation that checks all operationIds in Link objects are valid by ayushshrivastv · Pull Request #404 · mattpolzin/OpenAPIKit · GitHub

  2. Added vendor extension support to Content.Encoding type
    Add vendor extension support to Content.Encoding type by ayushshrivastv · Pull Request #405 · mattpolzin/OpenAPIKit · GitHub

I’ve submitted my final proposal for the OpenAPI Integration with DocC Project on the Google Summer of Code Page.

While I could provide additional details, I think it would get too complicated. Since the proposal already has sixteen pages, instead I’ve added OpenAPI Integration with the DocC GitHub repository code link. This code has all my current progress, so it will be easy to run and test the initial development phase.

Final Submitted Proposal Google Summer of Code @Swift.pdf - Google Drive

Thank you so much for all the help! @sofiaromorales

1 Like

I need help with an issue I’ve been encountering when attempting to create a pull request for the Swift DocC repository. Despite disabling all reformatted settings, I’m noticing an excessive number of whitespaces being added to the entire file during the staging process. This issue is specific to this repository and doesn’t affect other repositories.

I’ve raised two PRs in the OpenAPIKit repository, and there wasn’t any such issue. I’m also not encountering any problems with current working project OpenAPI Integration with DocC repository.

I have tried git diff --cached, but still, the issue persists. I have already worked on issues Warn when the documentation contains more than one root page · Issue #1170 · swiftlang/swift-docc · GitHub, Order articles by title instead of by path · Issue #1192 · swiftlang/swift-docc · GitHub, but I'm unable to raise PR due to so many whitespaces in the files.

The Pull Request has been successfully merged, and I’ve also included it in the proposal.

OpenAPI Integration with DocC Project

Hi Everyone!

I've been working on OpenAPI Integration with DocC Project for the Google Summer of Code @Swift Project.

I'm excited to share my current progress on integrating OpenAPI specifications with DocC documentation. This project aims to create a seamless experience for Swift developers by converting OpenAPI documents into DocC compatible documentation, making API references consistent with the rest of the Swift ecosystem.

Current Progress

I've developed a working conversion tool that transforms OpenAPI documents into SymbolKit symbol graphs, which can then be processed by DocC to generate documentation.

Mapping OpenAPI to SymbolKit

Mapping OpenAPI to SymbolKit starts with defining a central container. A top level module symbol, that acts as the root of the API structure. Everything else is organised under this container to form a clear, modular layout that reflects the overall design of the API.

Each schema or model in the OpenAPI document is turned into a corresponding symbol in SymbolKit. The properties within these schemas are mapped as variables, with their types, constraints, and descriptions all preserved. This helps ensure the documentation remains accurate, readable, and fully aligned with the API's intended behavior.

API operations, like GET and POST are handled like functions. Each one includes its input parameters such as path, query, and body data and clearly defines what it returns by linking to the right model. This gives a structured, predictable view of how the API behaves.

To tie everything together, we define relationships between these symbols using SymbolKit’s built in types like .memberOf and .returns. These links show how different pieces are related, for example, which functions belong to which modules, and which models are returned from which endpoints. The result is a clean, well organised symbol graph that makes the entire API easy to explore and document using DocC.

Right now, most of this logic lives in the SymbolMapper struct located in Sources/SymbolMapping.swift, which implements the core logic for mapping OpenAPI elements to SymbolKit symbols.


OpenAPISymbolKind Enum

Defines internal symbol types (.namespace , .endpoint , .schema ) for mapping OpenAPI content to SymbolKit constructs.

enum OpenAPISymbolKind {
    case namespace
    case endpoint
    case schema
    case property
}

mapSchemaType Function

This function takes an OpenAPIKit.JSONSchema and recursively maps OpenAPI data types to their Swift equivalents, extracting constraints along the way.

static func mapSchemaType(_ schema: OpenAPIKit.JSONSchema) -> String {
    switch schema.coreContext.type {
    case .string:
        return "String"
    case .number:
        return "Double"
    case .integer:
        return "Int"
    case .boolean:
        return "Bool"
    case .array:
        if let items = schema.items {
            return "[\(mapSchemaType(items))]"
        }
        return "[Any]"
    case .object:
    default:
        return "Any"
    }
}

createSymbol Function

Creates a symbol based on the given kind, name, identifier, and path. Converts OpenAPISymbolKind into SymbolKit types like .schema → swift.struct .

static func createSymbol(
    kind: OpenAPISymbolKind,
    identifier: String,
    title: String,
    description: String?,
    pathComponents: [String]
) -> (SymbolGraph.Symbol, SymbolGraph.Relationship?)

createOperationSymbol Function

Builds symbols for HTTP methods like GET , POST , etc., combining route metadata and linking it to relevant schemas.

static func createOperationSymbol(
    operation: OpenAPI.Operation,
    path: String,
    method: String
) -> (symbol: SymbolGraph.Symbol, relationships: [SymbolGraph.Relationship]) {

createSchemaSymbol Function

Maps each schema into a swift.struct , including nested properties and relationships back to parent models.

static func createSchemaSymbol(
    name: String,
    schema: OpenAPIKit.JSONSchema
) -> (symbol: SymbolGraph.Symbol, relationships: [SymbolGraph.Relationship]) {

All the above logic comes together to generate a SymbolGraph , which DocC then uses to build final documentation.

let symbolGraph = SymbolKit.SymbolGraph(
    metadata: SymbolKit.SymbolGraph.Metadata(
        formatVersion: SymbolKit.SymbolGraph.SemanticVersion(major: 1, minor: 0, patch: 0),
        generator: "OpenAPItoSymbolGraph"
    ),
    module: SymbolKit.SymbolGraph.Module(
        name: "API",
        platform: SymbolKit.SymbolGraph.Platform(/* details */)
    ),
    symbols: symbols,
    relationships: relationships
)

I've added a code base link for the complete mapping process as this post just summarizes the mapping process. You can refer to the code base if I missed something here.

SymbolGraph Mapping Code link

OpenAPI to Symbol Graph Code link


So far, I’ve only used existing SymbolKit symbol kinds - I haven't needed to create new ones.


Swift Build Command Output

$ swift build
Building for debugging...
[7/7] Linking openapi-to-symbolgraph
Build complete! (1.37s)

After building, I ran a sample API file

$ swift run openapi-to-symbolgraph api.yaml
Building for debugging...
[7/7] Applying openapi-to-symbolgraph
Build of product 'openapi-to-symbolgraph' complete! (1.37s)
Parsing YAML...
Processing paths...
Processing schemas...
Symbol graph generated at /Users/ayushsrivastava/OpenAPI-integration-with-DocC/openapi.symbolgraph.json

This confirms that the tool is working as expected and the generated symbolgraph.json is ready for DocC conversion.

This .json symbol graph is then processed by DocC to produce user friendly documentation.

  "metadata": {
    "formatVersion": { "major": 0, "minor": 5, "patch": 0 },
    "generator": "openapi-to-symbolgraph"
  },
  "module": { "name": "API", "platform": {} },
  "symbols": [
    {
      "identifier": { "precise": "API", "interfaceLanguage": "swift" },
      "kind": { "displayName": "Module", "identifier": "swift.module" },
      "names": { "title": "PetStore API" },
      "docComment": { "lines": [{ "text": "A sample Pet Store API" }] }
    },
    {
      "identifier": { "precise": "s:API.Pet", "interfaceLanguage": "swift" },
      "kind": { "displayName": "Struct", "identifier": "swift.struct" },
      "names": { "title": "Pet" },
      "docComment": { "lines": [{ "text": "A pet in the store" }] }
    }
  ],
  "relationships": [
    {
      "source": "s:API.Pet",
      "target": "API",
      "kind": "memberOf"

Symbol graph contains API information for DocC.

dependencies: [
        .package(url: "https://github.com/mattpolzin/OpenAPIKit.git", from: "3.1.0"),
        .package(url: "https://github.com/swiftlang/swift-docc-symbolkit.git", from: "1.0.0"),
        .package(url: "https://github.com/apple/swift-argument-parser.git", from: "1.2.0"),
        .package(url: "https://github.com/jpsim/Yams.git", from: "5.0.0"),

This tool reads OpenAPI documents in YAML or JSON formats using the OpenAPIKit library. It takes the entire API structure, including operations, schemas, and relationships, and maps everything into a symbol graph.

This process keeps all the detailed documentation, like descriptions, examples, and status information, intact. After building the symbol graph, the tool outputs a standard JSON file that DocC can process to generate the final, user friendly documentation.

The conversion process involves parsing the OpenAPI document, creating and mapping a symbol graph, linking together all the elements, and then using DocC to produce the final documentation.

Right now, the tool can successfully parse OpenAPI documents.

Read the OpenAPI document

Creates valid symbol graph files

Handles schemas, operations, and their relationships

Has some symbol resolution issues when generating DocC documentation. In coming days, I will try to solve this issue while creating a REST API example.

I'm working on creating a publicly accessible example of a REST API documented with DocC. Currently, test APIs generate valid symbol graphs, but the final DocC integration needs some enhancement before sharing a public demo. But I'll have a well crafted example for a REST API that is documented using DocC before the Google Summer of Code period begins.

You can check out the initial project approach on GitHub
OpenAPI Integration with DocC

Solution

swift run openapi-to-symbolgraph <path-to-openapi.json>: Runs the tool to parse the OpenAPI document and generate `symbolgraph.json`.

docc convert symbolgraph.json --output-path docs: Converts the generated SymbolGraph into HTML documentation

Once we run the command to convert the symbolgraph.json into HTML documentation, the resulting files will be in the docs folder. Then we can host the static docs folder generated by DocC on an HTML server.

After that we can view the generated documentation for a sample User API at
https://ayushshrivastv.github.io/OpenAPI-integration-with-DocC/


While working on the issue in the repository OpenAPIKit, where I was attempting to add a validation that checks all operationIds in Link objects are valid, during the debugging process I got a better approach from my initial thinking of how we can use the mapping process, and I've started working on that approach as well.

For that, I've opened a pull request that proposes different approaches to the mapping process https://github.com/ayushshrivastv/OpenAPI-integration-with-DocC/pull/34. At present, I'm trying to work on branch before merging it to the main, where initial development is ongoing.


Additionally, these two pull requests have been successfully "Merged" into the OpenAPIKit Code base.



Thank you, @mattpolzin, for taking your time and assisting me!

I’ve spent the last few weeks working on this project and reading the surrounding documentation and code, and this post serves as my current progress after a month!

Since you all have more experience working with OpenAPIKit and DocC Codebases. If you guys can look into the actual code, that would be really helpful to clarify things.

In the coming weeks, I’ll first attempt to generate a REST API documented using DocC. I’ll also improve the code line up, as there are some version related warnings that are need to be addressed. Additionally, I’ll further enhance the path, schema, and query functions for mapping process and api operations.

I'd love to hear your feedback @sofiaromorales @ktoso @Honza_Dvorsky on the mapping approach and any suggestions for improving the integration between OpenAPI and DocC from the Swift community that will be highly helpful!

Thank you, and I look forward to your feedbacks! :evergreen_tree:

Ayush Srivastava

1 Like