swagger-api/swagger-js

Is there something missing in supporting OAS3 servers?

fulviodenza opened this issue ยท 9 comments

From this line we deduce that is still something missing in the OAS3 servers support:

// TODO: OAS3: support servers here

Although it looks it already has been added support to it:
https://github.com/swagger-api/swagger-js/tree/96d261987700297a472db5587c0a8c769095d73e/src/execute

I found it a bit confusing, is it to delete?

char0n commented

Hi @fulviodenza,

Good question. Investigating....


Maybe slightly related: #2967

Hi @fulviodenza,

Good question. Investigating....

Maybe slightly related: #2967

We are already using the feature with no issues, opening a PR to remove the stale comment.

char0n commented

@fulviodenza yes I can confirm as well. Probably the intention was to make server URLs absolute using the spec url when they are represented as relative URI Reference, but that is already handled in baseUrl function.

char0n commented

On the other hand, the following code is fully OpenAPI 2.0 specific:

  if (specUrl && specUrl.startsWith('http')) {
    const parsed = new URL(specUrl);
    if (!spec.host) {
      spec.host = parsed.host;
    }
    if (!spec.schemes) {
      spec.schemes = [parsed.protocol.replace(':', '')];
    }
    if (!spec.basePath) {
      spec.basePath = '/';
    }
  }

I think what the // TODO: OAS3: support servers here comment is trying to relay to us that we should do the same for OpenAPI 3.x.y Server Object. Interpolating here probable intention for OpenAPI 3.x.y:

if (specUrl && specUrl.startsWith('http') && spec is OpenAPI 3.x.y) {
  if (!spec.servers) {
    spec.servers = [{ url: specUrl }];
  }
}

@fulviodenza what do you think?

char0n commented

I've issued #3219 to align the code with #3143 (comment)

char0n commented

Closed by #3219. @fulviodenza thanks for pointing this TODO comment out. It lead to adding missing piece of functionality!

char0n commented

OpenAPI 3.x.y spec actually tells us what to do when, the OpenAPI.servers field is missing or is defined as empty array:

image

I'll have to amend the implementation to reflect this.

char0n commented

Closed by #3220 which introduces spec compliant default for OpenAPI.servers field in OpenAPI 3.x.y definitions.

Sorry for not answering before didn't read, I'm happy this led to a fix!