-
Notifications
You must be signed in to change notification settings - Fork 6.2k
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
OpenAPI spec for the REST API #2566
Comments
I ran across this project the other day that could be of some use when using a code first approach: https://github.com/bee-travels/openapi-comment-parser. However, I agree that using annotations or a middleware would be more preferable. |
Does it have to be automated from the beginning, or could we start with a manually edited file? |
It doesn't have to be automated. Having an OpenAPI spec for services included out of the box could be a good start. |
@taras wanna take a stab at it? |
I wouldn't mind but we need a way to ensure that they stay current. Any ideas? |
I think it looks like express-openapi indeed produces a complete specification, although you will have to write the spec for each route manually. The upside to that vs a completely manual spec on the side is that you get the spec closer to the implementation. You may also get validation middlewares for your routes (both for request and response data) amongst others, if desired.. ;) |
I tried out https://github.com/bee-travels/openapi-comment-parser recently and it will generate the openapi spec through JSDoc comments. It's still manual, but the spec ends up being right right above the code. I haven't tried it, but I suspect you could use some of the existing openapi tools like validation in conjunction with this approach. |
looked a bit more at express-openapi, and I must say that I was stumped to learn that you had to put your implementation along with the spec.. I don't fancy the idea that the spec drives/dictates the implementation, it should be the other way around (the spec reflects the registered routes) |
@kaos I agree - spec and implementation should be separate. We've been experimenting with this inside of our Backstage instance for integrating with our platform. We've been able to decouple the frontend from backend development by using OpenAPI spec in the middle. We generate a client with autorest and use Prism to mock service while in development. We're going to put it through the grind internally and then make an RFC when we're happy with the workflow. |
Thanks for the update, looking forward to it :) |
Just bumping this to say that there's definite interest in this still! :) |
Hey @taras,
Just curious if there is anything you'd like to share on your experience so far on this setup that you mention! |
@OrkoHunter yep, the setup that we have right now is this,
This is pretty spiky at the moment because Autorest is quite heavy. We could create a leaner generator that generates hooks automatically and eliminate glue. Prism is also not exactly what we want to because it allows mocking by matching requests but not a high fidelity simulation. There is an issue to make Prism more realistic. I would like to see and contribute to is having OpenAPI spec for each service in Backstage. Then generate clients wether at built time or runtime from the OpenAPI spec. |
@taras I'm very interested in seeing how you generated the OpenAPI spec for the catalog API, do you mind sharing your implementation somewhere? Can you push up a branch showcasing what you've built so far? Our end goal is to be able to build a catalog-client from the OpenAPI spec for the |
👋 @alexcurtin we haven't integrated with the catalog so far. We only used the clients that we created to integrate services that already have OpenAPI specs into Backstage. I might have an opportunity to do it this week, but I'm trying to figure out how to validate the implementation. |
I'm looking at using json-schema-to-openapi-schema to convert at least a part of https://github.com/backstage/backstage/blob/master/packages/catalog-model/src/schema/kinds/API.v1alpha1.schema.json to YAML. From there, I'm going to try to create an OpenAPI spect that includes the routes and references the generated files. |
Nice. Yeah if we could reduce the duplication of defining the entity shape it'd be nice. But why API? I'd have expected Entity instead, since that's the actual return type. Unless you wanna get fancy and do oneOf each of the specific kinds, but the value of that is probably very limited especially since it won't account for custom kinds etc |
You're right. I referenced the wrong file. It was the last file opened in my tab instead of the proper file :) https://github.com/backstage/backstage/blob/master/packages/catalog-model/src/schema/Entity.schema.json is the right file. |
@freben I started creating a |
Uh, I am not sure. @Rugvip @benjdlambert @jhaals any input on that? Gut feeling says that the catalog API, for one, is a thing of its own and should go in the |
Thanks @sennyeya my goal is to be able to scaffold a repository/go application based on a OpenAPI 3 spec. The link requires running cli commands wasn't sure how to best handle that in a template. |
@freben @taras Wanted to follow up on this as I have some free time and #15667 was finally merged ❤️. Since we have a spec for the catalog now, I want to take a look at generating the catalog-client. I'm going to focus primarily on |
Hello, just wanted to mention a bit of awkwardness on the decision to generate OpenAPI 3.1 specifically for the catalog-backend as opposed to 3.0. I just tried loading the generated YAML into the backstage catalog so that users can explore the REST API definition within backstage itself and noticed that backstage swagger-ui cannot render OpenAPI 3.1 yet as detailed in #8090. Is there another solution in the meantime to make the backstage REST API also support generating version 3.0 until the built in swagger UI can be updated? I would love to be able to "dogfood" the tools within backstage to show how you can document backstage with backstage, including the REST API. |
Quick update for those following this,
Looking forward, there are a couple of interesting areas I'd like to start exploring,
For a more up to date version of the above, check out #17482 Additionally, if folks are interested in writing API specs for their own plugins, I've started some documentation at https://github.com/backstage/backstage/blob/master/docs/openapi/test-case-validation.md and will be adding more soon. |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
Hej @aramissennyeydd - do you think this should stay open? |
Thanks for your service 🖖 |
Context
An organization that I'm working with is considering adopting Backstage as their developer portal. One of the hard(ish) requirements that they have is that all services that we consume provide an API specification. This requirement exists because the infrastructure team needs to automate communication with services. If a specification is available, then they can use code generators to generate API clients for these services.
Feature Suggestion
It would be very helpful if there was a way to ensure that services integrated into Backstage come automatically with specifications. .NET, Rails & FastAPI all provide a mechanism that automatically generates an OpenAPI definition from route definition. I'm not aware of any tools that work like this in Node.js world.
Possible Implementation
express-openapi is a middleware that generates some specification from routes. It doesn't produce complete specifications - I don't even know if this is possible.
This request could also be satisfied by a GraphQL API that wraps services that Backstages consumes. The only consideration is making sure that the design of the APIs covers plugin services as much as possible.
The text was updated successfully, but these errors were encountered: