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

bug: multiple specs are not working #538

Open
dnalborczyk opened this issue Feb 15, 2021 · 8 comments
Open

bug: multiple specs are not working #538

dnalborczyk opened this issue Feb 15, 2021 · 8 comments
Labels
bug Something isn't working

Comments

@dnalborczyk
Copy link

dnalborczyk commented Feb 15, 2021

Describe the bug

applying multiple specs to middleware does not seem to be supported. only the very first applied spec is working.

I found this issue, but it applied to a previous version of this project, and indicated it should have been fixed:
#281

To Reproduce

[spec1, spec2].forEach((spec) =>
  app.use(
    middleware({
      spec,
      operationHandlers: {
		...
	  },
    }),
  )
)

Actual behavior
only first (spec1) spec is known and maps operation handlers.

Expected behavior
both specs should map operation handlers.

Examples and context

@dnalborczyk
Copy link
Author

dnalborczyk commented Feb 16, 2021

after some debugging I got it working removing this block:

throwing an exception.

it seems every schema enters lookupRoute:

const matched = lookupRoute(req);
, and if not found in the very first schema, it throws an exception.

@cdimascio cdimascio added the bug Something isn't working label Feb 17, 2021
@cdimascio
Copy link
Owner

cdimascio commented Feb 28, 2021

@dnalborczyk i added some new multi-spec tests. the tests essentially replicate the example 2 multi-spec. the tests succeed. one key difference is that the tests do not use operation handlers.

i wonder if this issue is specific to operation handlers?

would you mind modifying example 2 with a route or two from your spec. if it works, then I'll know the issue is related to operation handlers.

@dnalborczyk
Copy link
Author

@cdimascio thank you for looking into this!

would you mind modifying example 2 with a route or two from your spec.

yes, absolutely! I'll have a look tomorrow and report back. 👍

@dnalborczyk
Copy link
Author

dnalborczyk commented Mar 3, 2021

@cdimascio I added a (failing) multi spec test: #552 based on your other multi spec test.

notice that this test is not using any server url:

and therefore not any base paths:

@jp93arg
Copy link

jp93arg commented Aug 2, 2022

I'm currently facing the same issue. Is there any update?
Thanks in advance!

@juanda99
Copy link

juanda99 commented Jan 26, 2023

It fails also with v5, and it's not related to the usage of operationHandlers.

I fixed it simply by using one middleware per route, changing this in the docs example:

const versions = [1, 2];

for (const v of versions) {
  const apiSpec = path.join(__dirname, `api.v${v}.yaml`);
  app.use(`api_v${v}`,
    OpenApiValidator.middleware({
      apiSpec,
    }),
  );

  routes(app, v);
}

@PawSaj89
Copy link

I'm facing the same issue when applying multiple specs.
When I'm using 2 swaggers, endpoints from first swagger work properly but there are problems with second swagger.

@mauritsderoover
Copy link

mauritsderoover commented Feb 27, 2023

I had the same as well, loading it the way @juanda99 did, also did not fix it for me.

It works for the first set of routers that I pass with app.use(someRouterInstance)

What is interesting is that when I did
app.use("/api", OpenApiValidator.middleware({ apiSpec: C:/projects/skills/api-definitions/${definition}.yaml, validateResponses: true, }))

It actually works more or less. The requests get validated but the responses do not.

What I also think is very interesting is that when I add "/api", I can seem to use a relative path like this ./../../api-definitions ...

However when I do not use "/api", it is not able to find it this way

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

6 participants