- Notifications
You must be signed in to change notification settings - Fork 115
Add support for code generator property name hints #203
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
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think this PR is necessary. The spec writer already gives us an indentifier, which is the generic parameter name, from which we can derive the identifier.
This is examplified with TDocument having the document identifier.
In the case of TBody having the contents identifier, we should just rename the generic parameter to TContents: even from a spec perspective TBody isn't descriptive enough.
So let's keep things minimal, both for the spec writer and the model. The identifier can be derived with a simple rule like "if the generic parameter name starts with an uppercase T followed by an uppercase letter, remove the T". No need for an additional annotation and an additional property in the model.
And if we want to enforce the convention that open generics must start with a T, this can be a new validation rule.
| @swallez I'm afraid I have to disagree. I think it's better to be explicit rather than have a rule written somewhere in the documentation and force every language generator to rewrite this logic. The model is machine-friendly, and we should keep it in that way without having external conventions. |
This is what I'd like to avoid, only for 2 occurences, when the information is already out there. And if we consider that dropping the FWIW this is the only occurrence of the hungarian notation in our specs. Adding something to the json model should not be taken lightly and we should keep it as minimal as possible.
This is a very different use case. This tag is necessary for enums when values on the wire are not case insensitive distinct and so cannot be used to generate distinct identifiers following a target language's naming conventions. These values are not defined by us (spec writers). The case of open generic parameters is different as we choose their names. So in all likelyhood we will end up with: /** @identifier foo */ body?: TFooThis |
| After internal discussion we have decided to bench this one out and revisit it in the future. |
| Having thought more about this, I finally understood where my discomfort with the proposed change comes from. The change is as follows: body?: ValueBody | PropertiesBody behaviors?: Implements[] attachedBehaviors?: string[] /** * The parameter name language generator should use, * normally used when the entire body is a generic. */ bodyIdentifier?: stringAs it is, it is "polluting" the main request definition with a field that is only applicable for request bodies defined as a single value rather than a set of properties. And the doc comment further constrains the applicable scenarios to generic parameters only. Now we actually have this distinction built into the body definition: export class ValueBody { kind: 'value' value: ValueOf /** Identifier to use to represent the body in the request structure */ identifier?: string }Now is this really needed? I suggested to use the generic parameter name as the identifier. It does work with the use cases that we currently have, that is when So I'm changing my mind. If Note also the change in the doc comment that no longer mentions generic parameters. It's just a property of body-as-a-value, whatever its type. Modeling is hard, and metamodeling even more 😉 |
| I like your suggestion @swallez! I'll update the pr to implement it :) |
This will allow the JSON model to suggest to language generators how to call the requests body parameter if it's a generic and not a structured object.
It's extremely useful for clients that abstract away the HTTP lingo from the surface API of the client.
Example usage:
How it will look like in the JSON model: