Comments (7)
@chris48s @bourdakos1 have there been any developments on the additional language examples functionality you mentioned in number 2? At the very least an update to the docs to indicate to users that they can set something like the following in their theme config:
// working theme config edit to add more languages
themeConfig:
/** @type {import('docusaurus-preset-openapi').ThemeConfig} */
({
languageTabs: [
{
tabName: "cURL",
highlight: "bash",
language: "curl",
variant: "curl",
options: {
longFormat: false,
followRedirect: true,
trimRequestBody: true,
},
},
{
tabName: "Javascript",
highlight: "javascript",
language: "javascript",
variant: "fetch",
options: {
ES6_enabled: true,
trimRequestBody: true,
},
},
...
I've noticed that while this does generate the code for all supported languages from the postman-code-generator, it doesn't support highlighting for all the languages via prism-react-renderer. For example python, javascript (axios and fetch), and go all highlight perfectly. However when I try the same pattern set for the other languages but specifying something like Dart, Swift, Ruby, or Rust - the highlighting no longer works.
So, TLDR: I think this open issue sounds like a lot of great ideas and I think even just adding more clear support for other language examples as part of these customization enhancements would be quite useful as an end user!
// This generates the code but highlighting does not work
{
tabName: "Rust",
highlight: "rust",
language: "rust",
variant: "reqwest",
options: {
followRedirect: true,
trimRequestBody: true,
},
},
from docusaurus-openapi.
The way we solved this was:
docusaurus-theme-openapi >=0.6.4
allows the Curl
component to be swizzled in isolation
We made a custom Curl
component which substitutes the placeholder string $url
in examples from x-code-samples
with postmanRequest.url.toString()
: https://github.com/badges/shields/blob/master/frontend/src/theme/ApiDemoPanel/Curl/index.js#L188-L191
We define our code examples in x-code-samples
. So our x-code-samples
block might look like
"x-code-samples": [
{
"lang": "URL",
"label": "URL",
"source": "$url"
},
{
"lang": "Markdown",
"label": "Markdown",
"source": "![PyPI - License]($url)"
},
{
"lang": "reStructuredText",
"label": "rSt",
"source": ".. image:: $url\n: alt: PyPI - License"
},
{
"lang": "AsciiDoc",
"label": "AsciiDoc",
"source": "image:$url[PyPI - License]"
},
{
"lang": "HTML",
"label": "HTML",
"source": "<img alt=\"PyPI - License\" src=\"$url\">"
}
]
..and then the page that generates is https://shields.io/badges/py-pi-license
Not sure how much that helps. This works for us, but it might not be the right solution for everyone. The way we are using this is a bit esoteric in some ways, but quite simple in others.
from docusaurus-openapi.
2 and 3 sound good to me :)
for 1 have you tried swizzling? https://docusaurus.io/docs/swizzling Iβve never done it before, but this sounds like it might be a good use case? If it works we can better document it so that others can easily create their own response panels
from docusaurus-openapi.
Thanks for the response. I must admit, I am a first-time swizzler π . Conceptually this seems a lot like the solution I was looking for. It also seems like marking certain components as 'safe' means there is already a mechanism to provide a stable plugin interface.
Having had a bit of an experiment, here's some findings:
I was not able to swizzle the Response
component in isolation. When run npm run swizzle
, it is listed as a component I can swizzle and does spit out a file I can modify, but I still have to swizzle the whole ApiDemoPanel
component to get it to pick up the local version of the component, so that didn't really help. Same thing for the Curl
component.
My theory is that this is either to do with
- The nested structure (
Response
is a subdir underApiDemoPanel
) or - The import statements are relative paths (i.e:
import Response from "./Response";
notimport Response from "@theme/ApiDemoPanel/Response";
, or whatever)
or possibly a combination of both, but I haven't really dug into it.
One thing I was able to do using this approach was I removed the pagination by swizzling the core DocPaginator
component and replacing it with
import React from 'react';
export default function DocPaginator(props) {
return '';
}
so that worked at least.
from docusaurus-openapi.
Yea, Iβm guessing itβs the relative imports. Looking at the standard Docusaurus theme, they have a nested structure, but use β@theme/β¦β for all imports. We should update all of our imports to match.
from docusaurus-openapi.
Thanks so much for the reply! I'll take a look at this and see how you all managed to get the functionality implemented.
from docusaurus-openapi.
@brittonhayes did you ever figure out how to get syntax highlighting working with Rust, Java, C# etc?
from docusaurus-openapi.
Related Issues (20)
- Fix for header auth persistence.
- Error: `Cannot mix different versions of joi schemas` when adding docusaurus-plugin-openapi.
- bug: hideable for sidebar is not fully supported HOT 1
- oneOf doesn't work HOT 1
- Add visual indicator for deprecated path parameter
- Add visual indicator for deprecated request/response body field
- Response schema marked as "Optional"
- Getting theme error while useing @docusaurus/preset-classic with docusaurus-plugin-openapi in plugins HOT 2
- Code examples tabs overflow in narrow browser windows
- Quick Overview failing HOT 1
- Support of readonly attributes HOT 1
- MDX content in params is displayed in form elements HOT 1
- embed generated API menu in an existing sidebar
- This page crashed - URI malformed - When inserting win10 keyboard emoji on api field HOT 6
- Mocking all the request/responses interactions
- Postman collection support
- Docusaurus 3.0 support HOT 4
- formatting issues in v0.7.0 HOT 3
- cURL highlighting issues on 0.7.1 HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
π Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. πππ
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google β€οΈ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from docusaurus-openapi.