redoc icon indicating copy to clipboard operation
redoc copied to clipboard

Add x-immutable vendor extension

Open codyaray opened this issue 4 years ago • 7 comments

Hi - One of the issues we're running into with our API spec and API docs is around immutable properties. That is, a property that can be set on create (POST) but not updated later (via PATCH or PUT).

Today ReDoc shows immutable: true inside the "Request Body Schema" since I'm using an x-immutable: true vendor extension in my OpenAPI doc. However, what I'd really like is to just not show these properties in the Request Body Schema on PUT/PATCH at all.

Screen Shot 2020-06-04 at 3 32 25 AM

Ideally this immutable attribute would be standardized by OpenAPI itself, but until that happens... vendor extensions are our next best bet.

One obvious alternative option is to use separate schemas, like FooCreate and FooUpdate but that doesn't work well with other tooling (e.g., SDKs from openapi-generator would end up with separate classes for each schema and lots of unnecessary boilerplate translation inside each client). This was the way we were using originally...

codyaray avatar Jun 04 '20 08:06 codyaray

what I'd really like is to just not show these properties in the Request Body Schema on PUT/PATCH at all.

How do we know that the PUT is not creating a resource?

It seems there would need to be maybe a configuration map to define which http methods the immutability applies to...

adamaltman avatar Jun 04 '20 20:06 adamaltman

@adamaltman Yeah, if we need a config map that would be ok by me. I know that some APIs use PUT for creation for idempotency.

If you don't want a boolean x-immutable, we could solve my problem a bit more generically with the extensions discussed here like x-createOnly, x-updateOnly, and so on...

codyaray avatar Jun 05 '20 08:06 codyaray

@adamaltman Come to think of it, even if a field is immutable, it still has to be specified on PUT according to HTTP semantics of being an idempotent replacement, right? In this case, I think we only need this behavior on PATCH and won't need any additional configs.

codyaray avatar Jun 05 '20 17:06 codyaray

That makes the scope clear. 👍 🎉

Thanks @codyaray!

adamaltman avatar Jun 05 '20 17:06 adamaltman

Microsoft use x-ms-mutability property for that. See details at https://github.com/Azure/autorest/blob/master/docs/extensions/readme.md#x-ms-mutability . Microsoft has solved the issue of parameters that can only be set when creating a resource.

ad-m avatar Jul 14 '20 02:07 ad-m

Still interested in this :)

codyaray avatar Jul 14 '21 20:07 codyaray

me too

spacedsweden avatar Jan 27 '22 23:01 spacedsweden