autorest icon indicating copy to clipboard operation
autorest copied to clipboard

Plan to support OpenAPI 3.0

Open hellosnow opened this issue 9 years ago • 42 comments

A quick questions on whether we have plan to support OpenAPI 3.0? Thanks!

hellosnow avatar Oct 31 '17 02:10 hellosnow

We are indeed discussing it and weighing it against other priorities - the main question is what OpenAPI 3.0 would enable us to do that wasn't possible before. It comes with great features, but many of them already have workarounds in Swagger 2.0 (x-nullable vs nullable, x-ms-parameterized-host vs servers, x-ms-skip-url-encoding vs allowReserved, etc.). Having a standard way to do stuff is obviously awesome and desirable, but given our resources, our efforts are mainly driven by enabling much required features rather than "refactoring" what was already possible before. 😐

Currently, one of the main features that could drive us towards OpenAPI 3.0 seems to be oneOf/anyOf, as we have encountered some popular scenarios that are not modelable in a satisfying way without those. Then again, it may be cheaper for us to bring x-oneOf/x-anyOf to Swagger 2.0. The thing is that once we advertise support for OpenAPI 3.0, we should support all of it.

So do we "plan to support OpenAPI 3.0"? Sure, but it is not a top priority. Driven by influx of customer scenarios and wishes, that priority may of course suddenly change 😉 This issue shall hereby be our way of communicating any changes to our plans/priorities and collect customer feedback!

olydis avatar Nov 03 '17 20:11 olydis

@olydis get it, sounds like Azure REST APIs will maintain in OpenAPI 2.0, before AutoRest supports 3.0?

hellosnow avatar Nov 06 '17 03:11 hellosnow

correct :-) in fact, for the Azure REST APIs repo, AutoRest isn't the only limiting factor, I think there is some other tooling consuming these specs, we'll have to make sure everything/everyone is ready before allowing 3.0 in that repo or even convert over

olydis avatar Nov 06 '17 20:11 olydis

@olydis get it now, thanks for the info!

hellosnow avatar Nov 07 '17 03:11 hellosnow

use cases encountered that call for OpenAPI 3.0

oneOf

  • some services return errors of different shape, but under same status code, with no discriminator (technically: this is often because ASP.NET may complain before even reaching the service, also the service may complain, so different models can show up on the same endpoint)
  • data factory has scenario of "expression" (string) vs object (=> primitive types obviously don't have a discriminator field, no way to model right now)

olydis avatar Nov 07 '17 23:11 olydis

Request/Response bodies can vary by media type in OAS 3.0.

https://swagger.io/docs/specification/describing-request-body/

    "requestBody": {
      "description": "Pet object that needs to be added to the store",
      "content": {
        "application/json": {
          "schema": {
            "$ref": "#/components/schemas/Cat"
          }
        },
        "application/xml": {
          "schema": {
            "$ref": "#/components/schemas/Lizard"
          }
        }
      },
      "required": false
    },

jonschoning avatar Nov 10 '17 19:11 jonschoning

Use case for OAS 3.0 Feature: Callbacks

To reduce the efficiency drain from constantly polling the status of operations, it would be better to set up a webhook to update the client when an operation is complete. Some services have monthly quotas of transactions that a user can perform, and polling detracts from the monthly quota with no real positive to the user (perhaps 5 requests are sent, but only one will say if an operation is complete). Related to this, webhooks are becoming more common either as standalone offerings, or coupled with a regular REST API.


OpenAPI 3 Snippet on Callbacks:

In OpenAPI 3 specs, you can define callbacks – asynchronous, out-of-band requests that your service will send to some other service in response to certain events. This helps you improve the workflow your API offers to clients.

A typical example of a callback is a subscription functionality – users subscribe to certain events of your service and receive notification when this or that event occurs. For example, an e-shop can send a notification to the manager on each purchase. These notifications will be “out-of-band”, that is, they will go in other connection than the connection in which a visitor works, and they will be asynchronous as they will be out of the regular request-response flow.

In OpenAPI 3, you can define the format of the “subscription” operation as well as the format of callback messages and expected responses to these messages. This description will simplify communication between different servers and will help you standardize use of webhooks in your API.

stevengum avatar Nov 28 '17 23:11 stevengum

Any update here, looks like this is still deprioritized? Have run into several situations where it would be useful to have OpenAPI 3 for client generation -- notably primitive return types with multiple possible values (oneOf) and serving the same API shape via two hosts with their own base paths (servers).

alexeldeib avatar Apr 29 '18 18:04 alexeldeib

We've done a bunch of work under the covers to support OAI3; unfortunately, your primary ask is literally the thing that's the most challenging to implement (oneOf).

With @olydis having moved on, I'm not likely going to get to this for a while yet.

fearthecowboy avatar Apr 29 '18 18:04 fearthecowboy

Thanks for the update Garrett -- Awesome to hear that, wasn't sure if this was underway at all so great to know it's on the road map (if not anytime soon).

alexeldeib avatar May 01 '18 01:05 alexeldeib

@fearthecowboy Anything the community can do to help move toward OpenAPI 3.0? I'm building a new API now, and would really love to have good tooling like this around a 3.0 spec, instead of using 2.0. Thanks!

anseljh avatar Jun 05 '18 13:06 anseljh

At this point, to accept the format (using no OAI3-specific features), I have to write a new loader pipeline. It's probably only about three days work, but it's queued up behind the critical work that I'm doing now. I'm quite sad I didn't get @olydis to do it before he left.

fearthecowboy avatar Jun 05 '18 16:06 fearthecowboy

@fearthecowboy, We are building .NET based solution for PSD2 and we have been relying on Autorest parser and generator. The Berlin Group as the most prominent PSD2 API standardization effort in Europe recently published their spec in OAS3 format. Given the number of countries backing this specific API standard, hundreds of banks are going to search for a REST API solutions compatible with OAS3.

It would be a really bad thing for those on .NET ecosystem to miss out or have to switch to Java in order to meet the regulatory deadlines.

How can we help accelerate the support for OAS3 in Autorest? Is such support realistic in next 4-5 weeks?

amilos avatar Aug 06 '18 11:08 amilos

I have a new hire starting soon; it's going to be his first task to enable the OAI 3.0 support in autorest.

The first cut won't have support for anyOf or oneOf, but the format should be able to be processed.

fearthecowboy avatar Aug 06 '18 15:08 fearthecowboy

We are developing APIs right now and want to make a decision on 2.0 or 3.0. Please could we know what the timelines look like?

nazneen84 avatar Jan 23 '19 20:01 nazneen84

Even I am looking for timeline on upgrade to 3.0

shwetashukla avatar Jan 23 '19 22:01 shwetashukla

OAI 3.0 would be great for AutoRest, The support by other tools is getting better (e.g. we now can import OAI3.0 specs into Postman), so new API's are likely to be 3.0.

klacol avatar Feb 03 '19 09:02 klacol

Initial Support for OpenAPI 3 is in the AutoRest 3.0 beta

To Upgrade to the beta:

npm install -g autorest@beta autorest --reset

fearthecowboy avatar Feb 22 '19 17:02 fearthecowboy

@fearthecowboy is there a repo with a changelog-type file so that developers can see what's available in the current beta?

Edit: This is a beta fresh off the press, but a roadmap (if available) would also be fantastic 😄

stevengum avatar Feb 22 '19 18:02 stevengum

No; I haven't done a changelog for it yet; so much coding, so little time 🍺

Mainly:

  • we rewrote a large part of the way that AutoRest loads files and resolve $refs , which allowed us to also load OpenAPI3 files.
  • some changes to allow Azure ARM specs to load all the specs for all the api versions, and then do processing on EVERYTHING.
  • enabled --powershell generator
  • enabled --interactive to assist in debugging the internals of AutoRest. (very cool to just watch it run :D )
  • refactored the repository layout quite a bit, using rushjs to build as a monorepo
  • we have a couple of pipeline steps that can radically optimize schemas (deduplication and subset-model-reduction) -- generators have to be updated to take advantage of those, so the PowerShell generator is the first one to use it. (the first deduplicates schemas that are identical, replacing them with a single common schema, and the second does analysis to find out if it can reduce duplication between schemas by making some inherit from others. )
  • Moved to Node10 -- should be a bit faster than before.

It's not a lot of new visibile features, but a hell of a lot of new code so we can implement a lot of new features.

fearthecowboy avatar Feb 22 '19 18:02 fearthecowboy