Skip to content

Feature Idea - Provide "aliases" for language labels #4

Description

@thim81

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

Example: -t csharp results in the label Csharp + Restsharp

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#

The feature idea would provide the option to manipulate the results and modify the lang: Csharp + Restsharp to lang: C# (the passed on alias parameter value).

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

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.

fetchSnippets(api: OpenAPI.Document, path: string, method: string, targets: ReadonlyArray<string>) {
    const snippets = OpenAPISnippet.getEndpointSnippets(api, path, method, targets)
      .snippets
      .map(snippet => ({ lang: snippet.title, source: snippet.content }))
    return snippets
  }

The openapi-snippet library returns a result object, which contains an array of snippets, so potentially we can transform the lang: snippet.title with the "alias" value in the fetchSnippets function.

I pitched the idea to "ErikWittern" (owner of the "openapi-snippet"), he suggested that the use-case would fit better in the CLI.

Would this be a valuable addition for the openapi-snippet-cli package?
If it would, how would you prefer the structure the param to pass the "alias" label, so I can perhaps create PR for it.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions