Skip to content

Support API mounting #2854

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

Closed
MaxenceMaire opened this issue Jan 8, 2022 · 7 comments
Closed

Support API mounting #2854

MaxenceMaire opened this issue Jan 8, 2022 · 7 comments
Labels
Moved to Moonwalk Issues that can be closed or migrated as being addressed in Moonwalk

Comments

@MaxenceMaire
Copy link

MaxenceMaire commented Jan 8, 2022

This follows a comment on issue #647.

It would be great to be able to mount API specs onto another spec for service composition.

As an example, I have two independent services A and B, both having their own OAS files. I would like to 'merge' A and B together into a single, centralized spec.

If both services have, say, a /resource endpoint, I would like to discriminate them by prefixing their paths with the name of the services, /A and /B respectively (resulting in /A/resource and /B/resource).

One naive solution would be to list and redefine each path in the root OAS file and $ref the related A or B content, but changing the design of either A or B would require updating the root OAS file.

A possible alternative would be to support path nesting (discarded here):

paths:
  '/A':
    '/resource':
       get:
           # ....
  '/B':
    '/resource':
       get:
           # ....

I suggest considering introducing a mount field under Path Item Objects and taking a Paths Object:

paths:
  '/A':
    mount:
      $ref: 'A.yaml#/paths'
  '/B':
    mount:
      $ref: 'B.yaml#/paths'
@SmallhillCZ
Copy link

SmallhillCZ commented Feb 15, 2022

I have the same use case, but I would rather show in some way, that under this path there is another API with its own spec and so I would rather reference not the paths included in its OAS, but the full OAS file. So more like a link to another API than a $ref.

@nickshoe
Copy link

nickshoe commented Feb 17, 2022

Another possibility could be to allow multiple $ref right under paths:

...
info: ...
tags: ...
...
paths:
  $ref: './service-a.yaml#/paths'
  $ref: './service-b.yaml#/paths'

Assuming that the content of the referenced file is the following:

# service-a.yaml
...
paths:
  '/service-a/foo':
    ...
# service-b.yaml
...
paths:
  '/service-b/bar':
    ...

The root spec content would finally be rendered as:

...
info: ...
tags: ...
...
paths:
  '/service-a/foo':
    ...
  '/service-b/bar':
    ...

Is this simplistic? I know that the current spec doesn't allow it, am I missing some hidden aspect about why it shouldn't be done this way in the first place?

@MaxenceMaire
Copy link
Author

I have the same use case, but I would rather show in some way, that under this path there is another API with its own spec and so I would rather reference not the paths included in its OAS, but the full OAS file. So more like a link to another API than a $ref.

@SmallhillCZ You make a good point. Especially since mounted APIs can live on different servers (or to specify useful metadata), I think it makes sense to include a complete OAS and not just the paths. A $ref could still work though I guess? (e.g. $ref: 'A.yaml' instead of $ref: 'A.yaml#/paths').

@MaxenceMaire
Copy link
Author

Another possibility could be to allow multiple $ref right under paths:

...
info: ...
tags: ...
...
paths:
  $ref: './service-a.yaml#/paths'
  $ref: './service-b.yaml#/paths'

Assuming that the content of the referenced file is the following:

# service-a.yaml
...
paths:
  '/service-a/foo':
    ...
# service-b.yaml
...
paths:
  '/service-b/bar':
    ...

The root spec content would finally be rendered as:

...
info: ...
tags: ...
...
paths:
  '/service-a/foo':
    ...
  '/service-b/bar':
    ...

Is this simplistic? I know that the current spec doesn't allow it, am I missing some hidden aspect about why it shouldn't be done this way in the first place?

@nickshoe As you noted, the spec says the following about this:

Any sibling elements of a $ref are ignored. This is because $ref works by replacing itself and everything on its level with the definition it is pointing at.

Meaning only one $ref is evaluated (hence the idea of a new property). Replacing paths with a list (instead of an object) would allow for multiple $ref, although it would also permit listing identical Path Item Objects multiple times (which I think is why paths is an object in the first place).

@nickshoe
Copy link

nickshoe commented Mar 2, 2022

@MaxenceMaire thanks for clarifying the use of $ref.

My example was an alternative proposal. Anyways, I like your proposal too (I've put a thumbs up).

We ended up defining separate OpenAPI documents for each microservice and using them independently. It would be nice to be able to squash together separate specs, without having to break them down according to the root keys of the spec. If conflicts arise, then one should handle them by changing one of the sub-specs.

@gimbimloki
Copy link

gimbimloki commented Mar 7, 2023

@nickshoe @MaxenceMaire

I asked "Reference Objects in Paths Object".
As a rsult, it is duplicated keys and it is not allowed in YAML/JSON.
I think we should find another? altinative? way(add new field, list and something... ).

@handrews handrews added the Moved to Moonwalk Issues that can be closed or migrated as being addressed in Moonwalk label Jan 27, 2024
@handrews
Copy link
Member

I believe this is addressed by OAS 4 Moonwalk's separation of concerns principle. Specifically:

I'm going to close this as "moved to moonwalk", but please join the linked discussion if you are still interested!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Moved to Moonwalk Issues that can be closed or migrated as being addressed in Moonwalk
Projects
None yet
Development

No branches or pull requests

6 participants
@SmallhillCZ @handrews @gimbimloki @MaxenceMaire @nickshoe and others