Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Give x-fern-examples separate fields for sample-name and language #5550

Open
cwcowell opened this issue Jan 7, 2025 · 0 comments
Open

Give x-fern-examples separate fields for sample-name and language #5550

cwcowell opened this issue Jan 7, 2025 · 0 comments
Labels
feature Requests for new features. product/docs Fern Docs which builds and hosts a developer documentation site

Comments

@cwcowell
Copy link
Contributor

cwcowell commented Jan 7, 2025

Feature Description

We add sample code for each API operation's x-fern-examples > code-samples field in openapi.yaml. This is successfully shown to the user in a sample code box.

image

We include 3 types of sample code in that box for each API operation, showing 3 ways of accessing that API operation:

  • Make a direct API call with curl. For this sample code, we set the code sample’s language field to curl
  • Make a direct API call with Python. For this sample code, we set the code sample’s language field to Python API
  • Make an API call with the Python SDK. For this sample code, we set the code sample’s language field to Python SDK

This approach mostly works: we see all 3 values in the dropdown, and sample code for each shows correctly.

2025-01-07_14-53-34 (1)

The one problem we have with this approach stems from the fact that for each code sample, the x-fern-examples > code-samples > language field sets both the dropdown option name and the language. The former is needed to populate the dropdown picker, and the latter is needed to figure how to do syntax highlighting for the sample code.

This means that if we set the language field to Python API or Python SDK, it can’t tell what language the sample code is in, so it disables syntax highlighting.

image

To preserve syntax highlighting, we’d like a way to specify the dropdown option name separately from the language of the sample code.

For example, maybe have these 2 fields for each piece of sample code in openapi.yaml:

  • x-fern-examples > code-samples > sample-name which might be set to “Python SDK"
  • x-fern-examples > code-samples > language which might be set to “python”

In openapi.yaml the proposed scheme might look like this:

      x-fern-examples:
        - code-samples:
            - sample-name: curl
              language: bash
              code: curl foo
            - sample-name: Python API
              language: python
              code: print("bar")
            - sample-name: Python SDK
              language: python
              code: print("baz")

Use Case

see above

Proposed Experience (Optional)

see above

Alternatives Considered (Optional)

No response

@cwcowell cwcowell added feature Requests for new features. product/docs Fern Docs which builds and hosts a developer documentation site labels Jan 7, 2025
@cwcowell cwcowell changed the title Give x-fern-examples separate fields for code-title and language Give x-fern-examples separate fields for sample-name and language Jan 7, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature Requests for new features. product/docs Fern Docs which builds and hosts a developer documentation site
Development

No branches or pull requests

1 participant