Skip to content

Commit

Permalink
Improve deprecation information adding deprecatedInVersion and deprec…
Browse files Browse the repository at this point in the history
…atedMessage in the comments (#363)

* Add deprecatedInVersion and deprecatedMessage

* Include deprecatedMessage only when provided

---------

Co-authored-by: Beppe Catanese <[email protected]>
  • Loading branch information
gcatanese and Beppe Catanese authored Oct 15, 2024
1 parent 3782e1a commit d0cab2f
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 11 deletions.
10 changes: 7 additions & 3 deletions templates/custom/api.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@ type {{#structPrefix}}{{&classname}}{{/structPrefix}}{{#lambda.titlecase}}{{oper
// {{.}}
{{/description}}
{{#isDeprecated}}
// Deprecated
//
// Deprecated {{#vendorExtensions.x-deprecatedInVersion}}since {{#appName}}{{{.}}}{{/appName}} v{{.}}{{/vendorExtensions.x-deprecatedInVersion}}{{#vendorExtensions.x-deprecatedMessage}}
// {{{.}}}{{/vendorExtensions.x-deprecatedMessage}}
{{/isDeprecated}}
func (r {{#structPrefix}}{{&classname}}{{/structPrefix}}{{#lambda.titlecase}}{{operationId}}{{/lambda.titlecase}}Input) {{vendorExtensions.x-export-param-name}}({{paramName}} {{{dataType}}}) {{#structPrefix}}{{&classname}}{{/structPrefix}}{{#lambda.titlecase}}{{operationId}}{{/lambda.titlecase}}Input {
r.{{paramName}} = {{^isFile}}&{{/isFile}}{{paramName}}
Expand All @@ -46,7 +48,8 @@ Prepare a request for {{#lambda.titlecase}}{{operationId}}{{/lambda.titlecase}}
@return {{#structPrefix}}{{&classname}}{{/structPrefix}}{{#lambda.titlecase}}{{operationId}}{{/lambda.titlecase}}Input
{{#isDeprecated}}

Deprecated
Deprecated {{#vendorExtensions.x-deprecatedInVersion}}since {{#appName}}{{{.}}}{{/appName}} v{{.}}{{/vendorExtensions.x-deprecatedInVersion}}{{#vendorExtensions.x-deprecatedMessage}}
{{{.}}}{{/vendorExtensions.x-deprecatedMessage}}
{{/isDeprecated}}
*/
func (a *{{{classname}}}) {{{nickname}}}Input({{#pathParams}}{{paramName}} {{{dataType}}}{{^-last}}, {{/-last}}{{/pathParams}}) {{#structPrefix}}{{&classname}}{{/structPrefix}}{{#lambda.titlecase}}{{operationId}}{{/lambda.titlecase}}Input {
Expand All @@ -69,7 +72,8 @@ func (a *{{{classname}}}) {{{nickname}}}Input({{#pathParams}}{{paramName}} {{{da
@return {{#returnType}}{{{returnType}}}, {{/returnType}}*http.Response, error
{{#isDeprecated}}

Deprecated
Deprecated {{#vendorExtensions.x-deprecatedInVersion}}since {{#appName}}{{{.}}}{{/appName}} v{{.}}{{/vendorExtensions.x-deprecatedInVersion}}{{#vendorExtensions.x-deprecatedMessage}}
{{{.}}}{{/vendorExtensions.x-deprecatedMessage}}
{{/isDeprecated}}
*/
func (a *{{{classname}}}) {{#lambda.titlecase}}{{operationId}}{{/lambda.titlecase}}(ctx context.Context, r {{#structPrefix}}{{&classname}}{{/structPrefix}}{{#lambda.titlecase}}{{operationId}}{{/lambda.titlecase}}Input) ({{#returnType}}{{{returnType}}}, {{/returnType}}*http.Response, error) {
Expand Down
24 changes: 16 additions & 8 deletions templates/custom/model_simple.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ type {{classname}} struct {
// {{{.}}}
{{/description}}
{{#deprecated}}
// Deprecated
// Deprecated {{#vendorExtensions.x-deprecatedInVersion}}since {{#appName}}{{{.}}}{{/appName}} v{{.}}{{/vendorExtensions.x-deprecatedInVersion}}{{#vendorExtensions.x-deprecatedMessage}}
// {{{.}}}{{/vendorExtensions.x-deprecatedMessage}}
{{/deprecated}}
{{name}} {{^required}}{{^isNullable}}{{^isArray}}{{^isFreeFormObject}}*{{/isFreeFormObject}}{{/isArray}}{{/isNullable}}{{/required}}{{#isNullable}}{{#isPrimitiveType}}common.{{/isPrimitiveType}}{{/isNullable}}{{{dataType}}} `json:"{{baseName}}{{^required}},omitempty{{/required}}"{{#withXml}} xml:"{{baseName}}{{#isXmlAttribute}},attr{{/isXmlAttribute}}"{{/withXml}}{{#vendorExtensions.x-go-custom-tag}} {{{.}}}{{/vendorExtensions.x-go-custom-tag}}`
{{/vars}}
Expand Down Expand Up @@ -95,7 +96,8 @@ func New{{classname}}WithDefaults() *{{classname}} {
// If the value is explicit nil, the zero value for {{vendorExtensions.x-go-base-type}} will be returned
{{/isNullable}}
{{#deprecated}}
// Deprecated
// Deprecated {{#vendorExtensions.x-deprecatedInVersion}}since {{#appName}}{{{.}}}{{/appName}} v{{.}}{{/vendorExtensions.x-deprecatedInVersion}}{{#vendorExtensions.x-deprecatedMessage}}
// {{{.}}}{{/vendorExtensions.x-deprecatedMessage}}
{{/deprecated}}
func (o *{{classname}}) Get{{name}}() {{vendorExtensions.x-go-base-type}} {
if o == nil{{#isNullable}}{{^vendorExtensions.x-golang-is-container}} || o.{{name}}.Get() == nil{{/vendorExtensions.x-golang-is-container}}{{/isNullable}} {
Expand All @@ -122,7 +124,8 @@ func (o *{{classname}}) Get{{name}}() {{vendorExtensions.x-go-base-type}} {
// NOTE: If the value is an explicit nil, `nil, true` will be returned
{{/isNullable}}
{{#deprecated}}
// Deprecated
// Deprecated {{#vendorExtensions.x-deprecatedInVersion}}since {{#appName}}{{{.}}}{{/appName}} v{{.}}{{/vendorExtensions.x-deprecatedInVersion}}{{#vendorExtensions.x-deprecatedMessage}}
// {{{.}}}{{/vendorExtensions.x-deprecatedMessage}}
{{/deprecated}}
func (o *{{classname}}) Get{{name}}Ok() ({{^isArray}}{{^isFreeFormObject}}*{{/isFreeFormObject}}{{/isArray}}{{vendorExtensions.x-go-base-type}}, bool) {
if o == nil{{#isNullable}}{{#vendorExtensions.x-golang-is-container}} || common.IsNil(o.{{name}}){{/vendorExtensions.x-golang-is-container}}{{/isNullable}} {
Expand All @@ -148,7 +151,8 @@ func (o *{{classname}}) Get{{name}}Ok() ({{^isArray}}{{^isFreeFormObject}}*{{/is

// Set{{name}} sets field value
{{#deprecated}}
// Deprecated
// Deprecated {{#vendorExtensions.x-deprecatedInVersion}}since {{#appName}}{{{.}}}{{/appName}} v{{.}}{{/vendorExtensions.x-deprecatedInVersion}}{{#vendorExtensions.x-deprecatedMessage}}
// {{{.}}}{{/vendorExtensions.x-deprecatedMessage}}
{{/deprecated}}
func (o *{{classname}}) Set{{name}}(v {{vendorExtensions.x-go-base-type}}) {
{{#isNullable}}
Expand All @@ -168,7 +172,8 @@ func (o *{{classname}}) Set{{name}}(v {{vendorExtensions.x-go-base-type}}) {
{{^required}}
// Get{{name}} returns the {{name}} field value if set, zero value otherwise{{#isNullable}} (both if not set or set to explicit null){{/isNullable}}.
{{#deprecated}}
// Deprecated
// Deprecated {{#vendorExtensions.x-deprecatedInVersion}}since {{#appName}}{{{.}}}{{/appName}} v{{.}}{{/vendorExtensions.x-deprecatedInVersion}}{{#vendorExtensions.x-deprecatedMessage}}
// {{{.}}}{{/vendorExtensions.x-deprecatedMessage}}
{{/deprecated}}
func (o *{{classname}}) Get{{name}}() {{vendorExtensions.x-go-base-type}} {
if o == nil{{^isNullable}} || common.IsNil(o.{{name}}){{/isNullable}}{{#isNullable}}{{^vendorExtensions.x-golang-is-container}} || common.IsNil(o.{{name}}.Get()){{/vendorExtensions.x-golang-is-container}}{{/isNullable}} {
Expand All @@ -194,7 +199,8 @@ func (o *{{classname}}) Get{{name}}() {{vendorExtensions.x-go-base-type}} {
// NOTE: If the value is an explicit nil, `nil, true` will be returned
{{/isNullable}}
{{#deprecated}}
// Deprecated
// Deprecated {{#vendorExtensions.x-deprecatedInVersion}}since {{#appName}}{{{.}}}{{/appName}} v{{.}}{{/vendorExtensions.x-deprecatedInVersion}}{{#vendorExtensions.x-deprecatedMessage}}
// {{{.}}}{{/vendorExtensions.x-deprecatedMessage}}
{{/deprecated}}
func (o *{{classname}}) Get{{name}}Ok() ({{^isArray}}{{^isFreeFormObject}}*{{/isFreeFormObject}}{{/isArray}}{{vendorExtensions.x-go-base-type}}, bool) {
if o == nil{{^isNullable}} || common.IsNil(o.{{name}}){{/isNullable}}{{#isNullable}}{{#vendorExtensions.x-golang-is-container}} || common.IsNil(o.{{name}}){{/vendorExtensions.x-golang-is-container}}{{/isNullable}} {
Expand Down Expand Up @@ -229,7 +235,8 @@ func (o *{{classname}}) Has{{name}}() bool {

// Set{{name}} gets a reference to the given {{dataType}} and assigns it to the {{name}} field.
{{#deprecated}}
// Deprecated
// Deprecated {{#vendorExtensions.x-deprecatedInVersion}}since {{#appName}}{{{.}}}{{/appName}} v{{.}}{{/vendorExtensions.x-deprecatedInVersion}}{{#vendorExtensions.x-deprecatedMessage}}
// {{{.}}}{{/vendorExtensions.x-deprecatedMessage}}
{{/deprecated}}
func (o *{{classname}}) Set{{name}}(v {{vendorExtensions.x-go-base-type}}) {
{{#isNullable}}
Expand Down Expand Up @@ -343,7 +350,8 @@ func (o *{{{classname}}}) UnmarshalJSON(bytes []byte) (err error) {
// {{{.}}}
{{/description}}
{{#deprecated}}
// Deprecated
// Deprecated {{#vendorExtensions.x-deprecatedInVersion}}since {{#appName}}{{{.}}}{{/appName}} v{{.}}{{/vendorExtensions.x-deprecatedInVersion}}{{#vendorExtensions.x-deprecatedMessage}}
// {{{.}}}{{/vendorExtensions.x-deprecatedMessage}}
{{/deprecated}}
{{name}} {{^required}}{{^isNullable}}{{^isArray}}{{^isFreeFormObject}}*{{/isFreeFormObject}}{{/isArray}}{{/isNullable}}{{/required}}{{{dataType}}} `json:"{{baseName}}{{^required}},omitempty{{/required}}"{{#withXml}} xml:"{{baseName}}{{#isXmlAttribute}},attr{{/isXmlAttribute}}"{{/withXml}}{{#vendorExtensions.x-go-custom-tag}} {{{.}}}{{/vendorExtensions.x-go-custom-tag}}`
{{/vars}}
Expand Down

0 comments on commit d0cab2f

Please sign in to comment.