CCF icon indicating copy to clipboard operation
CCF copied to clipboard

OpenAPI suggests that "operationId" (or "operationref") is mandatory.

Open lemmy opened this issue 1 year ago • 4 comments

nt

lemmy avatar Jul 03 '24 21:07 lemmy

From https://swagger.io/specification/:

In the following description, if a field is not explicitly REQUIRED or described with a MUST or SHALL, it can be considered OPTIONAL.

The description for operationId is under https://swagger.io/specification/:

Unique string used to identify the operation. The id MUST be unique among all operations described in the API. The operationId value is case-sensitive. Tools and libraries MAY use the operationId to uniquely identify an operation, therefore, it is RECOMMENDED to follow common programming naming conventions.

There is no mention of REQUIRED, and although the unicity is a MUST, there is no explicit statement about existence. Issues on the OpenAPI repository (#1019, #1907) asking for it be made mandatory have been rejected, and clarify that it is not mandatory.

This next bit is my opinion: there is no valid reason to demand that someone manually writes an operationId, creating one from the path/verb is trivial to automate correctly. It is bizarre that the SDK generators are both demanding this manual de-normalisation while complaining about duplicates.

Anyway, there is clearly no downside to having this, thank you for adding it.

achamayou avatar Jul 04 '24 09:07 achamayou

To fix the tests (I tried to do, but I can't seem to write to your fork), it is necessary to:

  1. rev up openapi_info.document_version in src/node/rpc/node_frontend.h, src/node/rpc/member_frontend.h and samples/app/logging/logging.cpp (I suggest +0.1.0 in this case, but any amount will work).
  2. re-build
  3. re-run the schema test ./tests.sh -VV -R schema which will produce the new OpenAPI schemas (it will fail, but that's ok)
  4. commit them

achamayou avatar Jul 04 '24 09:07 achamayou

I tried to do, but I can't seem to write to your fork

You and the others should have collaborator permissions in my fork:

image

lemmy avatar Jul 04 '24 14:07 lemmy

@lemmy weird, tried again and it worked. Tests should pass now.

achamayou avatar Jul 04 '24 17:07 achamayou

Using the verb concatenated with the camel-cased path appears to be a common default. For example, the verb delete combined with the path app/log/private/all becomes the operationId DeleteAppLogPrivateAll. Does the CCF codebase have a built-in function for converting a string to camel case?

lemmy avatar Jul 08 '24 15:07 lemmy

Does the CCF codebase have a built-in function for converting a string to camel case?

No, though it's easy enough to add. Proposed impl is here: #6349, let me know if that works for you and we'll get it merged.

eddyashton avatar Jul 10 '24 14:07 eddyashton