-
Notifications
You must be signed in to change notification settings - Fork 9.1k
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
Separate annotation per enum value #348
Comments
+1. (Yes, github should have a voting button.) |
@cowwoc @bgrant0607 how would you propose this is represented in the description? For example, the current enum system uses primitive arrays: myValue:
properties:
statusFields:
type: string
enum:
- 1
- 2 I suppose these could be objects, but we'll have to be prescriptive of the structure. |
Each enum entry could be an object with |
+1 |
I would love to be able to use an object/hash for enums. For example I've got an app with credit card transactions that use rather cryptic values for the CVV checks. Here's what I'm forced to do to document it: cvv_check:
type: string
title: CVV check
description: |
When processed, result from checking the CVV/CVC value on the transaction.
* `D` - Suspicious transaction
* `I` - Failed data validation check
* `M` - Match
* `N` - No Match
* `P` - Not Processed
* `S` - Should have been present
* `U` - Issuer unable to process request
* `X` - Card does not support verification
enum:
- D
- I
- M
- N
- P
- S
- U
- X
maxLength: 1 It would be much nicer to just have: cvv_check:
type: string
title: CVV check
description: When processed, result from checking the CVV/CVC value on the transaction.
enum:
D: Suspicious transaction
I: Failed data validation check
M: Match
N: No Match
P: Not Processed
S: Should have been present
U: Issuer unable to process request
X: Card does not support verification
maxLength: 1 Clients could either just use the keys and ignore the values, or show both in a |
+1 |
I think there's a similar proposal for this for draft 5 of JSON Schema, will look for it. |
Parent issue: json-schema-org/json-schema-spec#579 |
+1 |
Currently the enum feature allows any kind of JSON thing in it – objects, arrays, strings, numbers, even mixed (though I'm not sure if things other than strings are supported by various toolings). With the map variant proposed by @drewish we would be limited to strings. (This is not necessarily a problem for most cases, I just wanted to point it out.) A more flexible version (though more verbose) would be to have an array of value/description pairs: cvv_check:
type: string
title: CVV check
description: When processed, result from checking the CVV/CVC value on the transaction.
enum:
- value: D
description: Suspicious transaction
- value: I
description: Failed data validation check
- value: M:
description: Match
- value: N
description: No Match
- value: P
description: Not Processed
- value: S
description: Should have been present
- value: U
description: Issuer unable to process request
- value: X
description: Card does not support verification I guess this corresponds to what @cowwoc proposed. |
Tackling PR: json-schema-org/json-schema-spec#741 |
I would be interested in this feature: I know it's not supported, are there any plans to introduce this in the future? |
The recommended way in JSON Schema to do this (using draft-06's cvv_check:
type: string
title: CVV check
description: When processed, result from checking the CVV/CVC value on the transaction.
oneOf:
- const: D
description: Suspicious transaction
- const: I
description: Failed data validation check
- const: M
description: Match
- const: N
description: No Match
- const: P
description: Not Processed
- const: S
description: Should have been present
- const: U
description: Issuer unable to process request
- const: X
description: Card does not support verification |
Thanks! This seems clean, but unfortunately seems also not supported in swagger-codegen 2.2.3 (I just tried) :( |
I came here looking to see how I could do this - I wanted to be able to programmatically get the labels for options and thus build a The concern for maintaining backward-compatibility for Finger-in-the-air feeling is that |
It doesn't appear to have got any further though. This is really important for documentation purposes (as you all know). |
Hi all, could you please provide an example of an enum with a label if it is already possible in OAS? |
+1 |
@pedy711 @jearton the solution for OAS 3.1 is as detailed here: #348 (comment) |
|
This is the equivalent in OAS 3.0 (although of course, if tooling vendors don't support it, or OAS 3.1, that's something you have to raise on their repos as we cannot do anything about it from here - the Swagger UI issue for OAS 3.1 support is swagger-api/swagger-ui#5891). Anyway, in OAS 3.0 you can just use 1-element cvv_check:
type: string
title: CVV check
description: When processed, result from checking the CVV/CVC value on the transaction.
oneOf:
- enum: [D]
description: Suspicious transaction
- enum: [I]
description: Failed data validation check
- enum: [M]
description: Match
- enum: [N]
description: No Match
- enum: [P]
description: Not Processed
- enum: [S]
description: Should have been present
- enum: [U]
description: Issuer unable to process request
- enum: [X]
description: Card does not support verification |
This is a real problem, at Redocly we have this extension |
@lornajane it's definitely a real problem, but should we hold onto this or declare it to be a JSON Schema issue and not one that we will address? We could consider adding another JSON Schema extension keyword to 3.2, but that just starts widening the gap with standard JSON Schema again. |
I vote we hold onto this for now, it's not obvious what the best answer is, but I think it would be a good addition to have at some point - for docs tools particularly where the extra context can really help users. |
And once we know the answer this is a good place for pointing to it. |
@ralfhandl I've tagged this and other issues with |
+1 |
Following up on swagger-api/swagger-core#1012 I'd like a service to return an Enum type and then document enum values by providing a separate annotation per value. I expect Swagger to aggregate these annotations so that all values and their descriptions are listed in the resulting documentation.
The text was updated successfully, but these errors were encountered: