Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support selection of Server Variables #315

Open
juliangrube1988 opened this issue Jan 16, 2024 · 0 comments
Open

Support selection of Server Variables #315

juliangrube1988 opened this issue Jan 16, 2024 · 0 comments
Labels
oas3.1 OpenAPI 3.1 specification support

Comments

@juliangrube1988
Copy link

juliangrube1988 commented Jan 16, 2024

OpenApi 3.1 allows a Server Variable Object like:

{
  "servers": [
    {
      "url": "https://{username}.gigantic-server.com:{port}/{basePath}",
      "description": "The production API server",
      "variables": {
        "username": {
          "default": "demo",
          "description": "this value is assigned by the service provider, in this example `gigantic-server.com`"
        },
        "port": {
          "enum": [
            "8443",
            "443"
          ],
          "default": "8443"
        },
        "basePath": {
          "default": "v2"
        }
      }
    }
  ]
}

ng-openapi-gen only uses the provided default values:

private readRootUrl() {
    if (!this.openApi.servers || this.openApi.servers.length === 0) {
      return '';
    }
    const server = this.openApi.servers[0];
    let rootUrl = server.url;
    if (rootUrl == null || rootUrl.length === 0) {
      return '';
    }
    const vars = server.variables || {};
    for (const key of Object.keys(vars)) {
      const value = String(vars[key].default);
      rootUrl = rootUrl.replace(`{${key}}`, value);
    }
    return rootUrl;
  }

It would be great if users can provide values for the variables

@luisfpg luisfpg added the oas3.1 OpenAPI 3.1 specification support label Sep 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
oas3.1 OpenAPI 3.1 specification support
Projects
None yet
Development

No branches or pull requests

2 participants