OpenAPITools / OpenAPITools/openapi-generator

[REQ] generate constants with OAuth scopes

Open
#7,895 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Enhancement: Feature
Dominant language
Java
Stars
26.8k
Forks
7.7k
PR merge metrics
PR metrics pending

Description

Is your feature request related to a problem? Please describe.

As a generated API user I want to reference to oauth scopes defined in the open api specification.

Describe the solution you'd like

The generator is aware of the available oauth scopes - it lists them in README.md.
It would be very useful to have a utility class that lists these scopes as string constants, so that they can be referenced by an API user. For example in java it could look like:

public class OAuthScopes {

    /**
    * scope description
    */
    public static final String SCOPE_AS_JAVA_CONSTANT = "actual.scope.name";
    /**
    * another scope description
    */
    public static final String ANOTHER_SCOPE = "another.scope";

    public static final List<String> ALL_SCOPES = List.of(
        SCOPE_AS_JAVA_CONSTANT,
        ANOTHER_SCOPE
    );
}

Describe alternatives you've considered

In theory one could just create a custom template to achieve this. However, due to mustache limitations the scope constant name would have to be defined in the scope data model on the generator side. As for now there is only scope name (scope) and description in the model (and of course the "hasMore").

Additional context

https://oauth.net/2/scope/

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with README.md and trace how the generator's scope data model exposes scope names and descriptions to templates, including the existing hasMore field. Define the generated Java output's constants and ALL_SCOPES collection, then verify that scope names, Java constant names, and descriptions are represented in generated clients.

Written by the indexing model from the issue text.

Assessment

Tech stack
java, openapi
Domain
api, tooling
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.