Giter Club home page Giter Club logo

Comments (9)

MikeRalphson avatar MikeRalphson commented on July 17, 2024 1

@corvinusy there is a new option --environment or -e which allows you to load an options object from a file in yaml or json format at runtime without requiring a wrapper script. This should make it easier to override the language_tabs or any other options.

I've just released v2.2.0 including this enhancement.

Please feel free to re-open this issue if you encounter the output corruption bug again.

from widdershins.

MikeRalphson avatar MikeRalphson commented on July 17, 2024

Hi @corvinusy yes there's a couple of existing ways of doing this.

If you have x-code-samples specification extensions in your OpenAPI definition, you can use the --lang switch to enable automatic detection of the necessary language tab entries.

If you are using the programmatic API, you can specify in your options object that you want to override the default language-tabs.

E.g.

var converter = require('widdershins');
var options = {};
options.language_tabs = [{ 'http': 'HTTP' }, { 'javascript': 'JavaScript' }, { 'javascript--nodejs': 'Node.JS' }, { 'python': 'Python' }, { 'ruby': 'Ruby' }];
converter.convert(swaggerObj,options,function(err,str){
  //
});

This would only output the language-tabs specified (omitting shell and java). I have updated the README file to make this clearer.

If you need to do this from the command-line, I can see a potential way to do it, by allowing a config-file to be read to set the default options. Would this be of help?

Can I also ask whether you are using the npm package, or direct from git?

from widdershins.

corvinusy avatar corvinusy commented on July 17, 2024

I use npm package and run it in terminal as CLI-command.
I have generated openapi.json from other source language tool and want to create static *.md for project documentation.
I always tried to modify source code by removing items from language_tabs directly, but this lead to corrupted output.

Now I see how to do it with JS-wrapper script.
Thank you for fast reaction.

The issue can be closed if you don't want to see it as a reminder to update README or to provide some wrapper.

from widdershins.

MikeRalphson avatar MikeRalphson commented on July 17, 2024

Great. I'll leave the issue open for a while, in case you hit any snags (like corrupted output) when trying to override the language_tabs option. I've updated the README now, but the ability to read the options in from a config file might still be useful...

from widdershins.

corvinusy avatar corvinusy commented on July 17, 2024

If you need details about corrupted output: I removed all languages except shell, nodejs and python. And got not a properly closed sample tag (```) and end-braces. Seems nodejs sample generation has a dependency on pure javascript one.

Anyway, thank you for this good tool.

from widdershins.

MikeRalphson avatar MikeRalphson commented on July 17, 2024

Thanks for letting me know, I'll try it out a couple of ways and see if I can reproduce it.

from widdershins.

MikeRalphson avatar MikeRalphson commented on July 17, 2024

I've just realised the example above and in the README was wrong, you now need to pass a callback to the convert function, which takes an err and str parameters:

var converter = require('widdershins');
var options = {};
options.language_tabs = [{ 'http': 'HTTP' }, { 'javascript': 'JavaScript' }, { 'javascript--nodejs': 'Node.JS' }, { 'python': 'Python' }, { 'ruby': 'Ruby' }];
converter.convert(swaggerObj,options,function(err,str){
  // str contains the output markdown
});

from widdershins.

areebaasad77 avatar areebaasad77 commented on July 17, 2024

Hi. Is there a way I can get C# code through widdershins in my langugage tab?

from widdershins.

MikeRalphson avatar MikeRalphson commented on July 17, 2024

Hi, @areebaasad77 there's a number of ways to do it!

  • Create a code_csharp.dot template and specify a --user_templates option
  • Include x-code-samples extensions in your API definition and use the --lang option
  • Use the --httpsnippet and --language-tabs options

All as per the help / README. If you did option 1 then you could contribute it back as a pull request.

Let me know if you need anything further.

from widdershins.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.