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

Add x-immutable vendor extension #1290

Open
codyaray opened this issue Jun 4, 2020 · 7 comments
Open

Add x-immutable vendor extension #1290

codyaray opened this issue Jun 4, 2020 · 7 comments

Comments

@codyaray
Copy link

codyaray commented Jun 4, 2020

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...

@adamaltman
Copy link
Member

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...

@codyaray
Copy link
Author

codyaray commented Jun 5, 2020

@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
Copy link
Author

codyaray commented Jun 5, 2020

@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.

@adamaltman
Copy link
Member

That makes the scope clear. 👍 🎉

Thanks @codyaray!

@ad-m
Copy link

ad-m commented Jul 14, 2020

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.

@codyaray
Copy link
Author

Still interested in this :)

@spacedsweden
Copy link

me too

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants