ErikWittern / openapi-snippet

Generates code snippets for given Swagger / Open API documents
MIT License
115 stars 66 forks source link

Feature Request - Provide "aliases" for language labels #55

Closed thim81 closed 3 years ago

thim81 commented 3 years ago

Currently the generated examples are shown by their "full name"

Example: -t csharp results in the label Csharp + Restsharp (see screenshot).

CleanShot 2021-01-27 at 12 11 24@2x

It would be nice if an alias could be provided via the CLI to manipulate the label.

Example: -t csharp -a "C#" results in the label C#

ErikWittern commented 3 years ago

@thim81 Thanks for making that request. However, I am not sure I fully understand it. This project, openapi-snippet, does neither implement a CLI (which you mention in your text) nor a UI (which your screenshot shows). Could this issue maybe be resolved in the application / CLI that is using openapi-snippet in your use-case? Or am I missing something?

thim81 commented 3 years ago

@ErikWittern Thanks for looking into it and reaching out for more context.

The CLI inserts thex-codeSamples part in the Yaml/JSON spec file.

I'm looking for an option to manipulate the results a bit and modify the lang: Csharp + Restsharp to lang: C# (the passed on alias parameter value.

Currently x-codeSamples is added by the CLI

 x-codeSamples:
- lang: Csharp + Restsharp
          source: >-
            var client = new
            RestClient("https://demo.eu/api/lists/v2?%24top=SOME_INTEGER_VALUE&%24skip=SOME_INTEGER_VALUE&%24count=SOME_BOOLEAN_VALUE");

            var request = new RestRequest(Method.GET);

            request.AddHeader("X-ApiKey", "REPLACE_KEY_VALUE");

            IRestResponse response = client.Execute(request);

So perhaps there is an option to modify the lang: value and replace it with the Alias value.

I just used the screenshot to display the result, but that result is based on the OpenAPI spec with x-codeSamples part. If the request is confusing, let me know, so I'll try to provide more info.

ErikWittern commented 3 years ago

@thim81 Thanks for this additional information. The CLI you are using is implemented in another project, which likely depends on openapi-snippet. This library itself does not implement a CLI. I think that the CLI should provide the option you are seeking, I am not convinced this should be handled in openapi-snippet itself.

This library returns a result object, which contains an array of snippets. The CLI code could rewrite it using something like this:

const betterNamedSnippets = result.snippets.map(snippet => {
  return {
    title: title === 'Csharp + Restsharp' ? 'C#' : title,
    ...snippet
  }
})
thim81 commented 3 years ago

Thanks again for the input. I ll see what I can do to in the repo of the CLI wrapper. your example is handy to kickstart my effort for a PR.

ErikWittern commented 3 years ago

@thim81 Thanks for closing this, and good luck filing the PR in the CLI wrapper.